Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,39 @@ public <S> T visit(MatchRecognize matchRecognize, S context) {
matchRecognize.getInput().accept(this, context);
matchRecognize
.forEachExpression(expression -> expression.accept(expressionVisitor, context));
visitPivots(matchRecognize, context);
return null;
}

/** Walks the PIVOT / UNPIVOT clause the grammar may attach to any FROM item. */
private <S> void visitPivots(FromItem fromItem, S context) {
PivotVisitorAdapter<T> pivots = new PivotVisitorAdapter<>(expressionVisitor);
if (matchRecognize.getPivot() != null) {
matchRecognize.getPivot().accept(pivots, context);
if (fromItem.getPivot() != null) {
fromItem.getPivot().accept(pivots, context);
}
if (matchRecognize.getUnPivot() != null) {
matchRecognize.getUnPivot().accept(pivots, context);
if (fromItem.getUnPivot() != null) {
fromItem.getUnPivot().accept(pivots, context);
}
return null;
}

@Override
public <S> T visit(Table table, S context) {
visitPivots(table, context);
return null;
}

@Override
public <S> T visit(ParenthesedSelect select, S context) {
return select.getSelect().accept(selectVisitor, context);
T result = select.getSelect().accept(selectVisitor, context);
visitPivots(select, context);
return result;
}

@Override
public <S> T visit(LateralSubSelect lateralSubSelect, S context) {
return lateralSubSelect.getSelect().accept(selectVisitor, context);
T result = lateralSubSelect.getSelect().accept(selectVisitor, context);
visitPivots(lateralSubSelect, context);
return result;
}

@Override
Expand All @@ -123,13 +133,15 @@ public <S> T visit(TableFunction tableFunction, S context) {
function.accept(expressionVisitor, context);
}
}
visitPivots(tableFunction, context);
return null;
}

@Override
public <S> T visit(ParenthesedFromItem fromItem, S context) {
T result = fromItem.getFromItem().accept(this, context);
visitJoins(fromItem.getJoins(), context);
visitPivots(fromItem, context);
return result;
}

Expand All @@ -138,6 +150,7 @@ public <S> T visit(Values values, S context) {
for (Expression expression : values.getExpressions()) {
expression.accept(expressionVisitor, context);
}
visitPivots(values, context);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,17 @@ public <S> Void visit(Table table, S context) {
public <S> Void visit(Pivot pivot, S context) {
validateFeature(Feature.pivot);
validateOptionalExpressions(pivot.getForColumns());
validatePivotFunctions(pivot, context);
return null;
}

private <S> void validatePivotFunctions(Pivot pivot, S context) {
if (isNotEmpty(pivot.getFunctionItems())) {
ExpressionValidator v = getValidator(ExpressionValidator.class);
pivot.getFunctionItems().forEach(f -> f.getExpression().accept(v, context));
}
}

@Override
public <S> Void visit(UnPivot unpivot, S context) {
validateFeature(Feature.unpivot);
Expand All @@ -358,10 +366,7 @@ public <S> Void visit(UnPivot unpivot, S context) {
public <S> Void visit(PivotXml pivot, S context) {
validateFeature(Feature.pivotXml);
validateOptionalExpressions(pivot.getForColumns());
if (isNotEmpty(pivot.getFunctionItems())) {
ExpressionValidator v = getValidator(ExpressionValidator.class);
pivot.getFunctionItems().forEach(f -> f.getExpression().accept(v, context));
}
validatePivotFunctions(pivot, context);
if (pivot.getInSelect() != null) {
pivot.getInSelect().accept((SelectVisitor<Void>) this, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,11 +714,15 @@
"SET x = pg_read_file('x')",
"DECLARE @x INT = length(pg_read_file('x'))",
"ASSERT length(pg_read_file('x')) > 0",
"SELECT * FROM t PIVOT (sum(pg_read_file('x')) FOR a IN (1))",
"SELECT * FROM (SELECT a, b FROM t) PIVOT (sum(pg_read_file('x')) FOR a IN (1))",
"SELECT * FROM u JOIN t PIVOT (sum(pg_read_file('x')) FOR a IN (1)) ON 1 = 1",
"SELECT * FROM t PIVOT XML (sum(b) FOR a IN (SELECT pg_read_file('x') FROM u))"})
"SHOW TABLES WHERE length(pg_read_file('x')) > 0",

Check failure on line 721 in src/test/java/net/sf/jsqlparser/statement/StatementFeatureVisitorTest.java

View workflow job for this annotation

GitHub Actions / Gradle Check (ubuntu-latest)

illegal start of type

Check failure on line 721 in src/test/java/net/sf/jsqlparser/statement/StatementFeatureVisitorTest.java

View workflow job for this annotation

GitHub Actions / Gradle Check (macos-latest)

illegal start of type
"SHOW TABLE STATUS WHERE length(pg_read_file('x')) > 0",
"SHOW COLUMNS FROM t WHERE length(pg_read_file('x')) > 0",
"SHOW INDEX FROM t WHERE length(pg_read_file('x')) > 0",
"SHOW VARIABLES WHERE length(pg_read_file('x')) > 0"})

Check failure on line 725 in src/test/java/net/sf/jsqlparser/statement/StatementFeatureVisitorTest.java

View workflow job for this annotation

GitHub Actions / Gradle Check (ubuntu-latest)

illegal start of type

Check failure on line 725 in src/test/java/net/sf/jsqlparser/statement/StatementFeatureVisitorTest.java

View workflow job for this annotation

GitHub Actions / Gradle Check (macos-latest)

illegal start of type
void functionIsChecked(String sql) throws JSQLParserException {
StatementFeatures impure = analyseAllPureExcept(sql, "pg_read_file");
assertThat(impure.getUnresolvedReferences()).containsExactly("pg_read_file");
Expand Down Expand Up @@ -804,4 +808,4 @@
assertThat(f.mayModifyData()).isFalse();
}
}
}

Check failure on line 811 in src/test/java/net/sf/jsqlparser/statement/StatementFeatureVisitorTest.java

View workflow job for this annotation

GitHub Actions / Gradle Check (ubuntu-latest)

class, interface, or enum expected

Check failure on line 811 in src/test/java/net/sf/jsqlparser/statement/StatementFeatureVisitorTest.java

View workflow job for this annotation

GitHub Actions / Gradle Check (macos-latest)

class, interface, or enum expected
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ public void testValidateTableFunctionArguments(String sql) {
"SELECT a FROM t LIMIT 1 OFFSET upper(a)",
"SELECT a FROM t OFFSET upper(a) ROWS",
"SELECT a FROM t FETCH FIRST upper(a) ROWS ONLY",
"SELECT a FROM t UNION SELECT b FROM u LIMIT upper(a)"})
"SELECT a FROM t UNION SELECT b FROM u LIMIT upper(a)",
"SELECT * FROM t PIVOT (max(upper(a)) FOR b IN (1))"})
public void testValidateFunctionOutsideWhere(String sql) {
validateNotAllowed(sql, 1, 1,
new FeaturesAllowed(Feature.values()).remove(Feature.function), Feature.function);
Expand Down
Loading