Skip to content

Commit

Permalink
Import a value type in electric vehicles example to demonstrate the p…
Browse files Browse the repository at this point in the history
…ublish feature
  • Loading branch information
georg-schwarz committed May 29, 2024
1 parent 9b99142 commit 2d58952
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 67 deletions.
73 changes: 6 additions & 67 deletions example/electric-vehicles.jv
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
// - Understand how to construct a pipeline with multiple sinks
// - Understand the use of runtime parameters

// 0. We can use elements defined in other files using the "use" syntax.
// In this case, we use the value type UsStateCode when later specifying the table column value types.
use { UsStateCode } from './state-codes.jv';


// 1. This Jayvee model describes a pipeline
// from a CSV file in the web
// to a SQLite file and a PostgreSQL db sink.
Expand Down Expand Up @@ -51,7 +56,7 @@ pipeline ElectricVehiclesPipeline {
"VIN (1-10)" oftype VehicleIdentificationNumber10,
"County" oftype text,
"City" oftype text,
"State" oftype UsStateCode,
"State" oftype UsStateCode, // We can just use the element as if it was defined in this file.
"Postal Code" oftype text,
"Model Year" oftype integer,
"Make" oftype text,
Expand Down Expand Up @@ -125,69 +130,3 @@ valuetype VehicleIdentificationNumber10 oftype text {
constraint OnlyCapitalLettersAndDigits on text: value matches /^[A-Z0-9]*$/;

constraint ExactlyTenCharacters on text: value.length == 10;

valuetype UsStateCode oftype text {
constraints: [
UsStateCodeAllowlist,
];
}

constraint UsStateCodeAllowlist on text: value in [
"AL",
"AK",
"AZ",
"AR",
"AS",
"CA",
"CO",
"CT",
"DE",
"DC",
"FL",
"GA",
"GU",
"HI",
"ID",
"IL",
"IN",
"IA",
"KS",
"KY",
"LA",
"ME",
"MD",
"MA",
"MI",
"MN",
"MS",
"MO",
"MT",
"NE",
"NV",
"NH",
"NJ",
"NM",
"NY",
"NC",
"ND",
"MP",
"OH",
"OK",
"OR",
"PA",
"PR",
"RI",
"SC",
"SD",
"TN",
"TX",
"TT",
"UT",
"VT",
"VA",
"VI",
"WA",
"WV",
"WI",
"WY",
];
78 changes: 78 additions & 0 deletions example/state-codes.jv
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg
//
// SPDX-License-Identifier: AGPL-3.0-only

// This file belongs to example 2: Electric Vehicles
// Learning goals:
// - Understand how to publish elements to use them in other files

// 1. The publish keyword can be used directly when defining an element.
publish valuetype UsStateCode oftype text {
constraints: [
UsStateCodeAllowlist,
];
}

// 2. The publish keyword can be used after definition (see below).
// When using this delayed publish syntax, the published element can also be renamed for access from outside of the file.
constraint UsStateCodeAllowlist on text: value in [
"AL",
"AK",
"AZ",
"AR",
"AS",
"CA",
"CO",
"CT",
"DE",
"DC",
"FL",
"GA",
"GU",
"HI",
"ID",
"IL",
"IN",
"IA",
"KS",
"KY",
"LA",
"ME",
"MD",
"MA",
"MI",
"MN",
"MS",
"MO",
"MT",
"NE",
"NV",
"NH",
"NJ",
"NM",
"NY",
"NC",
"ND",
"MP",
"OH",
"OK",
"OR",
"PA",
"PR",
"RI",
"SC",
"SD",
"TN",
"TX",
"TT",
"UT",
"VT",
"VA",
"VI",
"WA",
"WV",
"WI",
"WY",
];

publish UsStateCodeAllowlist as UsStateCodeConstraint;

0 comments on commit 2d58952

Please sign in to comment.