Skip to content

parser/bigquery: PIVOT/UNPIVOT rejected although BigQuery capabilities advertise support #854

Closed

Description

@ajitpratap0

Summary

dialect.Capabilities for BigQuery sets SupportsPivotUnpivot: true (pkg/sql/dialect/capabilities.go), but the parser gates PIVOT/UNPIVOT on a hard-coded dialect list that omits BigQuery:

// pkg/sql/parser/pivot.go
func (p *Parser) pivotDialectAllowed() bool {
	return p.dialect == string(keywords.DialectSQLServer) ||
		p.dialect == string(keywords.DialectOracle) ||
		p.dialect == string(keywords.DialectSnowflake)
}

Reproduce (v1.16.0)

gosqlx validate --dialect bigquery "SELECT * FROM sales PIVOT (SUM(amount) FOR quarter IN ('Q1', 'Q2'))"
# ❌ Invalid SQL: Error E2002 at line 1, column 27: expected statement, got LPAREN

The same query is valid under --dialect snowflake and --dialect sqlserver.

Suggested fix

Gate on p.Capabilities().SupportsPivotUnpivot (as isQualifyKeyword does with SupportsQualify) instead of the dialect list, then add BigQuery PIVOT/UNPIVOT parser tests and check that BigQuery's syntax differences (e.g. aliases on IN values, UNPIVOT ... INCLUDE NULLS) are handled. Check that no other dialect's capabilities claim PIVOT without parser support.

Found while fixing the v1.16.0 release review notes (#853); the README deliberately does not list PIVOT for BigQuery until this is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions