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

Implement parser support for all select modifiers #16396

Merged
merged 6 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ type (
Select struct {
Cache *bool // a reference here so it can be nil
Distinct bool
HighPriority bool
StraightJoinHint bool
SQLSmallResult bool
SQLBigResult bool
SQLBufferResult bool
SQLCalcFoundRows bool
// The With field needs to come before the FROM clause, so any CTEs have been handled before we analyze it
With *With
Expand Down
4 changes: 4 additions & 0 deletions go/vt/sqlparser/ast_equals.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,21 @@ func (node *Select) Format(buf *TrackedBuffer) {
buf.literal(SQLNoCacheStr)
}
}
if node.HighPriority {
buf.literal(HighPriorityStr)
}
if node.StraightJoinHint {
buf.literal(StraightJoinHint)
}
if node.SQLSmallResult {
buf.literal(SQLSmallResultStr)
}
if node.SQLBigResult {
buf.literal(SQLBigResultStr)
}
if node.SQLBufferResult {
buf.literal(SQLBufferResultStr)
}
if node.SQLCalcFoundRows {
buf.literal(SQLCalcFoundRowsStr)
}
Expand Down
12 changes: 12 additions & 0 deletions go/vt/sqlparser/ast_format_fast.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ func NewSelect(
windows NamedWindows,
) *Select {
var cache *bool
var distinct, straightJoinHint, sqlFoundRows bool
var distinct, highPriority, straightJoinHint, sqlSmallResult, sqlBigResult, SQLBufferResult, sqlFoundRows bool
for _, option := range selectOptions {
switch strings.ToLower(option) {
case DistinctStr:
Expand All @@ -811,8 +811,16 @@ func NewSelect(
case SQLNoCacheStr:
truth := false
cache = &truth
case HighPriorityStr:
highPriority = true
case StraightJoinHint:
straightJoinHint = true
case SQLSmallResultStr:
sqlSmallResult = true
case SQLBigResultStr:
sqlBigResult = true
case SQLBufferResultStr:
SQLBufferResult = true
case SQLCalcFoundRowsStr:
sqlFoundRows = true
}
Expand All @@ -821,7 +829,11 @@ func NewSelect(
Cache: cache,
Comments: comments.Parsed(),
Distinct: distinct,
HighPriority: highPriority,
StraightJoinHint: straightJoinHint,
SQLSmallResult: sqlSmallResult,
SQLBigResult: sqlBigResult,
SQLBufferResult: SQLBufferResult,
SQLCalcFoundRows: sqlFoundRows,
SelectExprs: exprs,
Into: into,
Expand Down
4 changes: 4 additions & 0 deletions go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ const (
// Select.Distinct
AllStr = "all "
DistinctStr = "distinct "
HighPriorityStr = "high_priority "
StraightJoinHint = "straight_join "
SQLSmallResultStr = "sql_small_result "
SQLBigResultStr = "sql_big_result "
SQLBufferResultStr = "sql_buffer_result "
SQLCalcFoundRowsStr = "sql_calc_found_rows "

// Select.Lock
Expand Down
7 changes: 4 additions & 3 deletions go/vt/sqlparser/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ var keywords = []keyword{
{"hash", HASH},
{"having", HAVING},
{"header", HEADER},
{"high_priority", UNUSED},
{"high_priority", HIGH_PRIORITY},
{"hosts", HOSTS},
{"hour", HOUR},
{"hour_microsecond", HOUR_MICROSECOND},
Expand Down Expand Up @@ -594,11 +594,12 @@ var keywords = []keyword{
{"sqlexception", UNUSED},
{"sqlstate", UNUSED},
{"sqlwarning", UNUSED},
{"sql_big_result", UNUSED},
{"sql_big_result", SQL_BIG_RESULT},
{"sql_cache", SQL_CACHE},
{"sql_calc_found_rows", SQL_CALC_FOUND_ROWS},
{"sql_no_cache", SQL_NO_CACHE},
{"sql_small_result", UNUSED},
{"sql_small_result", SQL_SMALL_RESULT},
{"sql_buffer_result", SQL_BUFFER_RESULT},
{"sql_tsi_day", SQL_TSI_DAY},
{"sql_tsi_week", SQL_TSI_WEEK},
{"sql_tsi_hour", SQL_TSI_HOUR},
Expand Down
20 changes: 19 additions & 1 deletion go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2646,9 +2646,24 @@ var (
}, {
input: "select sql_no_cache straight_join distinct 'foo' from t",
output: "select distinct sql_no_cache straight_join 'foo' from t",
}, {
input: "select sql_buffer_result 'foo' from t",
output: "select sql_buffer_result 'foo' from t",
}, {
input: "select high_priority 'foo' from t",
output: "select high_priority 'foo' from t",
}, {
input: "select straight_join distinct sql_no_cache 'foo' from t",
output: "select distinct sql_no_cache straight_join 'foo' from t",
}, {
input: "select sql_small_result 'foo' from t",
output: "select sql_small_result 'foo' from t",
}, {
input: "select distinct sql_small_result 'foo' from t",
output: "select distinct sql_small_result 'foo' from t",
}, {
input: "select sql_big_result 'foo' from t",
output: "select sql_big_result 'foo' from t",
}, {
input: "select sql_calc_found_rows 'foo' from t",
output: "select sql_calc_found_rows 'foo' from t",
Expand Down Expand Up @@ -6426,8 +6441,11 @@ func testFile(t *testing.T, filename, tempDir string) {
errPresent := ""
if err != nil {
errPresent = err.Error()
expected.WriteString(fmt.Sprintf("ERROR\n%s\nEND\n", escapeNewLines(errPresent)))
} else {
out := String(tree)
expected.WriteString(fmt.Sprintf("OUTPUT\n%s\nEND\n", escapeNewLines(out)))
}
expected.WriteString(fmt.Sprintf("ERROR\n%s\nEND\n", escapeNewLines(errPresent)))
if err == nil || tcase.errStr != err.Error() {
fail = true
t.Errorf("File: %s, Line: %d\nDiff:\n%s\n[%s] \n[%s]", filename, tcase.lineno, cmp.Diff(tcase.errStr, errPresent), tcase.errStr, errPresent)
Expand Down
Loading
Loading