|
87 | 87 | %nonterm gnf_column logic.GNFColumn |
88 | 88 | %nonterm gnf_column_path Sequence[String] |
89 | 89 | %nonterm gnf_columns Sequence[logic.GNFColumn] |
| 90 | +%nonterm named_column logic.NamedColumn |
| 91 | +%nonterm relation_keys Sequence[logic.NamedColumn] |
| 92 | +%nonterm target_relation logic.TargetRelation |
| 93 | +%nonterm non_cdc_relations Sequence[logic.TargetRelation] |
| 94 | +%nonterm cdc_inserts Sequence[logic.TargetRelation] |
| 95 | +%nonterm cdc_deletes Sequence[logic.TargetRelation] |
| 96 | +%nonterm relation_body logic.TargetRelations |
| 97 | +%nonterm target_relations logic.TargetRelations |
90 | 98 | %nonterm csv_config logic.CSVConfig |
91 | 99 | %nonterm csv_data logic.CSVData |
92 | 100 | %nonterm csv_locator_inline_data String |
@@ -1108,13 +1116,58 @@ csv_asof |
1108 | 1116 | : "(" "asof" STRING ")" |
1109 | 1117 |
|
1110 | 1118 | csv_data |
1111 | | - : "(" "csv_data" csvlocator csv_config gnf_columns csv_asof ")" |
1112 | | - construct: $$ = logic.CSVData(locator=$3, config=$4, columns=$5, asof=$6) |
| 1119 | + : "(" "csv_data" csvlocator csv_config gnf_columns? target_relations? csv_asof ")" |
| 1120 | + construct: $$ = construct_csv_data($3, $4, $5, $6, $7) |
1113 | 1121 | deconstruct: |
1114 | 1122 | $3: logic.CSVLocator = $$.locator |
1115 | 1123 | $4: logic.CSVConfig = $$.config |
1116 | | - $5: Sequence[logic.GNFColumn] = $$.columns |
1117 | | - $6: String = $$.asof |
| 1124 | + $5: Optional[Sequence[logic.GNFColumn]] = deconstruct_csv_data_columns_optional($$) |
| 1125 | + $6: Optional[logic.TargetRelations] = deconstruct_csv_data_relations_optional($$) |
| 1126 | + $7: String = $$.asof |
| 1127 | + |
| 1128 | +named_column |
| 1129 | + : "(" "column" STRING type ")" |
| 1130 | + construct: $$ = logic.NamedColumn(name=$3, type=$4) |
| 1131 | + deconstruct: |
| 1132 | + $3: String = $$.name |
| 1133 | + $4: logic.Type = $$.type |
| 1134 | + |
| 1135 | +relation_keys |
| 1136 | + : "(" "keys" named_column* ")" |
| 1137 | + |
| 1138 | +target_relation |
| 1139 | + : "(" "relation" relation_id named_column* ")" |
| 1140 | + construct: $$ = logic.TargetRelation(target_id=$3, values=$4) |
| 1141 | + deconstruct: |
| 1142 | + $3: logic.RelationId = $$.target_id |
| 1143 | + $4: Sequence[logic.NamedColumn] = $$.values |
| 1144 | + |
| 1145 | +non_cdc_relations |
| 1146 | + : target_relation* |
| 1147 | + |
| 1148 | +cdc_inserts |
| 1149 | + : "(" "inserts" target_relation* ")" |
| 1150 | + |
| 1151 | +cdc_deletes |
| 1152 | + : "(" "deletes" target_relation* ")" |
| 1153 | + |
| 1154 | +relation_body |
| 1155 | + : non_cdc_relations |
| 1156 | + construct: $$ = construct_non_cdc_relations($1) |
| 1157 | + deconstruct if builtin.has_proto_field($$, 'plain'): |
| 1158 | + $1: Sequence[logic.TargetRelation] = $$.plain.targets |
| 1159 | + | cdc_inserts cdc_deletes |
| 1160 | + construct: $$ = construct_cdc_relations($1, $2) |
| 1161 | + deconstruct if builtin.has_proto_field($$, 'cdc'): |
| 1162 | + $1: Sequence[logic.TargetRelation] = $$.cdc.inserts |
| 1163 | + $2: Sequence[logic.TargetRelation] = $$.cdc.deletes |
| 1164 | + |
| 1165 | +target_relations |
| 1166 | + : "(" "relations" relation_keys relation_body ")" |
| 1167 | + construct: $$ = construct_relations($3, $4) |
| 1168 | + deconstruct: |
| 1169 | + $3: Sequence[logic.NamedColumn] = $$.keys |
| 1170 | + $4: logic.TargetRelations = $$ |
1118 | 1171 |
|
1119 | 1172 | csv_locator_paths |
1120 | 1173 | : "(" "paths" STRING* ")" |
@@ -1484,6 +1537,62 @@ def _try_extract_value_string_list(value: Optional[logic.Value]) -> Optional[Seq |
1484 | 1537 | return None |
1485 | 1538 |
|
1486 | 1539 |
|
| 1540 | +def construct_non_cdc_relations( |
| 1541 | + targets: Sequence[logic.TargetRelation], |
| 1542 | +) -> logic.TargetRelations: |
| 1543 | + return logic.TargetRelations( |
| 1544 | + keys=list[logic.NamedColumn](), |
| 1545 | + plain=logic.PlainTargets(targets=targets), |
| 1546 | + ) |
| 1547 | + |
| 1548 | + |
| 1549 | +def construct_cdc_relations( |
| 1550 | + inserts: Sequence[logic.TargetRelation], |
| 1551 | + deletes: Sequence[logic.TargetRelation], |
| 1552 | +) -> logic.TargetRelations: |
| 1553 | + return logic.TargetRelations( |
| 1554 | + keys=list[logic.NamedColumn](), |
| 1555 | + cdc=logic.CDCTargets(inserts=inserts, deletes=deletes), |
| 1556 | + ) |
| 1557 | + |
| 1558 | + |
| 1559 | +def construct_relations( |
| 1560 | + keys: Sequence[logic.NamedColumn], |
| 1561 | + body: logic.TargetRelations, |
| 1562 | +) -> logic.TargetRelations: |
| 1563 | + if builtin.has_proto_field(body, "plain"): |
| 1564 | + return logic.TargetRelations(keys=keys, plain=body.plain) |
| 1565 | + return logic.TargetRelations(keys=keys, cdc=body.cdc) |
| 1566 | + |
| 1567 | + |
| 1568 | +def construct_csv_data( |
| 1569 | + locator: logic.CSVLocator, |
| 1570 | + config: logic.CSVConfig, |
| 1571 | + columns_opt: Optional[Sequence[logic.GNFColumn]], |
| 1572 | + relations_opt: Optional[logic.TargetRelations], |
| 1573 | + asof: String, |
| 1574 | +) -> logic.CSVData: |
| 1575 | + return logic.CSVData( |
| 1576 | + locator=locator, |
| 1577 | + config=config, |
| 1578 | + columns=builtin.unwrap_option_or(columns_opt, list[logic.GNFColumn]()), |
| 1579 | + asof=asof, |
| 1580 | + relations=relations_opt, |
| 1581 | + ) |
| 1582 | + |
| 1583 | + |
| 1584 | +def deconstruct_csv_data_columns_optional(msg: logic.CSVData) -> Optional[Sequence[logic.GNFColumn]]: |
| 1585 | + if builtin.has_proto_field(msg, "relations"): |
| 1586 | + return builtin.none() |
| 1587 | + return builtin.some(msg.columns) |
| 1588 | + |
| 1589 | + |
| 1590 | +def deconstruct_csv_data_relations_optional(msg: logic.CSVData) -> Optional[logic.TargetRelations]: |
| 1591 | + if builtin.has_proto_field(msg, "relations"): |
| 1592 | + return builtin.some(builtin.unwrap_option(msg.relations)) |
| 1593 | + return builtin.none() |
| 1594 | + |
| 1595 | + |
1487 | 1596 | def construct_csv_config( |
1488 | 1597 | config_dict: Sequence[Tuple[String, logic.Value]], |
1489 | 1598 | storage_integration_opt: Optional[Sequence[Tuple[String, logic.Value]]], |
|
0 commit comments