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 @@ -71,6 +71,9 @@ public <S> T visitJoins(Collection<Join> joins, S context) {
if (joins != null) {
for (Join join : joins) {
join.getFromItem().accept(this, context);
if (join.getSimilarity() != null) {
join.getSimilarity().accept(expressionVisitor, context);
}
if (join.getUsingColumns() != null) {
for (Column column : join.getUsingColumns()) {
column.accept(expressionVisitor, context);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2457,6 +2457,9 @@ private <S> void visitJoins(List<Join> joins, S context) {
}
for (Join join : joins) {
join.getFromItem().accept(this, context);
if (join.getSimilarity() != null) {
join.getSimilarity().accept(this, context);
}
for (Expression expression : join.getOnExpressions()) {
expression.accept(this, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ public void validateOptionalJoin(Join join) {
}

validateOptionalFromItem(join.getFromItem());
validateOptionalExpression(join.getSimilarity());
for (Expression onExpression : join.getOnExpressions()) {
validateOptionalExpression(onExpression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,9 @@ private StatementFeatures analyseAllPureExcept(String sql, String impure)
"FROM t |> WINDOW sum(pg_read_file('x')) OVER () AS w",
"SELECT * FROM (FROM t |> WHERE length(pg_read_file('x')) > 0)",
"SELECT a FROM t LATERAL VIEW explode(pg_read_file('x')) v AS c",
"SELECT a FROM t LATERAL VIEW OUTER explode(pg_read_file('x')) v AS c"})
"SELECT a FROM t LATERAL VIEW OUTER explode(pg_read_file('x')) v AS c",
"SELECT a FROM t JOIN u APPROX NEAREST 2 BY SIMILARITY pg_read_file('x')",
"SELECT a FROM (t JOIN u APPROX NEAREST 2 BY SIMILARITY pg_read_file('x'))"})
void functionIsChecked(String sql) throws JSQLParserException {
StatementFeatures impure = analyseAllPureExcept(sql, "pg_read_file");
assertThat(impure.getUnresolvedReferences()).containsExactly("pg_read_file");
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,16 @@ void testSubqueryInTopOrStarReplaceIsFound(String sqlStr) throws JSQLParserExcep
assertThat(TablesNamesFinder.findTables(sqlStr)).containsExactlyInAnyOrder("t", "secrets");
}

@ParameterizedTest
@ValueSource(strings = {
"SELECT a FROM t JOIN u APPROX NEAREST 2 BY SIMILARITY (SELECT max(pw) FROM secrets)",
"SELECT a FROM (t JOIN u APPROX NEAREST 2 BY SIMILARITY (SELECT max(pw) FROM secrets))",
"UPDATE t SET a = 1 FROM s JOIN u APPROX NEAREST 2 BY SIMILARITY (SELECT max(pw) FROM secrets)",
"DELETE FROM t USING s JOIN u APPROX NEAREST 2 BY SIMILARITY (SELECT max(pw) FROM secrets)"})
void testSubqueryInJoinSimilarityIsFound(String sqlStr) throws JSQLParserException {
assertThat(TablesNamesFinder.findTables(sqlStr)).contains("secrets");
}

@ParameterizedTest
@ValueSource(strings = {
"DECLARE @x INT = (SELECT max(pw) FROM secrets)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ public void testValidateTableFunctionArguments(String sql) {
"SELECT a FROM t FETCH FIRST upper(a) ROWS ONLY",
"SELECT a FROM t UNION SELECT b FROM u LIMIT upper(a)",
"SELECT * FROM t PIVOT (max(upper(a)) FOR b IN (1))",
"SELECT a FROM t LATERAL VIEW explode(b) v AS c"})
"SELECT a FROM t LATERAL VIEW explode(b) v AS c",
"SELECT a FROM t JOIN u APPROX NEAREST 2 BY SIMILARITY upper(a)"})
public void testValidateFunctionOutsideWhere(String sql) {
validateNotAllowed(sql, 1, 1,
new FeaturesAllowed(Feature.values()).remove(Feature.function), Feature.function);
Expand Down
Loading