Skip to content

Commit 01c423e

Browse files
committed
remove redundant code
1 parent c3d8746 commit 01c423e

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

src/snowflake/snowpark/_internal/analyzer/select_statement.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@
5151

5252
from snowflake.snowpark._internal.analyzer import analyzer_utils
5353
from snowflake.snowpark._internal.analyzer.analyzer_utils import (
54-
quote_name_without_upper_casing,
5554
result_scan_statement,
5655
schema_value_statement,
57-
unquote_if_quoted,
5856
)
5957
from snowflake.snowpark._internal.analyzer.binary_expression import And
6058
from snowflake.snowpark._internal.analyzer.expression import (
@@ -87,7 +85,6 @@
8785
has_invalid_projection_merge_functions,
8886
)
8987
from snowflake.snowpark._internal.utils import (
90-
ALREADY_QUOTED,
9188
ExprAliasUpdateDict,
9289
is_sql_select_statement,
9390
quote_name,
@@ -1596,9 +1593,10 @@ def select(self, cols: List[Expression]) -> "SelectStatement":
15961593
# When describe reduction is on and the inner select already has resolved
15971594
# attributes, infer new.attributes for this outer select by reusing datatype and
15981595
# nullable from the subquery: (0) skip if parent column names collide, (1) index
1599-
# attributes by normalized name, (2) walk new.projection, (3) only handle plain
1600-
# columns or Alias(column), (4) resolve source via quoted-identifier-aware lookup,
1601-
# (5) assign only if every output column was inferred (length matches projection).
1596+
# attributes by quote_name (Snowflake identifier rules; invalid delimited forms
1597+
# raise), (2) walk new.projection, (3) only handle plain columns or Alias(column),
1598+
# (4) resolve source via the same quote_name key lookup, (5) assign only if every
1599+
# output column was inferred (length matches projection).
16021600
if self._session.reduce_describe_query_enabled and self.attributes is not None:
16031601
parent_attributes = self.attributes
16041602
projection = new.projection
@@ -1609,9 +1607,9 @@ def select(self, cols: List[Expression]) -> "SelectStatement":
16091607
attributes_by_normalized: Dict[str, Attribute] = {}
16101608
collision = False
16111609
for attr in parent_attributes:
1612-
key = _normalized_snowflake_identifier_key(attr.name)
1610+
key = quote_name(attr.name)
16131611
existing = attributes_by_normalized.get(key)
1614-
# Skip: two parent columns normalize to the same key.
1612+
# Skip: two parent columns map to the same quote_name key.
16151613
if existing is not None and existing is not attr:
16161614
collision = True
16171615
break
@@ -1639,7 +1637,7 @@ def select(self, cols: List[Expression]) -> "SelectStatement":
16391637
inferred_attributes = []
16401638
break
16411639
source_attr = attributes_by_normalized.get(
1642-
_normalized_snowflake_identifier_key(source_column_name)
1640+
quote_name(source_column_name)
16431641
)
16441642
# Skip: no parent column for this source name.
16451643
if source_attr is None:
@@ -2156,13 +2154,6 @@ class DeriveColumnDependencyError(Exception):
21562154
"""When deriving column dependencies from the subquery."""
21572155

21582156

2159-
def _normalized_snowflake_identifier_key(name: str) -> str:
2160-
"""Canonical quoted key: delimited identifiers preserve case; unquoted follow Snowflake uppercasing."""
2161-
if ALREADY_QUOTED.match(name):
2162-
return quote_name_without_upper_casing(unquote_if_quoted(name))
2163-
return quote_name(name)
2164-
2165-
21662157
def parse_column_name(
21672158
column: Expression,
21682159
analyzer: "Analyzer",

tests/integ/test_reduce_describe_query.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
from snowflake.snowpark._internal.analyzer.schema_utils import analyze_attributes
1818
from snowflake.snowpark._internal.utils import (
1919
TempObjectType,
20+
quote_name,
2021
random_name_for_temp_object,
2122
)
23+
from snowflake.snowpark.exceptions import SnowparkPlanException
2224
from snowflake.snowpark.functions import (
2325
avg,
2426
col,
@@ -663,6 +665,21 @@ def test_select_inference_skips_on_duplicate_parent_keys_and_missing_alias_name(
663665
assert new_ss.attributes is None
664666

665667

668+
def test_quote_name_malformed_delimited_identifier_not_accepted():
669+
"""Keys for reduce-describe attribute inference use quote_name; malformed delimited names raise (SNOW-3384967)."""
670+
for bad in ('"ab"c"', '""col"', '"col""'):
671+
with pytest.raises(SnowparkPlanException) as ex_info:
672+
quote_name(bad)
673+
assert ex_info.value.error_code == "1200"
674+
assert "Invalid identifier" in str(ex_info.value)
675+
676+
677+
def test_quote_name_valid_keys_for_reduce_describe_inference():
678+
"""quote_name keys used for inference: case-sensitive quoted id; unquoted uppercased."""
679+
assert quote_name('"MixedCase"') == '"MixedCase"'
680+
assert quote_name("a") == '"A"'
681+
682+
666683
def test_select_star_after_cached_parent(session):
667684
"""SELECT * after parent schema is cached: infer_metadata can copy child attributes when reduce_describe is on."""
668685
df = session.create_dataframe([[1, 2]], schema=["a", "b"])

0 commit comments

Comments
 (0)