Skip to content

Commit

Permalink
SNOW-1369648: Add test for structured type parameter binding (#1976)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jrose authored Jun 18, 2024
1 parent 3746237 commit 42fa6eb
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/integ/test_arrow_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,42 @@ def test_array(datatype, examples, iceberg, pandas, conn_cnx):
)


@pytest.mark.skipif(
not STRUCTURED_TYPES_SUPPORTED, reason="Testing structured type feature."
)
def test_structured_type_binds(conn_cnx):
original_style = snowflake.connector.paramstyle
snowflake.connector.paramstyle = "qmark"
data = (
1,
[True, False, True],
{"k1": 1, "k2": 2, "k3": 3, "k4": 4, "k5": 5},
{"city": "san jose", "population": 0.05},
[1.0, 3.1, 4.5],
)
json_data = [json.dumps(d) for d in data]
schema = "(num number, arr_b array(boolean), map map(varchar, int), obj object(city varchar, population float), arr_f array(float))"
table_name = f"arrow_structured_type_binds_test_{random_string(5)}"
with conn_cnx() as conn:
try:
conn.cursor().execute("alter session set enable_bind_stage_v2=Enable")
conn.cursor().execute(f"create table if not exists {table_name} {schema}")
conn.cursor().execute(
f"insert into {table_name} select ?, ?, ?, ?, ?", json_data
)
result = conn.cursor().execute(f"select * from {table_name}").fetchall()
assert result[0] == data

# Binds don't work with values statement yet
with pytest.raises(ProgrammingError):
conn.cursor().execute(
f"insert into {table_name} values (?, ?, ?, ?, ?)", json_data
)
finally:
snowflake.connector.paramstyle = original_style
conn.cursor().execute(f"drop table if exists {table_name}")


@pytest.mark.skipif(
not STRUCTURED_TYPES_SUPPORTED, reason="map type not supported in this environment"
)
Expand Down

0 comments on commit 42fa6eb

Please sign in to comment.