Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#### Bug Fixes

- Fixed a bug where `AsyncJob.result("no_result")` sometimes silently returned without raising error for failed queries.
- Fixed a bug where `INTERVAL YEAR TO MONTH` values with zero months were displayed incorrectly (e.g. `INTERVAL '0-4' YEAR TO MONTH` instead of `INTERVAL '4-0' YEAR TO MONTH`) when using `snowflake-connector-python>=4.3.0`.

#### Improvements

Expand Down
10 changes: 5 additions & 5 deletions src/snowflake/snowpark/_internal/type_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1764,11 +1764,11 @@ def format_year_month_interval_for_display(
years = str(int(parts[0]))
months = str(int(parts[1]))
else:
# Format like "+2" or "-3"
if (
start_field == YearMonthIntervalType.YEAR
and end_field == YearMonthIntervalType.YEAR
):
# Format like "+2" or "-3" — a single number without a year-month dash.
# When start_field is YEAR the value represents years (connector >=4.3.0
# omits the "-0" suffix when months=0). Only treat as months when the
# interval type starts at MONTH.
if start_field == YearMonthIntervalType.YEAR:
years = str(int(remaining))
else:
months = str(int(remaining))
Expand Down
86 changes: 86 additions & 0 deletions tests/unit/test_datatype_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
to_sql,
to_sql_no_cast,
)
from snowflake.snowpark._internal.type_utils import (
format_year_month_interval_for_display,
)
from snowflake.snowpark._internal.udf_utils import generate_call_python_sp_sql
from snowflake.snowpark.types import (
ArrayType,
Expand Down Expand Up @@ -809,3 +812,86 @@ def test_schema_expression():
schema_expression(DayTimeIntervalType(), False)
== "INTERVAL '1 01:01:01.0001' DAY TO SECOND"
)


@pytest.mark.parametrize(
"cell, start_field, end_field, expected",
[
(
"+1-6",
YearMonthIntervalType.YEAR,
YearMonthIntervalType.MONTH,
"INTERVAL '1-6' YEAR TO MONTH",
),
(
"-2-3",
YearMonthIntervalType.YEAR,
YearMonthIntervalType.MONTH,
"INTERVAL '-2-3' YEAR TO MONTH",
),
(
"+0-5",
YearMonthIntervalType.YEAR,
YearMonthIntervalType.MONTH,
"INTERVAL '0-5' YEAR TO MONTH",
),
(
"+4",
YearMonthIntervalType.YEAR,
YearMonthIntervalType.MONTH,
"INTERVAL '4-0' YEAR TO MONTH",
),
(
"-7",
YearMonthIntervalType.YEAR,
YearMonthIntervalType.MONTH,
"INTERVAL '-7-0' YEAR TO MONTH",
),
(
"+12",
YearMonthIntervalType.YEAR,
YearMonthIntervalType.MONTH,
"INTERVAL '12-0' YEAR TO MONTH",
),
(
"+4",
YearMonthIntervalType.YEAR,
YearMonthIntervalType.YEAR,
"INTERVAL '4' YEAR",
),
(
"-1",
YearMonthIntervalType.YEAR,
YearMonthIntervalType.YEAR,
"INTERVAL '-1' YEAR",
),
(
"+5",
YearMonthIntervalType.MONTH,
YearMonthIntervalType.MONTH,
"INTERVAL '5' MONTH",
),
(
"-12",
YearMonthIntervalType.MONTH,
YearMonthIntervalType.MONTH,
"INTERVAL '-12' MONTH",
),
(
"+5-0",
YearMonthIntervalType.YEAR,
YearMonthIntervalType.YEAR,
"INTERVAL '5' YEAR",
),
(
"+0-3",
YearMonthIntervalType.MONTH,
YearMonthIntervalType.MONTH,
"INTERVAL '3' MONTH",
),
],
)
def test_format_year_month_interval_for_display(cell, start_field, end_field, expected):
assert (
format_year_month_interval_for_display(cell, start_field, end_field) == expected
)
Loading