Skip to content

Fix: Parametrized bigdecimal mapping was being concatenated with params#7584

Open
themisvaltinos wants to merge 1 commit intomainfrom
themis/bigdec
Open

Fix: Parametrized bigdecimal mapping was being concatenated with params#7584
themisvaltinos wants to merge 1 commit intomainfrom
themis/bigdec

Conversation

@themisvaltinos
Copy link
Copy Markdown
Collaborator

the default BIGDECIMAL to DECIMAL(38, 5) mapping was being concatenated with explicit (76, 38) params, producing DECIMAL(38, 5)(76, 38) in ducked:

DECLARE x DECIMAL(38, 5)(76, 38)

added a check in _datatype_sql to pass through the usersupplied params when present instead and falling back to the default otherwise

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

SQLGlot Integration Test Results

Comparing:

  • this branch (sqlglot:themis/bigdec, sqlglot version: themis/bigdec)
  • baseline (main, sqlglot version: 0.0.1.dev1)

By Dialect

dialect main sqlglot:themis/bigdec transitions links
bigquery -> bigquery 24647/24652 passed (100.0%) 24647/24652 passed (100.0%) No change full result / delta
bigquery -> duckdb 867/1154 passed (75.1%) 867/1154 passed (75.1%) No change full result / delta
duckdb -> duckdb 5823/5823 passed (100.0%) 5823/5823 passed (100.0%) No change full result / delta
snowflake -> duckdb 1063/1961 passed (54.2%) 0/0 passed (0.0%) Results not found full result / delta
snowflake -> snowflake 65133/65133 passed (100.0%) 63027/63027 passed (100.0%) No change full result / delta
databricks -> databricks 1370/1370 passed (100.0%) 1370/1370 passed (100.0%) No change full result / delta
postgres -> postgres 6042/6042 passed (100.0%) 6042/6042 passed (100.0%) No change full result / delta
redshift -> redshift 7101/7101 passed (100.0%) 7101/7101 passed (100.0%) No change full result / delta

Overall

main: 113236 total, 112046 passed (pass rate: 98.9%), sqlglot version: 0.0.1.dev1

sqlglot:themis/bigdec: 109169 total, 108877 passed (pass rate: 99.7%), sqlglot version: themis/bigdec

Transitions:
No change

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

✅ 38 test(s) passed

Comment thread sqlglot/generator.py
Comment on lines +1691 to +1692
if not expr_nested and isinstance(type_value, exp.DType):
expression = self.datatype_param_bound_limiter(expression, type_value)
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.

datatype_sql is hot so I think we should gate this by whether the dialect has type bounds, wdyt?

Comment thread sqlglot/generator.py
and int(param_value.to_py()) > bound
):
self.unsupported(
f"{type_value.value} parameter ({int(param_value.to_py())}) "
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.

Do we need to convert to to_py() and wrap with int? Can we just let it be as param_value?

Comment thread sqlglot/generator.py
):
self.unsupported(
f"{type_value.value} parameter ({int(param_value.to_py())}) "
f"exceeds {self.dialect.__class__.__name__}'s maximum capping to {bound}"
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.

Not sure if this reads well, did you mean to write it as <type> parameter exceeds dialects maximum <bound>; Capping.?

Comment thread sqlglot/generator.py
Comment on lines +1670 to +1677
new_param = param.copy()
capped = exp.Literal.number(bound)
if isinstance(new_param, exp.DataTypeParam):
new_param.set("this", capped)
else:
new_param = capped
new_params[i] = new_param
changed = True
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.

Do we need the copy here and the swap logic?

Comment thread tests/test_expressions.py
assert expr1.meta == {}

def test_pipe_and_apply(self) -> None:

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.

Stray diff?

Comment thread sqlglot/generator.py
Comment on lines +623 to +624
TYPE_DEFAULT_PARAMS: t.ClassVar[dict[exp.DType, tuple[int, ...]]] = {}
TYPE_PARAM_BOUNDS: t.ClassVar[dict[exp.DType, tuple[int | None, ...]]] = {}
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.

I wonder whether these could be a single data structure to avoid separate dict lookups

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.

3 participants