From 8923e61b978e2b023615e60e31ea2faef3ce3f73 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 23 Dec 2025 18:47:24 +0000 Subject: [PATCH] Add ON filegroup and TEXTIMAGE_ON clause parsing for CREATE TABLE - Add OnFileGroupOrPartitionScheme and TextImageOn fields to CreateTableStatement AST - Parse ON [filegroup] and TEXTIMAGE_ON [filegroup] clauses after column definitions - Fix NOT NULL parsing after IDENTITY specification (NOT was being consumed when checking for NOT FOR REPLICATION) - Enable BaselinesCommon_TSqlParserTestScript2 and TSqlParserTestScript2 tests --- ast/create_table_statement.go | 12 ++++--- parser/marshal.go | 36 +++++++++++++++++++ .../metadata.json | 2 +- .../TSqlParserTestScript2/metadata.json | 2 +- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/ast/create_table_statement.go b/ast/create_table_statement.go index 7801d56a..596c154f 100644 --- a/ast/create_table_statement.go +++ b/ast/create_table_statement.go @@ -2,11 +2,13 @@ package ast // CreateTableStatement represents a CREATE TABLE statement type CreateTableStatement struct { - SchemaObjectName *SchemaObjectName - AsEdge bool - AsFileTable bool - AsNode bool - Definition *TableDefinition + SchemaObjectName *SchemaObjectName + AsEdge bool + AsFileTable bool + AsNode bool + Definition *TableDefinition + OnFileGroupOrPartitionScheme *FileGroupOrPartitionScheme + TextImageOn *IdentifierOrValueExpression } func (s *CreateTableStatement) node() {} diff --git a/parser/marshal.go b/parser/marshal.go index a9e9b741..45d8d406 100644 --- a/parser/marshal.go +++ b/parser/marshal.go @@ -2493,6 +2493,32 @@ func (p *Parser) parseCreateTableStatement() (*ast.CreateTableStatement, error) p.nextToken() } + // Parse optional ON filegroup and TEXTIMAGE_ON filegroup clauses + for { + upperLit := strings.ToUpper(p.curTok.Literal) + if p.curTok.Type == TokenOn { + p.nextToken() // consume ON + // Parse filegroup identifier + ident := p.parseIdentifier() + stmt.OnFileGroupOrPartitionScheme = &ast.FileGroupOrPartitionScheme{ + Name: &ast.IdentifierOrValueExpression{ + Value: ident.Value, + Identifier: ident, + }, + } + } else if upperLit == "TEXTIMAGE_ON" { + p.nextToken() // consume TEXTIMAGE_ON + // Parse filegroup identifier + ident := p.parseIdentifier() + stmt.TextImageOn = &ast.IdentifierOrValueExpression{ + Value: ident.Value, + Identifier: ident, + } + } else { + break + } + } + // Skip optional semicolon if p.curTok.Type == TokenSemicolon { p.nextToken() @@ -2556,6 +2582,10 @@ func (p *Parser) parseColumnDefinition() (*ast.ColumnDefinition, error) { p.nextToken() // consume REPLICATION identityOpts.NotForReplication = true } + } else if p.curTok.Type == TokenNull { + // NOT NULL after IDENTITY - handle it here since NOT was already consumed + p.nextToken() // consume NULL + col.Constraints = append(col.Constraints, &ast.NullableConstraintDefinition{Nullable: false}) } } @@ -2875,6 +2905,12 @@ func createTableStatementToJSON(s *ast.CreateTableStatement) jsonNode { if s.Definition != nil { node["Definition"] = tableDefinitionToJSON(s.Definition) } + if s.OnFileGroupOrPartitionScheme != nil { + node["OnFileGroupOrPartitionScheme"] = fileGroupOrPartitionSchemeToJSON(s.OnFileGroupOrPartitionScheme) + } + if s.TextImageOn != nil { + node["TextImageOn"] = identifierOrValueExpressionToJSON(s.TextImageOn) + } return node } diff --git a/parser/testdata/BaselinesCommon_TSqlParserTestScript2/metadata.json b/parser/testdata/BaselinesCommon_TSqlParserTestScript2/metadata.json index ccffb5b9..9e26dfee 100644 --- a/parser/testdata/BaselinesCommon_TSqlParserTestScript2/metadata.json +++ b/parser/testdata/BaselinesCommon_TSqlParserTestScript2/metadata.json @@ -1 +1 @@ -{"todo": true} \ No newline at end of file +{} \ No newline at end of file diff --git a/parser/testdata/TSqlParserTestScript2/metadata.json b/parser/testdata/TSqlParserTestScript2/metadata.json index ccffb5b9..9e26dfee 100644 --- a/parser/testdata/TSqlParserTestScript2/metadata.json +++ b/parser/testdata/TSqlParserTestScript2/metadata.json @@ -1 +1 @@ -{"todo": true} \ No newline at end of file +{} \ No newline at end of file