Skip to content

feat(optimizer)!: type annotation for databricks REGR_SXX, REGR_SXY, REGR_SYY#7851

Open
fivetran-amrutabhimsenayachit wants to merge 3 commits into
mainfrom
type-inference-batch-4
Open

feat(optimizer)!: type annotation for databricks REGR_SXX, REGR_SXY, REGR_SYY#7851
fivetran-amrutabhimsenayachit wants to merge 3 commits into
mainfrom
type-inference-batch-4

Conversation

@fivetran-amrutabhimsenayachit

Copy link
Copy Markdown
Collaborator

Summary

Adds Databricks type inference support for REGR_SXX (DOUBLE), REGR_SXY (DOUBLE), and REGR_SYY (DOUBLE), including a parser fix to handle the DISTINCT modifier correctly for these two-argument aggregates.

Tickets

  • RD-1229643 (REGR_SXX) — DOUBLE, new typing + parser fix
  • RD-1229644 (REGR_SXY) — DOUBLE, new typing + parser fix
  • RD-1229645 (REGR_SYY) — DOUBLE, new typing + parser fix
  • RD-1229647 (REPEAT) — already complete, no changes
  • RD-1229648 (REPLACE) — already complete, no changes

Test plan

  • make style — PASS
  • make unit — PASS (1342 tests, 0 failures)
  • test_annotate_funcs fixture — PASS
  • Engine verified on Databricks: DISTINCT and OVER variants return DOUBLE

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

SQLGlot Integration Test Results

✅ All tests passed

Comparing:

  • this branch (sqlglot:type-inference-batch-4 @ sqlglot d0011b6)
  • baseline (main @ sqlglot 122b44f)

Overall

main: 192416 total, 153532 passed (pass rate: 79.8%)

sqlglot:type-inference-batch-4: 180222 total, 142385 passed (pass rate: 79.0%)

Transitions:
No change

Dialect pair changes: 0 previous results not found, 3 current results not found

✅ All tests passed

@geooo109 geooo109 self-assigned this Jul 10, 2026
Comment thread sqlglot/parsers/databricks.py Outdated
@geooo109 geooo109 changed the title feat(typing): add databricks type inference for REGR_SXX, REGR_SXY, REGR_SYY feat(optimizer)!: type annotation for databricks REGR_SXX, REGR_SXY, REGR_SYY Jul 10, 2026
Comment thread sqlglot/generators/databricks.py Outdated
Comment on lines +120 to +134
def regrsxx_sql(self, expression: exp.RegrSxx) -> str:
x = expression.expression
if isinstance(x, exp.Distinct):
return self.func(
"REGR_SXX", exp.Distinct(expressions=[expression.this]), *x.expressions
)
return self.func("REGR_SXX", expression.this, x)

def regrsyy_sql(self, expression: exp.RegrSyy) -> str:
x = expression.expression
if isinstance(x, exp.Distinct):
return self.func(
"REGR_SYY", exp.Distinct(expressions=[expression.this]), *x.expressions
)
return self.func("REGR_SYY", expression.this, x)

@geooo109 geooo109 Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's refactor here:

    def _regr_sql(self, expression: exp.RegrAvgx  | exp.RegrSxx | exp.RegrSyy) -> str:
        name = expression.sql_name()
        x = expression.expression
        if isinstance(x, exp.Distinct):
            return self.func(name, exp.Distinct(expressions=[expression.this]), *x.expressions)
       
        return self.func(name, expression.this, x)

Then we can resue this ^ for all the 3 cases.

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.

2 participants