Skip to content

Commit c85d213

Browse files
committed
fix nested repeated (not allowed in proto) + grammar + equality
1 parent e78edfc commit c85d213

3 files changed

Lines changed: 67 additions & 23 deletions

File tree

meta/src/meta/grammar.y

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@
116116
%nonterm export_csv_config transactions.ExportCSVConfig
117117
%nonterm export_csv_path String
118118
%nonterm export_csv_source transactions.ExportCSVSource
119+
%nonterm export_iceberg_column transactions.ExportIcebergColumn
120+
%nonterm export_iceberg_column_source transactions.ExportIcebergColumns
121+
%nonterm export_iceberg_columns transactions.ExportIcebergColumns
119122
%nonterm export_iceberg_config transactions.ExportIcebergConfig
120123
%nonterm iceberg_catalog_config logic.IcebergCatalogConfig
121124
%nonterm iceberg_catalog_config_scope String
122125
%nonterm iceberg_data logic.IcebergData
123-
%nonterm iceberg_export_column transactions.ExportIcebergColumn
124126
%nonterm iceberg_locator logic.IcebergLocator
125127
%nonterm iceberg_property_entry Tuple[String, String]
126128
%nonterm iceberg_to_snapshot String
@@ -1167,14 +1169,30 @@ iceberg_catalog_config
11671169
$10: Sequence[Tuple[String, String]] = builtin.dict_to_pairs($$.properties)
11681170
$14: Sequence[Tuple[String, String]] = builtin.dict_to_pairs($$.auth_properties)
11691171

1170-
iceberg_export_column
1171-
: "(" "iceberg_column" STRING relation_id type boolean_value ")"
1172-
construct: $$ = transactions.ExportIcebergColumn(name=$3, column_data=$4, type=$5, nullable=$6)
1172+
export_iceberg_column
1173+
: "(" "iceberg_column" STRING type boolean_value ")"
1174+
construct: $$ = transactions.ExportIcebergColumn(name=$3, type=$4, nullable=$5)
11731175
deconstruct:
11741176
$3: String = $$.name
1175-
$4: logic.RelationId = $$.column_data
1176-
$5: logic.Type = $$.type
1177-
$6: Boolean = $$.nullable
1177+
$4: logic.Type = $$.type
1178+
$5: Boolean = $$.nullable
1179+
1180+
export_iceberg_column_source
1181+
: "(" "source_gnf_defs" relation_id* ")"
1182+
construct: $$ = transactions.ExportIcebergColumns(source_gnf_defs=transactions.ExportIcebergGnfDefs(defs=$3))
1183+
deconstruct if builtin.has_proto_field($$, 'source_gnf_defs'):
1184+
$3: Sequence[logic.RelationId] = $$.source_gnf_defs.defs
1185+
| "(" "source_table_def" relation_id ")"
1186+
construct: $$ = transactions.ExportIcebergColumns(source_table_def=$3)
1187+
deconstruct if builtin.has_proto_field($$, 'source_table_def'):
1188+
$3: logic.RelationId = $$.source_table_def
1189+
1190+
export_iceberg_columns
1191+
: "(" "columns" export_iceberg_column_source "(" "target_columns" export_iceberg_column* ")" ")"
1192+
construct: $$ = merge_export_iceberg_columns($3, $6)
1193+
deconstruct:
1194+
$3: transactions.ExportIcebergColumns = $$
1195+
$6: Sequence[transactions.ExportIcebergColumn] = $$.target_columns
11781196

11791197
iceberg_to_snapshot
11801198
: "(" "to_snapshot" STRING ")"
@@ -1311,14 +1329,14 @@ export_csv_source
13111329
$3: logic.RelationId = $$.table_def
13121330

