Skip to content

Commit

Permalink
feat(grammar): Make FROM_CLAUSE optional in queries, aligning with Or…
Browse files Browse the repository at this point in the history
…acle 23ai
  • Loading branch information
felipebz committed Sep 29, 2024
1 parent 44a4089 commit ed033a6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,6 @@
"examples/select_time.sql" : [
1
],
"examples/select_without_from.sql" : [
1
],
"examples/simple04.sql" : [
7
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"adjsn/clauses-used-in-functions-and-conditions-for-json-14.sql" : [
9
],
"adjsn/clauses-used-in-functions-and-conditions-for-json-7.sql" : [
2
],
"adjsn/conditions-is-json-and-is-not-json-6.sql" : [
6
],
Expand Down Expand Up @@ -131,9 +128,6 @@
"adjsn/json-schema-22.sql" : [
3
],
"adjsn/json-schema-25.sql" : [
2
],
"adjsn/json-schema-3.sql" : [
2
],
Expand All @@ -143,9 +137,6 @@
"adjsn/json-schema-6.sql" : [
2
],
"adjsn/json-schema-7.sql" : [
5
],
"adjsn/json-schema-8.sql" : [
2
],
Expand Down Expand Up @@ -1748,30 +1739,12 @@
"sqlrf/CALL-4.sql" : [
9
],
"sqlrf/CAST-12.sql" : [
5
],
"sqlrf/CAST-13.sql" : [
2
],
"sqlrf/CAST-14.sql" : [
2
],
"sqlrf/CAST-15.sql" : [
2
],
"sqlrf/CAST-16.sql" : [
2
],
"sqlrf/CAST-17.sql" : [
2
],
"sqlrf/CAST-18.sql" : [
2
],
"sqlrf/CAST-6.sql" : [
5
],
"sqlrf/CHR-5.sql" : [
2
],
Expand Down Expand Up @@ -2442,7 +2415,7 @@
2
],
"sqlrf/CUME_DIST-0.sql" : [
2
3
],
"sqlrf/CV-0.sql" : [
6
Expand Down Expand Up @@ -2478,7 +2451,7 @@
11
],
"sqlrf/DENSE_RANK-0.sql" : [
2
3
],
"sqlrf/DISASSOCIATE-STATISTICS-0.sql" : [
2
Expand Down Expand Up @@ -2631,7 +2604,7 @@
3
],
"sqlrf/PERCENT_RANK-0.sql" : [
2
3
],
"sqlrf/PREDICTION-0.sql" : [
4
Expand Down Expand Up @@ -2679,10 +2652,10 @@
2
],
"sqlrf/RANK-0.sql" : [
2
3
],
"sqlrf/RANK-1.sql" : [
2
3
],
"sqlrf/REF-1.sql" : [
2
Expand Down Expand Up @@ -2741,9 +2714,6 @@
"sqlrf/SELECT-11.sql" : [
4
],
"sqlrf/SELECT-112.sql" : [
2
],
"sqlrf/SELECT-116.sql" : [
4
],
Expand Down Expand Up @@ -2999,24 +2969,6 @@
"sqlrf/boolean_or_agg-6.sql" : [
4
],
"sqlrf/ceil-datetime-1.sql" : [
2
],
"sqlrf/ceil-datetime-2.sql" : [
2
],
"sqlrf/ceil-interval-0.sql" : [
2
],
"sqlrf/ceil-interval-1.sql" : [
2
],
"sqlrf/ceil-interval-2.sql" : [
2
],
"sqlrf/ceil-interval-3.sql" : [
2
],
"sqlrf/constraint-1.sql" : [
10
],
Expand Down Expand Up @@ -3107,9 +3059,6 @@
"sqlrf/create-domain-4.sql" : [
2
],
"sqlrf/create-domain-41.sql" : [
2
],
"sqlrf/create-domain-43.sql" : [
2
],
Expand Down Expand Up @@ -3194,21 +3143,9 @@
"sqlrf/domain_check-1.sql" : [
2
],
"sqlrf/domain_check-11.sql" : [
2
],
"sqlrf/domain_check-2.sql" : [
4
],
"sqlrf/domain_check-3.sql" : [
2
],
"sqlrf/domain_check-4.sql" : [
2
],
"sqlrf/domain_check-5.sql" : [
4
],
"sqlrf/domain_check-6.sql" : [
2
],
Expand All @@ -3221,21 +3158,9 @@
"sqlrf/domain_check_type-0.sql" : [
2
],
"sqlrf/domain_check_type-1.sql" : [
4
],
"sqlrf/domain_check_type-10.sql" : [
2
],
"sqlrf/domain_check_type-2.sql" : [
2
],
"sqlrf/domain_check_type-3.sql" : [
2
],
"sqlrf/domain_check_type-4.sql" : [
4
],
"sqlrf/domain_check_type-5.sql" : [
2
],
Expand Down Expand Up @@ -3284,27 +3209,6 @@
"sqlrf/file_specification-5.sql" : [
2
],
"sqlrf/floor-datetime-1.sql" : [
2
],
"sqlrf/floor-datetime-2.sql" : [
2
],
"sqlrf/floor-interval-0.sql" : [
2
],
"sqlrf/floor-interval-1.sql" : [
2
],
"sqlrf/floor-interval-2.sql" : [
2
],
"sqlrf/from_vector-0.sql" : [
2
],
"sqlrf/from_vector-1.sql" : [
2
],
"sqlrf/from_vector-2.sql" : [
2
],
Expand Down Expand Up @@ -3410,36 +3314,9 @@
"sqlrf/graph_table-operator-5.sql" : [
4
],
"sqlrf/round-interval-0.sql" : [
2
],
"sqlrf/round-interval-1.sql" : [
2
],
"sqlrf/round-interval-2.sql" : [
2
],
"sqlrf/round-interval-3.sql" : [
2
],
"sqlrf/storage_clause-0.sql" : [
6
],
"sqlrf/to_boolean-0.sql" : [
2
],
"sqlrf/to_vector-0.sql" : [
2
],
"sqlrf/trunc-interval-0.sql" : [
2
],
"sqlrf/trunc-interval-1.sql" : [
2
],
"sqlrf/trunc-interval-2.sql" : [
2
],
"sqlrf/value-expressions-graph_table-0.sql" : [
4
],
Expand Down Expand Up @@ -3470,12 +3347,6 @@
"sqlrf/vector_chunks-1.sql" : [
14
],
"sqlrf/vector_dimension_count-0.sql" : [
2
],
"sqlrf/vector_dimension_format-0.sql" : [
2
],
"sqlrf/vector_distance-11.sql" : [
2
],
Expand All @@ -3497,12 +3368,6 @@
"sqlrf/vector_distance-9.sql" : [
2
],
"sqlrf/vector_norm-0.sql" : [
2
],
"sqlrf/vector_serialize-0.sql" : [
2
],
"sqlrf/vector_serialize-1.sql" : [
2
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ColumnsShouldHaveTableNameCheck : AbstractBaseCheck() {

val selectExpression = node.parentOrNull
if (selectExpression != null &&
selectExpression.hasDirectChildren(DmlGrammar.FROM_CLAUSE) &&
selectExpression.getFirstChild(DmlGrammar.FROM_CLAUSE).getChildren(DmlGrammar.DML_TABLE_EXPRESSION_CLAUSE).size > 1 &&
candidate.typeIs(PlSqlGrammar.IDENTIFIER_NAME) &&
!candidate.hasDirectChildren(PlSqlGrammar.NON_RESERVED_KEYWORD) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ begin
my_var, -- compliant
other.baz
from other, other2);

select my_var; -- do not report error in queries without tables
end;

-- DML in scripts should be checked too
Expand All @@ -34,4 +36,4 @@ select col, -- Noncompliant {{Specify the table of column "col".}}
func(col),
'text'
from tab, tab2
/
/
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ enum class DmlGrammar : GrammarRuleKey {
b.sequence(
SELECT, b.optional(b.firstOf(ALL, DISTINCT, UNIQUE)), SELECT_COLUMN, b.zeroOrMore(COMMA, SELECT_COLUMN),
b.optional(INTO_CLAUSE),
FROM_CLAUSE,
b.optional(FROM_CLAUSE),
b.optional(WHERE_CLAUSE),
b.optional(b.firstOf(
b.sequence(GROUP_BY_CLAUSE, b.optional(HAVING_CLAUSE)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,16 @@ class SelectExpressionTest : RuleTest() {
fun matchesSelectFromValues() {
assertThat(p).matches("select 1 from (values (1, 'foo'), (2, 'bar')) as t(a, b)")
}

@Test
fun matchesShortSelect() {
assertThat(p).matches("select 1")
assertThat(p).matches("select 1 into var")
}

@Test
fun matchesShortSelectWithWhere() {
assertThat(p).matches("select 1 where 1 = 1")
assertThat(p).matches("select 1 into var where 1 = 1")
}
}

0 comments on commit ed033a6

Please sign in to comment.