Type conversion · cast
---
config:
flowchart:
useMaxWidth: false
---
flowchart TB
classDef ok fill:#d4edda,stroke:#28a745,color:#000
classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
O["Type conversion · cast 📌<br/>🟢41"]:::ok
subgraph G_ds["Dataset"]
direction LR
v_string_to_integer_ds["cast(DS#60;string#62;, integer)"]:::ok
end
subgraph G_comp["Component"]
direction LR
v_integer_to_boolean["cast(comp#60;integer#62;, boolean)"]:::ok
v_number_to_boolean["cast(comp#60;number#62;, boolean)"]:::ok
v_boolean_to_integer["cast(comp#60;boolean#62;, integer)"]:::ok
v_boolean_to_number["cast(comp#60;boolean#62;, number)"]:::ok
v_time_to_date["cast(comp#60;time#62;, date)"]:::ok
v_time_to_time_period["cast(comp#60;time#62;, time_period)"]:::ok
v_date_to_time_period["cast(comp#60;date#62;, time_period)"]:::ok
v_time_period_to_date["cast(comp#60;time_period#62;, date)"]:::ok
v_string_to_boolean["cast(comp#60;string#62;, boolean)"]:::ok
v_integer_to_number["cast(comp#60;integer#62;, number)"]:::ok
v_boolean_to_string["cast(comp#60;boolean#62;, string)"]:::ok
v_date_to_time["cast(comp#60;date#62;, time)"]:::ok
v_time_period_to_time["cast(comp#60;time_period#62;, time)"]:::ok
v_integer_to_string["cast(comp#60;integer#62;, string)"]:::ok
v_integer_to_string_mask["cast(comp#60;integer#62;, string, mask)"]:::ok
v_number_to_string["cast(comp#60;number#62;, string)"]:::ok
v_number_to_string_mask["cast(comp#60;number#62;, string, mask)"]:::ok
v_time_to_string["cast(comp#60;time#62;, string)"]:::ok
v_time_to_string_mask["cast(comp#60;time#62;, string, mask)"]:::ok
v_date_to_string["cast(comp#60;date#62;, string)"]:::ok
v_date_to_string_mask["cast(comp#60;date#62;, string, mask)"]:::ok
v_time_period_to_string["cast(comp#60;time_period#62;, string) 📌"]:::ok
v_time_period_to_string_mask["cast(comp#60;time_period#62;, string, mask)"]:::ok
v_duration_to_string["cast(comp#60;duration#62;, string)"]:::ok
v_duration_to_string_mask["cast(comp#60;duration#62;, string, mask)"]:::ok
v_string_to_integer["cast(comp#60;string#62;, integer)"]:::ok
v_string_to_integer_mask["cast(comp#60;string#62;, integer, mask)"]:::ok
v_string_to_number["cast(comp#60;string#62;, number)"]:::ok
v_string_to_number_mask["cast(comp#60;string#62;, number, mask)"]:::ok
v_string_to_time["cast(comp#60;string#62;, time)"]:::ok
v_string_to_time_mask["cast(comp#60;string#62;, time, mask)"]:::ok
v_string_to_date["cast(comp#60;string#62;, date)"]:::ok
v_string_to_date_mask["cast(comp#60;string#62;, date, mask)"]:::ok
v_string_to_time_period["cast(comp#60;string#62;, time_period)"]:::ok
v_string_to_time_period_mask["cast(comp#60;string#62;, time_period, mask)"]:::ok
v_string_to_duration["cast(comp#60;string#62;, duration)"]:::ok
v_string_to_duration_mask["cast(comp#60;string#62;, duration, mask)"]:::ok
v_string_to_value_domain["cast(comp#60;string#62;, VD)"]:::ok
v_value_domain_to_value_domain["cast(comp#60;VD#62;, VD)"]:::ok
end
subgraph G_sc["Scalar"]
direction LR
v_string_to_integer_sc["cast(sc#60;string#62;, integer)"]:::ok
end
O --- G_ds
O --- G_comp
O --- G_sc
style G_ds fill:#f8f9fa,stroke:#495057,stroke-width:2px
style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
style G_sc fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 2 3
click v_integer_to_boolean href "#form-integer-to-boolean"
click v_number_to_boolean href "#form-number-to-boolean"
click v_boolean_to_integer href "#form-boolean-to-integer"
click v_boolean_to_number href "#form-boolean-to-number"
click v_time_to_date href "#form-time-to-date"
click v_time_to_time_period href "#form-time-to-time-period"
click v_date_to_time_period href "#form-date-to-time-period"
click v_time_period_to_date href "#form-time-period-to-date"
click v_string_to_boolean href "#form-string-to-boolean"
click v_integer_to_number href "#form-integer-to-number"
click v_boolean_to_string href "#form-boolean-to-string"
click v_date_to_time href "#form-date-to-time"
click v_time_period_to_time href "#form-time-period-to-time"
click v_integer_to_string href "#form-integer-to-string"
click v_integer_to_string_mask href "#form-integer-to-string-mask"
click v_number_to_string href "#form-number-to-string"
click v_number_to_string_mask href "#form-number-to-string-mask"
click v_time_to_string href "#form-time-to-string"
click v_time_to_string_mask href "#form-time-to-string-mask"
click v_date_to_string href "#form-date-to-string"
click v_date_to_string_mask href "#form-date-to-string-mask"
click v_time_period_to_string href "#form-time-period-to-string"
click v_time_period_to_string_mask href "#form-time-period-to-string-mask"
click v_duration_to_string href "#form-duration-to-string"
click v_duration_to_string_mask href "#form-duration-to-string-mask"
click v_string_to_integer href "#form-string-to-integer"
click v_string_to_integer_mask href "#form-string-to-integer-mask"
click v_string_to_number href "#form-string-to-number"
click v_string_to_number_mask href "#form-string-to-number-mask"
click v_string_to_time href "#form-string-to-time"
click v_string_to_time_mask href "#form-string-to-time-mask"
click v_string_to_date href "#form-string-to-date"
click v_string_to_date_mask href "#form-string-to-date-mask"
click v_string_to_time_period href "#form-string-to-time-period"
click v_string_to_time_period_mask href "#form-string-to-time-period-mask"
click v_string_to_duration href "#form-string-to-duration"
click v_string_to_duration_mask href "#form-string-to-duration-mask"
click v_string_to_integer_ds href "#form-string-to-integer-ds"
click v_string_to_integer_sc href "#form-string-to-integer-sc"
click v_string_to_value_domain href "#form-string-to-value-domain"
click v_value_domain_to_value_domain href "#form-value-domain-to-value-domain"
Types
Takes number, integer, string, boolean, time, date, time_period, duration, value domain, any scalar · Gives number, integer, string, boolean, time, date, time_period, duration, any type
Comes from: any operator that returns a value
Comes from · value domain: none
Goes to: whatever takes its input's type
Goes to · number, integer, string, boolean, time, date, time_period, duration — 78 operators in 12 blocks 🟢78
Join operators (4) 🟢4
String operators (11) 🟢11
||Whitespace removal trimLeading whitespace removal ltrimTrailing whitespace removal rtrimUpper case conversion upperLower case conversion lowerSub-string extraction substrString pattern replacement replaceString pattern location instrString length lengthString distances string_distanceNumeric operators (18) 🟢18
Comparison operators (1) 🟢1
Boolean operators (4) 🟢4
Time operators (16) 🟢16
period_indicatorFill time series fill_time_seriesFlow to stock flow_to_stockStock to flow stock_to_flowTime shift timeshiftTime aggregation time_aggDays between two dates datediffAdd time unit to date dateaddExtract the year getyearExtract the month getmonthExtract the day of the month dayofmonthExtract the day of the year dayofyearNumber of days to years and days daytoyearNumber of days to months and days daytomonthYears and days to number of days yeartodayMonths and days to number of days monthtodayHierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (13) 🟢13
Data validation operators (2) 🟢2
Conditional operators (2) 🟢2
Clause operators (2) 🟢2
Definitions (VTL-DL) (4) 🟢4
Goes to · operators that take any scalar — 35 operators in 7 blocks 🟢35
General purpose operators (6) 🟢6
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (5) 🟢5
Data validation operators (1) 🟢1
Conditional operators (1) 🟢1
Forms
cast(DS<string>, integer) 🟢 · string → integer
Default measure name 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(DS_1, integer)on a dataset with one String measure.- Manual:
Operators changing the data type: “the operators changing the data type are allowed only on mono-measure operand Data Sets […]. A default generic Measure is assigned by default to the result Data Set, depending on the data type of the result”,
int_varfor an integer.- Expected:
Id_1and the measureint_var, 42 and -7 by the rule of Type conversion: “a sequence of digits is consumed to determine its absolute value”.
DS_r := cast(DS_1, integer);
| Id_1 | Me_1 |
|---|---|
| 1 | 42 |
| 2 | -7 |
| Id_1 | int_var |
|---|---|
| 1 | 42 |
| 2 | -7 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<integer>, boolean) 🟢 · integer → boolean
Zero and non zero 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, boolean)on an Integer measure, an explicit cast without mask.- Manual:
Type conversion: “From integer to boolean: if the
integervalue is not equal to zero, then the booleantrueliteral is returned, in every other case the booleanfalseliteral is returned.”- Expected:
0givesfalse;7and-2givetrue.
DS_r := DS_1[calc Me_2 := cast(Me_1, boolean)];
| Id_1 | Me_1 |
|---|---|
| 1 | 0 |
| 2 | 7 |
| 3 | -2 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 0 | false |
| 2 | 7 | true |
| 3 | -2 | true |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<number>, boolean) 🟢 · number → boolean
Zero and non zero 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, boolean)on a Number measure, an explicit cast without mask.- Manual:
Type conversion: “From number to boolean: if the
numberabsolute value is not equal to zero, then the booleantrueliteral is returned, in every other case the booleanfalseliteral is returned.”- Expected:
0.0givesfalse;0.5and-3.25givetrue.
DS_r := DS_1[calc Me_2 := cast(Me_1, boolean)];
| Id_1 | Me_1 |
|---|---|
| 1 | 0.0 |
| 2 | 0.5 |
| 3 | -3.25 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 0.0 | false |
| 2 | 0.5 | true |
| 3 | -3.25 | true |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<boolean>, integer) 🟢 · boolean → integer
True and false 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, integer)on a Boolean measure, an explicit cast without mask.- Manual:
Type conversion: “From boolean to integer: the integer
0is returned if thebooleanvalue is false,1if its true.”- Expected:
truegives 1 andfalsegives 0.
DS_r := DS_1[calc Me_2 := cast(Me_1, integer)];
| Id_1 | Me_1 |
|---|---|
| 1 | true |
| 2 | false |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | true | 1 |
| 2 | false | 0 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<boolean>, number) 🟢 · boolean → number
True and false 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, number)on a Boolean measure, an explicit cast without mask.- Manual:
Type conversion: “From boolean to number: the number
0.0is returned if thebooleanvalue is false,1.0if its true.”- Expected:
truegives 1.0 andfalsegives 0.0.
DS_r := DS_1[calc Me_2 := cast(Me_1, number)];
| Id_1 | Me_1 |
|---|---|
| 1 | true |
| 2 | false |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | true | 1.0 |
| 2 | false | 0.0 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<time>, date) 🟢 · time → date
Single day intervals 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, date)on a Time measure whose intervals start and end on the same day, an explicit cast without mask.- Manual:
Type conversion: “From time to date: A
datevalue is returned if thetimevalue start and ends at the same date, otherwise an error is raised.”- Expected:
2020-01-15and2021-12-31; neither raises the error.
DS_r := DS_1[calc Me_2 := cast(Me_1, date)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2020-01-15/2020-01-15 |
| 2 | 2021-12-31/2021-12-31 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2020-01-15/2020-01-15 | 2020-01-15 |
| 2 | 2021-12-31/2021-12-31 | 2021-12-31 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<time>, time_period) 🟢 · time → time_period
Year quarter and month 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, time_period)on a Time measure of a whole year, a quarter and a month, an explicit cast without mask.- Manual:
Type conversion: “From time to time_period: A
time_periodvalue is returned if the time value has a regular duration (see above for its meaning) otherwise an error is raised.” Nothing above defines it: the inputs have the durations that the page accepts for a period parsed from an interval, “an entire year, a half of a year, a quarter of a year or a month”.- Expected:
2020A,2020Q2and2020M07, the comparison taking2020Aand2020as the same period.
DS_r := DS_1[calc Me_2 := cast(Me_1, time_period)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2020-01-01/2020-12-31 |
| 2 | 2020-04-01/2020-06-30 |
| 3 | 2020-07-01/2020-07-31 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2020-01-01/2020-12-31 | 2020A |
| 2 | 2020-04-01/2020-06-30 | 2020Q2 |
| 3 | 2020-07-01/2020-07-31 | 2020M07 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<date>, time_period) 🟢 · date → time_period
Daily periods 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, time_period)on a Date measure, an explicit cast without mask.- Manual:
Type conversion: “From date to time_period: A
time_periodvalue with a daily duration is returned, starting and ending at the specifieddatevalue.”- Expected:
Daily periods, written
YYYYDand the day of the year:2020D15,2020D61for March 1st, after the 31 days of January and the 29 of February, and2021D365, 2021 not being a leap year.
DS_r := DS_1[calc Me_2 := cast(Me_1, time_period)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2020-01-15 |
| 2 | 2020-03-01 |
| 3 | 2021-12-31 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2020-01-15 | 2020D15 |
| 2 | 2020-03-01 | 2020D61 |
| 3 | 2021-12-31 | 2021D365 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<time_period>, date) 🟢 · time_period → date
Daily periods 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, date)on a Time_Period measure of daily periods, an explicit cast without mask.- Manual:
Type conversion: “From time_period to date: A
datevalue is returned if the inputtime_periodhas a duration of a single day, representing that day; otherwise an error is raised.”- Expected:
2020D15gives2020-01-15and2020D61gives2020-03-01, 2020 being a leap year; both are daily, so neither raises the error.
DS_r := DS_1[calc Me_2 := cast(Me_1, date)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2020D15 |
| 2 | 2020D61 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2020D15 | 2020-01-15 |
| 2 | 2020D61 | 2020-03-01 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Non daily period 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, date)on a Time_Period measure whose period,2020Q1, is not a single day: the first error that the page states for a conversion between basic scalar types.- Manual:
Type conversion: “From time_period to date: A
datevalue is returned if the inputtime_periodhas a duration of a single day, representing that day; otherwise an error is raised.”- Expected:
The error
2-1-5-1, “Impossible to cast{value}from type {type_1} to {type_2}.”, as2020Q1lasts a quarter, not a single day: “otherwise an error is raised”.
DS_r := DS_1[calc Me_2 := cast(Me_1, date)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2020Q1 |
Expected error 2-1-5-1: Impossible to cast {value} from type {type_1} to {type_2}.
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/error.json · example page ↗
cast(comp<string>, boolean) 🟢 · string → boolean
True in any case 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, boolean)on a String measure, an explicit cast without mask:truein any case.- Manual:
Type conversion: “From string to boolean: The
booleanvalue representing true is returned if the input string, with any leading or trailing blanks removed, is equal to"true"not considering the case. Thebooleanvalue representing false is returned in any other case.”- Expected:
trueandTRUEgivetrue, andfalsegivesfalse.
DS_r := DS_1[calc Me_2 := cast(Me_1, boolean)];
| Id_1 | Me_1 |
|---|---|
| 1 | true |
| 2 | TRUE |
| 3 | false |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | true | true |
| 2 | TRUE | true |
| 3 | false | false |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Other strings are false 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, boolean)on strings that are neithertruenorfalse.- Manual:
Type conversion: the boolean true is returned if the string “is equal to
"true"not considering the case”, and “Thebooleanvalue representing false is returned in any other case.”- Expected:
yesand1givefalse: the rule compares with the texttrueonly. The strings have no blanks around them, as the loading of blanks is not what the example tests.
DS_r := DS_1[calc Me_2 := cast(Me_1, boolean)];
| Id_1 | Me_1 |
|---|---|
| 1 | yes |
| 2 | 1 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | yes | false |
| 2 | 1 | false |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<integer>, number) 🟢 · integer → number
Zero decimal part 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, number)on an Integer measure, an implicit conversion written as an explicit cast, whose “behavior remains the same”.- Manual:
Type conversion: “From integer to number: a
numbervalue is returned having the integer part equal to theintegervalue, and the decimal part equal to zero.”- Expected:
5gives 5.0 and-3gives -3.0.
DS_r := DS_1[calc Me_2 := cast(Me_1, number)];
| Id_1 | Me_1 |
|---|---|
| 1 | 5 |
| 2 | -3 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 5 | 5.0 |
| 2 | -3 | -3.0 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<boolean>, string) 🟢 · boolean → string
True and false 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string)on a Boolean measure, an implicit conversion written as an explicit cast, whose “behavior remains the same”.- Manual:
Type conversion: “From boolean to string: Either one of the string values
"true"and"false"is returned, depending on the input.”- Expected:
truegives the stringtrueandfalsegivesfalse, in lower case as the manual writes them; a string is compared exactly.
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
| Id_1 | Me_1 |
|---|---|
| 1 | true |
| 2 | false |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | true | true |
| 2 | false | false |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<date>, time) 🟢 · date → time
Same start and end 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, time)on a Date measure, an implicit conversion written as an explicit cast, whose “behavior remains the same”.- Manual:
Type conversion: “From date to time: a
timevalue is returned having its start equal to its end, and both equal to the inputdatevalue.”- Expected:
2020-01-15/2020-01-15and2021-12-31/2021-12-31, atimewrittenstart/end, as vtlengine reads it.
DS_r := DS_1[calc Me_2 := cast(Me_1, time)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2020-01-15 |
| 2 | 2021-12-31 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2020-01-15 | 2020-01-15/2020-01-15 |
| 2 | 2021-12-31 | 2021-12-31/2021-12-31 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<time_period>, time) 🟢 · time_period → time
Start and end of the period 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, time)on a Time_Period measure: atimefrom the start to the end of each period, an implicit conversion written as an explicit cast, whose “behavior remains the same”.- Manual:
Type conversion: “From time_period to time: a
timevalue is returned having the stame start and end of the inputtime_periodvalue.”- Expected:
2020Q1gives2020-01-01/2020-03-31and2021M02gives2021-02-01/2021-02-28, 2021 not being a leap year: atimewrittenstart/end, as vtlengine reads it.
DS_r := DS_1[calc Me_2 := cast(Me_1, time)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2020Q1 |
| 2 | 2021M02 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2020Q1 | 2020-01-01/2020-03-31 |
| 2 | 2021M02 | 2021-02-01/2021-02-28 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<integer>, string) 🟢 · integer → string
Digits and sign 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string)on an Integer measure, without a mask: the default format.- Manual:
Type conversion: “From integer: the
integervalue is printed as a sequence of digits, without any leading zeroes or thousands separators, possibly preceded by a-.”- Expected:
1500with no thousands separator,-7preceded by-, and0.
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
| Id_1 | Me_1 |
|---|---|
| 1 | 1500 |
| 2 | -7 |
| 3 | 0 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 1500 | 1500 |
| 2 | -7 | -7 |
| 3 | 0 | 0 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<integer>, string, mask) 🟢 · integer, string → string
Two digit mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string, "DD")on an Integer measure: a number mask of two digits.- Manual:
Type Conversion and Formatting Mask: ““D” one numeric digit (for the mantissa of the scientific notation)”.
- Expected:
42and17, and07from7: the mask writes a digit for eachD, so a value of one digit gets a leading zero, which the conversion without a mask does not write.
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "DD")];
| Id_1 | Me_1 |
|---|---|
| 1 | 42 |
| 2 | 17 |
| 3 | 7 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 42 | 42 |
| 2 | 17 | 17 |
| 3 | 7 | 07 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<number>, string) 🟢 · number → string
Plain decimal notation 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string)on a Number measure, without a mask: the default format.- Manual:
Type conversion: “From number: the
numbervalue may be printed either in the scientific notation, or as a sequence of digits, possibly preceded by a-, with.as the decimal separator, without any leading zeroes or thousands separators.”- Expected:
The sequence of digits,
3.5and-12.75, values exact in binary floating point; they are not between -1 and 1, so the reading of “without any leading zeroes” (0.5or.5) does not matter. A scientific result, which the manual allows too, would not match these strings.
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
| Id_1 | Me_1 |
|---|---|
| 1 | 3.5 |
| 2 | -12.75 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 3.5 | 3.5 |
| 2 | -12.75 | -12.75 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<number>, string, mask) 🟢 · number, string → string
Decimal mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string, "DD.DDD")on a Number measure: the mask of the page’s Example 1.- Manual:
Type Conversion and Formatting Mask: ““D” one numeric digit (for the mantissa of the scientific notation)” and ““.” (dot) can be used as a separator between the integer and the decimal parts”.
- Expected:
12.375and40.125, and03.500from3.5: two digits, a dot and three digits, a digit for eachD, so3.5gets a leading zero and two trailing zeros, which the conversion without a mask does not write. The values are exact in binary floating point, so none is rounded.
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "DD.DDD")];
| Id_1 | Me_1 |
|---|---|
| 1 | 12.375 |
| 2 | 40.125 |
| 3 | 3.5 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 12.375 | 12.375 |
| 2 | 40.125 | 40.125 |
| 3 | 3.5 | 03.500 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<time>, string) 🟢 · time → string
Iso 8601 intervals 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string)on a Time measure, without a mask: the default format.- Manual:
Type conversion: “From time: the
timevalue is printed using the ISO-8601 representation for generic time intervals, up to a maximum of day precision, in the form start/end.”- Expected:
2020-01-01/2020-06-30and2021-03-15/2021-03-20, with the dates in the ISO-8601 extended formYYYY-MM-DD.
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2020-01-01/2020-06-30 |
| 2 | 2021-03-15/2021-03-20 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2020-01-01/2020-06-30 | 2020-01-01/2020-06-30 |
| 2 | 2021-03-15/2021-03-20 | 2021-03-15/2021-03-20 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<time>, string, mask) 🟢 · time, string → string
Start and end mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string, "YYYY-MM-DD/YYYY-MM-DD")on a Time measure: the mask that the manual gives for a time with “Start and end”, to the day, also on a time whose start and end have times of day.- Manual:
Type Conversion and Formatting Mask: “Example of other possible ISO formats having accuracy reduced to the day”, “The number of letters matches the number of digits”, and “Any other character can be used in the mask, meaning simply that it appears in the same position”.
- Expected:
2015-03-03/2018-04-05and2020-01-01/2020-06-30, and2015-03-03/2018-04-05for the time from2015-03-03T09:30:45to2018-04-05T12:30:15: the mask has no hours, minutes or seconds. The manual’s sample value,20150303/20180405, has no-, which its mask has: the example follows the mask. By the manual, the conversion without a mask prints a time “up to a maximum of day precision”, the same text: no value tells the mask apart, but vtlengine keeps the times of day, which the third data point shows.
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "YYYY-MM-DD/YYYY-MM-DD")];
| Id_1 | Me_1 |
|---|---|
| 1 | 2015-03-03/2018-04-05 |
| 2 | 2020-01-01/2020-06-30 |
| 3 | 2015-03-03T09:30:45/2018-04-05T12:30:15 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2015-03-03/2018-04-05 | 2015-03-03/2018-04-05 |
| 2 | 2020-01-01/2020-06-30 | 2020-01-01/2020-06-30 |
| 3 | 2015-03-03T09:30:45/2018-04-05T12:30:15 | 2015-03-03/2018-04-05 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<date>, string) 🟢 · date → string
Iso 8601 dates 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string)on a Date measure, without a mask: the default format.- Manual:
Type conversion: “From date: the
datevalue is printed using the ISO-8601 representation for dates, with the year, month and day of month fields always present.”- Expected:
The ISO-8601 extended form
YYYY-MM-DD:2020-01-15and2021-12-31.
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2020-01-15 |
| 2 | 2021-12-31 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2020-01-15 | 2020-01-15 |
| 2 | 2021-12-31 | 2021-12-31 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<date>, string, mask) 🟢 · date, string → string
Year month day mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string, "YYYYMMDD")on a Date measure: four digits for the year, two for the month and two for the day.- Manual:
Type Conversion and Formatting Mask: “YYYMMDD means four digits for the year followed by two digits for the month and then two digits for the day (e.g., 20180405 means the year 2018, month April, day 5th)”, and “The number of letters matches the number of digits”.
- Expected:
20180405and20200115. The manual’sYYYMMDDhas threeYfor four digits; the mask has one per digit.
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "YYYYMMDD")];
| Id_1 | Me_1 |
|---|---|
| 1 | 2018-04-05 |
| 2 | 2020-01-15 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2018-04-05 | 20180405 |
| 2 | 2020-01-15 | 20200115 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Optional digits 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string, "{D}D/{M}M/YYYY")on a Date measure: braces around the digit of the day and of the month that may be left out.- Manual:
Type Conversion and Formatting Mask: “If the numerical representation is not padded, the optional digits that can be omitted (if equal to zero) are enclosed within braces; for example {M}M means that April is represented by 4 and December by 12”.
- Expected:
5/4/2018,31/12/2021and15/1/2020: a day or a month below 10 is written with one digit, whereDDandMMwould pad it with a zero.
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "{D}D/{M}M/YYYY")];
| Id_1 | Me_1 |
|---|---|
| 1 | 2018-04-05 |
| 2 | 2021-12-31 |
| 3 | 2020-01-15 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2018-04-05 | 5/4/2018 |
| 2 | 2021-12-31 | 31/12/2021 |
| 3 | 2020-01-15 | 15/1/2020 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Date and time with separators 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string, "YYYY-MM-DDThh:mm:ssZ")on a Date measure with a time of day: the manual’s mask for a “Date and day time with separators”.- Manual:
Type Conversion and Formatting Mask: “A date scalar type is a point in time”, “Date and day time with separators: “2015-03-03T09:30:45Z”” with the mask
YYYY-MM-DDThh:mm:ssZ, andTandZare among the “fixed characters used in the ISO 8601 standard which can appear as fixed characters in the relevant masks”.- Expected:
2015-03-03T09:30:45Z, the manual’s value, and2018-04-05T12:30:15Z.Zis a fixed character: the time is written as it is.
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "YYYY-MM-DDThh:mm:ssZ")];
| Id_1 | Me_1 |
|---|---|
| 1 | 2015-03-03T09:30:45 |
| 2 | 2018-04-05T12:30:15 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2015-03-03T09:30:45 | 2015-03-03T09:30:45Z |
| 2 | 2018-04-05T12:30:15 | 2018-04-05T12:30:15Z |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<time_period>, string) 🟢 · time_period → string
Start and end dates 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string)on a Time_Period measure, without a mask: the default format.- Manual:
Type conversion: “From time_period: the
time_periodvalue is printed using the ISO-8601 representation for generic time intervals, up to a precision of days, in the form start/end.”- Expected:
the period codes:
2020Q1gives2020Q1and2021M02gives2021M2; a string is compared exactly.- Team decision:
#1254: the text of
castfollows the pandas engine, which writes the period code, where the manual prints the intervalstart/end(2020-01-01/2020-03-31).
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2020Q1 |
| 2 | 2021M02 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2020Q1 | 2020Q1 |
| 2 | 2021M02 | 2021M2 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<time_period>, string, mask) 🟢 · time_period, string → string
Monthly period mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string, "YYYY\MMM")on a Time_Period measure: the mask that the manual gives for a “Monthly period”.- Manual:
Type Conversion and Formatting Mask: special characters “prefixed by the reverse slash […] appear in the same position”, so
\Mis the letterM, and “MM that the month is of 2 digits”.- Expected:
2015M03, as in the manual, and2020M11. Only the mask explains the0of2015M03: without a mask, a period is printed as its interval, start/end, where vtlengine prints its code,2015M3(start_and_end_dates).
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "YYYY\MMM")];
| Id_1 | Me_1 |
|---|---|
| 1 | 2015M03 |
| 2 | 2020M11 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2015M03 | 2015M03 |
| 2 | 2020M11 | 2020M11 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<duration>, string) 🟢 · duration → string
Iso 8601 durations 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string)on a Duration measure, without a mask: the default format.- Manual:
Type conversion: “From duration: the
durationvalue is printed using the ISO-8601 representation for durations.”- Expected:
The inputs are the one-letter codes that vtlengine reads (“A Year”, “M Month”, “D Day” in the mask section), and one year, month and day are
P1Y,P1MandP1Din ISO-8601.
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
| Id_1 | Me_1 |
|---|---|
| 1 | A |
| 2 | M |
| 3 | D |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | A | P1Y |
| 2 | M | P1M |
| 3 | D | P1D |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<duration>, string, mask) 🟢 · duration, string → string
Period indicator mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string, "P")on a Duration measure: the one-character mask of a duration, with each of its codes.- Manual:
Type Conversion and Formatting Mask: “Non ISO representation of the duration in one character, whose possible codes are”: “D Day”, “W Week”, “M Month”, “Q Quarter”, “S Semester” and “A Year”, with “VTL Mask: P (period indicator)”.
- Expected:
The codes
A,M,D,W,QandS. Only the mask explains them: without it, a duration is printed in ISO 8601, such asP1Yfor a year.
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "P")];
| Id_1 | Me_1 |
|---|---|
| 1 | A |
| 2 | M |
| 3 | D |
| 4 | W |
| 5 | Q |
| 6 | S |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | A | A |
| 2 | M | M |
| 3 | D | D |
| 4 | W | W |
| 5 | Q | Q |
| 6 | S | S |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Number of periods 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, string, "\PppP")on a Duration measure: the “ISO 4 characters representation” of a duration.- Manual:
Type Conversion and Formatting Mask: “ISO 4 characters representation: P10M (ten months), P02Q (two quarters) …”, with “VTL Mask:
\PppP”, and “the letter p denotes the number of periods”.- Expected:
P01M, one month, andP01Q, one quarter: aP, the number of periods in two digits and the period indicator. Only the mask explains them: without it, a duration is printed in ISO 8601:P1Mfor a month, and noQfor a quarter.
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "\PppP")];
| Id_1 | Me_1 |
|---|---|
| 1 | M |
| 2 | Q |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | M | P01M |
| 2 | Q | P01Q |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<string>, integer) 🟢 · string → integer
Signs leading zeros and null 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, integer)on a String measure, without a mask: signs, leading zeroes and a null.- Manual:
Type conversion: “First a
+or-is possibly consumed to determine the sign of the integer […] Finally, a sequence of digits is consumed to determine its absolute value; leading zeroes are skipped”, and “anullinput string is converted to the correspondingnullvalue of the desired value domain”.- Expected:
42,-7,7from+007, and null from the empty field. The inputs have no blanks for the conversion to remove.
DS_r := DS_1[calc Me_2 := cast(Me_1, integer)];
| Id_1 | Me_1 |
|---|---|
| 1 | 42 |
| 2 | -7 |
| 3 | +007 |
| 4 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 42 | 42 |
| 2 | -7 | -7 |
| 3 | +007 | 7 |
| 4 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<string>, integer, mask) 🟢 · string → integer
Two digit mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, integer, "DD")on a String measure: a number mask of two digits.- Manual:
Type Conversion and Formatting Mask: ““D” one numeric digit (for the mantissa of the scientific notation)”.
- Expected:
42, and7from07: each value has as many digits as the mask. The conversion without a mask, which skips leading zeroes, gives the same: the mask shows in the strings that it refuses, such as7or123.
DS_r := DS_1[calc Me_2 := cast(Me_1, integer, "DD")];
| Id_1 | Me_1 |
|---|---|
| 1 | 42 |
| 2 | 07 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 42 | 42 |
| 2 | 07 | 7 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<string>, number) 🟢 · string → number
Sign decimals and exponent 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, number)on a String measure, without a mask: a sign, decimals, an exponent and no decimal part.- Manual:
Type conversion, “To number”: a sign “is possibly consumed”, then the integer part, then “a
.is possibly consumed; if it’s not present, the parsing ends and the number is returned without a decimal part”, then the decimal part, and “Eis possibly consumed to determine if a base-ten exponent is present”.- Expected:
3.25,-0.5,150from1.5E2, and2from+2. By the rule an exponent needs a.before it, which1.5E2has; the inputs have no blanks for the conversion to remove.
DS_r := DS_1[calc Me_2 := cast(Me_1, number)];
| Id_1 | Me_1 |
|---|---|
| 1 | 3.25 |
| 2 | -0.5 |
| 3 | 1.5E2 |
| 4 | +2 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 3.25 | 3.25 |
| 2 | -0.5 | -0.5 |
| 3 | 1.5E2 | 150 |
| 4 | +2 | 2 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<string>, number, mask) 🟢 · string → number
Decimal mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, number, "DD.DDD")on a String measure: the mask of the page’s Example 1,cast(m1, number, "DD.DDD") + 2.- Manual:
Type Conversion and Formatting Mask: ““D” one numeric digit (for the mantissa of the scientific notation)” and ““.” (dot) can be used as a separator between the integer and the decimal parts”.
- Expected:
12.375, and3.5from03.500: two digits, a dot and three digits. The conversion without a mask, which skips leading zeroes, gives the same: the mask shows in the strings that it refuses, such as12.5or12.3755.
DS_r := DS_1[calc Me_2 := cast(Me_1, number, "DD.DDD")];
| Id_1 | Me_1 |
|---|---|
| 1 | 12.375 |
| 2 | 03.500 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 12.375 | 12.375 |
| 2 | 03.500 | 3.5 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Decimal comma mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, number, "DD,DDD")on a String measure: the mask of the page’s Example 1, with a comma for the dot.- Manual:
Type Conversion and Formatting Mask: ““,” (comma) can be used as a separator between the integer and the decimal parts.”
- Expected:
12.375from12,375, and3.5from03,500: two digits, a comma and three digits. The conversion without a mask takes a dot only, so it would leave,375and,500unconsumed, an error.
DS_r := DS_1[calc Me_2 := cast(Me_1, number, "DD,DDD")];
| Id_1 | Me_1 |
|---|---|
| 1 | 12,375 |
| 2 | 03,500 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 12,375 | 12.375 |
| 2 | 03,500 | 3.5 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<string>, time) 🟢 · string → time
Iso 8601 intervals 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, time)on a String measure, without a mask: ISO-8601 intervals.- Manual:
Type conversion: “To time: the input string is parsed, according to the ISO-8601 standard for time intervals, up to a precision of days, and the corresponding
timevalue is returned.”- Expected:
2020-01-01/2020-06-30and2021-03-15/2021-03-20, atimewrittenstart/end, as vtlengine reads it. The inputs have no blanks for the conversion to remove.
DS_r := DS_1[calc Me_2 := cast(Me_1, time)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2020-01-01/2020-06-30 |
| 2 | 2021-03-15/2021-03-20 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2020-01-01/2020-06-30 | 2020-01-01/2020-06-30 |
| 2 | 2021-03-15/2021-03-20 | 2021-03-15/2021-03-20 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<string>, time, mask) 🟢 · string → time
Start and end mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, time, "YYYY-MM-DD/YYYY-MM-DD")on a String measure: the mask that the manual gives for a time with “Start and end”.- Manual:
Type Conversion and Formatting Mask: “The number of letters matches the number of digits”, and “Any other character can be used in the mask, meaning simply that it appears in the same position”.
- Expected:
2015-03-03/2018-04-05and2020-01-01/2020-06-30. The manual’s sample value for this mask,20150303/20180405, has no-; the inputs follow the mask. They are ISO 8601 intervals that the conversion reads without a mask as well, so no value tells the two apart.
DS_r := DS_1[calc Me_2 := cast(Me_1, time, "YYYY-MM-DD/YYYY-MM-DD")];
| Id_1 | Me_1 |
|---|---|
| 1 | 2015-03-03/2018-04-05 |
| 2 | 2020-01-01/2020-06-30 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2015-03-03/2018-04-05 | 2015-03-03/2018-04-05 |
| 2 | 2020-01-01/2020-06-30 | 2020-01-01/2020-06-30 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<string>, date) 🟢 · string → date
Iso 8601 dates 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, date)on a String measure, without a mask: the default parsing.- Manual:
Type conversion, “To date”: “exactly four digits are consumed to determine the year”, then a
-, “exactly two digits are consumed to determine the month in the range 01-12”, a-again, and “exactly two digits are consumed to determine the day of the month”.- Expected:
2020-01-15and2021-12-31. The inputs have no blanks for the conversion to remove.
DS_r := DS_1[calc Me_2 := cast(Me_1, date)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2020-01-15 |
| 2 | 2021-12-31 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2020-01-15 | 2020-01-15 |
| 2 | 2021-12-31 | 2021-12-31 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<string>, date, mask) 🟢 · string → date
Year month day mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, date, "YYYY-MM-DD")on a String measure: the mask of the page’s Example 2,cast(m1, date, "YYYY-MM-DD").- Manual:
Type Conversion and Formatting Mask: “The number of letters matches the number of digits, for example YYYY means that the year is represented with four digits and MM that the month is of 2 digits”, and “Any other character can be used in the mask, meaning simply that it appears in the same position”.
- Expected:
The dates
2020-01-15and2021-12-31. The mask is the format that the conversion reads without a mask, so no value tells the two apart: the other masks of this form do.
DS_r := DS_1[calc Me_2 := cast(Me_1, date, "YYYY-MM-DD")];
| Id_1 | Me_1 |
|---|---|
| 1 | 2020-01-15 |
| 2 | 2021-12-31 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2020-01-15 | 2020-01-15 |
| 2 | 2021-12-31 | 2021-12-31 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Day month year order 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, date, "DD/MM/YYYY")on a String measure: the day first, then the month and the year, separated by/.- Manual:
Type Conversion and Formatting Mask: “The position of the digits in the mask denotes the position of the corresponding values”, and “Any other character can be used in the mask, meaning simply that it appears in the same position”.
- Expected:
2018-04-05and2021-12-31:05/04/2018is the 5th of April.
DS_r := DS_1[calc Me_2 := cast(Me_1, date, "DD/MM/YYYY")];
| Id_1 | Me_1 |
|---|---|
| 1 | 05/04/2018 |
| 2 | 31/12/2021 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 05/04/2018 | 2018-04-05 |
| 2 | 31/12/2021 | 2021-12-31 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
String not matching mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, date, "DD/MM/YYYY")on a String measure whose value,2018-04-05, is a date in the format of the conversion without a mask, not in the mask.- Manual:
Type conversion: “When performing a conversion from a
stringvalue, all leading and trailing blanks are removed from the input string value before performing the conversion. Then, if the input string or a part of it cannot be matched to the specified or default mask, an error is raised.”- Expected:
The error
2-1-5-3, “Impossible to cast {value} from type {type_1} to {type_2} using mask {mask}.”:2018-04-05has a-where the mask has a/. Without the mask, it would be the date 2018-04-05.
DS_r := DS_1[calc Me_2 := cast(Me_1, date, "DD/MM/YYYY")];
| Id_1 | Me_1 |
|---|---|
| 1 | 2018-04-05 |
Expected error 2-1-5-3: Impossible to cast {value} from type {type_1} to {type_2} using mask {mask}.
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/error.json · example page ↗
cast(comp<string>, time_period) 🟢 · string → time_period
Quarter month and year 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, time_period)on a String measure, without a mask: a quarter, a month with a-, and a year.- Manual:
Type conversion, “To time_period”: four digits for the year, then “a
-is consumed if present”, then “one of eitherH,Q,MorDis possibly consumed to determine the duration of the period; if neither of these are present, atime_periodrepresenting the entire determined year is returned”.- Expected:
2000Q1,2000M03from2000-M03, and the year2001Afrom2001, the comparison taking2001Aand2001as the same period. The inputs have no blanks for the conversion to remove.
DS_r := DS_1[calc Me_2 := cast(Me_1, time_period)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2000Q1 |
| 2 | 2000-M03 |
| 3 | 2001 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2000Q1 | 2000Q1 |
| 2 | 2000-M03 | 2000M03 |
| 3 | 2001 | 2001A |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<string>, time_period, mask) 🟢 · string → time_period
Quarter mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, time_period, "YYYY\QQ")on a String measure: the mask of the page’s Example 9,cast ( "2000Q1", time_period, "YYYY\QQ" ), “The first quarter of year 2000”.- Manual:
Type Conversion and Formatting Mask: “The special characters and the special words, if prefixed by the reverse slash […] in the mask, appear in the same position in the time format”, so
\Qis the letterQ, andQthe quarter.- Expected:
2000Q1, the first quarter of 2000, and2001Q4. The conversion without a mask reads these strings the same way, so no value tells the two apart.
DS_r := DS_1[calc Me_2 := cast(Me_1, time_period, "YYYY\QQ")];
| Id_1 | Me_1 |
|---|---|
| 1 | 2000Q1 |
| 2 | 2001Q4 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2000Q1 | 2000Q1 |
| 2 | 2001Q4 | 2001Q4 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Quarter after dash 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, time_period, "YYYY-Q")on a String measure: the mask of the page’s Example 9,cast ( "2000-1", time_period, "YYYY-Q" ): the quarter as a digit, with no letterQ.- Manual:
Type Conversion and Formatting Mask: the special characters include “Q quarter”; “The number of letters matches the number of digits”, and “Any other character can be used in the mask, meaning simply that it appears in the same position”.
- Expected:
2000Q1, “The first quarter of year 2000”, and2001Q4. Only the mask reads the digit as a quarter: without it, the conversion consumes the year and the-, finds none ofH,Q,MorD, and raises an error for the digit left over, and vtlengine reads2000-1as the month2000M1.
DS_r := DS_1[calc Me_2 := cast(Me_1, time_period, "YYYY-Q")];
| Id_1 | Me_1 |
|---|---|
| 1 | 2000-1 |
| 2 | 2001-4 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2000-1 | 2000Q1 |
| 2 | 2001-4 | 2001Q4 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Period indicator and number 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, time_period, "YYYYP{ppp}")on a String measure: the mask of a “Generic time period within the year”, with each period indicator.- Manual:
Type Conversion and Formatting Mask: “VTL Mask: YYYYP{ppp} where P is the period indicator and ppp three digits for the number of periods, in the values, the period indicator may assume one of the values of the duration scalar type listed below”:
D,W,M,Q,SandA.- Expected:
The manual’s
2015Q4,2015M12and2015D365, then2015S2,2015W12, and the year2015Afrom2015A1,Abeing the code of a year. Only the mask explains the last three: without it, the conversion reads the year, finds none ofH,Q,MorD, and raises an error for the characters left over, and vtlengine reads2015S2and2015W12as they are and raises an error only for2015A1.
DS_r := DS_1[calc Me_2 := cast(Me_1, time_period, "YYYYP{ppp}")];
| Id_1 | Me_1 |
|---|---|
| 1 | 2015Q4 |
| 2 | 2015M12 |
| 3 | 2015D365 |
| 4 | 2015S2 |
| 5 | 2015W12 |
| 6 | 2015A1 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 2015Q4 | 2015Q4 |
| 2 | 2015M12 | 2015M12 |
| 3 | 2015D365 | 2015D365 |
| 4 | 2015S2 | 2015S2 |
| 5 | 2015W12 | 2015W12 |
| 6 | 2015A1 | 2015A |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<string>, duration) 🟢 · string → duration
One letter codes 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, duration)on a String measure, without a mask: the one-letter codes.- Manual:
Type conversion: “To duration: If the input string starts with
P, the entire string is consumed and parsed, according to the ISO-8601 standard for durations […]. Otherwise, one ofA,S,Q,M,WorDis consumed, and adurationvalue is returned representing the duration respectively of a year, a half of a year, a quarter of a year, a month, a week and a day.”- Expected:
A year, a quarter and a day, written with the same codes:
A,QandD. The inputs have no blanks for the conversion to remove.
DS_r := DS_1[calc Me_2 := cast(Me_1, duration)];
| Id_1 | Me_1 |
|---|---|
| 1 | A |
| 2 | Q |
| 3 | D |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | A | A |
| 2 | Q | Q |
| 3 | D | D |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<string>, duration, mask) 🟢 · string → duration
Period indicator mask 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, duration, "P")on a String measure: the one-character mask of a duration, with each of its codes.- Manual:
Type Conversion and Formatting Mask: “Non ISO representation of the duration in one character, whose possible codes are”: “D Day”, “W Week”, “M Month”, “Q Quarter”, “S Semester” and “A Year”, with “VTL Mask: P (period indicator)”.
- Expected:
The durations
A,M,D,W,QandS. The conversion without a mask reads these codes the same way, so no value tells the two apart.
DS_r := DS_1[calc Me_2 := cast(Me_1, duration, "P")];
| Id_1 | Me_1 |
|---|---|
| 1 | A |
| 2 | M |
| 3 | D |
| 4 | W |
| 5 | Q |
| 6 | S |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | A | A |
| 2 | M | M |
| 3 | D | D |
| 4 | W | W |
| 5 | Q | Q |
| 6 | S | S |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
cast(comp<string>, VD) 🟢 · string, value domain → string
Values in the domain 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, VD_1)on a String measure whose values are inVD_1, after the page’s Example 6,cast(GEO_STRING, GEO_AREA).- Manual:
Type conversion: “VTL allows any value of a basic scalar type to be implicitly converted into a value belonging to a value domain or value domain subset based on that basic scalar type (downcast)”, and
scalarTypeis any “scalar type (see the section: Data type syntax)”, which a value domain is.- Expected:
VD_1is a String value domain ofA,BandC, soAandBare kept as they are, andMe_2is defined onVD_1, of the basic type String.
DS_r := DS_1[calc Me_2 := cast(Me_1, VD_1)];
| Id_1 | Me_1 |
|---|---|
| 1 | A |
| 2 | B |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | A | A |
| 2 | B | B |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · value_domains/VD_1.json · example page ↗
cast(comp<VD>, VD) 🟢 · any scalar, value domain → any type
Values in both domains 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(Me_1, VD_1)on a measure of the value domainVD_2, after the page’s Example 8,cast (GEO, GEO_AREA1).- Manual:
Type conversion: “Since an element of a value domain is implicitly upcast into its corresponding basic scalar type, and in turn that value can be implictly downcast into another value domain based on that scalar type (or one of its subsets), an implicit conversion between those two domains is straightforward.”
- Expected:
Me_1takes its values fromVD_2,AandB(its type in the input structure), which are inVD_1,A,BandC, so they are kept;Me_1stays defined onVD_2andMe_2is defined onVD_1, of the basic type String.
DS_r := DS_1[calc Me_2 := cast(Me_1, VD_1)];
| Id_1 | Me_1 |
|---|---|
| 1 | A |
| 2 | B |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | A | A |
| 2 | B | B |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · value_domains/VD_1.json · value_domains/VD_2.json · example page ↗
cast(sc<string>, integer) 🟢 · string → integer
String of digits 🟢 pandas ✅ · DuckDB ✅
- Tests:
cast(SC_1, integer)on a scalar, withSC_1= 42, a String.- Manual:
Type conversion, whose
opmay be ascalar: “a sequence of digits is consumed to determine its absolute value”.- Expected:
SC_r = 42, an Integer.
SC_r := cast(SC_1, integer);
| SC_1 |
|---|
| 42 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