Skip to content

Commit 7b3d36f

Browse files
committed
code optimization
1 parent 4074ca4 commit 7b3d36f

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

bigframes/bigquery/_operations/ai.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ def generate(
113113
if output_schema is None:
114114
output_schema_str = None
115115
else:
116-
sorted_fields = sorted(tuple(output_schema.items()), key=lambda t: t[0])
117116
output_schema_str = ", ".join(
118-
[f"{name} {sql_type}" for name, sql_type in sorted_fields]
117+
[f"{name} {sql_type}" for name, sql_type in output_schema.items()]
119118
)
120119
# Validate user input
121120
output_schemas.parse_sql_fields(output_schema_str)

bigframes/operations/output_schemas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def parse_sql_type(sql: str) -> pa.DataType:
4949

5050
if sql.startswith("STRUCT<") and sql.endswith(">"):
5151
inner_fields = parse_sql_fields(sql[len("STRUCT<") : -1])
52-
return pa.struct(sorted(inner_fields, key=lambda f: f.name))
52+
return pa.struct(inner_fields)
5353

5454
raise ValueError(f"Unsupported SQL type: {sql}")
5555

@@ -76,7 +76,7 @@ def parse_sql_fields(sql: str) -> tuple[pa.Field]:
7676
# Append the last field
7777
fields.append(parse_sql_field(sql[start_idx:]))
7878

79-
return tuple(fields)
79+
return tuple(sorted(fields, key=lambda f: f.name))
8080

8181

8282
def parse_sql_field(sql: str) -> pa.Field:

tests/unit/operations/test_output_schemas.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
pa.struct((pa.field("x", pa.int64()), pa.field("y", pa.float64()))),
3737
),
3838
(
39-
"ARRAY<STRUCT<x INT64, y INT64>>",
39+
"STRUCT<y INT64, x FLOAT64>",
40+
pa.struct((pa.field("x", pa.float64()), pa.field("y", pa.int64()))),
41+
),
42+
(
43+
"ARRAY<STRUCT<y INT64, x INT64>>",
4044
pa.list_(pa.struct((pa.field("x", pa.int64()), pa.field("y", pa.int64())))),
4145
),
4246
(

0 commit comments

Comments
 (0)