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
27 changes: 26 additions & 1 deletion src/snowflake/snowpark/mock/_nop_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
from snowflake.connector.cursor import ResultMetadata
from snowflake.snowpark._internal.analyzer.analyzer_utils import unquote_if_quoted
from snowflake.snowpark._internal.analyzer.expression import Attribute
from snowflake.snowpark._internal.analyzer.snowflake_plan import SnowflakePlan
from snowflake.snowpark._internal.analyzer.snowflake_plan import (
SnowflakePlan,
PlanQueryType,
)
from snowflake.snowpark._internal.analyzer.snowflake_plan_node import (
LogicalPlan,
SaveMode,
Expand Down Expand Up @@ -120,6 +123,28 @@ def execute(
]:
source_plan = plan.source_plan

if hasattr(source_plan, "execution_queries"):
# If temp read-only table, explicitly create it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe add a simple unit/integ test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's necessary/it would be redundant since the to_snowpark_pandas.test test will fail if there's something wrong with this generation

# This occurs when code such as to_snowpark_pandas is run where the Snowpark version of the table is
# cloned and then read.
from snowflake.snowpark.mock import TableEmulator

for plan_query_type, query in source_plan.execution_queries.items():
if query:
query_sql = query[0].sql
if (
plan_query_type == PlanQueryType.QUERIES
and "TEMPORARY READ ONLY TABLE" in query_sql
):
temp_table_name = query_sql.split("TEMPORARY READ ONLY TABLE ")[
1
].split(" ")[0]
self.entity_registry.write_table(
temp_table_name,
TableEmulator({"A": [1], "B": [1], "C": [1]}),
SaveMode.IGNORE,
)

if isinstance(source_plan, SnowflakeCreateTable):
result = self.entity_registry.write_table(
source_plan.table_name,
Expand Down
4 changes: 4 additions & 0 deletions src/snowflake/snowpark/mock/_nop_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any, Dict, List, Optional

import snowflake.snowpark
from snowflake.snowpark.mock import TableEmulator
from snowflake.snowpark._internal.analyzer.analyzer_utils import unquote_if_quoted
from snowflake.snowpark._internal.analyzer.binary_plan_node import Join
from snowflake.snowpark._internal.analyzer.expression import (
Expand Down Expand Up @@ -117,6 +118,9 @@ def resolve_attributes(
pivot_attrs.extend(pivot_result_cols)
attributes = pivot_attrs

elif isinstance(plan, TableEmulator):
attributes = [Attribute(name, _NumericType(), False) for name in plan.columns]

elif isinstance(plan, TableUpdate):
attributes = [
Attribute(name, _NumericType(), False)
Expand Down
6 changes: 4 additions & 2 deletions tests/ast/data/Dataframe.to_snowpark_pandas.test
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ body {
expr {
sp_table {
name {
sp_table_name_flat {
name: "table1"
name {
sp_name_flat {
name: "table1"
}
}
}
src {
Expand Down
Loading