Skip to content

Commit f0c3d99

Browse files
authored
Merge pull request #690 from jvalue/rfc-0021-impl
RFC 0021: Implementation
2 parents 0875fa8 + aef2161 commit f0c3d99

39 files changed

Lines changed: 293 additions & 243 deletions

apps/interpreter/test/assets/broken-model.jv

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ pipeline CarsPipeline {
4444
}
4545

4646
transform CarParser {
47-
from r oftype Collection<text>;
47+
from r oftype SheetRow;
4848
to car oftype Car;
4949

5050
car: {
51-
name: asText (r cellInColumn "name"),
52-
mpg: asDecimal (r cellInColumn "mpg"),
53-
cyl: asInteger (r cellInColumn 2),
54-
disp: asDecimal (r cellInColumn 3),
55-
hp: asInteger (r cellInColumn "hp"),
56-
drat: asDecimal (r cellInColumn "drat"),
57-
wt: asDecimal (r cellInColumn "wt"),
58-
qsec: asDecimal (r cellInColumn "qsec"),
59-
vs: asInteger (r cellInColumn "vs"),
60-
am: asInteger (r cellInColumn "am"),
61-
gear: asInteger (r cellInColumn "gear"),
62-
carb: asInteger (r cellInColumn "carb")
51+
name: asText (r . "name"),
52+
mpg: asDecimal (r . "mpg"),
53+
cyl: asInteger (r . 2),
54+
disp: asDecimal (r . 3),
55+
hp: asInteger (r . "hp"),
56+
drat: asDecimal (r . "drat"),
57+
wt: asDecimal (r . "wt"),
58+
qsec: asDecimal (r . "qsec"),
59+
vs: asInteger (r . "vs"),
60+
am: asInteger (r . "am"),
61+
gear: asInteger (r . "gear"),
62+
carb: asInteger (r . "carb")
6363
};
6464
}
6565

example/cars.jv

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,22 @@ pipeline CarsPipeline {
8989
}
9090

9191
transform CarParser {
92-
from r oftype Collection<text>;
92+
from r oftype SheetRow;
9393
to car oftype Car;
9494

9595
car: {
96-
name: asText (r cellInColumn "name"),
97-
mpg: asDecimal (r cellInColumn "mpg"),
98-
cyl: asInteger (r cellInColumn 2),
99-
disp: asDecimal (r cellInColumn 3),
100-
hp: asInteger (r cellInColumn "hp"),
101-
drat: asDecimal (r cellInColumn "drat"),
102-
wt: asDecimal (r cellInColumn "wt"),
103-
qsec: asDecimal (r cellInColumn "qsec"),
104-
vs: asInteger (r cellInColumn "vs"),
105-
am: asInteger (r cellInColumn "am"),
106-
gear: asInteger (r cellInColumn "gear"),
107-
carb: asInteger (r cellInColumn "carb")
96+
name: asText (r."name"),
97+
mpg: asDecimal (r . "mpg"),
98+
cyl: asInteger (r.2),
99+
disp: asDecimal (r . 3),
100+
hp: asInteger (r . "hp"),
101+
drat: asDecimal (r . "drat"),
102+
wt: asDecimal (r . "wt"),
103+
qsec: asDecimal (r . "qsec"),
104+
vs: asInteger (r . "vs"),
105+
am: asInteger (r . "am"),
106+
gear: asInteger (r . "gear"),
107+
carb: asInteger (r . "carb")
108108
};
109109
}
110110

example/electric-vehicles.jv

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,27 @@ pipeline ElectricVehiclesPipeline {
7070
}
7171

