Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable path keys in hints #250

Merged
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
2 changes: 1 addition & 1 deletion ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ type HintRecord struct {
// pos = Key.pos
// end = Value.end

Key *Ident
Key *Path
Value Expr
}

Expand Down
2 changes: 1 addition & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (p *Parser) tryParseHint() *ast.Hint {
}

func (p *Parser) parseHintRecord() *ast.HintRecord {
key := p.parseIdent()
key := p.parsePath()
p.expect("=")
value := p.parseExpr()
return &ast.HintRecord{
Expand Down
1 change: 1 addition & 0 deletions testdata/input/query/select_hint_path.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@{spanner.optimizer_version=5} SELECT 1
12 changes: 8 additions & 4 deletions testdata/result/dml/update_with_safe_ml_predict.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,14 @@ WHERE products.desc_embed IS NULL
Rbrace: 327,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 296,
NameEnd: 323,
Name: "remote_udf_max_rows_per_rpc",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 296,
NameEnd: 323,
Name: "remote_udf_max_rows_per_rpc",
},
},
},
Value: &ast.IntLiteral{
ValuePos: 324,
Expand Down
12 changes: 8 additions & 4 deletions testdata/result/query/!bad_hint_select_2.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ syntax error: testdata/input/query/!bad_hint_select_2.sql:1:19: unexpected token
Rbrace: 10,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 2,
NameEnd: 6,
Name: "hint",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 2,
NameEnd: 6,
Name: "hint",
},
},
},
Value: &ast.IntLiteral{
ValuePos: 9,
Expand Down
12 changes: 8 additions & 4 deletions testdata/result/query/select_album_with_index_directive.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ WHERE AlbumTitle >= @startTitle AND AlbumTitle < @endTitle
Rbrace: 87,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 57,
NameEnd: 68,
Name: "FORCE_INDEX",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 57,
NameEnd: 68,
Name: "FORCE_INDEX",
},
},
},
Value: &ast.Ident{
NamePos: 69,
Expand Down
12 changes: 8 additions & 4 deletions testdata/result/query/select_from_ml_predict_hint.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,14 @@ FROM ML.PREDICT(
Rbrace: 322,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 293,
NameEnd: 320,
Name: "remote_udf_max_rows_per_rpc",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 293,
NameEnd: 320,
Name: "remote_udf_max_rows_per_rpc",
},
},
},
Value: &ast.IntLiteral{
ValuePos: 321,
Expand Down
12 changes: 8 additions & 4 deletions testdata/result/query/select_from_ml_predict_textbison.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,14 @@ FROM ML.PREDICT(
Rbrace: 613,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 584,
NameEnd: 611,
Name: "remote_udf_max_rows_per_rpc",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 584,
NameEnd: 611,
Name: "remote_udf_max_rows_per_rpc",
},
},
},
Value: &ast.IntLiteral{
ValuePos: 612,
Expand Down
12 changes: 8 additions & 4 deletions testdata/result/query/select_function_hints.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,14 @@ FROM (SELECT SHA512(z) @{DISABLE_INLINE = TRUE} AS x FROM t)
Rbrace: 241,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 220,
NameEnd: 234,
Name: "DISABLE_INLINE",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 220,
NameEnd: 234,
Name: "DISABLE_INLINE",
},
},
},
Value: &ast.BoolLiteral{
ValuePos: 237,
Expand Down
24 changes: 16 additions & 8 deletions testdata/result/query/select_hint.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
Rbrace: 22,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 2,
NameEnd: 7,
Name: "hint1",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 2,
NameEnd: 7,
Name: "hint1",
},
},
},
Value: &ast.IntLiteral{
ValuePos: 10,
Expand All @@ -19,10 +23,14 @@
},
},
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 13,
NameEnd: 18,
Name: "hint2",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 13,
NameEnd: 18,
Name: "hint2",
},
},
},
Value: &ast.IntLiteral{
ValuePos: 21,
Expand Down
48 changes: 48 additions & 0 deletions testdata/result/query/select_hint_path.sql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--- select_hint_path.sql
@{spanner.optimizer_version=5} SELECT 1
--- AST
&ast.QueryStatement{
Hint: &ast.Hint{
Rbrace: 29,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 2,
NameEnd: 9,
Name: "spanner",
},
&ast.Ident{
NamePos: 10,
NameEnd: 27,
Name: "optimizer_version",
},
},
},
Value: &ast.IntLiteral{
ValuePos: 28,
ValueEnd: 29,
Base: 10,
Value: "5",
},
},
},
},
Query: &ast.Select{
Select: 31,
Results: []ast.SelectItem{
&ast.ExprSelectItem{
Expr: &ast.IntLiteral{
ValuePos: 38,
ValueEnd: 39,
Base: 10,
Value: "1",
},
},
},
},
}