13131331
export_iceberg_config
1314-
: "(" "export_iceberg_config" iceberg_locator iceberg_catalog_config "(" "columns" iceberg_export_column* ")" "(" "create_table_properties" iceberg_property_entry* ")" config_dict? ")"
1315-
construct: $$ = construct_export_iceberg_config_full($3, $4, $7, $11, $13)
1332+
: "(" "export_iceberg_config" iceberg_locator iceberg_catalog_config export_iceberg_columns "(" "table_properties" iceberg_property_entry* ")" config_dict? ")"
1333+
construct: $$ = construct_export_iceberg_config_full($3, $4, $5, $8, $10)
13161334
deconstruct:
13171335
$3: logic.IcebergLocator = $$.locator
13181336
$4: logic.IcebergCatalogConfig = $$.config
1319-
$7: Sequence[transactions.ExportIcebergColumn] = $$.columns
1320-
$11: Sequence[Tuple[String, String]] = builtin.dict_to_pairs($$.create_table_properties)
1321-
$13: Optional[Sequence[Tuple[String, logic.Value]]] = deconstruct_export_iceberg_config_optional($$)
1337+
$5: transactions.ExportIcebergColumns = $$.columns
1338+
$8: Sequence[Tuple[String, String]] = builtin.dict_to_pairs($$.table_properties)
1339+
$10: Optional[Sequence[Tuple[String, logic.Value]]] = deconstruct_export_iceberg_config_optional($$)
13221340

13231341

13241342
%%
@@ -1668,26 +1686,35 @@ def deconstruct_iceberg_data_to_snapshot_optional(msg: logic.IcebergData) -> Opt
16681686
def construct_export_iceberg_config_full(
16691687
locator: logic.IcebergLocator,
16701688
config: logic.IcebergCatalogConfig,
1671-
columns: Sequence[transactions.ExportIcebergColumn],
1672-
create_table_property_pairs: Sequence[Tuple[String, String]],
1689+
columns: transactions.ExportIcebergColumns,
1690+
table_property_pairs: Sequence[Tuple[String, String]],
16731691
config_dict: Optional[Sequence[Tuple[String, logic.Value]]],
16741692
) -> transactions.ExportIcebergConfig:
16751693
cfg: Dict[String, logic.Value] = builtin.dict_from_list(builtin.unwrap_option_or(config_dict, list[Tuple[String, logic.Value]]()))
16761694
prefix: String = _extract_value_string(builtin.dict_get(cfg, "prefix"), "")
16771695
target_file_size_bytes: int = _extract_value_int64(builtin.dict_get(cfg, "target_file_size_bytes"), 0)
16781696
compression: String = _extract_value_string(builtin.dict_get(cfg, "compression"), "")
1679-
create_table_props: Dict[String, String] = builtin.string_map_from_pairs(create_table_property_pairs)
1697+
table_props: Dict[String, String] = builtin.string_map_from_pairs(table_property_pairs)
16801698
return transactions.ExportIcebergConfig(
16811699
locator=locator,
16821700
config=config,
16831701
columns=columns,
16841702
prefix=builtin.some(prefix),
16851703
target_file_size_bytes=builtin.some(target_file_size_bytes),
16861704
compression=compression,
1687-
create_table_properties=create_table_props,
1705+
table_properties=table_props,
16881706
)
16891707

16901708

1709+
def merge_export_iceberg_columns(
1710+
source: transactions.ExportIcebergColumns,
1711+
target_columns: Sequence[transactions.ExportIcebergColumn],
1712+
) -> transactions.ExportIcebergColumns:
1713+
if builtin.has_proto_field(source, 'source_gnf_defs'):
1714+
return transactions.ExportIcebergColumns(source_gnf_defs=transactions.ExportIcebergGnfDefs(defs=source.source_gnf_defs.defs), target_columns=target_columns)
1715+
return transactions.ExportIcebergColumns(source_table_def=source.source_table_def, target_columns=target_columns)
1716+
1717+
16911718
def deconstruct_export_iceberg_config_optional(
16921719
msg: transactions.ExportIcebergConfig,
16931720
) -> Optional[Sequence[Tuple[String, logic.Value]]]:

proto/relationalai/lqp/v1/transactions.proto

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ message ExportIcebergColumn {
134134
bool nullable = 3;
135135
}
136136

