diff --git a/ast/ast.go b/ast/ast.go index 0f5ae5c5..6cf6a0af 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -65,6 +65,9 @@ func (RenameTable) isStatement() {} func (CreateIndex) isStatement() {} func (AlterIndex) isStatement() {} func (DropIndex) isStatement() {} +func (CreateSearchIndex) isStatement() {} +func (DropSearchIndex) isStatement() {} +func (AlterSearchIndex) isStatement() {} func (CreateView) isStatement() {} func (DropView) isStatement() {} func (CreateChangeStream) isStatement() {} @@ -277,6 +280,9 @@ func (CreateIndex) isDDL() {} func (AlterIndex) isDDL() {} func (DropIndex) isDDL() {} func (CreateView) isDDL() {} +func (CreateSearchIndex) isDDL() {} +func (DropSearchIndex) isDDL() {} +func (AlterSearchIndex) isDDL() {} func (DropView) isDDL() {} func (CreateChangeStream) isDDL() {} func (AlterChangeStream) isDDL() {} @@ -1720,10 +1726,11 @@ type CreateSequence struct { // {{.Type | sql}} {{if .NotNull}}NOT NULL{{end}} // {{.DefaultExpr | sqlOpt}} // {{.GeneratedExpr | sqlOpt}} +// {{if .Hidden.Invalid | not)}}HIDDEN{{end}} // {{.Options | sqlOpt}} type ColumnDef struct { // pos = Name.pos - // end = Options.end || GeneratedExpr.end || DefaultExpr.end || Null + 4 || Type.end + // end = Options.end || Hidden + 6 || GeneratedExpr.end || DefaultExpr.end || Null + 4 || Type.end Null token.Pos // position of "NULL" @@ -1732,6 +1739,7 @@ type ColumnDef struct { NotNull bool DefaultExpr *ColumnDefaultExpr // optional GeneratedExpr *GeneratedColumnExpr // optional + Hidden token.Pos // InvalidPos if not hidden Options *Options // optional } @@ -1750,17 +1758,31 @@ type ColumnDefaultExpr struct { // GeneratedColumnExpr is generated column expression. // -// AS ({{.Expr | sql}}) STORED +// AS ({{.Expr | sql}}) {{if .IsStored}}STORED{{end}} type GeneratedColumnExpr struct { // pos = As - // end = Stored + 6 + // end = Stored + 6 || Rparen + 1 As token.Pos // position of "AS" keyword - Stored token.Pos // position of "STORED" keyword + Stored token.Pos // position of "STORED" keyword, optional + Rparen token.Pos // position of ")" Expr Expr } +// ColumnDefOption is options for column definition. +// +// OPTIONS(allow_commit_timestamp = {{if .AllowCommitTimestamp}}true{{else}null{{end}}}) +type ColumnDefOptions struct { + // pos = Options + // end = Rparen + 1 + + Options token.Pos // position of "OPTIONS" keyword + Rparen token.Pos // position of ")" + + AllowCommitTimestamp bool +} + // TableConstraint is table constraint in CREATE TABLE and ALTER TABLE. // // {{if .Name}}CONSTRAINT {{.Name}}{{end}}{{.Constraint | sql}} @@ -2628,6 +2650,65 @@ type ArraySchemaType struct { Item SchemaType // ScalarSchemaType or SizedSchemaType } +// ================================================================================ +// +// Search Index DDL +// +// ================================================================================ + +// CreateSearchIndex represents CREATE SEARCH INDEX statement +// +// CREATE SEARCH INDEX {{.Name | sql}} +// ON {{.TableName | sql}} +// ({{.TokenListPart | sqlJoin ", "}}) +// {{.Storing | sqlOpt}} +// {{if .PartitionColumns}}PARTITION BY {{.PartitionColumns | sqlJoin ", "}}{{end}} +// {{.OrderBy | sqlOpt}} +// {{.Where | sqlOpt}} +// {{.Interleave | sqlOpt}} +// {{.Options | sqlOpt}} +type CreateSearchIndex struct { + // pos = Create + // end = (Options ?? Interleave ?? Where ?? OrderBy ?? PartitionColumns[$] ?? Storing).end || Rparen + 1 + + Create token.Pos + + Name *Ident + TableName *Ident + TokenListPart []*Ident + Rparen token.Pos // position of ")" after TokenListPart + Storing *Storing // optional + PartitionColumns []*Ident // optional + OrderBy *OrderBy // optional + Where *Where // optional + Interleave *InterleaveIn // optional + Options *Options // optional +} + +// DropSearchIndex represents DROP SEARCH INDEX statement. +// +// DROP SEARCH INDEX{{if .IfExists}}IF EXISTS{{end}} {{Name | sql}} +type DropSearchIndex struct { + // pos = Drop + // end = Name.end + + Drop token.Pos + IfExists bool + Name *Ident +} + +// AlterSearchIndex represents ALTER SEARCH INDEX statement. +// +// ALTER SEARCH INDEX {{.Name | sql}} {{.IndexAlteration | sql}} +type AlterSearchIndex struct { + // pos = Alter + // end = IndexAlteration.end + + Alter token.Pos + Name *Ident + IndexAlteration IndexAlteration +} + // ================================================================================ // // DML diff --git a/ast/ast_test.go b/ast/ast_test.go index 1a5d532b..82c26fde 100644 --- a/ast/ast_test.go +++ b/ast/ast_test.go @@ -144,6 +144,9 @@ func TestDDL(t *testing.T) { DDL(&CreateIndex{}).isDDL() DDL(&AlterIndex{}).isDDL() DDL(&DropIndex{}).isDDL() + DDL(&CreateSearchIndex{}).isDDL() + DDL(&DropSearchIndex{}).isDDL() + DDL(&AlterSearchIndex{}).isDDL() DDL(&CreateView{}).isDDL() DDL(&DropView{}).isDDL() DDL(&CreateChangeStream{}).isDDL() diff --git a/ast/const.go b/ast/const.go index 9ea04b10..5c564515 100644 --- a/ast/const.go +++ b/ast/const.go @@ -109,6 +109,7 @@ const ( TimestampTypeName ScalarTypeName = "TIMESTAMP" NumericTypeName ScalarTypeName = "NUMERIC" JSONTypeName ScalarTypeName = "JSON" + TokenListTypeName ScalarTypeName = "TOKENLIST" ) type OnDeleteAction string diff --git a/ast/pos.go b/ast/pos.go index 72a2a056..f11df8d8 100644 --- a/ast/pos.go +++ b/ast/pos.go @@ -49,6 +49,17 @@ func lastEnd[T Node](s []T) token.Pos { return lastNode(s).End() } +// firstValid returns the first valid token.Pos in arguments. +// This function corresponds to PosExpr ("||" PosExpr)* in ast.go +func firstValid(ps ...token.Pos) token.Pos { + for _, p := range ps { + if !p.Invalid() { + return p + } + } + return token.InvalidPos +} + // ================================================================================ // // SELECT @@ -593,26 +604,25 @@ func (c *ColumnDef) Pos() token.Pos { } func (c *ColumnDef) End() token.Pos { - if c.Options != nil { - return c.Options.End() - } - if c.GeneratedExpr != nil { - return c.GeneratedExpr.End() - } - if c.DefaultExpr != nil { - return c.DefaultExpr.End() - } - if !c.Null.Invalid() { - return c.Null + 4 - } - return c.Type.End() + return firstValid( + firstValidEnd(c.Options), + c.Hidden.Add(6), + firstValidEnd(c.GeneratedExpr, c.DefaultExpr), + c.Null.Add(4), + c.Type.End(), + ) } func (g *ColumnDefaultExpr) Pos() token.Pos { return g.Default } func (g *ColumnDefaultExpr) End() token.Pos { return g.Rparen } func (g *GeneratedColumnExpr) Pos() token.Pos { return g.As } -func (g *GeneratedColumnExpr) End() token.Pos { return g.Stored + 6 } +func (g *GeneratedColumnExpr) End() token.Pos { + return firstValid(g.Stored.Add(6), g.Rparen.Add(1)) +} + +func (c *ColumnDefOptions) Pos() token.Pos { return c.Options } +func (c *ColumnDefOptions) End() token.Pos { return c.Rparen + 1 } func (c *TableConstraint) Pos() token.Pos { if c.Name != nil { @@ -917,6 +927,36 @@ func (c *ChangeStreamForTable) End() token.Pos { return c.Rparen + 1 } +// ================================================================================ +// +// Search Index DDL +// +// ================================================================================ + +func (c *CreateSearchIndex) Pos() token.Pos { return c.Create } + +func (c *CreateSearchIndex) End() token.Pos { + return firstValid( + firstValidEnd(c.Options, + c.Interleave, + c.Where, + c.OrderBy, + lastNode(c.PartitionColumns), + c.Storing), + c.Rparen.Add(1)) +} + +func (d *DropSearchIndex) Pos() token.Pos { + return d.Drop +} + +func (d *DropSearchIndex) End() token.Pos { + return d.Name.End() +} + +func (a *AlterSearchIndex) Pos() token.Pos { return a.Alter } +func (a *AlterSearchIndex) End() token.Pos { return a.IndexAlteration.End() } + // ================================================================================ // // DML diff --git a/ast/sql.go b/ast/sql.go index 65c3f46b..dd38f0bc 100644 --- a/ast/sql.go +++ b/ast/sql.go @@ -810,20 +810,12 @@ func (c *CreateView) SQL() string { func (d *DropView) SQL() string { return "DROP VIEW " + d.Name.SQL() } func (c *ColumnDef) SQL() string { - sql := c.Name.SQL() + " " + c.Type.SQL() - if c.NotNull { - sql += " NOT NULL" - } - if c.DefaultExpr != nil { - sql += " " + c.DefaultExpr.SQL() - } - if c.GeneratedExpr != nil { - sql += " " + c.GeneratedExpr.SQL() - } - if c.Options != nil { - sql += " " + c.Options.SQL() - } - return sql + return c.Name.SQL() + " " + c.Type.SQL() + + strOpt(c.NotNull, " NOT NULL") + + sqlOpt(" ", c.DefaultExpr, "") + + sqlOpt(" ", c.GeneratedExpr, "") + + strOpt(!c.Hidden.Invalid(), " HIDDEN") + + sqlOpt(" ", c.Options, "") } func (c *TableConstraint) SQL() string { @@ -868,7 +860,7 @@ func (c *ColumnDefaultExpr) SQL() string { } func (g *GeneratedColumnExpr) SQL() string { - return "AS (" + g.Expr.SQL() + ") STORED" + return "AS (" + g.Expr.SQL() + ")" + strOpt(!g.Stored.Invalid(), " STORED") } func (i *IndexKey) SQL() string { @@ -1267,6 +1259,31 @@ func (a *ArraySchemaType) SQL() string { return "ARRAY<" + a.Item.SQL() + ">" } +// ================================================================================ +// +// Search Index DDL +// +// ================================================================================ + +func (c *CreateSearchIndex) SQL() string { + return "CREATE SEARCH INDEX " + c.Name.SQL() + " ON " + c.TableName.SQL() + + "(" + sqlJoin(c.TokenListPart, ", ") + ")" + + sqlOpt(" ", c.Storing, "") + + strOpt(len(c.PartitionColumns) > 0, " PARTITION BY "+sqlJoin(c.PartitionColumns, ", ")) + + sqlOpt(" ", c.OrderBy, "") + + sqlOpt(" ", c.Where, "") + + sqlOpt("", c.Interleave, "") + + sqlOpt(" ", c.Options, "") +} + +func (d *DropSearchIndex) SQL() string { + return "DROP SEARCH INDEX " + strOpt(d.IfExists, "IF EXISTS ") + d.Name.SQL() +} + +func (a *AlterSearchIndex) SQL() string { + return "ALTER SEARCH INDEX " + a.Name.SQL() + " " + a.IndexAlteration.SQL() +} + // ================================================================================ // // DML diff --git a/parser.go b/parser.go index fa2017f2..0d004854 100644 --- a/parser.go +++ b/parser.go @@ -2015,6 +2015,7 @@ var simpleTypes = []string{ "STRING", "BYTES", "JSON", + "TOKENLIST", } func (p *Parser) parseSimpleType() *ast.SimpleType { @@ -2161,6 +2162,8 @@ func (p *Parser) parseDDL() ast.DDL { return p.parseCreateIndex(pos) case p.Token.IsKeywordLike("VECTOR"): return p.parseCreateVectorIndex(pos) + case p.Token.IsKeywordLike("SEARCH"): + return p.parseCreateSearchIndex(pos) case p.Token.IsKeywordLike("ROLE"): return p.parseCreateRole(pos) case p.Token.IsKeywordLike("CHANGE"): @@ -2176,6 +2179,8 @@ func (p *Parser) parseDDL() ast.DDL { return p.parseAlterDatabase(pos) case p.Token.IsKeywordLike("INDEX"): return p.parseAlterIndex(pos) + case p.Token.IsKeywordLike("SEARCH"): + return p.parseAlterSearchIndex(pos) case p.Token.IsKeywordLike("SEQUENCE"): return p.parseAlterSequence(pos) case p.Token.IsKeywordLike("CHANGE"): @@ -2191,6 +2196,8 @@ func (p *Parser) parseDDL() ast.DDL { return p.parseDropTable(pos) case p.Token.IsKeywordLike("INDEX"): return p.parseDropIndex(pos) + case p.Token.IsKeywordLike("SEARCH"): + return p.parseDropSearchIndex(pos) case p.Token.IsKeywordLike("VECTOR"): return p.parseDropVectorIndex(pos) case p.Token.IsKeywordLike("SEQUENCE"): @@ -2387,6 +2394,12 @@ func (p *Parser) parseColumnDef() *ast.ColumnDef { t, notNull, null := p.parseTypeNotNull() defaultExpr := p.tryParseColumnDefaultExpr() generated := p.tryParseGeneratedColumnExpr() + + hiddenPos := token.InvalidPos + if p.Token.IsKeywordLike("HIDDEN") { + hiddenPos = p.expectKeywordLike("HIDDEN").Pos + } + options := p.tryParseOptions() return &ast.ColumnDef{ @@ -2396,6 +2409,7 @@ func (p *Parser) parseColumnDef() *ast.ColumnDef { NotNull: notNull, DefaultExpr: defaultExpr, GeneratedExpr: generated, + Hidden: hiddenPos, Options: options, } } @@ -2508,12 +2522,17 @@ func (p *Parser) tryParseGeneratedColumnExpr() *ast.GeneratedColumnExpr { pos := p.expect("AS").Pos p.expect("(") expr := p.parseExpr() - p.expect(")") - stored := p.expectKeywordLike("STORED").Pos + rparen := p.expect(")").Pos + + stored := token.InvalidPos + if p.Token.IsKeywordLike("STORED") { + stored = p.expectKeywordLike("STORED").Pos + } return &ast.GeneratedColumnExpr{ As: pos, Stored: stored, + Rparen: rparen, Expr: expr, } } @@ -2670,6 +2689,86 @@ func (p *Parser) parseCreateVectorIndex(pos token.Pos) *ast.CreateVectorIndex { } } +func (p *Parser) parseCreateSearchIndex(pos token.Pos) *ast.CreateSearchIndex { + p.expectKeywordLike("SEARCH") + p.expectKeywordLike("INDEX") + name := p.parseIdent() + + p.expect("ON") + tableName := p.parseIdent() + + p.expect("(") + columnName := parseCommaSeparatedList(p, p.parseIdent) + rparen := p.expect(")").Pos + + storing := p.tryParseStoring() + + var partitionColumns []*ast.Ident + if p.Token.Kind == "PARTITION" { + p.nextToken() + p.expect("BY") + partitionColumns = parseCommaSeparatedList(p, p.parseIdent) + } + + orderBy := p.tryParseOrderBy() + where := p.tryParseWhere() + interleave := p.tryParseInterleaveIn() + + options := p.tryParseOptions() + + return &ast.CreateSearchIndex{ + Create: pos, + Name: name, + TableName: tableName, + TokenListPart: columnName, + Rparen: rparen, + Storing: storing, + PartitionColumns: partitionColumns, + OrderBy: orderBy, + Where: where, + Interleave: interleave, + Options: options, + } +} + +func (p *Parser) parseDropSearchIndex(pos token.Pos) *ast.DropSearchIndex { + p.expectKeywordLike("SEARCH") + p.expectKeywordLike("INDEX") + ifExists := p.parseIfExists() + name := p.parseIdent() + return &ast.DropSearchIndex{ + Drop: pos, + IfExists: ifExists, + Name: name, + } + +} + +func (p *Parser) parseAlterSearchIndex(pos token.Pos) *ast.AlterSearchIndex { + p.expectKeywordLike("SEARCH") + p.expectKeywordLike("INDEX") + + name := p.parseIdent() + alteration := p.parseIndexAlteration() + + return &ast.AlterSearchIndex{ + Alter: pos, + Name: name, + IndexAlteration: alteration, + } +} + +func (p *Parser) parseIndexAlteration() ast.IndexAlteration { + switch { + case p.Token.IsKeywordLike("ADD"): + return p.parseAddStoredColumn() + case p.Token.IsKeywordLike("DROP"): + return p.parseDropStoredColumn() + default: + panic(p.errorfAtToken(&p.Token, "expected pseudo keyword: ADD, DROP, but: %s", p.Token.AsString)) + } +} + func (p *Parser) parseCreateIndex(pos token.Pos) *ast.CreateIndex { unique := false if p.Token.IsKeywordLike("UNIQUE") { @@ -3091,16 +3190,7 @@ func (p *Parser) parseAlterIndex(pos token.Pos) *ast.AlterIndex { p.expectKeywordLike("INDEX") name := p.parseIdent() - - var alteration ast.IndexAlteration - switch { - case p.Token.IsKeywordLike("ADD"): - alteration = p.parseAddStoredColumn() - case p.Token.IsKeywordLike("DROP"): - alteration = p.parseDropStoredColumn() - default: - p.panicfAtToken(&p.Token, "expected pseudo keyword: ADD, DROP, but: %s", p.Token.AsString) - } + alteration := p.parseIndexAlteration() return &ast.AlterIndex{ Alter: pos, @@ -3432,6 +3522,7 @@ var scalarSchemaTypes = []string{ "TIMESTAMP", "NUMERIC", "JSON", + "TOKENLIST", } var sizedSchemaTypes = []string{ diff --git a/testdata/input/ddl/alter_search_index_add_stored_column.sql b/testdata/input/ddl/alter_search_index_add_stored_column.sql new file mode 100644 index 00000000..680bb9d9 --- /dev/null +++ b/testdata/input/ddl/alter_search_index_add_stored_column.sql @@ -0,0 +1 @@ +ALTER SEARCH INDEX AlbumsIndex ADD STORED COLUMN Genre \ No newline at end of file diff --git a/testdata/input/ddl/alter_search_index_drop_stored_column.sql b/testdata/input/ddl/alter_search_index_drop_stored_column.sql new file mode 100644 index 00000000..a9dcd601 --- /dev/null +++ b/testdata/input/ddl/alter_search_index_drop_stored_column.sql @@ -0,0 +1 @@ +ALTER SEARCH INDEX AlbumsIndex DROP STORED COLUMN Genre \ No newline at end of file diff --git a/testdata/input/ddl/create_search_index_full.sql b/testdata/input/ddl/create_search_index_full.sql new file mode 100644 index 00000000..f9a98cfb --- /dev/null +++ b/testdata/input/ddl/create_search_index_full.sql @@ -0,0 +1,8 @@ +CREATE SEARCH INDEX AlbumsIndexFull +ON Albums(Title_Tokens, Studio_Tokens) +STORING(Genre) +PARTITION BY SingerId +ORDER BY ReleaseTimestamp DESC +WHERE Genre IS NOT NULL AND ReleaseTimestamp IS NOT NULL +, INTERLEAVE IN Singers +OPTIONS(sort_order_sharding=true) \ No newline at end of file diff --git a/testdata/input/ddl/create_search_index_null_filtered.sql b/testdata/input/ddl/create_search_index_null_filtered.sql new file mode 100644 index 00000000..68ad3f9c --- /dev/null +++ b/testdata/input/ddl/create_search_index_null_filtered.sql @@ -0,0 +1,4 @@ +CREATE SEARCH INDEX AlbumsIndex +ON Albums(AlbumTitle_Tokens) +STORING(Genre) +WHERE Genre IS NOT NULL \ No newline at end of file diff --git a/testdata/input/ddl/create_search_index_simple.sql b/testdata/input/ddl/create_search_index_simple.sql new file mode 100644 index 00000000..6414cc26 --- /dev/null +++ b/testdata/input/ddl/create_search_index_simple.sql @@ -0,0 +1,3 @@ +-- no optional clauses +CREATE SEARCH INDEX AlbumsIndex + ON Albums(AlbumTitle_Tokens) \ No newline at end of file diff --git a/testdata/input/ddl/create_table_fulltext_albums.sql b/testdata/input/ddl/create_table_fulltext_albums.sql new file mode 100644 index 00000000..4dbd2f86 --- /dev/null +++ b/testdata/input/ddl/create_table_fulltext_albums.sql @@ -0,0 +1,10 @@ +-- https://cloud.google.com/spanner/docs/full-text-search/search-indexes#search-index-schema-definitions +CREATE TABLE Albums ( + AlbumId STRING(MAX) NOT NULL, + SingerId INT64 NOT NULL, + ReleaseTimestamp INT64 NOT NULL, + AlbumTitle STRING(MAX), + Rating FLOAT64, + AlbumTitle_Tokens TOKENLIST AS (TOKENIZE_FULLTEXT(AlbumTitle)) HIDDEN, + Rating_Tokens TOKENLIST AS (TOKENIZE_NUMBER(Rating)) HIDDEN +) PRIMARY KEY(AlbumId) \ No newline at end of file diff --git a/testdata/input/ddl/drop_search_index.sql b/testdata/input/ddl/drop_search_index.sql new file mode 100644 index 00000000..101ff3fc --- /dev/null +++ b/testdata/input/ddl/drop_search_index.sql @@ -0,0 +1 @@ +DROP SEARCH INDEX IF EXISTS AlbumsIndex \ No newline at end of file diff --git a/testdata/result/ddl/alter_search_index_add_stored_column.sql.txt b/testdata/result/ddl/alter_search_index_add_stored_column.sql.txt new file mode 100644 index 00000000..e27c4f83 --- /dev/null +++ b/testdata/result/ddl/alter_search_index_add_stored_column.sql.txt @@ -0,0 +1,22 @@ +--- alter_search_index_add_stored_column.sql +ALTER SEARCH INDEX AlbumsIndex ADD STORED COLUMN Genre +--- AST +&ast.AlterSearchIndex{ + Alter: 0, + Name: &ast.Ident{ + NamePos: 19, + NameEnd: 30, + Name: "AlbumsIndex", + }, + IndexAlteration: &ast.AddStoredColumn{ + Add: 31, + Name: &ast.Ident{ + NamePos: 49, + NameEnd: 54, + Name: "Genre", + }, + }, +} + +--- SQL +ALTER SEARCH INDEX AlbumsIndex ADD STORED COLUMN Genre diff --git a/testdata/result/ddl/alter_search_index_drop_stored_column.sql.txt b/testdata/result/ddl/alter_search_index_drop_stored_column.sql.txt new file mode 100644 index 00000000..1a3f12bf --- /dev/null +++ b/testdata/result/ddl/alter_search_index_drop_stored_column.sql.txt @@ -0,0 +1,22 @@ +--- alter_search_index_drop_stored_column.sql +ALTER SEARCH INDEX AlbumsIndex DROP STORED COLUMN Genre +--- AST +&ast.AlterSearchIndex{ + Alter: 0, + Name: &ast.Ident{ + NamePos: 19, + NameEnd: 30, + Name: "AlbumsIndex", + }, + IndexAlteration: &ast.DropStoredColumn{ + Drop: 31, + Name: &ast.Ident{ + NamePos: 50, + NameEnd: 55, + Name: "Genre", + }, + }, +} + +--- SQL +ALTER SEARCH INDEX AlbumsIndex DROP STORED COLUMN Genre diff --git a/testdata/result/ddl/alter_table_add_column.sql.txt b/testdata/result/ddl/alter_table_add_column.sql.txt index d64d67bc..b4b8830c 100644 --- a/testdata/result/ddl/alter_table_add_column.sql.txt +++ b/testdata/result/ddl/alter_table_add_column.sql.txt @@ -28,6 +28,7 @@ alter table foo add column baz string(max) not null NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/alter_table_add_column_if_not_exists.sql.txt b/testdata/result/ddl/alter_table_add_column_if_not_exists.sql.txt index 143c229f..f4158ba6 100644 --- a/testdata/result/ddl/alter_table_add_column_if_not_exists.sql.txt +++ b/testdata/result/ddl/alter_table_add_column_if_not_exists.sql.txt @@ -29,6 +29,7 @@ alter table foo add column if not exists baz string(max) not null NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/alter_table_add_column_with_if_expression.sql.txt b/testdata/result/ddl/alter_table_add_column_with_if_expression.sql.txt index 6624b331..8726d656 100644 --- a/testdata/result/ddl/alter_table_add_column_with_if_expression.sql.txt +++ b/testdata/result/ddl/alter_table_add_column_with_if_expression.sql.txt @@ -27,6 +27,7 @@ ALTER TABLE foo ADD COLUMN expired_at TIMESTAMP AS (IF (status != "OPEN" AND sta GeneratedExpr: &ast.GeneratedColumnExpr{ As: 48, Stored: 153, + Rparen: 151, Expr: &ast.CallExpr{ Rparen: 150, Func: &ast.Ident{ @@ -115,6 +116,7 @@ ALTER TABLE foo ADD COLUMN expired_at TIMESTAMP AS (IF (status != "OPEN" AND sta Having: nil, }, }, + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/create_search_index_full.sql.txt b/testdata/result/ddl/create_search_index_full.sql.txt new file mode 100644 index 00000000..299f2fe0 --- /dev/null +++ b/testdata/result/ddl/create_search_index_full.sql.txt @@ -0,0 +1,121 @@ +--- create_search_index_full.sql +CREATE SEARCH INDEX AlbumsIndexFull +ON Albums(Title_Tokens, Studio_Tokens) +STORING(Genre) +PARTITION BY SingerId +ORDER BY ReleaseTimestamp DESC +WHERE Genre IS NOT NULL AND ReleaseTimestamp IS NOT NULL +, INTERLEAVE IN Singers +OPTIONS(sort_order_sharding=true) +--- AST +&ast.CreateSearchIndex{ + Create: 0, + Name: &ast.Ident{ + NamePos: 20, + NameEnd: 35, + Name: "AlbumsIndexFull", + }, + TableName: &ast.Ident{ + NamePos: 39, + NameEnd: 45, + Name: "Albums", + }, + TokenListPart: []*ast.Ident{ + &ast.Ident{ + NamePos: 46, + NameEnd: 58, + Name: "Title_Tokens", + }, + &ast.Ident{ + NamePos: 60, + NameEnd: 73, + Name: "Studio_Tokens", + }, + }, + Rparen: 73, + Storing: &ast.Storing{ + Storing: 75, + Rparen: 88, + Columns: []*ast.Ident{ + &ast.Ident{ + NamePos: 83, + NameEnd: 88, + Name: "Genre", + }, + }, + }, + PartitionColumns: []*ast.Ident{ + &ast.Ident{ + NamePos: 103, + NameEnd: 111, + Name: "SingerId", + }, + }, + OrderBy: &ast.OrderBy{ + Order: 112, + Items: []*ast.OrderByItem{ + &ast.OrderByItem{ + DirPos: 138, + Expr: &ast.Ident{ + NamePos: 121, + NameEnd: 137, + Name: "ReleaseTimestamp", + }, + Collate: (*ast.Collate)(nil), + Dir: "DESC", + }, + }, + }, + Where: &ast.Where{ + Where: 143, + Expr: &ast.BinaryExpr{ + Op: "AND", + Left: &ast.IsNullExpr{ + Null: 162, + Not: true, + Left: &ast.Ident{ + NamePos: 149, + NameEnd: 154, + Name: "Genre", + }, + }, + Right: &ast.IsNullExpr{ + Null: 195, + Not: true, + Left: &ast.Ident{ + NamePos: 171, + NameEnd: 187, + Name: "ReleaseTimestamp", + }, + }, + }, + }, + Interleave: &ast.InterleaveIn{ + Comma: 200, + TableName: &ast.Ident{ + NamePos: 216, + NameEnd: 223, + Name: "Singers", + }, + }, + Options: &ast.Options{ + Options: 224, + Rparen: 256, + Records: []*ast.OptionsDef{ + &ast.OptionsDef{ + Name: &ast.Ident{ + NamePos: 232, + NameEnd: 251, + Name: "sort_order_sharding", + }, + Value: &ast.BoolLiteral{ + ValuePos: 252, + Value: true, + }, + }, + }, + }, +} + +--- SQL +CREATE SEARCH INDEX AlbumsIndexFull ON Albums(Title_Tokens, Studio_Tokens) STORING (Genre) PARTITION BY SingerId ORDER BY ReleaseTimestamp DESC WHERE Genre IS NOT NULL AND ReleaseTimestamp IS NOT NULL, INTERLEAVE IN Singers OPTIONS (sort_order_sharding = true) diff --git a/testdata/result/ddl/create_search_index_null_filtered.sql.txt b/testdata/result/ddl/create_search_index_null_filtered.sql.txt new file mode 100644 index 00000000..f1fab7c1 --- /dev/null +++ b/testdata/result/ddl/create_search_index_null_filtered.sql.txt @@ -0,0 +1,57 @@ +--- create_search_index_null_filtered.sql +CREATE SEARCH INDEX AlbumsIndex +ON Albums(AlbumTitle_Tokens) +STORING(Genre) +WHERE Genre IS NOT NULL +--- AST +&ast.CreateSearchIndex{ + Create: 0, + Name: &ast.Ident{ + NamePos: 20, + NameEnd: 31, + Name: "AlbumsIndex", + }, + TableName: &ast.Ident{ + NamePos: 35, + NameEnd: 41, + Name: "Albums", + }, + TokenListPart: []*ast.Ident{ + &ast.Ident{ + NamePos: 42, + NameEnd: 59, + Name: "AlbumTitle_Tokens", + }, + }, + Rparen: 59, + Storing: &ast.Storing{ + Storing: 61, + Rparen: 74, + Columns: []*ast.Ident{ + &ast.Ident{ + NamePos: 69, + NameEnd: 74, + Name: "Genre", + }, + }, + }, + PartitionColumns: []*ast.Ident(nil), + OrderBy: (*ast.OrderBy)(nil), + Where: &ast.Where{ + Where: 76, + Expr: &ast.IsNullExpr{ + Null: 95, + Not: true, + Left: &ast.Ident{ + NamePos: 82, + NameEnd: 87, + Name: "Genre", + }, + }, + }, + Interleave: (*ast.InterleaveIn)(nil), + Options: (*ast.Options)(nil), +} + +--- SQL +CREATE SEARCH INDEX AlbumsIndex ON Albums(AlbumTitle_Tokens) STORING (Genre) WHERE Genre IS NOT NULL diff --git a/testdata/result/ddl/create_search_index_simple.sql.txt b/testdata/result/ddl/create_search_index_simple.sql.txt new file mode 100644 index 00000000..60072aa5 --- /dev/null +++ b/testdata/result/ddl/create_search_index_simple.sql.txt @@ -0,0 +1,35 @@ +--- create_search_index_simple.sql +-- no optional clauses +CREATE SEARCH INDEX AlbumsIndex + ON Albums(AlbumTitle_Tokens) +--- AST +&ast.CreateSearchIndex{ + Create: 23, + Name: &ast.Ident{ + NamePos: 43, + NameEnd: 54, + Name: "AlbumsIndex", + }, + TableName: &ast.Ident{ + NamePos: 60, + NameEnd: 66, + Name: "Albums", + }, + TokenListPart: []*ast.Ident{ + &ast.Ident{ + NamePos: 67, + NameEnd: 84, + Name: "AlbumTitle_Tokens", + }, + }, + Rparen: 84, + Storing: (*ast.Storing)(nil), + PartitionColumns: []*ast.Ident(nil), + OrderBy: (*ast.OrderBy)(nil), + Where: (*ast.Where)(nil), + Interleave: (*ast.InterleaveIn)(nil), + Options: (*ast.Options)(nil), +} + +--- SQL +CREATE SEARCH INDEX AlbumsIndex ON Albums(AlbumTitle_Tokens) diff --git a/testdata/result/ddl/create_table.sql.txt b/testdata/result/ddl/create_table.sql.txt index 09c6c3df..5cbba1fa 100644 --- a/testdata/result/ddl/create_table.sql.txt +++ b/testdata/result/ddl/create_table.sql.txt @@ -39,6 +39,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -55,6 +56,7 @@ create table foo ( NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -79,6 +81,7 @@ create table foo ( NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: &ast.Options{ Options: 83, Rparen: 120, @@ -120,6 +123,7 @@ create table foo ( GeneratedExpr: &ast.GeneratedColumnExpr{ As: 150, Stored: 172, + Rparen: 170, Expr: &ast.CallExpr{ Rparen: 169, Func: &ast.Ident{ @@ -149,6 +153,7 @@ create table foo ( Having: nil, }, }, + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -165,6 +170,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -197,6 +203,7 @@ create table foo ( }, }, GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/create_table_cluster.sql.txt b/testdata/result/ddl/create_table_cluster.sql.txt index b1f4a5c6..0d6a5d57 100644 --- a/testdata/result/ddl/create_table_cluster.sql.txt +++ b/testdata/result/ddl/create_table_cluster.sql.txt @@ -30,6 +30,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -46,6 +47,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/create_table_cluster_and_row_deletion_policy.sql.txt b/testdata/result/ddl/create_table_cluster_and_row_deletion_policy.sql.txt index c9501c97..e27a41de 100644 --- a/testdata/result/ddl/create_table_cluster_and_row_deletion_policy.sql.txt +++ b/testdata/result/ddl/create_table_cluster_and_row_deletion_policy.sql.txt @@ -32,6 +32,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -48,6 +49,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -64,6 +66,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/create_table_cluster_on_delete_no_action.sql.txt b/testdata/result/ddl/create_table_cluster_on_delete_no_action.sql.txt index 1b3868f6..7681612b 100644 --- a/testdata/result/ddl/create_table_cluster_on_delete_no_action.sql.txt +++ b/testdata/result/ddl/create_table_cluster_on_delete_no_action.sql.txt @@ -29,6 +29,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/create_table_cluster_set_on_delete.sql.txt b/testdata/result/ddl/create_table_cluster_set_on_delete.sql.txt index 7ba4d258..56a2e62d 100644 --- a/testdata/result/ddl/create_table_cluster_set_on_delete.sql.txt +++ b/testdata/result/ddl/create_table_cluster_set_on_delete.sql.txt @@ -29,6 +29,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/create_table_fulltext_albums.sql.txt b/testdata/result/ddl/create_table_fulltext_albums.sql.txt new file mode 100644 index 00000000..26d125f3 --- /dev/null +++ b/testdata/result/ddl/create_table_fulltext_albums.sql.txt @@ -0,0 +1,217 @@ +--- create_table_fulltext_albums.sql +-- https://cloud.google.com/spanner/docs/full-text-search/search-indexes#search-index-schema-definitions +CREATE TABLE Albums ( + AlbumId STRING(MAX) NOT NULL, + SingerId INT64 NOT NULL, + ReleaseTimestamp INT64 NOT NULL, + AlbumTitle STRING(MAX), + Rating FLOAT64, + AlbumTitle_Tokens TOKENLIST AS (TOKENIZE_FULLTEXT(AlbumTitle)) HIDDEN, + Rating_Tokens TOKENLIST AS (TOKENIZE_NUMBER(Rating)) HIDDEN +) PRIMARY KEY(AlbumId) +--- AST +&ast.CreateTable{ + Create: 105, + Rparen: 575, + IfNotExists: false, + Name: &ast.Ident{ + NamePos: 118, + NameEnd: 124, + Name: "Albums", + }, + Columns: []*ast.ColumnDef{ + &ast.ColumnDef{ + Null: 175, + Name: &ast.Ident{ + NamePos: 151, + NameEnd: 158, + Name: "AlbumId", + }, + Type: &ast.SizedSchemaType{ + NamePos: 159, + Rparen: 169, + Name: "STRING", + Max: true, + Size: nil, + }, + NotNull: true, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, + Options: (*ast.Options)(nil), + }, + &ast.ColumnDef{ + Null: 224, + Name: &ast.Ident{ + NamePos: 205, + NameEnd: 213, + Name: "SingerId", + }, + Type: &ast.ScalarSchemaType{ + NamePos: 214, + Name: "INT64", + }, + NotNull: true, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, + Options: (*ast.Options)(nil), + }, + &ast.ColumnDef{ + Null: 281, + Name: &ast.Ident{ + NamePos: 254, + NameEnd: 270, + Name: "ReleaseTimestamp", + }, + Type: &ast.ScalarSchemaType{ + NamePos: 271, + Name: "INT64", + }, + NotNull: true, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, + Options: (*ast.Options)(nil), + }, + &ast.ColumnDef{ + Null: -1, + Name: &ast.Ident{ + NamePos: 311, + NameEnd: 321, + Name: "AlbumTitle", + }, + Type: &ast.SizedSchemaType{ + NamePos: 322, + Rparen: 332, + Name: "STRING", + Max: true, + Size: nil, + }, + NotNull: false, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, + Options: (*ast.Options)(nil), + }, + &ast.ColumnDef{ + Null: -1, + Name: &ast.Ident{ + NamePos: 359, + NameEnd: 365, + Name: "Rating", + }, + Type: &ast.ScalarSchemaType{ + NamePos: 366, + Name: "FLOAT64", + }, + NotNull: false, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, + Options: (*ast.Options)(nil), + }, + &ast.ColumnDef{ + Null: -1, + Name: &ast.Ident{ + NamePos: 399, + NameEnd: 416, + Name: "AlbumTitle_Tokens", + }, + Type: &ast.ScalarSchemaType{ + NamePos: 417, + Name: "TOKENLIST", + }, + NotNull: false, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: &ast.GeneratedColumnExpr{ + As: 427, + Stored: -1, + Rparen: 460, + Expr: &ast.CallExpr{ + Rparen: 459, + Func: &ast.Ident{ + NamePos: 431, + NameEnd: 448, + Name: "TOKENIZE_FULLTEXT", + }, + Distinct: false, + Args: []ast.Arg{ + &ast.ExprArg{ + Expr: &ast.Ident{ + NamePos: 449, + NameEnd: 459, + Name: "AlbumTitle", + }, + }, + }, + NamedArgs: []*ast.NamedArg(nil), + NullHandling: nil, + Having: nil, + }, + }, + Hidden: 462, + Options: (*ast.Options)(nil), + }, + &ast.ColumnDef{ + Null: -1, + Name: &ast.Ident{ + NamePos: 494, + NameEnd: 507, + Name: "Rating_Tokens", + }, + Type: &ast.ScalarSchemaType{ + NamePos: 508, + Name: "TOKENLIST", + }, + NotNull: false, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: &ast.GeneratedColumnExpr{ + As: 518, + Stored: -1, + Rparen: 545, + Expr: &ast.CallExpr{ + Rparen: 544, + Func: &ast.Ident{ + NamePos: 522, + NameEnd: 537, + Name: "TOKENIZE_NUMBER", + }, + Distinct: false, + Args: []ast.Arg{ + &ast.ExprArg{ + Expr: &ast.Ident{ + NamePos: 538, + NameEnd: 544, + Name: "Rating", + }, + }, + }, + NamedArgs: []*ast.NamedArg(nil), + NullHandling: nil, + Having: nil, + }, + }, + Hidden: 547, + Options: (*ast.Options)(nil), + }, + }, + TableConstraints: []*ast.TableConstraint(nil), + PrimaryKeys: []*ast.IndexKey{ + &ast.IndexKey{ + DirPos: -1, + Name: &ast.Ident{ + NamePos: 568, + NameEnd: 575, + Name: "AlbumId", + }, + Dir: "", + }, + }, + Synonyms: []*ast.Synonym(nil), + Cluster: (*ast.Cluster)(nil), + RowDeletionPolicy: (*ast.CreateRowDeletionPolicy)(nil), +} + +--- SQL +CREATE TABLE Albums (AlbumId STRING(MAX) NOT NULL, SingerId INT64 NOT NULL, ReleaseTimestamp INT64 NOT NULL, AlbumTitle STRING(MAX), Rating FLOAT64, AlbumTitle_Tokens TOKENLIST AS (TOKENIZE_FULLTEXT(AlbumTitle)) HIDDEN, Rating_Tokens TOKENLIST AS (TOKENIZE_NUMBER(Rating)) HIDDEN) PRIMARY KEY (AlbumId) diff --git a/testdata/result/ddl/create_table_if_not_exists.sql.txt b/testdata/result/ddl/create_table_if_not_exists.sql.txt index 4ceac8b2..a3bce8e1 100644 --- a/testdata/result/ddl/create_table_if_not_exists.sql.txt +++ b/testdata/result/ddl/create_table_if_not_exists.sql.txt @@ -29,6 +29,7 @@ create table if not exists foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -45,6 +46,7 @@ create table if not exists foo ( NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/create_table_row_deletion_policy.sql.txt b/testdata/result/ddl/create_table_row_deletion_policy.sql.txt index 99b12727..c528214d 100644 --- a/testdata/result/ddl/create_table_row_deletion_policy.sql.txt +++ b/testdata/result/ddl/create_table_row_deletion_policy.sql.txt @@ -31,6 +31,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -47,6 +48,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -63,6 +65,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/create_table_synonyms.sql.txt b/testdata/result/ddl/create_table_synonyms.sql.txt index 3a34aa0c..9264d6f8 100644 --- a/testdata/result/ddl/create_table_synonyms.sql.txt +++ b/testdata/result/ddl/create_table_synonyms.sql.txt @@ -29,6 +29,7 @@ CREATE TABLE Singers ( NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -53,6 +54,7 @@ CREATE TABLE Singers ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/create_table_synonyms_abnormal.sql.txt b/testdata/result/ddl/create_table_synonyms_abnormal.sql.txt index 887f578a..412d563e 100644 --- a/testdata/result/ddl/create_table_synonyms_abnormal.sql.txt +++ b/testdata/result/ddl/create_table_synonyms_abnormal.sql.txt @@ -31,6 +31,7 @@ CREATE TABLE Singers ( NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -55,6 +56,7 @@ CREATE TABLE Singers ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/create_table_trailing_comma.sql.txt b/testdata/result/ddl/create_table_trailing_comma.sql.txt index 6bfa977d..8bded18d 100644 --- a/testdata/result/ddl/create_table_trailing_comma.sql.txt +++ b/testdata/result/ddl/create_table_trailing_comma.sql.txt @@ -32,6 +32,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -48,6 +49,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/create_table_types.sql.txt b/testdata/result/ddl/create_table_types.sql.txt index 7287c937..ee439007 100644 --- a/testdata/result/ddl/create_table_types.sql.txt +++ b/testdata/result/ddl/create_table_types.sql.txt @@ -40,6 +40,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -56,6 +57,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -72,6 +74,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -88,6 +91,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -104,6 +108,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -120,6 +125,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -144,6 +150,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -163,6 +170,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -187,6 +195,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -206,6 +215,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -226,6 +236,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -249,6 +260,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -275,6 +287,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/create_table_with_sequence_function.sql.txt b/testdata/result/ddl/create_table_with_sequence_function.sql.txt index 89610eda..0aea0698 100644 --- a/testdata/result/ddl/create_table_with_sequence_function.sql.txt +++ b/testdata/result/ddl/create_table_with_sequence_function.sql.txt @@ -56,6 +56,7 @@ CREATE TABLE foo }, }, GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -75,6 +76,7 @@ CREATE TABLE foo NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -91,6 +93,7 @@ CREATE TABLE foo NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/ddl/drop_search_index.sql.txt b/testdata/result/ddl/drop_search_index.sql.txt new file mode 100644 index 00000000..fe6d374c --- /dev/null +++ b/testdata/result/ddl/drop_search_index.sql.txt @@ -0,0 +1,15 @@ +--- drop_search_index.sql +DROP SEARCH INDEX IF EXISTS AlbumsIndex +--- AST +&ast.DropSearchIndex{ + Drop: 0, + IfExists: true, + Name: &ast.Ident{ + NamePos: 28, + NameEnd: 39, + Name: "AlbumsIndex", + }, +} + +--- SQL +DROP SEARCH INDEX IF EXISTS AlbumsIndex diff --git a/testdata/result/statement/alter_search_index_add_stored_column.sql.txt b/testdata/result/statement/alter_search_index_add_stored_column.sql.txt new file mode 100644 index 00000000..e27c4f83 --- /dev/null +++ b/testdata/result/statement/alter_search_index_add_stored_column.sql.txt @@ -0,0 +1,22 @@ +--- alter_search_index_add_stored_column.sql +ALTER SEARCH INDEX AlbumsIndex ADD STORED COLUMN Genre +--- AST +&ast.AlterSearchIndex{ + Alter: 0, + Name: &ast.Ident{ + NamePos: 19, + NameEnd: 30, + Name: "AlbumsIndex", + }, + IndexAlteration: &ast.AddStoredColumn{ + Add: 31, + Name: &ast.Ident{ + NamePos: 49, + NameEnd: 54, + Name: "Genre", + }, + }, +} + +--- SQL +ALTER SEARCH INDEX AlbumsIndex ADD STORED COLUMN Genre diff --git a/testdata/result/statement/alter_search_index_drop_stored_column.sql.txt b/testdata/result/statement/alter_search_index_drop_stored_column.sql.txt new file mode 100644 index 00000000..1a3f12bf --- /dev/null +++ b/testdata/result/statement/alter_search_index_drop_stored_column.sql.txt @@ -0,0 +1,22 @@ +--- alter_search_index_drop_stored_column.sql +ALTER SEARCH INDEX AlbumsIndex DROP STORED COLUMN Genre +--- AST +&ast.AlterSearchIndex{ + Alter: 0, + Name: &ast.Ident{ + NamePos: 19, + NameEnd: 30, + Name: "AlbumsIndex", + }, + IndexAlteration: &ast.DropStoredColumn{ + Drop: 31, + Name: &ast.Ident{ + NamePos: 50, + NameEnd: 55, + Name: "Genre", + }, + }, +} + +--- SQL +ALTER SEARCH INDEX AlbumsIndex DROP STORED COLUMN Genre diff --git a/testdata/result/statement/alter_table_add_column.sql.txt b/testdata/result/statement/alter_table_add_column.sql.txt index d64d67bc..b4b8830c 100644 --- a/testdata/result/statement/alter_table_add_column.sql.txt +++ b/testdata/result/statement/alter_table_add_column.sql.txt @@ -28,6 +28,7 @@ alter table foo add column baz string(max) not null NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/alter_table_add_column_if_not_exists.sql.txt b/testdata/result/statement/alter_table_add_column_if_not_exists.sql.txt index 143c229f..f4158ba6 100644 --- a/testdata/result/statement/alter_table_add_column_if_not_exists.sql.txt +++ b/testdata/result/statement/alter_table_add_column_if_not_exists.sql.txt @@ -29,6 +29,7 @@ alter table foo add column if not exists baz string(max) not null NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/alter_table_add_column_with_if_expression.sql.txt b/testdata/result/statement/alter_table_add_column_with_if_expression.sql.txt index 6624b331..8726d656 100644 --- a/testdata/result/statement/alter_table_add_column_with_if_expression.sql.txt +++ b/testdata/result/statement/alter_table_add_column_with_if_expression.sql.txt @@ -27,6 +27,7 @@ ALTER TABLE foo ADD COLUMN expired_at TIMESTAMP AS (IF (status != "OPEN" AND sta GeneratedExpr: &ast.GeneratedColumnExpr{ As: 48, Stored: 153, + Rparen: 151, Expr: &ast.CallExpr{ Rparen: 150, Func: &ast.Ident{ @@ -115,6 +116,7 @@ ALTER TABLE foo ADD COLUMN expired_at TIMESTAMP AS (IF (status != "OPEN" AND sta Having: nil, }, }, + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/create_search_index_full.sql.txt b/testdata/result/statement/create_search_index_full.sql.txt new file mode 100644 index 00000000..299f2fe0 --- /dev/null +++ b/testdata/result/statement/create_search_index_full.sql.txt @@ -0,0 +1,121 @@ +--- create_search_index_full.sql +CREATE SEARCH INDEX AlbumsIndexFull +ON Albums(Title_Tokens, Studio_Tokens) +STORING(Genre) +PARTITION BY SingerId +ORDER BY ReleaseTimestamp DESC +WHERE Genre IS NOT NULL AND ReleaseTimestamp IS NOT NULL +, INTERLEAVE IN Singers +OPTIONS(sort_order_sharding=true) +--- AST +&ast.CreateSearchIndex{ + Create: 0, + Name: &ast.Ident{ + NamePos: 20, + NameEnd: 35, + Name: "AlbumsIndexFull", + }, + TableName: &ast.Ident{ + NamePos: 39, + NameEnd: 45, + Name: "Albums", + }, + TokenListPart: []*ast.Ident{ + &ast.Ident{ + NamePos: 46, + NameEnd: 58, + Name: "Title_Tokens", + }, + &ast.Ident{ + NamePos: 60, + NameEnd: 73, + Name: "Studio_Tokens", + }, + }, + Rparen: 73, + Storing: &ast.Storing{ + Storing: 75, + Rparen: 88, + Columns: []*ast.Ident{ + &ast.Ident{ + NamePos: 83, + NameEnd: 88, + Name: "Genre", + }, + }, + }, + PartitionColumns: []*ast.Ident{ + &ast.Ident{ + NamePos: 103, + NameEnd: 111, + Name: "SingerId", + }, + }, + OrderBy: &ast.OrderBy{ + Order: 112, + Items: []*ast.OrderByItem{ + &ast.OrderByItem{ + DirPos: 138, + Expr: &ast.Ident{ + NamePos: 121, + NameEnd: 137, + Name: "ReleaseTimestamp", + }, + Collate: (*ast.Collate)(nil), + Dir: "DESC", + }, + }, + }, + Where: &ast.Where{ + Where: 143, + Expr: &ast.BinaryExpr{ + Op: "AND", + Left: &ast.IsNullExpr{ + Null: 162, + Not: true, + Left: &ast.Ident{ + NamePos: 149, + NameEnd: 154, + Name: "Genre", + }, + }, + Right: &ast.IsNullExpr{ + Null: 195, + Not: true, + Left: &ast.Ident{ + NamePos: 171, + NameEnd: 187, + Name: "ReleaseTimestamp", + }, + }, + }, + }, + Interleave: &ast.InterleaveIn{ + Comma: 200, + TableName: &ast.Ident{ + NamePos: 216, + NameEnd: 223, + Name: "Singers", + }, + }, + Options: &ast.Options{ + Options: 224, + Rparen: 256, + Records: []*ast.OptionsDef{ + &ast.OptionsDef{ + Name: &ast.Ident{ + NamePos: 232, + NameEnd: 251, + Name: "sort_order_sharding", + }, + Value: &ast.BoolLiteral{ + ValuePos: 252, + Value: true, + }, + }, + }, + }, +} + +--- SQL +CREATE SEARCH INDEX AlbumsIndexFull ON Albums(Title_Tokens, Studio_Tokens) STORING (Genre) PARTITION BY SingerId ORDER BY ReleaseTimestamp DESC WHERE Genre IS NOT NULL AND ReleaseTimestamp IS NOT NULL, INTERLEAVE IN Singers OPTIONS (sort_order_sharding = true) diff --git a/testdata/result/statement/create_search_index_null_filtered.sql.txt b/testdata/result/statement/create_search_index_null_filtered.sql.txt new file mode 100644 index 00000000..f1fab7c1 --- /dev/null +++ b/testdata/result/statement/create_search_index_null_filtered.sql.txt @@ -0,0 +1,57 @@ +--- create_search_index_null_filtered.sql +CREATE SEARCH INDEX AlbumsIndex +ON Albums(AlbumTitle_Tokens) +STORING(Genre) +WHERE Genre IS NOT NULL +--- AST +&ast.CreateSearchIndex{ + Create: 0, + Name: &ast.Ident{ + NamePos: 20, + NameEnd: 31, + Name: "AlbumsIndex", + }, + TableName: &ast.Ident{ + NamePos: 35, + NameEnd: 41, + Name: "Albums", + }, + TokenListPart: []*ast.Ident{ + &ast.Ident{ + NamePos: 42, + NameEnd: 59, + Name: "AlbumTitle_Tokens", + }, + }, + Rparen: 59, + Storing: &ast.Storing{ + Storing: 61, + Rparen: 74, + Columns: []*ast.Ident{ + &ast.Ident{ + NamePos: 69, + NameEnd: 74, + Name: "Genre", + }, + }, + }, + PartitionColumns: []*ast.Ident(nil), + OrderBy: (*ast.OrderBy)(nil), + Where: &ast.Where{ + Where: 76, + Expr: &ast.IsNullExpr{ + Null: 95, + Not: true, + Left: &ast.Ident{ + NamePos: 82, + NameEnd: 87, + Name: "Genre", + }, + }, + }, + Interleave: (*ast.InterleaveIn)(nil), + Options: (*ast.Options)(nil), +} + +--- SQL +CREATE SEARCH INDEX AlbumsIndex ON Albums(AlbumTitle_Tokens) STORING (Genre) WHERE Genre IS NOT NULL diff --git a/testdata/result/statement/create_search_index_simple.sql.txt b/testdata/result/statement/create_search_index_simple.sql.txt new file mode 100644 index 00000000..60072aa5 --- /dev/null +++ b/testdata/result/statement/create_search_index_simple.sql.txt @@ -0,0 +1,35 @@ +--- create_search_index_simple.sql +-- no optional clauses +CREATE SEARCH INDEX AlbumsIndex + ON Albums(AlbumTitle_Tokens) +--- AST +&ast.CreateSearchIndex{ + Create: 23, + Name: &ast.Ident{ + NamePos: 43, + NameEnd: 54, + Name: "AlbumsIndex", + }, + TableName: &ast.Ident{ + NamePos: 60, + NameEnd: 66, + Name: "Albums", + }, + TokenListPart: []*ast.Ident{ + &ast.Ident{ + NamePos: 67, + NameEnd: 84, + Name: "AlbumTitle_Tokens", + }, + }, + Rparen: 84, + Storing: (*ast.Storing)(nil), + PartitionColumns: []*ast.Ident(nil), + OrderBy: (*ast.OrderBy)(nil), + Where: (*ast.Where)(nil), + Interleave: (*ast.InterleaveIn)(nil), + Options: (*ast.Options)(nil), +} + +--- SQL +CREATE SEARCH INDEX AlbumsIndex ON Albums(AlbumTitle_Tokens) diff --git a/testdata/result/statement/create_table.sql.txt b/testdata/result/statement/create_table.sql.txt index 09c6c3df..5cbba1fa 100644 --- a/testdata/result/statement/create_table.sql.txt +++ b/testdata/result/statement/create_table.sql.txt @@ -39,6 +39,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -55,6 +56,7 @@ create table foo ( NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -79,6 +81,7 @@ create table foo ( NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: &ast.Options{ Options: 83, Rparen: 120, @@ -120,6 +123,7 @@ create table foo ( GeneratedExpr: &ast.GeneratedColumnExpr{ As: 150, Stored: 172, + Rparen: 170, Expr: &ast.CallExpr{ Rparen: 169, Func: &ast.Ident{ @@ -149,6 +153,7 @@ create table foo ( Having: nil, }, }, + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -165,6 +170,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -197,6 +203,7 @@ create table foo ( }, }, GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/create_table_cluster.sql.txt b/testdata/result/statement/create_table_cluster.sql.txt index b1f4a5c6..0d6a5d57 100644 --- a/testdata/result/statement/create_table_cluster.sql.txt +++ b/testdata/result/statement/create_table_cluster.sql.txt @@ -30,6 +30,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -46,6 +47,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/create_table_cluster_and_row_deletion_policy.sql.txt b/testdata/result/statement/create_table_cluster_and_row_deletion_policy.sql.txt index c9501c97..e27a41de 100644 --- a/testdata/result/statement/create_table_cluster_and_row_deletion_policy.sql.txt +++ b/testdata/result/statement/create_table_cluster_and_row_deletion_policy.sql.txt @@ -32,6 +32,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -48,6 +49,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -64,6 +66,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/create_table_cluster_on_delete_no_action.sql.txt b/testdata/result/statement/create_table_cluster_on_delete_no_action.sql.txt index 1b3868f6..7681612b 100644 --- a/testdata/result/statement/create_table_cluster_on_delete_no_action.sql.txt +++ b/testdata/result/statement/create_table_cluster_on_delete_no_action.sql.txt @@ -29,6 +29,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/create_table_cluster_set_on_delete.sql.txt b/testdata/result/statement/create_table_cluster_set_on_delete.sql.txt index 7ba4d258..56a2e62d 100644 --- a/testdata/result/statement/create_table_cluster_set_on_delete.sql.txt +++ b/testdata/result/statement/create_table_cluster_set_on_delete.sql.txt @@ -29,6 +29,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/create_table_fulltext_albums.sql.txt b/testdata/result/statement/create_table_fulltext_albums.sql.txt new file mode 100644 index 00000000..26d125f3 --- /dev/null +++ b/testdata/result/statement/create_table_fulltext_albums.sql.txt @@ -0,0 +1,217 @@ +--- create_table_fulltext_albums.sql +-- https://cloud.google.com/spanner/docs/full-text-search/search-indexes#search-index-schema-definitions +CREATE TABLE Albums ( + AlbumId STRING(MAX) NOT NULL, + SingerId INT64 NOT NULL, + ReleaseTimestamp INT64 NOT NULL, + AlbumTitle STRING(MAX), + Rating FLOAT64, + AlbumTitle_Tokens TOKENLIST AS (TOKENIZE_FULLTEXT(AlbumTitle)) HIDDEN, + Rating_Tokens TOKENLIST AS (TOKENIZE_NUMBER(Rating)) HIDDEN +) PRIMARY KEY(AlbumId) +--- AST +&ast.CreateTable{ + Create: 105, + Rparen: 575, + IfNotExists: false, + Name: &ast.Ident{ + NamePos: 118, + NameEnd: 124, + Name: "Albums", + }, + Columns: []*ast.ColumnDef{ + &ast.ColumnDef{ + Null: 175, + Name: &ast.Ident{ + NamePos: 151, + NameEnd: 158, + Name: "AlbumId", + }, + Type: &ast.SizedSchemaType{ + NamePos: 159, + Rparen: 169, + Name: "STRING", + Max: true, + Size: nil, + }, + NotNull: true, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, + Options: (*ast.Options)(nil), + }, + &ast.ColumnDef{ + Null: 224, + Name: &ast.Ident{ + NamePos: 205, + NameEnd: 213, + Name: "SingerId", + }, + Type: &ast.ScalarSchemaType{ + NamePos: 214, + Name: "INT64", + }, + NotNull: true, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, + Options: (*ast.Options)(nil), + }, + &ast.ColumnDef{ + Null: 281, + Name: &ast.Ident{ + NamePos: 254, + NameEnd: 270, + Name: "ReleaseTimestamp", + }, + Type: &ast.ScalarSchemaType{ + NamePos: 271, + Name: "INT64", + }, + NotNull: true, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, + Options: (*ast.Options)(nil), + }, + &ast.ColumnDef{ + Null: -1, + Name: &ast.Ident{ + NamePos: 311, + NameEnd: 321, + Name: "AlbumTitle", + }, + Type: &ast.SizedSchemaType{ + NamePos: 322, + Rparen: 332, + Name: "STRING", + Max: true, + Size: nil, + }, + NotNull: false, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, + Options: (*ast.Options)(nil), + }, + &ast.ColumnDef{ + Null: -1, + Name: &ast.Ident{ + NamePos: 359, + NameEnd: 365, + Name: "Rating", + }, + Type: &ast.ScalarSchemaType{ + NamePos: 366, + Name: "FLOAT64", + }, + NotNull: false, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, + Options: (*ast.Options)(nil), + }, + &ast.ColumnDef{ + Null: -1, + Name: &ast.Ident{ + NamePos: 399, + NameEnd: 416, + Name: "AlbumTitle_Tokens", + }, + Type: &ast.ScalarSchemaType{ + NamePos: 417, + Name: "TOKENLIST", + }, + NotNull: false, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: &ast.GeneratedColumnExpr{ + As: 427, + Stored: -1, + Rparen: 460, + Expr: &ast.CallExpr{ + Rparen: 459, + Func: &ast.Ident{ + NamePos: 431, + NameEnd: 448, + Name: "TOKENIZE_FULLTEXT", + }, + Distinct: false, + Args: []ast.Arg{ + &ast.ExprArg{ + Expr: &ast.Ident{ + NamePos: 449, + NameEnd: 459, + Name: "AlbumTitle", + }, + }, + }, + NamedArgs: []*ast.NamedArg(nil), + NullHandling: nil, + Having: nil, + }, + }, + Hidden: 462, + Options: (*ast.Options)(nil), + }, + &ast.ColumnDef{ + Null: -1, + Name: &ast.Ident{ + NamePos: 494, + NameEnd: 507, + Name: "Rating_Tokens", + }, + Type: &ast.ScalarSchemaType{ + NamePos: 508, + Name: "TOKENLIST", + }, + NotNull: false, + DefaultExpr: (*ast.ColumnDefaultExpr)(nil), + GeneratedExpr: &ast.GeneratedColumnExpr{ + As: 518, + Stored: -1, + Rparen: 545, + Expr: &ast.CallExpr{ + Rparen: 544, + Func: &ast.Ident{ + NamePos: 522, + NameEnd: 537, + Name: "TOKENIZE_NUMBER", + }, + Distinct: false, + Args: []ast.Arg{ + &ast.ExprArg{ + Expr: &ast.Ident{ + NamePos: 538, + NameEnd: 544, + Name: "Rating", + }, + }, + }, + NamedArgs: []*ast.NamedArg(nil), + NullHandling: nil, + Having: nil, + }, + }, + Hidden: 547, + Options: (*ast.Options)(nil), + }, + }, + TableConstraints: []*ast.TableConstraint(nil), + PrimaryKeys: []*ast.IndexKey{ + &ast.IndexKey{ + DirPos: -1, + Name: &ast.Ident{ + NamePos: 568, + NameEnd: 575, + Name: "AlbumId", + }, + Dir: "", + }, + }, + Synonyms: []*ast.Synonym(nil), + Cluster: (*ast.Cluster)(nil), + RowDeletionPolicy: (*ast.CreateRowDeletionPolicy)(nil), +} + +--- SQL +CREATE TABLE Albums (AlbumId STRING(MAX) NOT NULL, SingerId INT64 NOT NULL, ReleaseTimestamp INT64 NOT NULL, AlbumTitle STRING(MAX), Rating FLOAT64, AlbumTitle_Tokens TOKENLIST AS (TOKENIZE_FULLTEXT(AlbumTitle)) HIDDEN, Rating_Tokens TOKENLIST AS (TOKENIZE_NUMBER(Rating)) HIDDEN) PRIMARY KEY (AlbumId) diff --git a/testdata/result/statement/create_table_if_not_exists.sql.txt b/testdata/result/statement/create_table_if_not_exists.sql.txt index 4ceac8b2..a3bce8e1 100644 --- a/testdata/result/statement/create_table_if_not_exists.sql.txt +++ b/testdata/result/statement/create_table_if_not_exists.sql.txt @@ -29,6 +29,7 @@ create table if not exists foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -45,6 +46,7 @@ create table if not exists foo ( NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/create_table_row_deletion_policy.sql.txt b/testdata/result/statement/create_table_row_deletion_policy.sql.txt index 99b12727..c528214d 100644 --- a/testdata/result/statement/create_table_row_deletion_policy.sql.txt +++ b/testdata/result/statement/create_table_row_deletion_policy.sql.txt @@ -31,6 +31,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -47,6 +48,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -63,6 +65,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/create_table_synonyms.sql.txt b/testdata/result/statement/create_table_synonyms.sql.txt index 3a34aa0c..9264d6f8 100644 --- a/testdata/result/statement/create_table_synonyms.sql.txt +++ b/testdata/result/statement/create_table_synonyms.sql.txt @@ -29,6 +29,7 @@ CREATE TABLE Singers ( NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -53,6 +54,7 @@ CREATE TABLE Singers ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/create_table_synonyms_abnormal.sql.txt b/testdata/result/statement/create_table_synonyms_abnormal.sql.txt index 887f578a..412d563e 100644 --- a/testdata/result/statement/create_table_synonyms_abnormal.sql.txt +++ b/testdata/result/statement/create_table_synonyms_abnormal.sql.txt @@ -31,6 +31,7 @@ CREATE TABLE Singers ( NotNull: true, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -55,6 +56,7 @@ CREATE TABLE Singers ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/create_table_trailing_comma.sql.txt b/testdata/result/statement/create_table_trailing_comma.sql.txt index 6bfa977d..8bded18d 100644 --- a/testdata/result/statement/create_table_trailing_comma.sql.txt +++ b/testdata/result/statement/create_table_trailing_comma.sql.txt @@ -32,6 +32,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -48,6 +49,7 @@ create table foo ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/create_table_types.sql.txt b/testdata/result/statement/create_table_types.sql.txt index 7287c937..ee439007 100644 --- a/testdata/result/statement/create_table_types.sql.txt +++ b/testdata/result/statement/create_table_types.sql.txt @@ -40,6 +40,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -56,6 +57,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -72,6 +74,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -88,6 +91,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -104,6 +108,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -120,6 +125,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -144,6 +150,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -163,6 +170,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -187,6 +195,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -206,6 +215,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -226,6 +236,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -249,6 +260,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -275,6 +287,7 @@ create table types ( NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/create_table_with_sequence_function.sql.txt b/testdata/result/statement/create_table_with_sequence_function.sql.txt index 89610eda..0aea0698 100644 --- a/testdata/result/statement/create_table_with_sequence_function.sql.txt +++ b/testdata/result/statement/create_table_with_sequence_function.sql.txt @@ -56,6 +56,7 @@ CREATE TABLE foo }, }, GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -75,6 +76,7 @@ CREATE TABLE foo NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, &ast.ColumnDef{ @@ -91,6 +93,7 @@ CREATE TABLE foo NotNull: false, DefaultExpr: (*ast.ColumnDefaultExpr)(nil), GeneratedExpr: (*ast.GeneratedColumnExpr)(nil), + Hidden: -1, Options: (*ast.Options)(nil), }, }, diff --git a/testdata/result/statement/drop_search_index.sql.txt b/testdata/result/statement/drop_search_index.sql.txt new file mode 100644 index 00000000..fe6d374c --- /dev/null +++ b/testdata/result/statement/drop_search_index.sql.txt @@ -0,0 +1,15 @@ +--- drop_search_index.sql +DROP SEARCH INDEX IF EXISTS AlbumsIndex +--- AST +&ast.DropSearchIndex{ + Drop: 0, + IfExists: true, + Name: &ast.Ident{ + NamePos: 28, + NameEnd: 39, + Name: "AlbumsIndex", + }, +} + +--- SQL +DROP SEARCH INDEX IF EXISTS AlbumsIndex diff --git a/token/file.go b/token/file.go index 0d08fe5f..e4dd17be 100644 --- a/token/file.go +++ b/token/file.go @@ -18,6 +18,14 @@ func (p Pos) Invalid() bool { return p < 0 } +// Add returns Pos + offset, or InvalidPos if Pos.Invalid(). +func (p Pos) Add(offset int) Pos { + if p.Invalid() { + return InvalidPos + } + return p + Pos(offset) +} + // Position is source code position with file path // and source code around this position. type Position struct {