--- SQL
@{spanner.optimizer_version=5} SELECT 1
48 changes: 32 additions & 16 deletions testdata/result/query/select_singer_with_join_hint.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ FROM
Rbrace: 279,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 260,
NameEnd: 269,
Name: "JOIN_TYPE",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 260,
NameEnd: 269,
Name: "JOIN_TYPE",
},
},
},
Value: &ast.Ident{
NamePos: 270,
Expand All @@ -53,10 +57,14 @@ FROM
Rbrace: 209,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 189,
NameEnd: 198,
Name: "JOIN_TYPE",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 189,
NameEnd: 198,
Name: "JOIN_TYPE",
},
},
},
Value: &ast.Ident{
NamePos: 199,
Expand All @@ -73,10 +81,14 @@ FROM
Rbrace: 138,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 119,
NameEnd: 128,
Name: "JOIN_TYPE",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 119,
NameEnd: 128,
Name: "JOIN_TYPE",
},
},
},
Value: &ast.Ident{
NamePos: 129,
Expand All @@ -93,10 +105,14 @@ FROM
Rbrace: 68,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 47,
NameEnd: 63,
Name: "FORCE_JOIN_ORDER",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 47,
NameEnd: 63,
Name: "FORCE_JOIN_ORDER",
},
},
},
Value: &ast.BoolLiteral{
ValuePos: 64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ FROM
Rbrace: 61,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 27,
NameEnd: 38,
Name: "FORCE_INDEX",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 27,
NameEnd: 38,
Name: "FORCE_INDEX",
},
},
},
Value: &ast.Ident{
NamePos: 39,
Expand Down
12 changes: 8 additions & 4 deletions testdata/result/query/select_singer_with_table_hint.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ FROM
Rbrace: 61,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 27,
NameEnd: 38,
Name: "FORCE_INDEX",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 27,
NameEnd: 38,
Name: "FORCE_INDEX",
},
},
},
Value: &ast.Ident{
NamePos: 39,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ FROM
Rbrace: 23,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 2,
NameEnd: 18,
Name: "FORCE_JOIN_ORDER",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 2,
NameEnd: 18,
Name: "FORCE_JOIN_ORDER",
},
},
},
Value: &ast.BoolLiteral{
ValuePos: 19,
Expand Down
12 changes: 8 additions & 4 deletions testdata/result/query/select_unnest_with_offset.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ FROM
Rbrace: 44,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 36,
NameEnd: 40,
Name: "hint",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 36,
NameEnd: 40,
Name: "hint",
},
},
},
Value: &ast.IntLiteral{
ValuePos: 43,
Expand Down
12 changes: 8 additions & 4 deletions testdata/result/query/select_with_after_hint.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
Rbrace: 11,
Records: []*ast.HintRecord{
&ast.HintRecord{
Key: &ast.Ident{
NamePos: 2,
NameEnd: 7,
Name: "hint1",
Key: &ast.Path{
Idents: []*ast.Ident{
&ast.Ident{
NamePos: 2,
NameEnd: 7,
Name: "hint1",
},
},
},
Value: &ast.IntLiteral{
ValuePos: 10,
Expand Down
Loading
Loading