137+
message ExportIcebergGnfDefs {
138+
repeated RelationId defs = 1;
139+
}
140+
137141
message ExportIcebergColumns {
138142
oneof iceberg_columns {
139-
repeated RelationId source_gnf_defs = 1;
143+
ExportIcebergGnfDefs source_gnf_defs = 1;
140144
RelationId source_table_def = 2;
141145
}
142146
repeated ExportIcebergColumn target_columns = 3;

sdks/julia/LogicalQueryProtocol.jl/src/equality.jl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,24 @@ Base.isequal(a::IcebergCatalogConfig, b::IcebergCatalogConfig) =
366366

367367
# ExportIcebergColumn
368368
Base.:(==)(a::ExportIcebergColumn, b::ExportIcebergColumn) =
369-
a.name == b.name && a.column_data == b.column_data && a.var"#type" == b.var"#type" && a.nullable == b.nullable
369+
a.name == b.name && a.var"#type" == b.var"#type" && a.nullable == b.nullable
370370
Base.hash(a::ExportIcebergColumn, h::UInt) =
371-
hash(a.nullable, hash(a.var"#type", hash(a.column_data, hash(a.name, h))))
371+
hash(a.nullable, hash(a.var"#type", hash(a.name, h)))
372372
Base.isequal(a::ExportIcebergColumn, b::ExportIcebergColumn) =
373-
isequal(a.name, b.name) && isequal(a.column_data, b.column_data) && isequal(a.var"#type", b.var"#type") && isequal(a.nullable, b.nullable)
373+
isequal(a.name, b.name) && isequal(a.var"#type", b.var"#type") && isequal(a.nullable, b.nullable)
374+
375+
# ExportIcebergGnfDefs
376+
Base.:(==)(a::ExportIcebergGnfDefs, b::ExportIcebergGnfDefs) = a.defs == b.defs
377+
Base.hash(a::ExportIcebergGnfDefs, h::UInt) = hash(a.defs, h)
378+
Base.isequal(a::ExportIcebergGnfDefs, b::ExportIcebergGnfDefs) = isequal(a.defs, b.defs)
379+
380+
# ExportIcebergColumns
381+
Base.:(==)(a::ExportIcebergColumns, b::ExportIcebergColumns) =
382+
a.iceberg_columns == b.iceberg_columns && a.target_columns == b.target_columns
383+
Base.hash(a::ExportIcebergColumns, h::UInt) =
384+
hash(a.target_columns, hash(a.iceberg_columns, h))
385+
Base.isequal(a::ExportIcebergColumns, b::ExportIcebergColumns) =
386+
isequal(a.iceberg_columns, b.iceberg_columns) && isequal(a.target_columns, b.target_columns)
374387

375388
# ExportIcebergConfig
376389
Base.:(==)(a::ExportIcebergConfig, b::ExportIcebergConfig) =
@@ -380,9 +393,9 @@ Base.:(==)(a::ExportIcebergConfig, b::ExportIcebergConfig) =
380393
a.prefix == b.prefix &&
381394
a.target_file_size_bytes == b.target_file_size_bytes &&
382395
a.compression == b.compression &&
383-
a.create_table_properties == b.create_table_properties
396+
a.table_properties == b.table_properties
384397
Base.hash(a::ExportIcebergConfig, h::UInt) = hash(
385-
a.create_table_properties,
398+
a.table_properties,
386399
hash(
387400
a.compression,
388401
hash(
@@ -398,7 +411,7 @@ Base.isequal(a::ExportIcebergConfig, b::ExportIcebergConfig) =
398411
isequal(a.prefix, b.prefix) &&
399412
isequal(a.target_file_size_bytes, b.target_file_size_bytes) &&
400413
isequal(a.compression, b.compression) &&
401-
isequal(a.create_table_properties, b.create_table_properties)
414+
isequal(a.table_properties, b.table_properties)
402415

403416
# IcebergData
404417
Base.:(==)(a::IcebergData, b::IcebergData) =

0 commit comments

Comments
 (0)