7272
transform ElectricVehicleParser {
73-
from r oftype Collection<text>;
73+
from r oftype SheetRow;
7474
to ev oftype ElectricVehicle;
7575

7676
ev: {
77-
vin: r cellInColumn "VIN (1-10)",
78-
county: asText (r cellInColumn "County"),
79-
city: asText (r cellInColumn "City"),
80-
state: asText (r cellInColumn "State"),
81-
postal: asText (r cellInColumn "Postal Code"),
82-
modelYear: asInteger (r cellInColumn "Model Year"),
83-
make: asText (r cellInColumn "Make"),
84-
model: asText (r cellInColumn "Model"),
85-
evType: asText (r cellInColumn "Electric Vehicle Type"),
86-
cafvEligibility: asText (r cellInColumn "Clean Alternative Fuel Vehicle (CAFV) Eligibility"),
87-
electricRange: asInteger (r cellInColumn "Electric Range"),
88-
baseMSRP: asInteger (r cellInColumn "Base MSRP"),
89-
legislativeDistrict: asText (r cellInColumn "LegislativeDistrict"),
90-
dolID: asInteger (r cellInColumn "DOL Vehicle ID"),
91-
location: asText (r cellInColumn "Vehicle Location"),
92-
utility: asText (r cellInColumn "Electric Utility"),
93-
censusTract: asText (r cellInColumn "2020 Census Tract"),
77+
vin: r . "VIN (1-10)",
78+
county: asText (r . "County"),
79+
city: asText (r . "City"),
80+
state: asText (r . "State"),
81+
postal: asText (r . "Postal Code"),
82+
modelYear: asInteger (r . "Model Year"),
83+
make: asText (r . "Make"),
84+
model: asText (r . "Model"),
85+
evType: asText (r . "Electric Vehicle Type"),
86+
cafvEligibility: asText (r . "Clean Alternative Fuel Vehicle (CAFV) Eligibility"),
87+
electricRange: asInteger (r . "Electric Range"),
88+
baseMSRP: asInteger (r . "Base MSRP"),
89+
legislativeDistrict: asText (r . "LegislativeDistrict"),
90+
dolID: asInteger (r . "DOL Vehicle ID"),
91+
location: asText (r . "Vehicle Location"),
92+
utility: asText (r . "Electric Utility"),
93+
censusTract: asText (r . "2020 Census Tract"),
9494
};
9595
}
9696

