Fix SPARSE before MASKED WITH column ordering (#216) - #221
Open
NAVEEN NAIK (ZEUSXXIV) wants to merge 1 commit into
Open
Fix SPARSE before MASKED WITH column ordering (#216)#221NAVEEN NAIK (ZEUSXXIV) wants to merge 1 commit into
NAVEEN NAIK (ZEUSXXIV) wants to merge 1 commit into
Conversation
CREATE TABLE column definitions that combine SPARSE and MASKED WITH in the order documented by the CREATE TABLE reference (SPARSE first, then MASKED WITH) failed to parse with "Incorrect syntax near 'MASKED'", while the reversed order parsed fine. In regularColumnBody the grammar only accepted the leading maskedClause before the SPARSE/FILESTREAM storage options, so MASKED could never follow SPARSE. Add a second, guarded maskedClause after the storage block (before the HIDDEN clause where present) so both documented and reversed orders parse. The `!vParent.IsMasked` guard prevents MASKED WITH from being specified twice on the same column. Applied to all grammars that support MASKED WITH: TSql130 through TSql180 and TSqlFabricDW. Tests: - Positive round-trip: TestScripts/SparseMaskedColumnOrderTests130.sql with baseline Baselines130/SparseMaskedColumnOrderTests130.sql, wired through Only130SyntaxTests.cs (verified across the TSql130-TSql180 parsers). - Negative: SparseMaskedColumnNegativeTest in ParserErrorsTests.cs asserts MASKED WITH specified twice is a parse error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #216
CREATE TABLEcolumn definitions that combineSPARSEandMASKED WITHin the order documented by the CREATE TABLE reference (SPARSEfirst, thenMASKED WITH) failed to parse with "Incorrect syntax near 'MASKED'", even though the reversed order (MASKED WITH … SPARSE) parsed fine and both are accepted by the SQL Server engine.Failing before this change (documented order):
Worked before (reversed order):
Root cause
In the
regularColumnBodygrammar rule, themaskedClausewas only accepted before theSPARSE/FILESTREAM/COLUMN_SETstorage options. There was no way forMASKED WITHto followSPARSE, so the documented ordering produced a parse error.Fix
The
regularColumnBodyrule now acceptsmaskedClausein two positions:maskedClause(before the storage options) — handlesMASKED WITH … SPARSE(reversed order).maskedClauseafter the storage-options block, before theHIDDENclause where present — handlesSPARSE … MASKED WITH(documented order).The trailing occurrence is guarded by
{NextTokenMatches(Masked) && !vParent.IsMasked}?, which reuses the existingIDataMaskingSetter.IsMaskedstate so thatMASKED WITHcannot be specified twice on the same column (the guard makes the second position inert once the leading one has already consumed aMASKED WITH).Applied to every grammar that supports
MASKED WITH(a SQL Server 2016 feature):TSql130throughTSql180andTSqlFabricDW.Compatibility / non-breaking
This change is intentionally additive and does not alter the public API surface:
Ast.xmlchanges — no AST class, enum, or property was added, renamed, or retyped. It reuses the existingIDataMaskingSetter.IsMasked/MaskingFunctionandColumnStorageOptionsmembers.MASKEDtoken that previously produced a parse error, so no previously valid input changes its AST or output. All existing baselines are unchanged.SPARSE MASKED WITH …, so parse → generate → re-parse round-trips cleanly for both input orders.Tests
Test/SqlDom/TestScripts/SparseMaskedColumnOrderTests130.sqlwith baselineTest/SqlDom/Baselines130/SparseMaskedColumnOrderTests130.sql, wired throughOnly130SyntaxTests.cs. Covers the exact statement from the issue (documented order), the reversed order, andSPARSE FILESTREAM+MASKED WITH. Verified across theTSql130–TSql180parsers.SparseMaskedColumnNegativeTestinParserErrorsTests.csasserts that specifyingMASKED WITHtwice on one column is a parse error (SQL46010).Code Changes