Skip to content

Commit a4ea5be

Browse files
committed
Add more T-SQL statement support and enable 8 additional tests
- Add TRUNCATE TABLE with partition support - Add trivial statements (USE, KILL, CHECKPOINT, RECONFIGURE, SHUTDOWN, SETUSER, LINENO) - Add RAISERROR statement with WITH options - Add GlobalVariableExpression for @@variables - Add BooleanParenthesisExpression for parenthesized conditions - Add BooleanIsNullExpression for IS NULL/IS NOT NULL - Enable 8 new tests: TruncatePartitions120 (x2), TrivialStatementTests (x2), WhileStatementTests (x2), RaiseErrorStatementTests (x2)
1 parent 54796fe commit a4ea5be

File tree

16 files changed

+735
-8
lines changed

16 files changed

+735
-8
lines changed

ast/boolean_is_null_expression.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ast
2+
3+
// BooleanIsNullExpression represents an IS NULL / IS NOT NULL expression.
4+
type BooleanIsNullExpression struct {
5+
IsNot bool
6+
Expression ScalarExpression
7+
}
8+
9+
func (b *BooleanIsNullExpression) node() {}
10+
func (b *BooleanIsNullExpression) booleanExpression() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ast
2+
3+
// BooleanParenthesisExpression represents a parenthesized boolean expression.
4+
type BooleanParenthesisExpression struct {
5+
Expression BooleanExpression
6+
}
7+
8+
func (b *BooleanParenthesisExpression) node() {}
9+
func (b *BooleanParenthesisExpression) booleanExpression() {}

ast/global_variable_expression.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ast
2+
3+
// GlobalVariableExpression represents a global variable like @@IDENTITY, @@ERROR, etc.
4+
type GlobalVariableExpression struct {
5+
Name string
6+
}
7+
8+
func (g *GlobalVariableExpression) node() {}
9+
func (g *GlobalVariableExpression) scalarExpression() {}

ast/raiserror_statement.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ast
2+
3+
// RaiseErrorStatement represents a RAISERROR statement.
4+
type RaiseErrorStatement struct {
5+
FirstParameter ScalarExpression
6+
SecondParameter ScalarExpression
7+
ThirdParameter ScalarExpression
8+
OptionalParameters []ScalarExpression
9+
RaiseErrorOptions string
10+
}
11+
12+
func (r *RaiseErrorStatement) node() {}
13+
func (r *RaiseErrorStatement) statement() {}

ast/trivial_statements.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package ast
2+
3+
type UseStatement struct {
4+
DatabaseName *Identifier `json:"DatabaseName,omitempty"`
5+
}
6+
7+
func (u *UseStatement) node() {}
8+
func (u *UseStatement) statement() {}
9+
10+
type KillStatement struct {
11+
Parameter ScalarExpression `json:"Parameter,omitempty"`
12+
WithStatusOnly bool `json:"WithStatusOnly"`
13+
}
14+
15+
func (k *KillStatement) node() {}
16+
func (k *KillStatement) statement() {}
17+
18+
type CheckpointStatement struct {
19+
Duration ScalarExpression `json:"Duration,omitempty"`
20+
}
21+
22+
func (c *CheckpointStatement) node() {}
23+
func (c *CheckpointStatement) statement() {}
24+
25+
type ReconfigureStatement struct {
26+
WithOverride bool `json:"WithOverride"`
27+
}
28+
29+
func (r *ReconfigureStatement) node() {}
30+
func (r *ReconfigureStatement) statement() {}
31+
32+
type ShutdownStatement struct {
33+
WithNoWait bool `json:"WithNoWait"`
34+
}
35+
36+
func (s *ShutdownStatement) node() {}
37+
func (s *ShutdownStatement) statement() {}
38+
39+
type SetUserStatement struct {
40+
UserName ScalarExpression `json:"UserName,omitempty"`
41+
WithNoReset bool `json:"WithNoReset"`
42+
}
43+
44+
func (s *SetUserStatement) node() {}
45+
func (s *SetUserStatement) statement() {}
46+
47+
type LineNoStatement struct {
48+
LineNo ScalarExpression `json:"LineNo,omitempty"`
49+
}
50+
51+
func (l *LineNoStatement) node() {}
52+
func (l *LineNoStatement) statement() {}

ast/truncate_table_statement.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package ast
2+
3+
type TruncateTableStatement struct {
4+
TableName *SchemaObjectName `json:"TableName,omitempty"`
5+
PartitionRanges []*CompressionPartitionRange `json:"PartitionRanges,omitempty"`
6+
}
7+
8+
func (t *TruncateTableStatement) node() {}
9+
func (t *TruncateTableStatement) statement() {}
10+
11+
type CompressionPartitionRange struct {
12+
From ScalarExpression `json:"From,omitempty"`
13+
To ScalarExpression `json:"To,omitempty"`
14+
}

parser/lexer.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const (
9191
TokenValues
9292
TokenDefault
9393
TokenNull
94+
TokenIs
9495
TokenExec
9596
TokenExecute
9697
TokenOver
@@ -157,6 +158,16 @@ const (
157158
TokenMove
158159
TokenConversation
159160
TokenGet
161+
TokenUse
162+
TokenKill
163+
TokenCheckpoint
164+
TokenReconfigure
165+
TokenOverride
166+
TokenShutdown
167+
TokenSetuser
168+
TokenLineno
169+
TokenStatusonly
170+
TokenNoreset
160171
)
161172

162173
// Token represents a lexical token.
@@ -513,6 +524,7 @@ var keywords = map[string]TokenType{
513524
"VALUES": TokenValues,
514525
"DEFAULT": TokenDefault,
515526
"NULL": TokenNull,
527+
"IS": TokenIs,
516528
"EXEC": TokenExec,
517529
"EXECUTE": TokenExecute,
518530
"OVER": TokenOver,
@@ -566,6 +578,16 @@ var keywords = map[string]TokenType{
566578
"MOVE": TokenMove,
567579
"CONVERSATION": TokenConversation,
568580
"GET": TokenGet,
581+
"USE": TokenUse,
582+
"KILL": TokenKill,
583+
"CHECKPOINT": TokenCheckpoint,
584+
"RECONFIGURE": TokenReconfigure,
585+
"OVERRIDE": TokenOverride,
586+
"SHUTDOWN": TokenShutdown,
587+
"SETUSER": TokenSetuser,
588+
"LINENO": TokenLineno,
589+
"STATUSONLY": TokenStatusonly,
590+
"NORESET": TokenNoreset,
569591
}
570592

571593
func lookupKeyword(ident string) TokenType {

0 commit comments

Comments
 (0)