Skip to content

Commit 7b91a06

Browse files
SNOW-2255664: Populate type_code for interval types in ResultMetadata (#2467)
1 parent 451a60b commit 7b91a06

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
2323
- Moved `OAUTH_TYPE` to `CLIENT_ENVIROMENT`.
2424
- Fix bug where PAT with external session authenticator was used while `external_session_id` was not provided in `SnowflakeRestful.fetch`
2525
- Added support for parameter `use_vectorized_scanner` in function `write_pandas`.
26+
- Populate type_code in ResultMetadata for interval types.
2627

2728
- v3.16.0(July 04,2025)
2829
- Bumped numpy dependency from <2.1.0 to <=2.2.4.

src/snowflake/connector/constants.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@ def struct_pa_type(metadata: ResultMetadataV2) -> DataType:
183183
FieldType(
184184
name="FILE", dbapi_type=[DBAPI_TYPE_STRING], pa_type=lambda _: pa.string()
185185
),
186+
FieldType(
187+
name="INTERVAL_YEAR_MONTH",
188+
dbapi_type=[DBAPI_TYPE_NUMBER],
189+
pa_type=lambda _: pa.int64(),
190+
),
191+
FieldType(
192+
name="INTERVAL_DAY_TIME",
193+
dbapi_type=[DBAPI_TYPE_NUMBER],
194+
pa_type=lambda _: pa.int64(),
195+
),
186196
)
187197

188198
FIELD_NAME_TO_ID: DefaultDict[Any, int] = defaultdict(int)

test/integ/test_interval_types.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import numpy
77
import pytest
88

9+
from snowflake.connector import constants
10+
911
pytestmark = pytest.mark.skipolddriver # old test driver tests won't run this module
1012

1113

@@ -30,14 +32,17 @@ def test_select_year_month_interval(conn_cnx, use_numpy, result_format):
3032
cursor.execute("alter session set feature_interval_types=enabled")
3133
cursor.execute(f"create or replace table {table} (c1 interval year to month)")
3234
cursor.execute(f"insert into {table} values {values}")
33-
result = conn.cursor().execute(f"select * from {table}").fetchall()
35+
result = cursor.execute(f"select * from {table}").fetchall()
36+
# Validate column metadata.
37+
type_code = cursor._description[0].type_code
38+
assert (
39+
constants.FIELD_ID_TO_NAME[type_code] == "INTERVAL_YEAR_MONTH"
40+
), f"invalid column type: {type_code}"
41+
# Validate column values.
3442
result = [r[0] for r in result]
3543
assert result == expected
3644

3745

38-
@pytest.mark.skip(
39-
reason="SNOW-1878635: Add support for day-time interval in ArrowStreamWriter"
40-
)
4146
@pytest.mark.parametrize("use_numpy", [True, False])
4247
@pytest.mark.parametrize("result_format", ["json", "arrow"])
4348
def test_select_day_time_interval(conn_cnx, use_numpy, result_format):
@@ -71,6 +76,12 @@ def test_select_day_time_interval(conn_cnx, use_numpy, result_format):
7176
f"create or replace table {table} (c1 interval day(5) to second)"
7277
)
7378
cursor.execute(f"insert into {table} values {values}")
74-
result = conn.cursor().execute(f"select * from {table}").fetchall()
79+
result = cursor.execute(f"select * from {table}").fetchall()
80+
# Validate column metadata.
81+
type_code = cursor._description[0].type_code
82+
assert (
83+
constants.FIELD_ID_TO_NAME[type_code] == "INTERVAL_DAY_TIME"
84+
), f"invalid column type: {type_code}"
85+
# Validate column values.
7586
result = [r[0] for r in result]
7687
assert result == expected

0 commit comments

Comments
 (0)