Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document publish use feature #578

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/docs/docs/user/core-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,24 @@ constraint GasFillLevelRange on decimal:
value >= 0 and value <= 100;

publish GasFillLevelRange;
publish GasFillLevelRange as PercentGasFillLevel; // Alias for renaming the published element
```

2. Use the element in another file

```jayvee
// Define from where you want to take elements

// Wildcard "*" makes all published elements of the file available
use * from './relative/path/to/file.jv';

// Named use only makes the named elements available
use { GasFillLevelRange } './relative/path/to/file.jv';
use { GasFillLevelRange as FillLevelRange } './relative/path/to/file.jv'; // Alias locally renames elements


// Then just use them as if they were defined on root level

valuetype GasFillLevel oftype integer {
constraints: [ GasFillLevelRange ]; // GasFillLevelRange is defined in another file
}
Expand Down
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.
georg-schwarz marked this conversation as resolved.
Show resolved Hide resolved
// 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.
georg-schwarz marked this conversation as resolved.
Show resolved Hide resolved
"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 {
georg-schwarz marked this conversation as resolved.
Show resolved Hide resolved
constraints: [
UsStateCodeAllowlist,
];
}

// 2. The publish keyword can be used after definition (see below).
georg-schwarz marked this conversation as resolved.
Show resolved Hide resolved
// When using this delayed publish syntax, the published element can also be renamed for access from outside of the file.
georg-schwarz marked this conversation as resolved.
Show resolved Hide resolved
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;
Loading