example/gtfs-rt.jv

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,20 @@ pipeline GtfsRTSimplePipeline {
7171
property entityTripUpdateStopTimeUpdateDepartureTime oftype text;
7272
}
7373
transform TripUpdateParser {
74-
from r oftype Collection<text>;
74+
from r oftype SheetRow;
7575
to tripUpdate oftype TripUpdate;
7676

7777
tripUpdate: {
78-
headerGtfsRealtimeVersion: r cellInColumn "header.gtfs_realtime_version",
79-
headerTimestamp: r cellInColumn "header.timestamp",
80-
headerIncrementality: r cellInColumn "header.incrementality",
81-
entityId: r cellInColumn "entity.id",
82-
entityTripUpdateTripTripId: r cellInColumn "entity.trip_update.trip.trip_id",
83-
entityTripUpdateTripRouteId: r cellInColumn "entity.trip_update.trip.route_id",
84-
entityTripUpdateStopTimeUpdateStopSequence: r cellInColumn "entity.trip_update.stop_time_update.stop_sequence",
85-
entityTripUpdateStopTimeUpdateStopId: r cellInColumn "entity.trip_update.stop_time_update.stop_id",
86-
entityTripUpdateStopTimeUpdateArrivalTime: r cellInColumn "entity.trip_update.stop_time_update.arrival.time",
87-
entityTripUpdateStopTimeUpdateDepartureTime: r cellInColumn "entity.trip_update.stop_time_update.departure.time",
78+
headerGtfsRealtimeVersion: r . "header.gtfs_realtime_version",
79+
headerTimestamp: r . "header.timestamp",
80+
headerIncrementality: r . "header.incrementality",
81+
entityId: r . "entity.id",
82+
entityTripUpdateTripTripId: r . "entity.trip_update.trip.trip_id",
83+
entityTripUpdateTripRouteId: r . "entity.trip_update.trip.route_id",
84+
entityTripUpdateStopTimeUpdateStopSequence: r . "entity.trip_update.stop_time_update.stop_sequence",
85+
entityTripUpdateStopTimeUpdateStopId: r . "entity.trip_update.stop_time_update.stop_id",
86+
entityTripUpdateStopTimeUpdateArrivalTime: r . "entity.trip_update.stop_time_update.arrival.time",
87+
entityTripUpdateStopTimeUpdateDepartureTime: r . "entity.trip_update.stop_time_update.departure.time",
8888
};
8989
}
9090
block TripUpdateTableInterpreter oftype TableInterpreter {
@@ -107,20 +107,20 @@ pipeline GtfsRTSimplePipeline {
107107
property entityVehiclePositionTimestamp oftype text;
108108
}
109109
transform VehiclePositionParser {
110-
from r oftype Collection<text>;
110+
from r oftype SheetRow;
111111
to vehiclePosition oftype VehiclePosition;
112112

113113
vehiclePosition: {
114-
headerGtfsRealtimeVersion: r cellInColumn "header.gtfs_realtime_version",
115-
headerTimestamp: r cellInColumn "header.timestamp",
116-
headerIncrementality: r cellInColumn "header.incrementality",
117-
entityId: r cellInColumn "entity.id",
118-
entityVehiclePositionVehicleDescriptorId: r cellInColumn "entity.vehicle_position.vehicle_descriptor.id",
119-
entityVehiclePositionTripTripId: r cellInColumn "entity.vehicle_position.trip.trip_id",
120-
entityVehiclePositionTripRouteId: r cellInColumn "entity.vehicle_position.trip.route_id",
121-
entityVehiclePositionPositionLatitude: r cellInColumn "entity.vehicle_position.position.latitude",
122-
entityVehiclePositionPositionLongitude: r cellInColumn "entity.vehicle_position.position.longitude",
123-
entityVehiclePositionTimestamp: r cellInColumn "entity.vehicle_position.timestamp",
114+
headerGtfsRealtimeVersion: r . "header.gtfs_realtime_version",
115+
headerTimestamp: r . "header.timestamp",
116+
headerIncrementality: r . "header.incrementality",
117+
entityId: r . "entity.id",
118+
entityVehiclePositionVehicleDescriptorId: r . "entity.vehicle_position.vehicle_descriptor.id",
119+
entityVehiclePositionTripTripId: r . "entity.vehicle_position.trip.trip_id",
120+
entityVehiclePositionTripRouteId: r . "entity.vehicle_position.trip.route_id",
121+
entityVehiclePositionPositionLatitude: r . "entity.vehicle_position.position.latitude",
122+
entityVehiclePositionPositionLongitude: r . "entity.vehicle_position.position.longitude",
123+
entityVehiclePositionTimestamp: r . "entity.vehicle_position.timestamp",
124124
};
125125
}
126126
block VehiclePositionTableInterpreter oftype TableInterpreter {
@@ -140,17 +140,17 @@ pipeline GtfsRTSimplePipeline {
140140
property entityAlertDescriptionText oftype text;
141141
}
142142
transform AlertParser {
143-
from r oftype Collection<text>;
143+
from r oftype SheetRow;
144144
to alert oftype Alert;
145145

146146
alert: {
147-
headerGtfsRealtimeVersion: r cellInColumn "header.gtfs_realtime_version",
148-
headerTimestamp: r cellInColumn "header.timestamp",
149-
headerIncrementality: r cellInColumn "header.incrementality",
150-
entityId: r cellInColumn "entity.id",
151-
entityAlertInformedEntityRouteId: r cellInColumn "entity.alert.informed_entity.route_id",
152-
entityAlertHeaderText: r cellInColumn "entity.alert.header_text",
153-
entityAlertDescriptionText: r cellInColumn "entity.alert.description_text",
147+
headerGtfsRealtimeVersion: r . "header.gtfs_realtime_version",
148+
headerTimestamp: r . "header.timestamp",
149+
headerIncrementality: r . "header.incrementality",
150+
entityId: r . "entity.id",
151+
entityAlertInformedEntityRouteId: r . "entity.alert.informed_entity.route_id",
152+
entityAlertHeaderText: r . "entity.alert.header_text",
153+
entityAlertDescriptionText: r . "entity.alert.description_text",
154154
};
155155
}
156156
block AlertTableInterpreter oftype TableInterpreter {

libs/execution/src/lib/transforms/transform-executor.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { strict as assert } from 'assert';
77

88
import {
99
ERROR_TYPEGUARD,
10+
onlyElementOrUndefined,
1011
type InternalErrorValueRepresentation,
1112
type InternalValidValueRepresentation,
1213
InvalidValue,
@@ -64,9 +65,9 @@ export class TransformExecutor {
6465

6566
getOutputAssignment(): TransformOutputAssignment {
6667
const outputAssignments = this.transform.body.outputAssignments;
67-
assert(outputAssignments.length === 1);
68-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
69-
return outputAssignments[0]!;
68+
const outputAssignment = onlyElementOrUndefined(outputAssignments);
69+
assert(outputAssignment !== undefined);
70+
return outputAssignment;
7071
}
7172

7273
executeTransform(

libs/execution/src/lib/types/value-types/internal-representation-parsing.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,8 @@ class InternalRepresentationParserVisitor extends ValueTypeVisitor<
147147
`Cannot parse valuetype definitions into internal values`,
148148
);
149149
}
150+
151+
override visitSheetRow(): InvalidValue {
152+
return new InvalidValue(`Cannot parse sheet rows into internal values`);
153+
}
150154
}

libs/execution/src/lib/types/value-types/value-representation-validity.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { strict as assert } from 'assert';
77

88
import {
9+
type SheetRowValueType,
910
type AtomicValueType,
1011
type BooleanValuetype,
1112
type CellRangeValuetype,
@@ -130,6 +131,10 @@ class ValueRepresentationValidityVisitor extends ValueTypeVisitor<boolean> {
130131
return this.isValidForPrimitiveValuetype(valueType);
131132
}
132133

134+
override visitSheetRow(valueType: SheetRowValueType): boolean {
135+
return this.isValidForPrimitiveValuetype(valueType);
136+
}
137+
133138
override visitTransform(valueType: TransformValuetype): boolean {
134139
return this.isValidForPrimitiveValuetype(valueType);
135140
}

libs/execution/src/lib/types/value-types/visitors/sql-column-type-visitor.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ export class SQLColumnTypeVisitor extends ValueTypeVisitor<string> {
7676
);
7777
}
7878

79+
override visitSheetRow(): string {
80+
throw new Error(
81+
'No visit implementation given for sheet rows. Cannot be the type of a column.',
82+
);
83+
}
84+
7985
override visitTransform(): string {
8086
throw new Error(
8187
'No visit implementation given for transforms. Cannot be the type of a column.',

libs/execution/src/lib/types/value-types/visitors/sql-value-representation-visitor.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ export class SQLValueRepresentationVisitor extends ValueTypeVisitor<
130130
);
131131
}
132132

133+
override visitSheetRow(): (
134+
value: InternalValidValueRepresentation | InternalErrorValueRepresentation,
135+
) => string {
136+
throw new Error(
137+
'No visit implementation given for sheet row. Cannot be the type of a column.',
138+
);
139+
}
140+
133141
override visitTransform(): (
134142
value: InternalValidValueRepresentation | InternalErrorValueRepresentation,
135143
) => string {

libs/extensions/tabular/exec/test/assets/table-interpreter-executor/valid-empty-columns-with-header.jv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pipeline TestPipeline {
1212

1313

1414
transform Parser {
15-
from r oftype Collection<text>;
15+
from r oftype SheetRow;
1616
to t oftype TestValueType;
1717

1818
t: { };

0 commit comments

Comments
 (0)