Skip to content

Commit 1559f31

Browse files
committed
fix empty case
1 parent 4004f7b commit 1559f31

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

src/snowflake/snowpark/types.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,13 @@ def json_value(self) -> Dict[str, Any]:
780780

781781
def _fill_ast(self, ast: proto.SpDataType) -> None:
782782
ast.sp_struct_type.structured = self.structured
783-
for field in self.fields or []:
784-
field._fill_ast(ast.sp_struct_type.fields.list.add())
783+
if self.fields is None:
784+
return
785+
elif len(self.fields) > 0:
786+
for field in self.fields or []:
787+
field._fill_ast(ast.sp_struct_type.fields.list.add())
788+
else:
789+
ast.sp_struct_type.fields.list.extend([])
785790

786791

787792
class VariantType(DataType):

tests/ast/data/col_cast.test

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ df = df.select(col("A").cast(MapType(StringType(), StringType(), structured=Fals
101101

102102
df = df.select(col("A").cast(VectorType(FloatType(), 42)))
103103

104-
df = df.select(col("A").cast(StructType(structured=False)))
104+
df = df.select(col("A").cast(StructType([], structured=False)))
105105

106-
df = df.select(col("A").cast(StructType(structured=False)))
106+
df = df.select(col("A").cast(StructType([], structured=False)))
107107

108108
df = df.select(col("A").cast(StructType([StructField("B", IntegerType(), nullable=True)], structured=False)))
109109

@@ -1572,6 +1572,8 @@ body {
15721572
}
15731573
to {
15741574
sp_struct_type {
1575+
fields {
1576+
}
15751577
}
15761578
}
15771579
}
@@ -1651,6 +1653,8 @@ body {
16511653
}
16521654
to {
16531655
sp_struct_type {
1656+
fields {
1657+
}
16541658
}
16551659
}
16561660
}

tests/ast/data/col_try_cast.test

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ df = df.select(col("A").try_cast(MapType(StringType(), StringType(), structured=
9393

9494
df = df.select(col("A").try_cast(VectorType(FloatType(), 42)))
9595

96-
df = df.select(col("A").try_cast(StructType(structured=False)))
96+
df = df.select(col("A").try_cast(StructType([], structured=False)))
9797

9898
df = df.select(col("A").try_cast(VariantType()))
9999

@@ -1478,6 +1478,8 @@ body {
14781478
}
14791479
to {
14801480
sp_struct_type {
1481+
fields {
1482+
}
14811483
}
14821484
}
14831485
}

tests/ast/data/sproc.test

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ res34 = sproc("select_sp", return_type=StructType([StructField("A", IntegerType(
175175

176176
session.sql("SELECT 1 as A, 2 as B").show()
177177

178-
res38 = sproc("select_sp", return_type=StructType(structured=False), input_types=[IntegerType(), IntegerType()], source_code_display=False, _registered_object_name="\"MOCK_DATABASE\".\"MOCK_SCHEMA\".\"SNOWPARK_TEMP_PROCEDURE_xxx\"")(1, 2)
178+
res38 = sproc("select_sp", return_type=StructType([], structured=False), input_types=[IntegerType(), IntegerType()], source_code_display=False, _registered_object_name="\"MOCK_DATABASE\".\"MOCK_SCHEMA\".\"SNOWPARK_TEMP_PROCEDURE_xxx\"")(1, 2)
179179

180180
session.sql("SELECT 1 as A, 2 as B").show()
181181

182-
res42 = sproc("select_sp", return_type=StructType(structured=False), input_types=[LongType(), LongType()], _registered_object_name="\"MOCK_DATABASE\".\"MOCK_SCHEMA\".\"SNOWPARK_TEMP_PROCEDURE_xxx\"")(1, 2)
182+
res42 = sproc("select_sp", return_type=StructType([], structured=False), input_types=[LongType(), LongType()], _registered_object_name="\"MOCK_DATABASE\".\"MOCK_SCHEMA\".\"SNOWPARK_TEMP_PROCEDURE_xxx\"")(1, 2)
183183

184184
session.sql("SELECT 1 as A, 2 as B").show()
185185

@@ -1995,6 +1995,8 @@ body {
19951995
parallel: 4
19961996
return_type {
19971997
sp_struct_type {
1998+
fields {
1999+
}
19982000
}
19992001
}
20002002
src {
@@ -2140,6 +2142,8 @@ body {
21402142
parallel: 4
21412143
return_type {
21422144
sp_struct_type {
2145+
fields {
2146+
}
21432147
}
21442148
}
21452149
source_code_display: true

0 commit comments

Comments
 (0)