From c91334c943398ff4ff81edf4b82e325f45ae310d Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Dec 2026 05:29:27 +0000 Subject: [PATCH] Fix nested comments, non-reserved keywords as names, xml .query(), MERGE USING VALUES - Lexer: block comments nest, so /* a /* b */ c */ is one comment (#66) - Accept non-reserved keywords (MESSAGE, TYPE, QUERY, PASSWORD, ...) as column names in expressions, INSERT column lists, SET clauses and as method names after a dot (#65, #67) - MERGE ... USING (VALUES ...) AS alias (cols) parses as an InlineDerivedTable (#64) Golden ast.json files generated with TsqlAstParser. Fixes #64 Fixes #65 Fixes #66 Fixes #67 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LuRZ4JrivjQabmGfjNqrzq --- parser/lexer.go | 36 +- parser/marshal.go | 5 +- parser/parse_dml.go | 2 +- parser/parse_select.go | 13 +- parser/testdata/MergeUsingValues/ast.json | 1006 +++++++++++ .../testdata/MergeUsingValues/metadata.json | 1 + parser/testdata/MergeUsingValues/query.sql | 11 + parser/testdata/NestedBlockComments/ast.json | 242 +++ .../NestedBlockComments/metadata.json | 1 + parser/testdata/NestedBlockComments/query.sql | 4 + .../NonReservedKeywordsAsColumns/ast.json | 1548 +++++++++++++++++ .../metadata.json | 1 + .../NonReservedKeywordsAsColumns/query.sql | 7 + parser/testdata/XmlQueryMethod/ast.json | 620 +++++++ parser/testdata/XmlQueryMethod/metadata.json | 1 + parser/testdata/XmlQueryMethod/query.sql | 4 + 16 files changed, 3494 insertions(+), 8 deletions(-) create mode 100644 parser/testdata/MergeUsingValues/ast.json create mode 100644 parser/testdata/MergeUsingValues/metadata.json create mode 100644 parser/testdata/MergeUsingValues/query.sql create mode 100644 parser/testdata/NestedBlockComments/ast.json create mode 100644 parser/testdata/NestedBlockComments/metadata.json create mode 100644 parser/testdata/NestedBlockComments/query.sql create mode 100644 parser/testdata/NonReservedKeywordsAsColumns/ast.json create mode 100644 parser/testdata/NonReservedKeywordsAsColumns/metadata.json create mode 100644 parser/testdata/NonReservedKeywordsAsColumns/query.sql create mode 100644 parser/testdata/XmlQueryMethod/ast.json create mode 100644 parser/testdata/XmlQueryMethod/metadata.json create mode 100644 parser/testdata/XmlQueryMethod/query.sql diff --git a/parser/lexer.go b/parser/lexer.go index b3ef3bd7..ba21d154 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -607,11 +607,24 @@ func (l *Lexer) skipWhitespaceAndComments() { if l.ch == '/' && l.peekChar() == '*' { l.readChar() // skip / l.readChar() // skip * + // T-SQL block comments nest: track depth so an inner /* ... */ + // does not terminate the outer comment. + depth := 1 for l.ch != 0 { + if l.ch == '/' && l.peekChar() == '*' { + l.readChar() + l.readChar() + depth++ + continue + } if l.ch == '*' && l.peekChar() == '/' { l.readChar() // skip * l.readChar() // skip / - break + depth-- + if depth == 0 { + break + } + continue } l.readChar() } @@ -1077,3 +1090,24 @@ func lookupKeyword(ident string) TokenType { } return TokenIdent } + +// isNonReservedKeyword reports whether t is a keyword token for a word that is +// not a reserved keyword in T-SQL. The lexer gives these words their own token +// types because some statements use them as contextual keywords (for example +// MESSAGE in Service Broker statements), but SQL Server accepts them unquoted +// as column, table and method names. +func isNonReservedKeyword(t TokenType) bool { + switch t { + case TokenCookie, TokenScoped, TokenCredential, TokenTies, TokenRollup, + TokenCube, TokenTry, TokenCatch, TokenNowait, TokenFast, TokenMaxdop, + TokenWork, TokenDelay, TokenTime, TokenMaster, TokenEncryption, + TokenPassword, TokenMove, TokenConversation, TokenDialog, TokenGet, + TokenOverride, TokenStatusonly, TokenNoreset, TokenSend, TokenMessage, + TokenTyp, TokenReceive, TokenLogin, TokenCaller, TokenNoRevert, + TokenLanguage, TokenFilestream, TokenReturns, TokenSymmetric, + TokenAsymmetric, TokenStats, TokenJob, TokenQuery, TokenNotification, + TokenSubscription, TokenDecryption, TokenCertificate: + return true + } + return false +} diff --git a/parser/marshal.go b/parser/marshal.go index 936b9e2e..9ae49d55 100644 --- a/parser/marshal.go +++ b/parser/marshal.go @@ -6740,8 +6740,9 @@ func (p *Parser) parseMergeSourceTableReference() (ast.TableReference, error) { // Check for parenthesized expression if p.curTok.Type == TokenLParen { // Check if this is a derived table (subquery) or a join - if p.peekTok.Type == TokenSelect { - // This is a derived table like (SELECT ...) AS alias + if p.peekTok.Type == TokenSelect || p.peekTok.Type == TokenValues { + // This is a derived table like (SELECT ...) AS alias, or an + // inline derived table like (VALUES (...)) AS alias (cols) spanV2, spanErr2 := p.parseDerivedTableReference() return spanned(p, spanV2, astStart), spanErr2 } diff --git a/parser/parse_dml.go b/parser/parse_dml.go index d709c199..9b993c4b 100644 --- a/parser/parse_dml.go +++ b/parser/parse_dml.go @@ -1251,7 +1251,7 @@ func (p *Parser) parseMultiPartIdentifierAsColumn() (*ast.ColumnReferenceExpress continue } - if p.curTok.Type != TokenIdent { + if p.curTok.Type != TokenIdent && !isNonReservedKeyword(p.curTok.Type) { break } diff --git a/parser/parse_select.go b/parser/parse_select.go index 4c7c359b..a7d0c618 100644 --- a/parser/parse_select.go +++ b/parser/parse_select.go @@ -847,7 +847,7 @@ func (p *Parser) isKeywordAsIdentifier() bool { TokenTyp, TokenScoped: return true default: - return false + return isNonReservedKeyword(p.curTok.Type) } } @@ -1054,7 +1054,7 @@ func (p *Parser) parsePostfixExpression() (ast.ScalarExpression, error) { for { // Check for method/property access: expr.func() or expr.prop // The next token after the dot must be an identifier (plain or bracketed) - if p.curTok.Type == TokenDot && (p.peekTok.Type == TokenIdent || (len(p.peekTok.Literal) > 0 && p.peekTok.Literal[0] == '[')) { + if p.curTok.Type == TokenDot && (p.peekTok.Type == TokenIdent || isNonReservedKeyword(p.peekTok.Type) || (len(p.peekTok.Literal) > 0 && p.peekTok.Literal[0] == '[')) { p.nextToken() // consume dot if !p.isIdentifierToken() { @@ -1161,7 +1161,7 @@ func (p *Parser) parsePostfixExpression() (ast.ScalarExpression, error) { func (p *Parser) handlePostfixOperations(expr ast.ScalarExpression) (ast.ScalarExpression, error) { for { // Check for method/property access: expr.func() or expr.prop - if p.curTok.Type == TokenDot && (p.peekTok.Type == TokenIdent || (len(p.peekTok.Literal) > 0 && p.peekTok.Literal[0] == '[')) { + if p.curTok.Type == TokenDot && (p.peekTok.Type == TokenIdent || isNonReservedKeyword(p.peekTok.Type) || (len(p.peekTok.Literal) > 0 && p.peekTok.Literal[0] == '[')) { p.nextToken() // consume dot // Check for bracket-quoted identifier or regular identifier token @@ -1535,6 +1535,11 @@ func (p *Parser) parsePrimaryExpression() (ast.ScalarExpression, error) { spanV21, spanErr21 := p.parseColumnReferenceOrFunctionCall() return spanned(p, spanV21, astStart), spanErr21 default: + if isNonReservedKeyword(p.curTok.Type) { + // Non-reserved keywords (MESSAGE, TYPE, QUERY, ...) are valid column names + spanV, spanErr := p.parseColumnReferenceOrFunctionCall() + return spanned(p, spanV, astStart), spanErr + } return nil, fmt.Errorf("unexpected token in expression: %s", p.curTok.Literal) } } @@ -1981,7 +1986,7 @@ func (p *Parser) isIdentifierToken() bool { TokenTime: return true default: - return false + return isNonReservedKeyword(p.curTok.Type) } } diff --git a/parser/testdata/MergeUsingValues/ast.json b/parser/testdata/MergeUsingValues/ast.json new file mode 100644 index 00000000..ed404b25 --- /dev/null +++ b/parser/testdata/MergeUsingValues/ast.json @@ -0,0 +1,1006 @@ +{ + "$type": "TSqlScript", + "StartOffset": 0, + "FragmentLength": 497, + "StartLine": 1, + "StartColumn": 1, + "Batches": [ + { + "$type": "TSqlBatch", + "StartOffset": 0, + "FragmentLength": 496, + "StartLine": 1, + "StartColumn": 1, + "Statements": [ + { + "$type": "MergeStatement", + "StartOffset": 0, + "FragmentLength": 228, + "StartLine": 1, + "StartColumn": 1, + "MergeSpecification": { + "$type": "MergeSpecification", + "StartOffset": 0, + "FragmentLength": 227, + "StartLine": 1, + "StartColumn": 1, + "TableAlias": { + "$type": "Identifier", + "StartOffset": 22, + "FragmentLength": 6, + "StartLine": 1, + "StartColumn": 23, + "Value": "target", + "QuoteType": "NotQuoted" + }, + "TableReference": { + "$type": "InlineDerivedTable", + "StartOffset": 35, + "FragmentLength": 43, + "StartLine": 2, + "StartColumn": 7, + "RowValues": [ + { + "$type": "RowValue", + "StartOffset": 43, + "FragmentLength": 12, + "StartLine": 2, + "StartColumn": 15, + "ColumnValues": [ + { + "$type": "StringLiteral", + "StartOffset": 44, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 16, + "LiteralType": "String", + "IsNational": true, + "IsLargeObject": false, + "Value": "a" + }, + { + "$type": "StringLiteral", + "StartOffset": 50, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 22, + "LiteralType": "String", + "IsNational": true, + "IsLargeObject": false, + "Value": "b" + } + ] + } + ], + "Columns": [ + { + "$type": "Identifier", + "StartOffset": 68, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 40, + "Value": "name", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 74, + "FragmentLength": 3, + "StartLine": 2, + "StartColumn": 46, + "Value": "bio", + "QuoteType": "NotQuoted" + } + ], + "Alias": { + "$type": "Identifier", + "StartOffset": 60, + "FragmentLength": 6, + "StartLine": 2, + "StartColumn": 32, + "Value": "source", + "QuoteType": "NotQuoted" + }, + "ForPath": false + }, + "SearchCondition": { + "$type": "BooleanComparisonExpression", + "StartOffset": 82, + "FragmentLength": 25, + "StartLine": 3, + "StartColumn": 4, + "ComparisonType": "Equals", + "FirstExpression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 82, + "FragmentLength": 11, + "StartLine": 3, + "StartColumn": 4, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 82, + "FragmentLength": 11, + "StartLine": 3, + "StartColumn": 4, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 82, + "FragmentLength": 6, + "StartLine": 3, + "StartColumn": 4, + "Value": "target", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 89, + "FragmentLength": 4, + "StartLine": 3, + "StartColumn": 11, + "Value": "name", + "QuoteType": "NotQuoted" + } + ] + } + }, + "SecondExpression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 96, + "FragmentLength": 11, + "StartLine": 3, + "StartColumn": 18, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 96, + "FragmentLength": 11, + "StartLine": 3, + "StartColumn": 18, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 96, + "FragmentLength": 6, + "StartLine": 3, + "StartColumn": 18, + "Value": "source", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 103, + "FragmentLength": 4, + "StartLine": 3, + "StartColumn": 25, + "Value": "name", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + "ActionClauses": [ + { + "$type": "MergeActionClause", + "StartOffset": 126, + "FragmentLength": 27, + "StartLine": 4, + "StartColumn": 19, + "Condition": "Matched", + "Action": { + "$type": "UpdateMergeAction", + "StartOffset": 126, + "FragmentLength": 27, + "StartLine": 4, + "StartColumn": 19, + "SetClauses": [ + { + "$type": "AssignmentSetClause", + "StartOffset": 137, + "FragmentLength": 16, + "StartLine": 4, + "StartColumn": 30, + "Column": { + "$type": "ColumnReferenceExpression", + "StartOffset": 137, + "FragmentLength": 3, + "StartLine": 4, + "StartColumn": 30, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 137, + "FragmentLength": 3, + "StartLine": 4, + "StartColumn": 30, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 137, + "FragmentLength": 3, + "StartLine": 4, + "StartColumn": 30, + "Value": "bio", + "QuoteType": "NotQuoted" + } + ] + } + }, + "NewValue": { + "$type": "ColumnReferenceExpression", + "StartOffset": 143, + "FragmentLength": 10, + "StartLine": 4, + "StartColumn": 36, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 143, + "FragmentLength": 10, + "StartLine": 4, + "StartColumn": 36, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 143, + "FragmentLength": 6, + "StartLine": 4, + "StartColumn": 36, + "Value": "source", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 150, + "FragmentLength": 3, + "StartLine": 4, + "StartColumn": 43, + "Value": "bio", + "QuoteType": "NotQuoted" + } + ] + } + }, + "AssignmentKind": "Equals" + } + ] + } + }, + { + "$type": "MergeActionClause", + "StartOffset": 176, + "FragmentLength": 51, + "StartLine": 5, + "StartColumn": 23, + "Condition": "NotMatched", + "Action": { + "$type": "InsertMergeAction", + "StartOffset": 176, + "FragmentLength": 51, + "StartLine": 5, + "StartColumn": 23, + "Columns": [ + { + "$type": "ColumnReferenceExpression", + "StartOffset": 184, + "FragmentLength": 4, + "StartLine": 5, + "StartColumn": 31, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 184, + "FragmentLength": 4, + "StartLine": 5, + "StartColumn": 31, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 184, + "FragmentLength": 4, + "StartLine": 5, + "StartColumn": 31, + "Value": "name", + "QuoteType": "NotQuoted" + } + ] + } + }, + { + "$type": "ColumnReferenceExpression", + "StartOffset": 190, + "FragmentLength": 3, + "StartLine": 5, + "StartColumn": 37, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 190, + "FragmentLength": 3, + "StartLine": 5, + "StartColumn": 37, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 190, + "FragmentLength": 3, + "StartLine": 5, + "StartColumn": 37, + "Value": "bio", + "QuoteType": "NotQuoted" + } + ] + } + } + ], + "Source": { + "$type": "ValuesInsertSource", + "StartOffset": 195, + "FragmentLength": 32, + "StartLine": 5, + "StartColumn": 42, + "IsDefaultValues": false, + "RowValues": [ + { + "$type": "RowValue", + "StartOffset": 202, + "FragmentLength": 25, + "StartLine": 5, + "StartColumn": 49, + "ColumnValues": [ + { + "$type": "ColumnReferenceExpression", + "StartOffset": 203, + "FragmentLength": 11, + "StartLine": 5, + "StartColumn": 50, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 203, + "FragmentLength": 11, + "StartLine": 5, + "StartColumn": 50, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 203, + "FragmentLength": 6, + "StartLine": 5, + "StartColumn": 50, + "Value": "source", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 210, + "FragmentLength": 4, + "StartLine": 5, + "StartColumn": 57, + "Value": "name", + "QuoteType": "NotQuoted" + } + ] + } + }, + { + "$type": "ColumnReferenceExpression", + "StartOffset": 216, + "FragmentLength": 10, + "StartLine": 5, + "StartColumn": 63, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 216, + "FragmentLength": 10, + "StartLine": 5, + "StartColumn": 63, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 216, + "FragmentLength": 6, + "StartLine": 5, + "StartColumn": 63, + "Value": "source", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 223, + "FragmentLength": 3, + "StartLine": 5, + "StartColumn": 70, + "Value": "bio", + "QuoteType": "NotQuoted" + } + ] + } + } + ] + } + ] + } + } + } + ], + "Target": { + "$type": "NamedTableReference", + "StartOffset": 11, + "FragmentLength": 7, + "StartLine": 1, + "StartColumn": 12, + "SchemaObject": { + "$type": "SchemaObjectName", + "StartOffset": 11, + "FragmentLength": 7, + "StartLine": 1, + "StartColumn": 12, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 11, + "FragmentLength": 7, + "StartLine": 1, + "StartColumn": 12, + "Value": "authors", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + }, + "ForPath": false + } + } + }, + { + "$type": "MergeStatement", + "StartOffset": 229, + "FragmentLength": 267, + "StartLine": 6, + "StartColumn": 1, + "MergeSpecification": { + "$type": "MergeSpecification", + "StartOffset": 229, + "FragmentLength": 266, + "StartLine": 6, + "StartColumn": 1, + "TableAlias": { + "$type": "Identifier", + "StartOffset": 251, + "FragmentLength": 6, + "StartLine": 6, + "StartColumn": 23, + "Value": "target", + "QuoteType": "NotQuoted" + }, + "TableReference": { + "$type": "InlineDerivedTable", + "StartOffset": 264, + "FragmentLength": 44, + "StartLine": 7, + "StartColumn": 7, + "RowValues": [ + { + "$type": "RowValue", + "StartOffset": 272, + "FragmentLength": 13, + "StartLine": 7, + "StartColumn": 15, + "ColumnValues": [ + { + "$type": "VariableReference", + "StartOffset": 273, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 16, + "Name": "@name" + }, + { + "$type": "VariableReference", + "StartOffset": 280, + "FragmentLength": 4, + "StartLine": 7, + "StartColumn": 23, + "Name": "@bio" + } + ] + } + ], + "Columns": [ + { + "$type": "Identifier", + "StartOffset": 298, + "FragmentLength": 4, + "StartLine": 7, + "StartColumn": 41, + "Value": "name", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 304, + "FragmentLength": 3, + "StartLine": 7, + "StartColumn": 47, + "Value": "bio", + "QuoteType": "NotQuoted" + } + ], + "Alias": { + "$type": "Identifier", + "StartOffset": 290, + "FragmentLength": 6, + "StartLine": 7, + "StartColumn": 33, + "Value": "source", + "QuoteType": "NotQuoted" + }, + "ForPath": false + }, + "SearchCondition": { + "$type": "BooleanComparisonExpression", + "StartOffset": 312, + "FragmentLength": 25, + "StartLine": 8, + "StartColumn": 4, + "ComparisonType": "Equals", + "FirstExpression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 312, + "FragmentLength": 11, + "StartLine": 8, + "StartColumn": 4, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 312, + "FragmentLength": 11, + "StartLine": 8, + "StartColumn": 4, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 312, + "FragmentLength": 6, + "StartLine": 8, + "StartColumn": 4, + "Value": "target", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 319, + "FragmentLength": 4, + "StartLine": 8, + "StartColumn": 11, + "Value": "name", + "QuoteType": "NotQuoted" + } + ] + } + }, + "SecondExpression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 326, + "FragmentLength": 11, + "StartLine": 8, + "StartColumn": 18, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 326, + "FragmentLength": 11, + "StartLine": 8, + "StartColumn": 18, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 326, + "FragmentLength": 6, + "StartLine": 8, + "StartColumn": 18, + "Value": "source", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 333, + "FragmentLength": 4, + "StartLine": 8, + "StartColumn": 25, + "Value": "name", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + "ActionClauses": [ + { + "$type": "MergeActionClause", + "StartOffset": 356, + "FragmentLength": 27, + "StartLine": 9, + "StartColumn": 19, + "Condition": "Matched", + "Action": { + "$type": "UpdateMergeAction", + "StartOffset": 356, + "FragmentLength": 27, + "StartLine": 9, + "StartColumn": 19, + "SetClauses": [ + { + "$type": "AssignmentSetClause", + "StartOffset": 367, + "FragmentLength": 16, + "StartLine": 9, + "StartColumn": 30, + "Column": { + "$type": "ColumnReferenceExpression", + "StartOffset": 367, + "FragmentLength": 3, + "StartLine": 9, + "StartColumn": 30, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 367, + "FragmentLength": 3, + "StartLine": 9, + "StartColumn": 30, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 367, + "FragmentLength": 3, + "StartLine": 9, + "StartColumn": 30, + "Value": "bio", + "QuoteType": "NotQuoted" + } + ] + } + }, + "NewValue": { + "$type": "ColumnReferenceExpression", + "StartOffset": 373, + "FragmentLength": 10, + "StartLine": 9, + "StartColumn": 36, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 373, + "FragmentLength": 10, + "StartLine": 9, + "StartColumn": 36, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 373, + "FragmentLength": 6, + "StartLine": 9, + "StartColumn": 36, + "Value": "source", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 380, + "FragmentLength": 3, + "StartLine": 9, + "StartColumn": 43, + "Value": "bio", + "QuoteType": "NotQuoted" + } + ] + } + }, + "AssignmentKind": "Equals" + } + ] + } + }, + { + "$type": "MergeActionClause", + "StartOffset": 406, + "FragmentLength": 51, + "StartLine": 10, + "StartColumn": 23, + "Condition": "NotMatched", + "Action": { + "$type": "InsertMergeAction", + "StartOffset": 406, + "FragmentLength": 51, + "StartLine": 10, + "StartColumn": 23, + "Columns": [ + { + "$type": "ColumnReferenceExpression", + "StartOffset": 414, + "FragmentLength": 4, + "StartLine": 10, + "StartColumn": 31, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 414, + "FragmentLength": 4, + "StartLine": 10, + "StartColumn": 31, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 414, + "FragmentLength": 4, + "StartLine": 10, + "StartColumn": 31, + "Value": "name", + "QuoteType": "NotQuoted" + } + ] + } + }, + { + "$type": "ColumnReferenceExpression", + "StartOffset": 420, + "FragmentLength": 3, + "StartLine": 10, + "StartColumn": 37, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 420, + "FragmentLength": 3, + "StartLine": 10, + "StartColumn": 37, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 420, + "FragmentLength": 3, + "StartLine": 10, + "StartColumn": 37, + "Value": "bio", + "QuoteType": "NotQuoted" + } + ] + } + } + ], + "Source": { + "$type": "ValuesInsertSource", + "StartOffset": 425, + "FragmentLength": 32, + "StartLine": 10, + "StartColumn": 42, + "IsDefaultValues": false, + "RowValues": [ + { + "$type": "RowValue", + "StartOffset": 432, + "FragmentLength": 25, + "StartLine": 10, + "StartColumn": 49, + "ColumnValues": [ + { + "$type": "ColumnReferenceExpression", + "StartOffset": 433, + "FragmentLength": 11, + "StartLine": 10, + "StartColumn": 50, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 433, + "FragmentLength": 11, + "StartLine": 10, + "StartColumn": 50, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 433, + "FragmentLength": 6, + "StartLine": 10, + "StartColumn": 50, + "Value": "source", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 440, + "FragmentLength": 4, + "StartLine": 10, + "StartColumn": 57, + "Value": "name", + "QuoteType": "NotQuoted" + } + ] + } + }, + { + "$type": "ColumnReferenceExpression", + "StartOffset": 446, + "FragmentLength": 10, + "StartLine": 10, + "StartColumn": 63, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 446, + "FragmentLength": 10, + "StartLine": 10, + "StartColumn": 63, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 446, + "FragmentLength": 6, + "StartLine": 10, + "StartColumn": 63, + "Value": "source", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 453, + "FragmentLength": 3, + "StartLine": 10, + "StartColumn": 70, + "Value": "bio", + "QuoteType": "NotQuoted" + } + ] + } + } + ] + } + ] + } + } + } + ], + "Target": { + "$type": "NamedTableReference", + "StartOffset": 240, + "FragmentLength": 7, + "StartLine": 6, + "StartColumn": 12, + "SchemaObject": { + "$type": "SchemaObjectName", + "StartOffset": 240, + "FragmentLength": 7, + "StartLine": 6, + "StartColumn": 12, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 240, + "FragmentLength": 7, + "StartLine": 6, + "StartColumn": 12, + "Value": "authors", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + }, + "ForPath": false + }, + "OutputClause": { + "$type": "OutputClause", + "StartOffset": 458, + "FragmentLength": 37, + "StartLine": 11, + "StartColumn": 1, + "SelectColumns": [ + { + "$type": "SelectScalarExpression", + "StartOffset": 465, + "FragmentLength": 17, + "StartLine": 11, + "StartColumn": 8, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 465, + "FragmentLength": 7, + "StartLine": 11, + "StartColumn": 8, + "ColumnType": "PseudoColumnAction" + }, + "ColumnName": { + "$type": "IdentifierOrValueExpression", + "StartOffset": 476, + "FragmentLength": 6, + "StartLine": 11, + "StartColumn": 19, + "Value": "action", + "Identifier": { + "$type": "Identifier", + "StartOffset": 476, + "FragmentLength": 6, + "StartLine": 11, + "StartColumn": 19, + "Value": "action", + "QuoteType": "NotQuoted" + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 484, + "FragmentLength": 11, + "StartLine": 11, + "StartColumn": 27, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 484, + "FragmentLength": 11, + "StartLine": 11, + "StartColumn": 27, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 484, + "FragmentLength": 11, + "StartLine": 11, + "StartColumn": 27, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 484, + "FragmentLength": 8, + "StartLine": 11, + "StartColumn": 27, + "Value": "INSERTED", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 493, + "FragmentLength": 2, + "StartLine": 11, + "StartColumn": 36, + "Value": "id", + "QuoteType": "NotQuoted" + } + ] + } + } + } + ] + } + } + } + ] + } + ] +} \ No newline at end of file diff --git a/parser/testdata/MergeUsingValues/metadata.json b/parser/testdata/MergeUsingValues/metadata.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/parser/testdata/MergeUsingValues/metadata.json @@ -0,0 +1 @@ +{} diff --git a/parser/testdata/MergeUsingValues/query.sql b/parser/testdata/MergeUsingValues/query.sql new file mode 100644 index 00000000..0deda6c5 --- /dev/null +++ b/parser/testdata/MergeUsingValues/query.sql @@ -0,0 +1,11 @@ +MERGE INTO authors AS target +USING (VALUES (N'a', N'b')) AS source (name, bio) +ON target.name = source.name +WHEN MATCHED THEN UPDATE SET bio = source.bio +WHEN NOT MATCHED THEN INSERT (name, bio) VALUES (source.name, source.bio); +MERGE INTO authors AS target +USING (VALUES (@name, @bio)) AS source (name, bio) +ON target.name = source.name +WHEN MATCHED THEN UPDATE SET bio = source.bio +WHEN NOT MATCHED THEN INSERT (name, bio) VALUES (source.name, source.bio) +OUTPUT $action AS action, INSERTED.id; diff --git a/parser/testdata/NestedBlockComments/ast.json b/parser/testdata/NestedBlockComments/ast.json new file mode 100644 index 00000000..9200afe6 --- /dev/null +++ b/parser/testdata/NestedBlockComments/ast.json @@ -0,0 +1,242 @@ +{ + "$type": "TSqlScript", + "StartOffset": 0, + "FragmentLength": 183, + "StartLine": 1, + "StartColumn": 1, + "Batches": [ + { + "$type": "TSqlBatch", + "StartOffset": 0, + "FragmentLength": 182, + "StartLine": 1, + "StartColumn": 1, + "Statements": [ + { + "$type": "SelectStatement", + "StartOffset": 0, + "FragmentLength": 52, + "StartLine": 1, + "StartColumn": 1, + "QueryExpression": { + "$type": "QuerySpecification", + "StartOffset": 0, + "FragmentLength": 51, + "StartLine": 1, + "StartColumn": 1, + "UniqueRowFilter": "NotSpecified", + "SelectElements": [ + { + "$type": "SelectScalarExpression", + "StartOffset": 7, + "FragmentLength": 44, + "StartLine": 1, + "StartColumn": 8, + "Expression": { + "$type": "IntegerLiteral", + "StartOffset": 7, + "FragmentLength": 1, + "StartLine": 1, + "StartColumn": 8, + "LiteralType": "Integer", + "Value": "1" + }, + "ColumnName": { + "$type": "IdentifierOrValueExpression", + "StartOffset": 48, + "FragmentLength": 3, + "StartLine": 1, + "StartColumn": 49, + "Value": "one", + "Identifier": { + "$type": "Identifier", + "StartOffset": 48, + "FragmentLength": 3, + "StartLine": 1, + "StartColumn": 49, + "Value": "one", + "QuoteType": "NotQuoted" + } + } + } + ] + } + }, + { + "$type": "SelectStatement", + "StartOffset": 53, + "FragmentLength": 129, + "StartLine": 2, + "StartColumn": 1, + "QueryExpression": { + "$type": "QuerySpecification", + "StartOffset": 53, + "FragmentLength": 128, + "StartLine": 2, + "StartColumn": 1, + "UniqueRowFilter": "NotSpecified", + "SelectElements": [ + { + "$type": "SelectScalarExpression", + "StartOffset": 60, + "FragmentLength": 2, + "StartLine": 2, + "StartColumn": 8, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 60, + "FragmentLength": 2, + "StartLine": 2, + "StartColumn": 8, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 60, + "FragmentLength": 2, + "StartLine": 2, + "StartColumn": 8, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 60, + "FragmentLength": 2, + "StartLine": 2, + "StartColumn": 8, + "Value": "id", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 79, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 27, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 79, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 27, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 79, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 27, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 79, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 27, + "Value": "name", + "QuoteType": "NotQuoted" + } + ] + } + } + } + ], + "FromClause": { + "$type": "FromClause", + "StartOffset": 96, + "FragmentLength": 12, + "StartLine": 3, + "StartColumn": 1, + "TableReferences": [ + { + "$type": "NamedTableReference", + "StartOffset": 101, + "FragmentLength": 7, + "StartLine": 3, + "StartColumn": 6, + "SchemaObject": { + "$type": "SchemaObjectName", + "StartOffset": 101, + "FragmentLength": 7, + "StartLine": 3, + "StartColumn": 6, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 101, + "FragmentLength": 7, + "StartLine": 3, + "StartColumn": 6, + "Value": "authors", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + }, + "ForPath": false + } + ] + }, + "WhereClause": { + "$type": "WhereClause", + "StartOffset": 163, + "FragmentLength": 18, + "StartLine": 4, + "StartColumn": 1, + "SearchCondition": { + "$type": "BooleanComparisonExpression", + "StartOffset": 169, + "FragmentLength": 12, + "StartLine": 4, + "StartColumn": 7, + "ComparisonType": "GreaterThan", + "FirstExpression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 169, + "FragmentLength": 2, + "StartLine": 4, + "StartColumn": 7, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 169, + "FragmentLength": 2, + "StartLine": 4, + "StartColumn": 7, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 169, + "FragmentLength": 2, + "StartLine": 4, + "StartColumn": 7, + "Value": "id", + "QuoteType": "NotQuoted" + } + ] + } + }, + "SecondExpression": { + "$type": "VariableReference", + "StartOffset": 174, + "FragmentLength": 7, + "StartLine": 4, + "StartColumn": 12, + "Name": "@min_id" + } + } + } + } + } + ] + } + ] +} \ No newline at end of file diff --git a/parser/testdata/NestedBlockComments/metadata.json b/parser/testdata/NestedBlockComments/metadata.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/parser/testdata/NestedBlockComments/metadata.json @@ -0,0 +1 @@ +{} diff --git a/parser/testdata/NestedBlockComments/query.sql b/parser/testdata/NestedBlockComments/query.sql new file mode 100644 index 00000000..334a67b4 --- /dev/null +++ b/parser/testdata/NestedBlockComments/query.sql @@ -0,0 +1,4 @@ +SELECT 1 /* outer /* inner */ still outer */ AS one; +SELECT id, /* the name */ name -- trailing +FROM authors /* outer /* nested /* deeper */ */ still a comment */ +WHERE id > @min_id; diff --git a/parser/testdata/NonReservedKeywordsAsColumns/ast.json b/parser/testdata/NonReservedKeywordsAsColumns/ast.json new file mode 100644 index 00000000..5925bdac --- /dev/null +++ b/parser/testdata/NonReservedKeywordsAsColumns/ast.json @@ -0,0 +1,1548 @@ +{ + "$type": "TSqlScript", + "StartOffset": 0, + "FragmentLength": 461, + "StartLine": 1, + "StartColumn": 1, + "Batches": [ + { + "$type": "TSqlBatch", + "StartOffset": 0, + "FragmentLength": 460, + "StartLine": 1, + "StartColumn": 1, + "Statements": [ + { + "$type": "CreateTableStatement", + "StartOffset": 0, + "FragmentLength": 81, + "StartLine": 1, + "StartColumn": 1, + "SchemaObjectName": { + "$type": "SchemaObjectName", + "StartOffset": 13, + "FragmentLength": 4, + "StartLine": 1, + "StartColumn": 14, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 13, + "FragmentLength": 4, + "StartLine": 1, + "StartColumn": 14, + "Value": "logs", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + }, + "AsEdge": false, + "AsFileTable": false, + "AsNode": false, + "Definition": { + "$type": "TableDefinition", + "StartOffset": 19, + "FragmentLength": 60, + "StartLine": 1, + "StartColumn": 20, + "ColumnDefinitions": [ + { + "$type": "ColumnDefinition", + "StartOffset": 19, + "FragmentLength": 6, + "StartLine": 1, + "StartColumn": 20, + "IsPersisted": false, + "IsRowGuidCol": false, + "IsHidden": false, + "IsMasked": false, + "ColumnIdentifier": { + "$type": "Identifier", + "StartOffset": 19, + "FragmentLength": 2, + "StartLine": 1, + "StartColumn": 20, + "Value": "id", + "QuoteType": "NotQuoted" + }, + "DataType": { + "$type": "SqlDataTypeReference", + "StartOffset": 22, + "FragmentLength": 3, + "StartLine": 1, + "StartColumn": 23, + "SqlDataTypeOption": "Int", + "Name": { + "$type": "SchemaObjectName", + "StartOffset": 22, + "FragmentLength": 3, + "StartLine": 1, + "StartColumn": 23, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 22, + "FragmentLength": 3, + "StartLine": 1, + "StartColumn": 23, + "Value": "INT", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + } + } + }, + { + "$type": "ColumnDefinition", + "StartOffset": 27, + "FragmentLength": 21, + "StartLine": 1, + "StartColumn": 28, + "IsPersisted": false, + "IsRowGuidCol": false, + "IsHidden": false, + "IsMasked": false, + "ColumnIdentifier": { + "$type": "Identifier", + "StartOffset": 27, + "FragmentLength": 7, + "StartLine": 1, + "StartColumn": 28, + "Value": "message", + "QuoteType": "NotQuoted" + }, + "DataType": { + "$type": "SqlDataTypeReference", + "StartOffset": 35, + "FragmentLength": 13, + "StartLine": 1, + "StartColumn": 36, + "SqlDataTypeOption": "NVarChar", + "Parameters": [ + { + "$type": "IntegerLiteral", + "StartOffset": 44, + "FragmentLength": 3, + "StartLine": 1, + "StartColumn": 45, + "LiteralType": "Integer", + "Value": "200" + } + ], + "Name": { + "$type": "SchemaObjectName", + "StartOffset": 35, + "FragmentLength": 8, + "StartLine": 1, + "StartColumn": 36, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 35, + "FragmentLength": 8, + "StartLine": 1, + "StartColumn": 36, + "Value": "NVARCHAR", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + } + } + }, + { + "$type": "ColumnDefinition", + "StartOffset": 50, + "FragmentLength": 8, + "StartLine": 1, + "StartColumn": 51, + "IsPersisted": false, + "IsRowGuidCol": false, + "IsHidden": false, + "IsMasked": false, + "ColumnIdentifier": { + "$type": "Identifier", + "StartOffset": 50, + "FragmentLength": 4, + "StartLine": 1, + "StartColumn": 51, + "Value": "type", + "QuoteType": "NotQuoted" + }, + "DataType": { + "$type": "SqlDataTypeReference", + "StartOffset": 55, + "FragmentLength": 3, + "StartLine": 1, + "StartColumn": 56, + "SqlDataTypeOption": "Int", + "Name": { + "$type": "SchemaObjectName", + "StartOffset": 55, + "FragmentLength": 3, + "StartLine": 1, + "StartColumn": 56, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 55, + "FragmentLength": 3, + "StartLine": 1, + "StartColumn": 56, + "Value": "INT", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + } + } + }, + { + "$type": "ColumnDefinition", + "StartOffset": 60, + "FragmentLength": 19, + "StartLine": 1, + "StartColumn": 61, + "IsPersisted": false, + "IsRowGuidCol": false, + "IsHidden": false, + "IsMasked": false, + "ColumnIdentifier": { + "$type": "Identifier", + "StartOffset": 60, + "FragmentLength": 5, + "StartLine": 1, + "StartColumn": 61, + "Value": "query", + "QuoteType": "NotQuoted" + }, + "DataType": { + "$type": "SqlDataTypeReference", + "StartOffset": 66, + "FragmentLength": 13, + "StartLine": 1, + "StartColumn": 67, + "SqlDataTypeOption": "NVarChar", + "Parameters": [ + { + "$type": "MaxLiteral", + "StartOffset": 75, + "FragmentLength": 3, + "StartLine": 1, + "StartColumn": 76, + "LiteralType": "Max", + "Value": "MAX" + } + ], + "Name": { + "$type": "SchemaObjectName", + "StartOffset": 66, + "FragmentLength": 8, + "StartLine": 1, + "StartColumn": 67, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 66, + "FragmentLength": 8, + "StartLine": 1, + "StartColumn": 67, + "Value": "NVARCHAR", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + } + } + } + ] + } + }, + { + "$type": "SelectStatement", + "StartOffset": 82, + "FragmentLength": 38, + "StartLine": 2, + "StartColumn": 1, + "QueryExpression": { + "$type": "QuerySpecification", + "StartOffset": 82, + "FragmentLength": 37, + "StartLine": 2, + "StartColumn": 1, + "UniqueRowFilter": "NotSpecified", + "SelectElements": [ + { + "$type": "SelectScalarExpression", + "StartOffset": 89, + "FragmentLength": 7, + "StartLine": 2, + "StartColumn": 8, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 89, + "FragmentLength": 7, + "StartLine": 2, + "StartColumn": 8, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 89, + "FragmentLength": 7, + "StartLine": 2, + "StartColumn": 8, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 89, + "FragmentLength": 7, + "StartLine": 2, + "StartColumn": 8, + "Value": "message", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 98, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 17, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 98, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 17, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 98, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 17, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 98, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 17, + "Value": "type", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 104, + "FragmentLength": 5, + "StartLine": 2, + "StartColumn": 23, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 104, + "FragmentLength": 5, + "StartLine": 2, + "StartColumn": 23, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 104, + "FragmentLength": 5, + "StartLine": 2, + "StartColumn": 23, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 104, + "FragmentLength": 5, + "StartLine": 2, + "StartColumn": 23, + "Value": "query", + "QuoteType": "NotQuoted" + } + ] + } + } + } + ], + "FromClause": { + "$type": "FromClause", + "StartOffset": 110, + "FragmentLength": 9, + "StartLine": 2, + "StartColumn": 29, + "TableReferences": [ + { + "$type": "NamedTableReference", + "StartOffset": 115, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 34, + "SchemaObject": { + "$type": "SchemaObjectName", + "StartOffset": 115, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 34, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 115, + "FragmentLength": 4, + "StartLine": 2, + "StartColumn": 34, + "Value": "logs", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + }, + "ForPath": false + } + ] + } + } + }, + { + "$type": "SelectStatement", + "StartOffset": 121, + "FragmentLength": 75, + "StartLine": 3, + "StartColumn": 1, + "QueryExpression": { + "$type": "QuerySpecification", + "StartOffset": 121, + "FragmentLength": 74, + "StartLine": 3, + "StartColumn": 1, + "UniqueRowFilter": "NotSpecified", + "SelectElements": [ + { + "$type": "SelectScalarExpression", + "StartOffset": 128, + "FragmentLength": 9, + "StartLine": 3, + "StartColumn": 8, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 128, + "FragmentLength": 9, + "StartLine": 3, + "StartColumn": 8, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 128, + "FragmentLength": 9, + "StartLine": 3, + "StartColumn": 8, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 128, + "FragmentLength": 1, + "StartLine": 3, + "StartColumn": 8, + "Value": "l", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 130, + "FragmentLength": 7, + "StartLine": 3, + "StartColumn": 10, + "Value": "message", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 139, + "FragmentLength": 6, + "StartLine": 3, + "StartColumn": 19, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 139, + "FragmentLength": 6, + "StartLine": 3, + "StartColumn": 19, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 139, + "FragmentLength": 6, + "StartLine": 3, + "StartColumn": 19, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 139, + "FragmentLength": 1, + "StartLine": 3, + "StartColumn": 19, + "Value": "l", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 141, + "FragmentLength": 4, + "StartLine": 3, + "StartColumn": 21, + "Value": "type", + "QuoteType": "NotQuoted" + } + ] + } + } + } + ], + "FromClause": { + "$type": "FromClause", + "StartOffset": 146, + "FragmentLength": 14, + "StartLine": 3, + "StartColumn": 26, + "TableReferences": [ + { + "$type": "NamedTableReference", + "StartOffset": 151, + "FragmentLength": 9, + "StartLine": 3, + "StartColumn": 31, + "SchemaObject": { + "$type": "SchemaObjectName", + "StartOffset": 151, + "FragmentLength": 4, + "StartLine": 3, + "StartColumn": 31, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 151, + "FragmentLength": 4, + "StartLine": 3, + "StartColumn": 31, + "Value": "logs", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + }, + "Alias": { + "$type": "Identifier", + "StartOffset": 159, + "FragmentLength": 1, + "StartLine": 3, + "StartColumn": 39, + "Value": "l", + "QuoteType": "NotQuoted" + }, + "ForPath": false + } + ] + }, + "WhereClause": { + "$type": "WhereClause", + "StartOffset": 161, + "FragmentLength": 20, + "StartLine": 3, + "StartColumn": 41, + "SearchCondition": { + "$type": "BooleanComparisonExpression", + "StartOffset": 167, + "FragmentLength": 14, + "StartLine": 3, + "StartColumn": 47, + "ComparisonType": "Equals", + "FirstExpression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 167, + "FragmentLength": 7, + "StartLine": 3, + "StartColumn": 47, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 167, + "FragmentLength": 7, + "StartLine": 3, + "StartColumn": 47, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 167, + "FragmentLength": 7, + "StartLine": 3, + "StartColumn": 47, + "Value": "message", + "QuoteType": "NotQuoted" + } + ] + } + }, + "SecondExpression": { + "$type": "StringLiteral", + "StartOffset": 177, + "FragmentLength": 4, + "StartLine": 3, + "StartColumn": 57, + "LiteralType": "String", + "IsNational": true, + "IsLargeObject": false, + "Value": "x" + } + } + }, + "OrderByClause": { + "$type": "OrderByClause", + "StartOffset": 182, + "FragmentLength": 13, + "StartLine": 3, + "StartColumn": 62, + "OrderByElements": [ + { + "$type": "ExpressionWithSortOrder", + "StartOffset": 191, + "FragmentLength": 4, + "StartLine": 3, + "StartColumn": 71, + "SortOrder": "NotSpecified", + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 191, + "FragmentLength": 4, + "StartLine": 3, + "StartColumn": 71, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 191, + "FragmentLength": 4, + "StartLine": 3, + "StartColumn": 71, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 191, + "FragmentLength": 4, + "StartLine": 3, + "StartColumn": 71, + "Value": "type", + "QuoteType": "NotQuoted" + } + ] + } + } + } + ] + } + } + }, + { + "$type": "InsertStatement", + "StartOffset": 197, + "FragmentLength": 50, + "StartLine": 4, + "StartColumn": 1, + "InsertSpecification": { + "$type": "InsertSpecification", + "StartOffset": 197, + "FragmentLength": 49, + "StartLine": 4, + "StartColumn": 1, + "InsertOption": "Into", + "InsertSource": { + "$type": "ValuesInsertSource", + "StartOffset": 230, + "FragmentLength": 16, + "StartLine": 4, + "StartColumn": 34, + "IsDefaultValues": false, + "RowValues": [ + { + "$type": "RowValue", + "StartOffset": 237, + "FragmentLength": 9, + "StartLine": 4, + "StartColumn": 41, + "ColumnValues": [ + { + "$type": "StringLiteral", + "StartOffset": 238, + "FragmentLength": 4, + "StartLine": 4, + "StartColumn": 42, + "LiteralType": "String", + "IsNational": true, + "IsLargeObject": false, + "Value": "x" + }, + { + "$type": "IntegerLiteral", + "StartOffset": 244, + "FragmentLength": 1, + "StartLine": 4, + "StartColumn": 48, + "LiteralType": "Integer", + "Value": "1" + } + ] + } + ] + }, + "Columns": [ + { + "$type": "ColumnReferenceExpression", + "StartOffset": 215, + "FragmentLength": 7, + "StartLine": 4, + "StartColumn": 19, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 215, + "FragmentLength": 7, + "StartLine": 4, + "StartColumn": 19, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 215, + "FragmentLength": 7, + "StartLine": 4, + "StartColumn": 19, + "Value": "message", + "QuoteType": "NotQuoted" + } + ] + } + }, + { + "$type": "ColumnReferenceExpression", + "StartOffset": 224, + "FragmentLength": 4, + "StartLine": 4, + "StartColumn": 28, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 224, + "FragmentLength": 4, + "StartLine": 4, + "StartColumn": 28, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 224, + "FragmentLength": 4, + "StartLine": 4, + "StartColumn": 28, + "Value": "type", + "QuoteType": "NotQuoted" + } + ] + } + } + ], + "Target": { + "$type": "NamedTableReference", + "StartOffset": 209, + "FragmentLength": 4, + "StartLine": 4, + "StartColumn": 13, + "SchemaObject": { + "$type": "SchemaObjectName", + "StartOffset": 209, + "FragmentLength": 4, + "StartLine": 4, + "StartColumn": 13, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 209, + "FragmentLength": 4, + "StartLine": 4, + "StartColumn": 13, + "Value": "logs", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + }, + "ForPath": false + } + } + }, + { + "$type": "InsertStatement", + "StartOffset": 248, + "FragmentLength": 56, + "StartLine": 5, + "StartColumn": 1, + "InsertSpecification": { + "$type": "InsertSpecification", + "StartOffset": 248, + "FragmentLength": 55, + "StartLine": 5, + "StartColumn": 1, + "InsertOption": "Into", + "InsertSource": { + "$type": "ValuesInsertSource", + "StartOffset": 286, + "FragmentLength": 17, + "StartLine": 5, + "StartColumn": 39, + "IsDefaultValues": false, + "RowValues": [ + { + "$type": "RowValue", + "StartOffset": 293, + "FragmentLength": 10, + "StartLine": 5, + "StartColumn": 46, + "ColumnValues": [ + { + "$type": "VariableReference", + "StartOffset": 294, + "FragmentLength": 8, + "StartLine": 5, + "StartColumn": 47, + "Name": "@message" + } + ] + } + ] + }, + "Columns": [ + { + "$type": "ColumnReferenceExpression", + "StartOffset": 277, + "FragmentLength": 7, + "StartLine": 5, + "StartColumn": 30, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 277, + "FragmentLength": 7, + "StartLine": 5, + "StartColumn": 30, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 277, + "FragmentLength": 7, + "StartLine": 5, + "StartColumn": 30, + "Value": "message", + "QuoteType": "NotQuoted" + } + ] + } + } + ], + "Target": { + "$type": "NamedTableReference", + "StartOffset": 260, + "FragmentLength": 15, + "StartLine": 5, + "StartColumn": 13, + "SchemaObject": { + "$type": "SchemaObjectName", + "StartOffset": 260, + "FragmentLength": 15, + "StartLine": 5, + "StartColumn": 13, + "SchemaIdentifier": { + "$type": "Identifier", + "StartOffset": 260, + "FragmentLength": 7, + "StartLine": 5, + "StartColumn": 13, + "Value": "logging", + "QuoteType": "NotQuoted" + }, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 268, + "FragmentLength": 7, + "StartLine": 5, + "StartColumn": 21, + "Value": "entries", + "QuoteType": "NotQuoted" + }, + "Count": 2, + "Identifiers": [ + { + "$ref": "Identifier" + }, + { + "$ref": "Identifier" + } + ] + }, + "ForPath": false + } + } + }, + { + "$type": "UpdateStatement", + "StartOffset": 305, + "FragmentLength": 61, + "StartLine": 6, + "StartColumn": 1, + "UpdateSpecification": { + "$type": "UpdateSpecification", + "StartOffset": 305, + "FragmentLength": 60, + "StartLine": 6, + "StartColumn": 1, + "SetClauses": [ + { + "$type": "AssignmentSetClause", + "StartOffset": 321, + "FragmentLength": 14, + "StartLine": 6, + "StartColumn": 17, + "Column": { + "$type": "ColumnReferenceExpression", + "StartOffset": 321, + "FragmentLength": 7, + "StartLine": 6, + "StartColumn": 17, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 321, + "FragmentLength": 7, + "StartLine": 6, + "StartColumn": 17, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 321, + "FragmentLength": 7, + "StartLine": 6, + "StartColumn": 17, + "Value": "message", + "QuoteType": "NotQuoted" + } + ] + } + }, + "NewValue": { + "$type": "StringLiteral", + "StartOffset": 331, + "FragmentLength": 4, + "StartLine": 6, + "StartColumn": 27, + "LiteralType": "String", + "IsNational": true, + "IsLargeObject": false, + "Value": "y" + }, + "AssignmentKind": "Equals" + }, + { + "$type": "AssignmentSetClause", + "StartOffset": 337, + "FragmentLength": 8, + "StartLine": 6, + "StartColumn": 33, + "Column": { + "$type": "ColumnReferenceExpression", + "StartOffset": 337, + "FragmentLength": 4, + "StartLine": 6, + "StartColumn": 33, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 337, + "FragmentLength": 4, + "StartLine": 6, + "StartColumn": 33, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 337, + "FragmentLength": 4, + "StartLine": 6, + "StartColumn": 33, + "Value": "type", + "QuoteType": "NotQuoted" + } + ] + } + }, + "NewValue": { + "$type": "IntegerLiteral", + "StartOffset": 344, + "FragmentLength": 1, + "StartLine": 6, + "StartColumn": 40, + "LiteralType": "Integer", + "Value": "2" + }, + "AssignmentKind": "Equals" + } + ], + "WhereClause": { + "$type": "WhereClause", + "StartOffset": 346, + "FragmentLength": 19, + "StartLine": 6, + "StartColumn": 42, + "SearchCondition": { + "$type": "BooleanIsNullExpression", + "StartOffset": 352, + "FragmentLength": 13, + "StartLine": 6, + "StartColumn": 48, + "IsNot": false, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 352, + "FragmentLength": 5, + "StartLine": 6, + "StartColumn": 48, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 352, + "FragmentLength": 5, + "StartLine": 6, + "StartColumn": 48, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 352, + "FragmentLength": 5, + "StartLine": 6, + "StartColumn": 48, + "Value": "query", + "QuoteType": "NotQuoted" + } + ] + } + } + } + }, + "Target": { + "$type": "NamedTableReference", + "StartOffset": 312, + "FragmentLength": 4, + "StartLine": 6, + "StartColumn": 8, + "SchemaObject": { + "$type": "SchemaObjectName", + "StartOffset": 312, + "FragmentLength": 4, + "StartLine": 6, + "StartColumn": 8, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 312, + "FragmentLength": 4, + "StartLine": 6, + "StartColumn": 8, + "Value": "logs", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + }, + "ForPath": false + } + } + }, + { + "$type": "SelectStatement", + "StartOffset": 367, + "FragmentLength": 93, + "StartLine": 7, + "StartColumn": 1, + "QueryExpression": { + "$type": "QuerySpecification", + "StartOffset": 367, + "FragmentLength": 92, + "StartLine": 7, + "StartColumn": 1, + "UniqueRowFilter": "NotSpecified", + "SelectElements": [ + { + "$type": "SelectScalarExpression", + "StartOffset": 374, + "FragmentLength": 6, + "StartLine": 7, + "StartColumn": 8, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 374, + "FragmentLength": 6, + "StartLine": 7, + "StartColumn": 8, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 374, + "FragmentLength": 6, + "StartLine": 7, + "StartColumn": 8, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 374, + "FragmentLength": 6, + "StartLine": 7, + "StartColumn": 8, + "Value": "status", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 382, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 16, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 382, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 16, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 382, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 16, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 382, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 16, + "Value": "level", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 389, + "FragmentLength": 4, + "StartLine": 7, + "StartColumn": 23, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 389, + "FragmentLength": 4, + "StartLine": 7, + "StartColumn": 23, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 389, + "FragmentLength": 4, + "StartLine": 7, + "StartColumn": 23, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 389, + "FragmentLength": 4, + "StartLine": 7, + "StartColumn": 23, + "Value": "name", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 395, + "FragmentLength": 4, + "StartLine": 7, + "StartColumn": 29, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 395, + "FragmentLength": 4, + "StartLine": 7, + "StartColumn": 29, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 395, + "FragmentLength": 4, + "StartLine": 7, + "StartColumn": 29, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 395, + "FragmentLength": 4, + "StartLine": 7, + "StartColumn": 29, + "Value": "role", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 401, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 35, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 401, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 35, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 401, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 35, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 401, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 35, + "Value": "state", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 408, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 42, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 408, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 42, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 408, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 42, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 408, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 42, + "Value": "value", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 415, + "FragmentLength": 8, + "StartLine": 7, + "StartColumn": 49, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 415, + "FragmentLength": 8, + "StartLine": 7, + "StartColumn": 49, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 415, + "FragmentLength": 8, + "StartLine": 7, + "StartColumn": 49, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 415, + "FragmentLength": 8, + "StartLine": 7, + "StartColumn": 49, + "Value": "password", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 425, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 59, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 425, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 59, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 425, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 59, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 425, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 59, + "Value": "login", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 432, + "FragmentLength": 8, + "StartLine": 7, + "StartColumn": 66, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 432, + "FragmentLength": 8, + "StartLine": 7, + "StartColumn": 66, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 432, + "FragmentLength": 8, + "StartLine": 7, + "StartColumn": 66, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 432, + "FragmentLength": 8, + "StartLine": 7, + "StartColumn": 66, + "Value": "language", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 442, + "FragmentLength": 3, + "StartLine": 7, + "StartColumn": 76, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 442, + "FragmentLength": 3, + "StartLine": 7, + "StartColumn": 76, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 442, + "FragmentLength": 3, + "StartLine": 7, + "StartColumn": 76, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 442, + "FragmentLength": 3, + "StartLine": 7, + "StartColumn": 76, + "Value": "job", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 447, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 81, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 447, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 81, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 447, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 81, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 447, + "FragmentLength": 5, + "StartLine": 7, + "StartColumn": 81, + "Value": "stats", + "QuoteType": "NotQuoted" + } + ] + } + } + } + ], + "FromClause": { + "$type": "FromClause", + "StartOffset": 453, + "FragmentLength": 6, + "StartLine": 7, + "StartColumn": 87, + "TableReferences": [ + { + "$type": "NamedTableReference", + "StartOffset": 458, + "FragmentLength": 1, + "StartLine": 7, + "StartColumn": 92, + "SchemaObject": { + "$type": "SchemaObjectName", + "StartOffset": 458, + "FragmentLength": 1, + "StartLine": 7, + "StartColumn": 92, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 458, + "FragmentLength": 1, + "StartLine": 7, + "StartColumn": 92, + "Value": "t", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + }, + "ForPath": false + } + ] + } + } + } + ] + } + ] +} \ No newline at end of file diff --git a/parser/testdata/NonReservedKeywordsAsColumns/metadata.json b/parser/testdata/NonReservedKeywordsAsColumns/metadata.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/parser/testdata/NonReservedKeywordsAsColumns/metadata.json @@ -0,0 +1 @@ +{} diff --git a/parser/testdata/NonReservedKeywordsAsColumns/query.sql b/parser/testdata/NonReservedKeywordsAsColumns/query.sql new file mode 100644 index 00000000..96d1c45a --- /dev/null +++ b/parser/testdata/NonReservedKeywordsAsColumns/query.sql @@ -0,0 +1,7 @@ +CREATE TABLE logs (id INT, message NVARCHAR(200), type INT, query NVARCHAR(MAX)); +SELECT message, type, query FROM logs; +SELECT l.message, l.type FROM logs AS l WHERE message = N'x' ORDER BY type; +INSERT INTO logs (message, type) VALUES (N'x', 1); +INSERT INTO logging.entries (message) VALUES (@message); +UPDATE logs SET message = N'y', type = 2 WHERE query IS NULL; +SELECT status, level, name, role, state, value, password, login, language, job, stats FROM t; diff --git a/parser/testdata/XmlQueryMethod/ast.json b/parser/testdata/XmlQueryMethod/ast.json new file mode 100644 index 00000000..f03fe91a --- /dev/null +++ b/parser/testdata/XmlQueryMethod/ast.json @@ -0,0 +1,620 @@ +{ + "$type": "TSqlScript", + "StartOffset": 0, + "FragmentLength": 270, + "StartLine": 1, + "StartColumn": 1, + "Batches": [ + { + "$type": "TSqlBatch", + "StartOffset": 0, + "FragmentLength": 269, + "StartLine": 1, + "StartColumn": 1, + "Statements": [ + { + "$type": "SelectStatement", + "StartOffset": 0, + "FragmentLength": 44, + "StartLine": 1, + "StartColumn": 1, + "QueryExpression": { + "$type": "QuerySpecification", + "StartOffset": 0, + "FragmentLength": 43, + "StartLine": 1, + "StartColumn": 1, + "UniqueRowFilter": "NotSpecified", + "SelectElements": [ + { + "$type": "SelectScalarExpression", + "StartOffset": 7, + "FragmentLength": 24, + "StartLine": 1, + "StartColumn": 8, + "Expression": { + "$type": "FunctionCall", + "StartOffset": 7, + "FragmentLength": 24, + "StartLine": 1, + "StartColumn": 8, + "CallTarget": { + "$type": "MultiPartIdentifierCallTarget", + "StartOffset": 7, + "FragmentLength": 3, + "StartLine": 1, + "StartColumn": 8, + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 7, + "FragmentLength": 3, + "StartLine": 1, + "StartColumn": 8, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 7, + "FragmentLength": 3, + "StartLine": 1, + "StartColumn": 8, + "Value": "doc", + "QuoteType": "NotQuoted" + } + ] + } + }, + "FunctionName": { + "$type": "Identifier", + "StartOffset": 11, + "FragmentLength": 5, + "StartLine": 1, + "StartColumn": 12, + "Value": "query", + "QuoteType": "NotQuoted" + }, + "Parameters": [ + { + "$type": "StringLiteral", + "StartOffset": 17, + "FragmentLength": 13, + "StartLine": 1, + "StartColumn": 18, + "LiteralType": "String", + "IsNational": false, + "IsLargeObject": false, + "Value": "/order/item" + } + ], + "UniqueRowFilter": "NotSpecified", + "WithArrayWrapper": false + } + } + ], + "FromClause": { + "$type": "FromClause", + "StartOffset": 32, + "FragmentLength": 11, + "StartLine": 1, + "StartColumn": 33, + "TableReferences": [ + { + "$type": "NamedTableReference", + "StartOffset": 37, + "FragmentLength": 6, + "StartLine": 1, + "StartColumn": 38, + "SchemaObject": { + "$type": "SchemaObjectName", + "StartOffset": 37, + "FragmentLength": 6, + "StartLine": 1, + "StartColumn": 38, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 37, + "FragmentLength": 6, + "StartLine": 1, + "StartColumn": 38, + "Value": "orders", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + }, + "ForPath": false + } + ] + } + } + }, + { + "$type": "SelectStatement", + "StartOffset": 45, + "FragmentLength": 173, + "StartLine": 2, + "StartColumn": 1, + "QueryExpression": { + "$type": "QuerySpecification", + "StartOffset": 45, + "FragmentLength": 172, + "StartLine": 2, + "StartColumn": 1, + "UniqueRowFilter": "NotSpecified", + "SelectElements": [ + { + "$type": "SelectScalarExpression", + "StartOffset": 52, + "FragmentLength": 2, + "StartLine": 2, + "StartColumn": 8, + "Expression": { + "$type": "ColumnReferenceExpression", + "StartOffset": 52, + "FragmentLength": 2, + "StartLine": 2, + "StartColumn": 8, + "ColumnType": "Regular", + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 52, + "FragmentLength": 2, + "StartLine": 2, + "StartColumn": 8, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 52, + "FragmentLength": 2, + "StartLine": 2, + "StartColumn": 8, + "Value": "id", + "QuoteType": "NotQuoted" + } + ] + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 56, + "FragmentLength": 47, + "StartLine": 2, + "StartColumn": 12, + "Expression": { + "$type": "FunctionCall", + "StartOffset": 56, + "FragmentLength": 35, + "StartLine": 2, + "StartColumn": 12, + "CallTarget": { + "$type": "MultiPartIdentifierCallTarget", + "StartOffset": 56, + "FragmentLength": 3, + "StartLine": 2, + "StartColumn": 12, + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 56, + "FragmentLength": 3, + "StartLine": 2, + "StartColumn": 12, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 56, + "FragmentLength": 3, + "StartLine": 2, + "StartColumn": 12, + "Value": "doc", + "QuoteType": "NotQuoted" + } + ] + } + }, + "FunctionName": { + "$type": "Identifier", + "StartOffset": 60, + "FragmentLength": 5, + "StartLine": 2, + "StartColumn": 16, + "Value": "value", + "QuoteType": "NotQuoted" + }, + "Parameters": [ + { + "$type": "StringLiteral", + "StartOffset": 66, + "FragmentLength": 17, + "StartLine": 2, + "StartColumn": 22, + "LiteralType": "String", + "IsNational": false, + "IsLargeObject": false, + "Value": "(/order/@id)[1]" + }, + { + "$type": "StringLiteral", + "StartOffset": 85, + "FragmentLength": 5, + "StartLine": 2, + "StartColumn": 41, + "LiteralType": "String", + "IsNational": false, + "IsLargeObject": false, + "Value": "INT" + } + ], + "UniqueRowFilter": "NotSpecified", + "WithArrayWrapper": false + }, + "ColumnName": { + "$type": "IdentifierOrValueExpression", + "StartOffset": 95, + "FragmentLength": 8, + "StartLine": 2, + "StartColumn": 51, + "Value": "order_id", + "Identifier": { + "$type": "Identifier", + "StartOffset": 95, + "FragmentLength": 8, + "StartLine": 2, + "StartColumn": 51, + "Value": "order_id", + "QuoteType": "NotQuoted" + } + } + }, + { + "$type": "SelectScalarExpression", + "StartOffset": 105, + "FragmentLength": 33, + "StartLine": 2, + "StartColumn": 61, + "Expression": { + "$type": "FunctionCall", + "StartOffset": 105, + "FragmentLength": 24, + "StartLine": 2, + "StartColumn": 61, + "CallTarget": { + "$type": "MultiPartIdentifierCallTarget", + "StartOffset": 105, + "FragmentLength": 3, + "StartLine": 2, + "StartColumn": 61, + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 105, + "FragmentLength": 3, + "StartLine": 2, + "StartColumn": 61, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 105, + "FragmentLength": 3, + "StartLine": 2, + "StartColumn": 61, + "Value": "doc", + "QuoteType": "NotQuoted" + } + ] + } + }, + "FunctionName": { + "$type": "Identifier", + "StartOffset": 109, + "FragmentLength": 5, + "StartLine": 2, + "StartColumn": 65, + "Value": "query", + "QuoteType": "NotQuoted" + }, + "Parameters": [ + { + "$type": "StringLiteral", + "StartOffset": 115, + "FragmentLength": 13, + "StartLine": 2, + "StartColumn": 71, + "LiteralType": "String", + "IsNational": false, + "IsLargeObject": false, + "Value": "/order/item" + } + ], + "UniqueRowFilter": "NotSpecified", + "WithArrayWrapper": false + }, + "ColumnName": { + "$type": "IdentifierOrValueExpression", + "StartOffset": 133, + "FragmentLength": 5, + "StartLine": 2, + "StartColumn": 89, + "Value": "items", + "Identifier": { + "$type": "Identifier", + "StartOffset": 133, + "FragmentLength": 5, + "StartLine": 2, + "StartColumn": 89, + "Value": "items", + "QuoteType": "NotQuoted" + } + } + } + ], + "FromClause": { + "$type": "FromClause", + "StartOffset": 139, + "FragmentLength": 15, + "StartLine": 3, + "StartColumn": 1, + "TableReferences": [ + { + "$type": "NamedTableReference", + "StartOffset": 144, + "FragmentLength": 10, + "StartLine": 3, + "StartColumn": 6, + "SchemaObject": { + "$type": "SchemaObjectName", + "StartOffset": 144, + "FragmentLength": 10, + "StartLine": 3, + "StartColumn": 6, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 144, + "FragmentLength": 10, + "StartLine": 3, + "StartColumn": 6, + "Value": "orders_xml", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + }, + "ForPath": false + } + ] + }, + "WhereClause": { + "$type": "WhereClause", + "StartOffset": 155, + "FragmentLength": 62, + "StartLine": 3, + "StartColumn": 17, + "SearchCondition": { + "$type": "BooleanComparisonExpression", + "StartOffset": 161, + "FragmentLength": 56, + "StartLine": 3, + "StartColumn": 23, + "ComparisonType": "Equals", + "FirstExpression": { + "$type": "FunctionCall", + "StartOffset": 161, + "FragmentLength": 52, + "StartLine": 3, + "StartColumn": 23, + "CallTarget": { + "$type": "MultiPartIdentifierCallTarget", + "StartOffset": 161, + "FragmentLength": 3, + "StartLine": 3, + "StartColumn": 23, + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 161, + "FragmentLength": 3, + "StartLine": 3, + "StartColumn": 23, + "Count": 1, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 161, + "FragmentLength": 3, + "StartLine": 3, + "StartColumn": 23, + "Value": "doc", + "QuoteType": "NotQuoted" + } + ] + } + }, + "FunctionName": { + "$type": "Identifier", + "StartOffset": 165, + "FragmentLength": 5, + "StartLine": 3, + "StartColumn": 27, + "Value": "exist", + "QuoteType": "NotQuoted" + }, + "Parameters": [ + { + "$type": "StringLiteral", + "StartOffset": 171, + "FragmentLength": 41, + "StartLine": 3, + "StartColumn": 33, + "LiteralType": "String", + "IsNational": false, + "IsLargeObject": false, + "Value": "/order[@status=sql:variable(\u0022@status\u0022)]" + } + ], + "UniqueRowFilter": "NotSpecified", + "WithArrayWrapper": false + }, + "SecondExpression": { + "$type": "IntegerLiteral", + "StartOffset": 216, + "FragmentLength": 1, + "StartLine": 3, + "StartColumn": 78, + "LiteralType": "Integer", + "Value": "1" + } + } + } + } + }, + { + "$type": "SelectStatement", + "StartOffset": 219, + "FragmentLength": 50, + "StartLine": 4, + "StartColumn": 1, + "QueryExpression": { + "$type": "QuerySpecification", + "StartOffset": 219, + "FragmentLength": 49, + "StartLine": 4, + "StartColumn": 1, + "UniqueRowFilter": "NotSpecified", + "SelectElements": [ + { + "$type": "SelectScalarExpression", + "StartOffset": 226, + "FragmentLength": 21, + "StartLine": 4, + "StartColumn": 8, + "Expression": { + "$type": "FunctionCall", + "StartOffset": 226, + "FragmentLength": 21, + "StartLine": 4, + "StartColumn": 8, + "CallTarget": { + "$type": "MultiPartIdentifierCallTarget", + "StartOffset": 226, + "FragmentLength": 5, + "StartLine": 4, + "StartColumn": 8, + "MultiPartIdentifier": { + "$type": "MultiPartIdentifier", + "StartOffset": 226, + "FragmentLength": 5, + "StartLine": 4, + "StartColumn": 8, + "Count": 2, + "Identifiers": [ + { + "$type": "Identifier", + "StartOffset": 226, + "FragmentLength": 1, + "StartLine": 4, + "StartColumn": 8, + "Value": "o", + "QuoteType": "NotQuoted" + }, + { + "$type": "Identifier", + "StartOffset": 228, + "FragmentLength": 3, + "StartLine": 4, + "StartColumn": 10, + "Value": "doc", + "QuoteType": "NotQuoted" + } + ] + } + }, + "FunctionName": { + "$type": "Identifier", + "StartOffset": 232, + "FragmentLength": 5, + "StartLine": 4, + "StartColumn": 14, + "Value": "query", + "QuoteType": "NotQuoted" + }, + "Parameters": [ + { + "$type": "StringLiteral", + "StartOffset": 238, + "FragmentLength": 8, + "StartLine": 4, + "StartColumn": 20, + "LiteralType": "String", + "IsNational": false, + "IsLargeObject": false, + "Value": "/order" + } + ], + "UniqueRowFilter": "NotSpecified", + "WithArrayWrapper": false + } + } + ], + "FromClause": { + "$type": "FromClause", + "StartOffset": 248, + "FragmentLength": 20, + "StartLine": 4, + "StartColumn": 30, + "TableReferences": [ + { + "$type": "NamedTableReference", + "StartOffset": 253, + "FragmentLength": 15, + "StartLine": 4, + "StartColumn": 35, + "SchemaObject": { + "$type": "SchemaObjectName", + "StartOffset": 253, + "FragmentLength": 10, + "StartLine": 4, + "StartColumn": 35, + "BaseIdentifier": { + "$type": "Identifier", + "StartOffset": 253, + "FragmentLength": 10, + "StartLine": 4, + "StartColumn": 35, + "Value": "orders_xml", + "QuoteType": "NotQuoted" + }, + "Count": 1, + "Identifiers": [ + { + "$ref": "Identifier" + } + ] + }, + "Alias": { + "$type": "Identifier", + "StartOffset": 267, + "FragmentLength": 1, + "StartLine": 4, + "StartColumn": 49, + "Value": "o", + "QuoteType": "NotQuoted" + }, + "ForPath": false + } + ] + } + } + } + ] + } + ] +} \ No newline at end of file diff --git a/parser/testdata/XmlQueryMethod/metadata.json b/parser/testdata/XmlQueryMethod/metadata.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/parser/testdata/XmlQueryMethod/metadata.json @@ -0,0 +1 @@ +{} diff --git a/parser/testdata/XmlQueryMethod/query.sql b/parser/testdata/XmlQueryMethod/query.sql new file mode 100644 index 00000000..71b252a2 --- /dev/null +++ b/parser/testdata/XmlQueryMethod/query.sql @@ -0,0 +1,4 @@ +SELECT doc.query('/order/item') FROM orders; +SELECT id, doc.value('(/order/@id)[1]', 'INT') AS order_id, doc.query('/order/item') AS items +FROM orders_xml WHERE doc.exist('/order[@status=sql:variable("@status")]') = 1; +SELECT o.doc.query('/order') FROM orders_xml AS o;