Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1619272: fix explode outer parameter type casting causing dynamic table creation failure #2154

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 @@ -34,6 +34,7 @@
- Fixed a bug in query generation from set operations that allowed generation of duplicate queries when children have common subqueries.
- Fixed a bug in `session.get_session_stage` that referenced a non-existing stage after switching database or schema.
- Fixed a bug where calling `DataFrame.to_snowpark_pandas_dataframe` without explicitly initializing the Snowpark pandas plugin caused an error.
- Fixed a bug where using the `explode` function in dynamic table creation caused a SQL compilation error due to improper boolean type casting on the `outer` parameter.

### Snowpark Local Testing Updates

Expand Down
10 changes: 8 additions & 2 deletions src/snowflake/snowpark/_internal/analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
from snowflake.snowpark._internal.error_message import SnowparkClientExceptionMessages
from snowflake.snowpark._internal.telemetry import TelemetryField
from snowflake.snowpark._internal.utils import quote_name
from snowflake.snowpark.types import _NumericType
from snowflake.snowpark.types import BooleanType, _NumericType

ARRAY_BIND_THRESHOLD = 512

Expand Down Expand Up @@ -605,7 +605,7 @@ def table_function_expression_extractor(
sql = named_arguments_function(
expr.func_name,
{
key: self.analyze(
key: self.to_sql_try_avoid_cast(
sfc-gh-aling marked this conversation as resolved.
Show resolved Hide resolved
value, df_aliased_col_name_to_real_col_name, parse_local_name
)
for key, value in expr.args.items()
Expand Down Expand Up @@ -745,6 +745,12 @@ def to_sql_try_avoid_cast(
# otherwise process as normal
if isinstance(expr, Literal) and isinstance(expr.datatype, _NumericType):
return numeric_to_sql_without_cast(expr.value, expr.datatype)
elif (
isinstance(expr, Literal)
and isinstance(expr.datatype, BooleanType)
and isinstance(expr.value, bool)
):
return str(expr.value).upper()
else:
return self.analyze(
expr, df_aliased_col_name_to_real_col_name, parse_local_name
Expand Down
25 changes: 25 additions & 0 deletions tests/integ/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3015,6 +3015,31 @@ def test_create_dynamic_table(session, table_name_1, is_transient):
Utils.drop_dynamic_table(session, dt_name)


@pytest.mark.xfail(
"config.getoption('local_testing_mode', default=False)",
reason="Dynamic table is a SQL feature",
run=False,
)
def test_create_dynamic_table_with_explode(session):
dt_name = Utils.random_name_for_temp_object(TempObjectType.DYNAMIC_TABLE)
temp_table = Utils.random_name_for_temp_object(TempObjectType.TABLE)
try:
df = session.create_dataframe(
[[1, [1, 2, 3]], [2, [11, 22]]], schema=["idx", "lists"]
)
df.write.mode("overwrite").save_as_table(temp_table)
df = session.table(temp_table)
df1 = df.select(df.idx, explode(df.lists))
df1.create_or_replace_dynamic_table(
dt_name, warehouse=session.get_current_warehouse(), lag="1 min"
)
session.sql(f"alter dynamic table {dt_name} refresh").collect()
res = session.sql(f"show dynamic tables like '{dt_name}'").collect()
assert len(res) == 1
sfc-gh-aling marked this conversation as resolved.
Show resolved Hide resolved
finally:
Utils.drop_table(session, temp_table)


@pytest.mark.xfail(
"config.getoption('local_testing_mode', default=False)",
reason="Dynamic table is a SQL feature",
Expand Down
Loading