Truncation · trunc
---
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["Truncation · trunc<br/>🟢11"]:::ok
subgraph G_ds["Dataset"]
direction LR
v_ds_digits["trunc(DS, n)"]:::ok
v_ds_no_digits["trunc(DS)"]:::ok
v_ds_placeholder["trunc(DS, _)"]:::ok
end
subgraph G_comp["Component"]
direction LR
v_comp_digits["trunc(comp, n)"]:::ok
v_comp_no_digits["trunc(comp)"]:::ok
v_comp_placeholder["trunc(comp, _)"]:::ok
v_comp_comp_digits["trunc(comp, comp)"]:::ok
v_sc_comp_digits["trunc(sc, comp)"]:::ok
end
subgraph G_sc["Scalar"]
direction LR
v_sc_digits["trunc(sc, n)"]:::ok
v_sc_no_digits["trunc(sc)"]:::ok
v_sc_placeholder["trunc(sc, _)"]:::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_ds_digits href "#form-ds-digits"
click v_ds_no_digits href "#form-ds-no-digits"
click v_ds_placeholder href "#form-ds-placeholder"
click v_comp_digits href "#form-comp-digits"
click v_comp_no_digits href "#form-comp-no-digits"
click v_comp_placeholder href "#form-comp-placeholder"
click v_comp_comp_digits href "#form-comp-comp-digits"
click v_sc_comp_digits href "#form-sc-comp-digits"
click v_sc_digits href "#form-sc-digits"
click v_sc_no_digits href "#form-sc-no-digits"
click v_sc_placeholder href "#form-sc-placeholder"
Types
Takes number, integer · Gives number, integer
Comes from · number, integer — 44 operators in 6 blocks 🟢44
General purpose operators (2) 🟢2
String operators (3) 🟢3
Numeric operators (17) 🟢17
Time operators (9) 🟢9
Aggregate and Analytic operators (10) 🟢10
Data validation operators (3) 🟢3
Comes from · operators that return any type (their input's) — 37 operators in 8 blocks 🟢37
General purpose operators (5) 🟢5
Join operators (4) 🟢4
Time operators (3) 🟢3
Set operators (4) 🟢4
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Conditional operators (3) 🟢3
Goes to · number, integer — 43 operators in 8 blocks 🟢43
General purpose operators (1) 🟢1
String operators (2) 🟢2
Numeric operators (17) 🟢17
Time operators (6) 🟢6
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (10) 🟢10
Data validation operators (2) 🟢2
Definitions (VTL-DL) (4) 🟢4
Goes to · operators that take any scalar — 46 operators in 8 blocks 🟢46
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (8) 🟢8
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Forms
trunc(DS, n) 🟢 · number, integer → number
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
truncto 0 digits on every measure ofDS_1.- Manual:
Truncation, Example 1, output verbatim: “The operator trunc truncates the operand to a number of positions at the right of the decimal point equal to the numDigit parameter.”
- Expected:
Me_17.5, 7.1, 36.2 and 44.5 give 7.0, 7.0, 36.0 and 44.0;Me_25.9, 5.5, 17.7 and 24.3 give 5.0, 5.0, 17.0 and 24.0. Both stay Number, asnumDigitis given.
DS_r := trunc(DS_1, 0);
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 7.5 | 5.9 |
| 10 | B | 7.1 | 5.5 |
| 11 | A | 36.2 | 17.7 |
| 11 | B | 44.5 | 24.3 |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 7.0 | 5.0 |
| 10 | B | 7.0 | 5.0 |
| 11 | A | 36.0 | 17.0 |
| 11 | B | 44.0 | 24.0 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
trunc(DS) 🟢 · number → integer
One number measure 🟢 pandas ✅ · DuckDB ✅
- Tests:
truncwithnumDigitomitted, on a dataset with one Number measure.- Manual:
Truncation: “The basic scalar type of the result is integer if numDigit is omitted”, and in the Typical behaviours, “Operators changing the data type”, the measure whose type changes is replaced: “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:
int_var, an Integer: 3.14159, 2.71828 and 12345.6 give 3, 2 and 12345.
DS_r := trunc(DS_1);
| Id_1 | Me_1 |
|---|---|
| 1 | 3.14159 |
| 2 | 2.71828 |
| 3 | 12345.6 |
| Id_1 | int_var |
|---|---|
| 1 | 3 |
| 2 | 2 |
| 3 | 12345 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Two number measures 🟢 pandas ✅ · DuckDB ✅
- Tests:
truncwithnumDigitomitted, on a dataset with two Number measures.- Manual:
Truncation: “The basic scalar type of the result is integer if numDigit is omitted”; the result is typed
dataset { measure<number> _+ }, and the unary operators give “homonymous Measures in DS_r”.- Expected:
both measures keep their names and become Integers:
Me_13, 2 and 7,Me_212345, 0 and 5. Ceiling and Floor Example 1 do the same, and nothing putstruncamong the “Operators changing the data type”, which allow one measure only.
DS_r := trunc(DS_1);
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 3.14159 | 12345.6 |
| 2 | 2.71828 | 0.4 |
| 3 | 7.2 | 5.9 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 3 | 12345 |
| 2 | 2 | 0 |
| 3 | 7 | 5 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
trunc(DS, _) 🟢 · number → integer
Placeholder for digits 🟢 pandas ✅ · DuckDB ✅
- Tests:
the placeholder
_fornumDigit, on a dataset with one Number measure.- Manual:
Truncation: “
trunc ( 12345.6, _ )gives12345”, and in the Typical behaviours, “Operators changing the data type”, the measure whose type changes is replaced: “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:
the placeholder stands for an omitted
numDigit, so the result is an Integer, as withtrunc(DS_1):int_var3, 2 and 12345.
DS_r := trunc(DS_1, _);
| Id_1 | Me_1 |
|---|---|
| 1 | 3.14159 |
| 2 | 2.71828 |
| 3 | 12345.6 |
| Id_1 | int_var |
|---|---|
| 1 | 3 |
| 2 | 2 |
| 3 | 12345 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
trunc(comp, n) 🟢 · number, integer → number
Manual example 3 🟢 pandas ✅ · DuckDB ✅
- Tests:
truncto a negative number of digits, on a component insidecalc.- Manual:
Truncation, Example 3, output verbatim: “If numDigit is negative, the truncation happens at the left of the decimal point.”
- Expected:
Me_20 = trunc(Me_1, -1)truncates to tens: 7.5, 7.1, 36.2 and 44.5 give 0.0, 0.0, 30.0 and 40.0; the other components are kept.
DS_r := DS_1[ calc Me_20:= trunc( Me_1 , -1 ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 7.5 | 5.9 |
| 10 | B | 7.1 | 5.5 |
| 11 | A | 36.2 | 17.7 |
| 11 | B | 44.5 | 24.3 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_20 |
|---|---|---|---|---|
| 10 | A | 7.5 | 5.9 | 0.0 |
| 10 | B | 7.1 | 5.5 | 0.0 |
| 11 | A | 36.2 | 17.7 | 30.0 |
| 11 | B | 44.5 | 24.3 | 40.0 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
trunc(comp) 🟢 · number → integer
Manual example 2 🟢 pandas ✅ · DuckDB ✅
- Tests:
truncwithnumDigitomitted, on a component insidecalc.- Manual:
Truncation, Example 2, output verbatim: “The basic scalar type of the result is integer if numDigit is omitted, number otherwise.”
- Expected:
Me_10 = trunc(Me_1)is an Integer: 7.5, 7.1, 36.2 and 44.5 give 7, 7, 36 and 44; the other components are kept.
DS_r := DS_1[ calc Me_10:= trunc( Me_1 ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 7.5 | 5.9 |
| 10 | B | 7.1 | 5.5 |
| 11 | A | 36.2 | 17.7 |
| 11 | B | 44.5 | 24.3 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_10 |
|---|---|---|---|---|
| 10 | A | 7.5 | 5.9 | 7 |
| 10 | B | 7.1 | 5.5 | 7 |
| 11 | A | 36.2 | 17.7 | 36 |
| 11 | B | 44.5 | 24.3 | 44 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
trunc(comp, _) 🟢 · number → integer
Placeholder for digits 🟢 pandas ✅ · DuckDB ✅
- Tests:
the placeholder
_fornumDigit, on a component insidecalc.- Manual:
Truncation: “
trunc ( 12345.6, _ )gives12345”.- Expected:
Me_2 = trunc(Me_1, _)is an Integer, as withnumDigitomitted: 3.14159, 2.71828 and 12345.6 give 3, 2 and 12345; the other components are kept.
DS_r := DS_1[calc Me_2 := trunc(Me_1, _)];
| Id_1 | Me_1 |
|---|---|
| 1 | 3.14159 |
| 2 | 2.71828 |
| 3 | 12345.6 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 3.141590 | 3 |
| 2 | 2.718280 | 2 |
| 3 | 12345.600000 | 12345 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
trunc(comp, comp) 🟢 · number, integer → number
Digits from component 🟢 pandas ✅ · DuckDB ✅
- Tests:
numDigitgiven by an Integer component, which may be negative.- Manual:
Truncation types
numDigitascomponent<integer> | integer, and “trunc( 12345.6, -1 )gives12340.0”.- Expected:
Me_3 = trunc(Me_1, Me_2):trunc(3.14159, 2) = 3.14,trunc(2.71828, 3) = 2.718andtrunc(12345.6, -1) = 12340.0, a Number; the other components are kept.
DS_r := DS_1[calc Me_3 := trunc(Me_1, Me_2)];
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 3.14159 | 2 |
| 2 | 2.71828 | 3 |
| 3 | 12345.6 | -1 |
| Id_1 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|
| 1 | 3.141590 | 2 | 3.140000 |
| 2 | 2.718280 | 3 | 2.718000 |
| 3 | 12345.600000 | -1 | 12340.000000 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
trunc(sc, comp) 🟢 · number, integer → number
Digits from component 🟢 pandas ✅ · DuckDB ✅
- Tests:
a scalar operand with
numDigitgiven by an Integer component, insidecalc.- Manual:
Truncation types
numDigitascomponent<integer> | integer, so it may be a component while the operand is a scalar.- Expected:
the error
1-1-15-8, “At op {op}: {op} operator cannot have a {comp_type} as parameter”: by a team decision,numDigitis a Component only when the operand is a Component too.
DS_r := DS_1[calc Me_2 := trunc(3.14159, Me_1)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2 |
| 2 | 4 |
| 3 | 0 |
Expected error 1-1-15-8: At op {op}: {op} operator cannot have a {comp_type} as parameter.
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/error.json · example page ↗
trunc(sc, n) 🟢 · number, integer → number
Drops after fourth decimal 🟢 pandas ✅ · DuckDB ✅
- Tests:
truncof a scalar withnumDigitgiven:trunc(SC_1, SC_2)withSC_1= 3.14159 andSC_2= 4.- Manual:
Truncation: “
trunc ( 3.14159, 4 )gives3.1415”.- Expected:
SC_r = 3.1415, a Number: the fourth decimal is kept and the rest dropped.
SC_r := trunc(SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| 3.14159 | 4 |
Name |
Type |
Value |
|---|---|---|
|
Number |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
trunc(sc) 🟢 · number → integer
Drops fraction to integer 🟢 pandas ✅ · DuckDB ✅
- Tests:
truncof a scalar withnumDigitomitted:trunc(SC_1)withSC_1= 12345.6.- Manual:
Truncation: “
trunc ( 12345.6 )gives12345”, and “The basic scalar type of the result is integer if numDigit is omitted”.- Expected:
SC_r = 12345, an Integer.
SC_r := trunc(SC_1);
| SC_1 |
|---|
| 12345.6 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
trunc(sc, _) 🟢 · number → integer
Placeholder for digits 🟢 pandas ✅ · DuckDB ✅
- Tests:
the placeholder
_fornumDigit, on a scalar:trunc(SC_1, _)withSC_1= 12345.6.- Manual:
Truncation: “
trunc ( 12345.6, _ )gives12345”.- Expected:
SC_r = 12345, an Integer: the placeholder stands for an omittednumDigit.
SC_r := trunc(SC_1, _);
| SC_1 |
|---|
| 12345.6 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