diff --git a/CHANGELOG.md b/CHANGELOG.md index b69f1d504..6bbd28242 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fix inline parameters (`use_inline_params=True`) so a sequence directly after `IN` renders as a list again: `x IN %(ids)s` renders as `x IN (1,2,3)` instead of `x IN ARRAY(1,2,3)`, which Spark rejects. Inside the list, tuples render as rows for a multi-column `IN`, and a `set` or `frozenset` is accepted again. Sequences anywhere else still render as `ARRAY(...)` ([#629](https://github.com/databricks/databricks-sql-python/issues/629)) - Speed up Thrift response handling: read replies in 1 MiB chunks and decode them with Thrift's C-accelerated protocol, and stop stringifying every request/response for the default no-op debug logger. Wide result schemas, metadata calls with many rows, and inline Arrow results benefit most. - Report `cursor.rowcount` after asynchronous DML completes on both the Thrift and kernel backends, preserving zero counts and fetched result rows. +- Correct explicit `DecimalParameter` precision and scale ordering and honor a declared zero scale. Callers that followed the previously reversed parameter descriptions must use `precision` for total digits and `scale` for fractional digits. Explicit zero precision is now sent as declared instead of silently using automatic sizing. # 4.9.0 (2026-11-04) - Upgrade Databricks SQL Kernel to 1.4.0, which keeps Lakehouse Real-Time session affinity and flushes shared telemetry only after the final session closes. diff --git a/src/databricks/sql/parameters/native.py b/src/databricks/sql/parameters/native.py index d0d811940..01339cdac 100644 --- a/src/databricks/sql/parameters/native.py +++ b/src/databricks/sql/parameters/native.py @@ -615,9 +615,9 @@ def __init__( The `name` argument to this function would be `my_param`. :scale: - The maximum precision (total number of digits) of the number between 1 and 38. + The number of digits to the right of the decimal point, from 0 to precision. :precision: - The number of digits to the right of the decimal point. + The maximum precision (total number of digits) of the number between 1 and 38. """ self.value: decimal.Decimal = value self.name = name @@ -638,8 +638,8 @@ def valid_scale_and_precision(self): return False def _cast_expr(self): - if self.scale and self.precision: - return self.CAST_EXPR.format(self.scale, self.precision) + if self.scale is not None and self.precision is not None: + return self.CAST_EXPR.format(self.precision, self.scale) else: return self.calculate_decimal_cast_string(self.value) diff --git a/tests/unit/test_parameters.py b/tests/unit/test_parameters.py index 0588eb499..66b0e48e9 100644 --- a/tests/unit/test_parameters.py +++ b/tests/unit/test_parameters.py @@ -107,6 +107,21 @@ def test_calculate_decimal_cast_string(value, expected): assert p._cast_expr() == expected +@pytest.mark.parametrize( + "value,precision,scale,expected", + ( + (Decimal("123.45"), 10, 2, "DECIMAL(10,2)"), + (Decimal("123"), 10, 0, "DECIMAL(10,0)"), + (Decimal("123.45"), None, None, "DECIMAL(5,2)"), + ), +) +def test_decimal_parameter_explicit_type(value, precision, scale, expected): + parameter = DecimalParameter(value, precision=precision, scale=scale) + bound = parameter.as_tspark_param(named=False) + assert bound.type == expected + assert bound.value.stringValue == str(value) + + class Primitive(Enum): """These are the inferrable types. This Enum is used for parametrized tests."""