Skip to content

Commit afc7a49

Browse files
SNOW-2187773 Add basic support for DECFLOAT (#2599)
* SNOW-2187773 Set Decimal precision to 38 * bring empty line back * add test for DECFLOAT; improved setting precision so it works in the real snow execution and in tests
1 parent be35060 commit afc7a49

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

RELEASE-NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* Fixed issues when pasting content with trailing new lines.
4141
* Improved output handling with streaming
4242
* Bumped `snowflake-connector-python` to 3.17.3
43+
* Extend `Decimal` precision to 38
4344

4445

4546
# v3.11.0

src/snowflake/cli/_app/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import decimal
1516
import logging
1617
import os
1718

@@ -20,3 +21,6 @@
2021

2122
# Restrict permissions of all created files
2223
os.umask(0o077)
24+
25+
# Set Decimal precision to reflect precision on Snowflake
26+
decimal.getcontext().prec = 38

src/snowflake/cli/_plugins/snowpark/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ def user_to_sql_type_mapper(user_provided_type: str) -> str:
349349
"FLOAT4",
350350
"FLOAT8",
351351
),
352+
("DECFLOAT", ""): ("DECFLOAT",),
352353
("TIMESTAMP_NTZ", ""): ("TIMESTAMP_NTZ", "TIMESTAMPNTZ", "DATETIME"),
353354
("TIMESTAMP_LTZ", ""): ("TIMESTAMP_LTZ", "TIMESTAMPLTZ"),
354355
("TIMESTAMP_TZ", ""): ("TIMESTAMP_TZ", "TIMESTAMPTZ"),

src/snowflake/cli/_plugins/sql/lexer/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"DATETIME",
1212
"DEC",
1313
"DECIMAL",
14+
"DECFLOAT",
1415
"DOUBLE",
1516
"FLOAT",
1617
"INT",

tests_integration/sql/test_sql.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,34 @@ def test_nested_json_backward_compatibility(runner):
347347
assert "profile" in user_obj
348348
assert "Alice" in user_obj
349349
assert "dark" in user_obj
350+
351+
352+
@pytest.mark.integration
353+
@pytest.mark.qa_only
354+
def test_decfloat_values(runner):
355+
"""Test DECFLOAT type with various value types: positive/negative, maximum/minimum, floating point."""
356+
357+
sql = """
358+
SELECT
359+
CAST('123456789012345678901234567890.123456789' AS DECFLOAT) AS positive_value,
360+
CAST('-123456789012345678901234567890.123456789' AS DECFLOAT) AS negative_value,
361+
CAST('3.14159265358979323846264338327950288419' AS DECFLOAT) AS floating_point,
362+
CAST('99999999999999999999999999999999999999e16384' AS DECFLOAT) AS maximum_value,
363+
CAST('-99999999999999999999999999999999999999e16384' AS DECFLOAT) AS minimum_value,
364+
"""
365+
366+
result = runner.invoke_with_connection_json(["sql", "-q", sql])
367+
assert result.exit_code == 0, f"Failed to select DECFLOAT values: {result.output}"
368+
369+
# Verify JSON response contains expected values
370+
assert len(result.json) == 1
371+
row = result.json[0]
372+
373+
# Assert exact values that Snowflake returns for DECFLOAT
374+
assert row["POSITIVE_VALUE"] == "123456789012345678901234567890.12345679"
375+
assert row["NEGATIVE_VALUE"] == "-123456789012345678901234567890.12345679"
376+
assert (
377+
row["FLOATING_POINT"] == "3.1415926535897932384626433832795028842"
378+
) # value is rounded up to 38 numbers
379+
assert row["MAXIMUM_VALUE"] == "9.9999999999999999999999999999999999999E+16421"
380+
assert row["MINIMUM_VALUE"] == "-9.9999999999999999999999999999999999999E+16421"

0 commit comments

Comments
 (0)