Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 11, 2025

The parser was failing when using CAST() on dotted identifiers with more than 3 parts (e.g., some.long.json.path). This worked fine in regular SELECT expressions but failed specifically within CAST expressions.

Root Cause

The parseColumnCastExpr function was calling parseColumnExpr to parse the first argument of CAST expressions. However, parseColumnExpr doesn't use precedence-based parsing, so when parseIdentOrFunction eagerly consumed up to 3 parts of a dotted identifier (database.table.column), any remaining parts were left unparsed, causing the parser to expect "AS" or "," but find "." instead.

Solution

Changed parseColumnCastExpr to use parseExpr instead of parseColumnExpr. The parseExpr function uses precedence-based parsing which properly handles chains of dot operations via IndexOperation nodes for identifiers with 4+ parts.

Examples

Before (failing):

SELECT CAST(some.long.json.path, 'String') AS value
-- Error: line 0:26 expected AS or , but got .

After (working):

-- All of these now work correctly
SELECT CAST(column, 'String') AS single_part;
SELECT CAST(table.column, 'String') AS two_parts;
SELECT CAST(db.table.column, 'String') AS three_parts;
SELECT CAST(some.long.json.path, 'String') AS four_parts;
SELECT CAST(a.very.long.nested.json.path, 'String') AS many_parts;

Backward Compatibility

  • 1-3 part identifiers continue to be parsed as Ident or ColumnIdentifier (unchanged behavior)
  • 4+ part identifiers are now parsed as ColumnIdentifier for the first 3 parts + chain of IndexOperations for remaining parts
  • All existing tests continue to pass

Fixes #187.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 17631696267

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 50.387%

Totals Coverage Status
Change from base Build 17367436417: 0.0%
Covered Lines: 7422
Relevant Lines: 14730

💛 - Coveralls

Co-authored-by: git-hulk <4987594+git-hulk@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] CAST with dotted identifiers of more than 3 parts fails Fix CAST expressions with dotted identifiers of more than 3 parts Sep 11, 2025
@Copilot Copilot AI requested a review from git-hulk September 11, 2025 02:06
Copilot finished work on behalf of git-hulk September 11, 2025 02:06
@git-hulk git-hulk closed this Sep 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CAST with dotted identifiers of more than 3 parts fails

3 participants