vtlengine 1.0.0__py3-none-any.whl → 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of vtlengine might be problematic. Click here for more details.

Files changed (54) hide show
  1. vtlengine/API/_InternalApi.py +153 -100
  2. vtlengine/API/__init__.py +109 -67
  3. vtlengine/AST/ASTConstructor.py +188 -98
  4. vtlengine/AST/ASTConstructorModules/Expr.py +306 -200
  5. vtlengine/AST/ASTConstructorModules/ExprComponents.py +172 -102
  6. vtlengine/AST/ASTConstructorModules/Terminals.py +158 -95
  7. vtlengine/AST/ASTEncoders.py +1 -1
  8. vtlengine/AST/ASTTemplate.py +8 -9
  9. vtlengine/AST/ASTVisitor.py +8 -12
  10. vtlengine/AST/DAG/__init__.py +43 -35
  11. vtlengine/AST/DAG/_words.py +4 -4
  12. vtlengine/AST/Grammar/lexer.py +732 -142
  13. vtlengine/AST/Grammar/parser.py +2188 -826
  14. vtlengine/AST/Grammar/tokens.py +128 -128
  15. vtlengine/AST/VtlVisitor.py +7 -4
  16. vtlengine/AST/__init__.py +22 -11
  17. vtlengine/DataTypes/NumericTypesHandling.py +5 -4
  18. vtlengine/DataTypes/TimeHandling.py +194 -301
  19. vtlengine/DataTypes/__init__.py +304 -218
  20. vtlengine/Exceptions/__init__.py +52 -27
  21. vtlengine/Exceptions/messages.py +134 -62
  22. vtlengine/Interpreter/__init__.py +781 -487
  23. vtlengine/Model/__init__.py +165 -121
  24. vtlengine/Operators/Aggregation.py +156 -95
  25. vtlengine/Operators/Analytic.py +115 -59
  26. vtlengine/Operators/Assignment.py +7 -4
  27. vtlengine/Operators/Boolean.py +27 -32
  28. vtlengine/Operators/CastOperator.py +177 -131
  29. vtlengine/Operators/Clause.py +137 -99
  30. vtlengine/Operators/Comparison.py +148 -117
  31. vtlengine/Operators/Conditional.py +149 -98
  32. vtlengine/Operators/General.py +68 -47
  33. vtlengine/Operators/HROperators.py +91 -72
  34. vtlengine/Operators/Join.py +217 -118
  35. vtlengine/Operators/Numeric.py +89 -44
  36. vtlengine/Operators/RoleSetter.py +16 -15
  37. vtlengine/Operators/Set.py +61 -36
  38. vtlengine/Operators/String.py +213 -139
  39. vtlengine/Operators/Time.py +334 -216
  40. vtlengine/Operators/Validation.py +117 -76
  41. vtlengine/Operators/__init__.py +340 -213
  42. vtlengine/Utils/__init__.py +195 -40
  43. vtlengine/__init__.py +1 -1
  44. vtlengine/files/output/__init__.py +15 -6
  45. vtlengine/files/output/_time_period_representation.py +10 -9
  46. vtlengine/files/parser/__init__.py +77 -52
  47. vtlengine/files/parser/_rfc_dialect.py +6 -5
  48. vtlengine/files/parser/_time_checking.py +46 -37
  49. vtlengine-1.0.1.dist-info/METADATA +236 -0
  50. vtlengine-1.0.1.dist-info/RECORD +58 -0
  51. {vtlengine-1.0.dist-info → vtlengine-1.0.1.dist-info}/WHEEL +1 -1
  52. vtlengine-1.0.dist-info/METADATA +0 -104
  53. vtlengine-1.0.dist-info/RECORD +0 -58
  54. {vtlengine-1.0.dist-info → vtlengine-1.0.1.dist-info}/LICENSE.md +0 -0
@@ -8,150 +8,150 @@ Vtl Token centralized.
8
8
  """
9
9
 
10
10
  # General
11
- PASSIGN = '<-'
12
- ASSIGN = ':='
13
- MEMBERSHIP = '#'
14
- LPAREN = '('
15
- RLPAREN = ')'
16
- COMMA = ','
17
- COLON = ':'
18
- SCOLON = ';'
11
+ PASSIGN = "<-"
12
+ ASSIGN = ":="
13
+ MEMBERSHIP = "#"
14
+ LPAREN = "("
15
+ RLPAREN = ")"
16
+ COMMA = ","
17
+ COLON = ":"
18
+ SCOLON = ";"
19
19
  # Numeric operators.
20
- PLUS = '+'
21
- MINUS = '-'
22
- MULT = '*'
23
- DIV = '/'
24
- MOD = 'mod'
25
- ROUND = 'round'
26
- TRUNC = 'trunc'
27
- CEIL = 'ceil'
28
- FLOOR = 'floor'
29
- ABS = 'abs'
30
- EXP = 'exp'
31
- LN = 'ln'
32
- POWER = 'power'
33
- LOG = 'log'
34
- SQRT = 'sqrt'
20
+ PLUS = "+"
21
+ MINUS = "-"
22
+ MULT = "*"
23
+ DIV = "/"
24
+ MOD = "mod"
25
+ ROUND = "round"
26
+ TRUNC = "trunc"
27
+ CEIL = "ceil"
28
+ FLOOR = "floor"
29
+ ABS = "abs"
30
+ EXP = "exp"
31
+ LN = "ln"
32
+ POWER = "power"
33
+ LOG = "log"
34
+ SQRT = "sqrt"
35
35
  # Boolean operators.
36
- AND = 'and'
37
- OR = 'or'
38
- XOR = 'xor'
39
- NOT = 'not'
36
+ AND = "and"
37
+ OR = "or"
38
+ XOR = "xor"
39
+ NOT = "not"
40
40
  # Comparison operators.
41
- EQ = '='
42
- NEQ = '<>'
43
- GT = '>'
44
- GTE = '>='
45
- LT = '<'
46
- LTE = '<='
47
- BETWEEN = 'between'
48
- IN = 'in'
49
- NOT_IN = 'not_in'
50
- CHARSET_MATCH = 'match_characters'
51
- ISNULL = 'isnull'
52
- EXISTS_IN = 'exists_in'
41
+ EQ = "="
42
+ NEQ = "<>"
43
+ GT = ">"
44
+ GTE = ">="
45
+ LT = "<"
46
+ LTE = "<="
47
+ BETWEEN = "between"
48
+ IN = "in"
49
+ NOT_IN = "not_in"
50
+ CHARSET_MATCH = "match_characters"
51
+ ISNULL = "isnull"
52
+ EXISTS_IN = "exists_in"
53
53
  # String operators.
54
- CONCAT = '||'
55
- TRIM = 'trim'
56
- RTRIM = 'rtrim'
57
- LTRIM = 'ltrim'
58
- UCASE = 'upper'
59
- LCASE = 'lower'
60
- SUBSTR = 'substr'
61
- REPLACE = 'replace'
62
- INSTR = 'instr'
63
- LEN = 'length'
54
+ CONCAT = "||"
55
+ TRIM = "trim"
56
+ RTRIM = "rtrim"
57
+ LTRIM = "ltrim"
58
+ UCASE = "upper"
59
+ LCASE = "lower"
60
+ SUBSTR = "substr"
61
+ REPLACE = "replace"
62
+ INSTR = "instr"
63
+ LEN = "length"
64
64
  # Set operators.
65
- UNION = 'union'
66
- INTERSECT = 'intersect'
67
- SETDIFF = 'setdiff'
68
- SYMDIFF = 'symdiff'
65
+ UNION = "union"
66
+ INTERSECT = "intersect"
67
+ SETDIFF = "setdiff"
68
+ SYMDIFF = "symdiff"
69
69
  # Conditional Operators.
70
- IF = 'if'
71
- THEN = 'then'
72
- ELSE = 'else'
73
- NVL = 'nvl'
70
+ IF = "if"
71
+ THEN = "then"
72
+ ELSE = "else"
73
+ NVL = "nvl"
74
74
  # Clause Operators.
75
- FILTER = 'filter'
76
- CALC = 'calc'
77
- AGGREGATE = 'aggr'
78
- KEEP = 'keep'
79
- DROP = 'drop'
80
- RENAME = 'rename'
81
- PIVOT = 'pivot'
82
- UNPIVOT = 'unpivot'
83
- SUBSPACE = 'sub'
75
+ FILTER = "filter"
76
+ CALC = "calc"
77
+ AGGREGATE = "aggr"
78
+ KEEP = "keep"
79
+ DROP = "drop"
80
+ RENAME = "rename"
81
+ PIVOT = "pivot"
82
+ UNPIVOT = "unpivot"
83
+ SUBSPACE = "sub"
84
84
  # Time Operators.
85
- PERIOD_INDICATOR = 'period_indicator'
86
- FILL_TIME_SERIES = 'fill_time_series'
87
- FLOW_TO_STOCK = 'flow_to_stock'
88
- STOCK_TO_FLOW = 'stock_to_flow'
89
- TIMESHIFT = 'timeshift'
90
- TIME_AGG = 'time_agg'
91
- CURRENT_DATE = 'current_date'
85
+ PERIOD_INDICATOR = "period_indicator"
86
+ FILL_TIME_SERIES = "fill_time_series"
87
+ FLOW_TO_STOCK = "flow_to_stock"
88
+ STOCK_TO_FLOW = "stock_to_flow"
89
+ TIMESHIFT = "timeshift"
90
+ TIME_AGG = "time_agg"
91
+ CURRENT_DATE = "current_date"
92
92
  # Join Operators.
93
- INNER_JOIN = 'inner_join'
94
- LEFT_JOIN = 'left_join'
95
- CROSS_JOIN = 'cross_join'
96
- FULL_JOIN = 'full_join'
93
+ INNER_JOIN = "inner_join"
94
+ LEFT_JOIN = "left_join"
95
+ CROSS_JOIN = "cross_join"
96
+ FULL_JOIN = "full_join"
97
97
  # Hierarchical aggregation.
98
- HIERARCHY = 'hierarchy'
98
+ HIERARCHY = "hierarchy"
99
99
  # Aggregate and analytic Operators.
100
- COUNT = 'count'
101
- MIN = 'min'
102
- MAX = 'max'
103
- MEDIAN = 'median'
104
- SUM = 'sum'
105
- AVG = 'avg'
106
- STDDEV_POP = 'stddev_pop'
107
- STDDEV_SAMP = 'stddev_samp'
108
- VAR_POP = 'var_pop'
109
- VAR_SAMP = 'var_samp'
110
- FIRST_VALUE = 'first_value'
111
- LAST_VALUE = 'last_value'
112
- LAG = 'lag'
113
- LEAD = 'lead'
114
- RANK = 'rank'
115
- RATIO_TO_REPORT = 'ratio_to_report'
100
+ COUNT = "count"
101
+ MIN = "min"
102
+ MAX = "max"
103
+ MEDIAN = "median"
104
+ SUM = "sum"
105
+ AVG = "avg"
106
+ STDDEV_POP = "stddev_pop"
107
+ STDDEV_SAMP = "stddev_samp"
108
+ VAR_POP = "var_pop"
109
+ VAR_SAMP = "var_samp"
110
+ FIRST_VALUE = "first_value"
111
+ LAST_VALUE = "last_value"
112
+ LAG = "lag"
113
+ LEAD = "lead"
114
+ RANK = "rank"
115
+ RATIO_TO_REPORT = "ratio_to_report"
116
116
  # Data validation Operators.
117
- CHECK_DATAPOINT = 'check_datapoint'
118
- CHECK_HIERARCHY = 'check_hierarchy'
119
- CHECK = 'check'
117
+ CHECK_DATAPOINT = "check_datapoint"
118
+ CHECK_HIERARCHY = "check_hierarchy"
119
+ CHECK = "check"
120
120
  # Role Operators.
121
- IDENTIFIER = 'identifier'
122
- MEASURE = 'measure'
123
- ATTRIBUTE = 'attribute'
124
- VIRAL_ATTRIBUTE = 'viral'
121
+ IDENTIFIER = "identifier"
122
+ MEASURE = "measure"
123
+ ATTRIBUTE = "attribute"
124
+ VIRAL_ATTRIBUTE = "viral"
125
125
  # Other Operators.
126
- TO = 'to'
127
- AS = 'as'
128
- USING = 'using'
129
- OPTIONAL = '_'
130
- HAVING = 'having'
131
- WHEN = 'when'
126
+ TO = "to"
127
+ AS = "as"
128
+ USING = "using"
129
+ OPTIONAL = "_"
130
+ HAVING = "having"
131
+ WHEN = "when"
132
132
  # Helping Tokens
133
- GROUP_BY = 'group by'
134
- GROUP_EXCEPT = 'group except'
135
- GROUP_ALL = 'group all'
136
- CAST = 'cast'
137
- INVALID = 'invalid'
138
- ALL = 'all'
139
- ALL_MEASURES = 'all_measures'
140
- COMPUTED = 'computed'
141
- DATASET = 'dataset'
142
- DATASET_PRIORITY = 'dataset_priority'
143
- RULE = 'rule'
144
- RULE_PRIORITY = 'rule_priority'
145
- NON_NULL = 'non_null'
146
- NON_ZERO = 'non_zero'
147
- PARTIAL_NULL = 'partial_null'
148
- PARTIAL_ZERO = 'partial_zero'
149
- ALWAYS_NULL = 'always_null'
150
- ALWAYS_ZERO = 'always_zero'
151
- APPLY = 'apply'
133
+ GROUP_BY = "group by"
134
+ GROUP_EXCEPT = "group except"
135
+ GROUP_ALL = "group all"
136
+ CAST = "cast"
137
+ INVALID = "invalid"
138
+ ALL = "all"
139
+ ALL_MEASURES = "all_measures"
140
+ COMPUTED = "computed"
141
+ DATASET = "dataset"
142
+ DATASET_PRIORITY = "dataset_priority"
143
+ RULE = "rule"
144
+ RULE_PRIORITY = "rule_priority"
145
+ NON_NULL = "non_null"
146
+ NON_ZERO = "non_zero"
147
+ PARTIAL_NULL = "partial_null"
148
+ PARTIAL_ZERO = "partial_zero"
149
+ ALWAYS_NULL = "always_null"
150
+ ALWAYS_ZERO = "always_zero"
151
+ APPLY = "apply"
152
152
  # Defined operators.
153
- OPERATOR = 'operator'
154
- EVAL = 'eval'
153
+ OPERATOR = "operator"
154
+ EVAL = "eval"
155
155
  # External.
156
156
  SQLITE = '"sqlite"'
157
157
  EXTERNAL = [SQLITE]
@@ -5,6 +5,7 @@ from vtlengine.AST.Grammar.parser import Parser
5
5
 
6
6
  # This class defines a complete generic visitor for a parse tree produced by Parser.
7
7
 
8
+
8
9
  class VtlVisitor(ParseTreeVisitor):
9
10
 
10
11
  # Visit a parse tree produced by Parser#start.
@@ -146,8 +147,9 @@ class VtlVisitor(ParseTreeVisitor):
146
147
  return self.visitChildren(ctx)
147
148
 
148
149
  # Visit a parse tree produced by Parser#conditionalFunctionsComponents.
149
- def visitConditionalFunctionsComponents(self,
150
- ctx: Parser.ConditionalFunctionsComponentsContext):
150
+ def visitConditionalFunctionsComponents(
151
+ self, ctx: Parser.ConditionalFunctionsComponentsContext
152
+ ):
151
153
  return self.visitChildren(ctx)
152
154
 
153
155
  # Visit a parse tree produced by Parser#aggregateFunctionsComponents.
@@ -335,8 +337,9 @@ class VtlVisitor(ParseTreeVisitor):
335
337
  return self.visitChildren(ctx)
336
338
 
337
339
  # Visit a parse tree produced by Parser#unaryWithOptionalNumericComponent.
338
- def visitUnaryWithOptionalNumericComponent(self,
339
- ctx: Parser.UnaryWithOptionalNumericComponentContext):
340
+ def visitUnaryWithOptionalNumericComponent(
341
+ self, ctx: Parser.UnaryWithOptionalNumericComponentContext
342
+ ):
340
343
  return self.visitChildren(ctx)
341
344
 
342
345
  # Visit a parse tree produced by Parser#binaryNumericComponent.
vtlengine/AST/__init__.py CHANGED
@@ -6,6 +6,7 @@ Description
6
6
  -----------
7
7
  Basic AST nodes.
8
8
  """
9
+
9
10
  from dataclasses import dataclass
10
11
  from typing import Any, Dict, List, Optional, Type, Union
11
12
 
@@ -39,9 +40,7 @@ class AST:
39
40
  return f"<{name}({', '.join(out)})>"
40
41
 
41
42
  def toJSON(self):
42
- base = {
43
- 'class_name': self.__class__.__name__
44
- }
43
+ base = {"class_name": self.__class__.__name__}
45
44
  for k in self.__all_annotations().keys():
46
45
  v = self.__getattribute__(k)
47
46
  base[k] = v
@@ -75,6 +74,7 @@ class PersistentAssignment(Assignment):
75
74
  """
76
75
  PersistentAssignment: (left, op, right)
77
76
  """
77
+
78
78
  pass
79
79
 
80
80
 
@@ -85,6 +85,7 @@ class VarID(AST):
85
85
  The Var node is constructed out of ID token.
86
86
  Could be: DATASET or a COMPONENT.
87
87
  """
88
+
88
89
  value: Any
89
90
 
90
91
 
@@ -105,7 +106,8 @@ class UnaryOp(AST):
105
106
  class BinOp(AST):
106
107
  """
107
108
  BinOp: (left, op, right)
108
- op types: "+", "-", "*", "/",MOD, MEMBERSHIP, PIVOT, UNPIVOT, LOG, POWER, CHARSET_MATCH, NVL, MOD
109
+ op types: "+", "-", "*", "/",MOD, MEMBERSHIP, PIVOT, UNPIVOT, LOG,
110
+ POWER, CHARSET_MATCH, NVL, MOD
109
111
  """
110
112
 
111
113
  left: AST
@@ -217,7 +219,7 @@ class Collection(AST):
217
219
  name: str
218
220
  type: str
219
221
  children: List[AST]
220
- kind: str = 'Set'
222
+ kind: str = "Set"
221
223
 
222
224
 
223
225
  @dataclass
@@ -233,9 +235,9 @@ class Windowing(AST):
233
235
  """
234
236
 
235
237
  type_: str
236
- start: int
238
+ start: str
237
239
  start_mode: str
238
- stop: int
240
+ stop: Union[int, str]
239
241
  stop_mode: str
240
242
 
241
243
 
@@ -245,7 +247,7 @@ class OrderBy(AST):
245
247
  order: str
246
248
 
247
249
  def __post_init__(self):
248
- if self.order not in ['asc', 'desc']:
250
+ if self.order not in ["asc", "desc"]:
249
251
  raise ValueError(f"Invalid order: {self.order}")
250
252
 
251
253
 
@@ -254,13 +256,14 @@ class Analytic(AST):
254
256
  """
255
257
  Analytic: (op, operand, partition_by, order_by, params)
256
258
 
257
- op: SUM, AVG, COUNT, MEDIAN, MIN, MAX, STDDEV_POP, STDDEV_SAMP, VAR_POP, VAR_SAMP, FIRST_VALUE, LAST_VALUE, LAG,
258
- LEAD, RATIO_TO_REPORT
259
+ op: SUM, AVG, COUNT, MEDIAN, MIN, MAX, STDDEV_POP, STDDEV_SAMP, VAR_POP, VAR_SAMP,
260
+ FIRST_VALUE, LAST_VALUE, LAG, LEAD, RATIO_TO_REPORT
259
261
 
260
262
  partition_by: List of components.
261
263
  order_by: List of components + mode (ASC, DESC).
262
264
  params: Windowing clause (no need to validate them) or Scalar Item in LAG/LEAD.
263
265
  """
266
+
264
267
  op: str
265
268
  operand: Optional[AST]
266
269
  window: Optional[Windowing] = None
@@ -307,6 +310,7 @@ class Aggregation(AST):
307
310
 
308
311
  grouping types: 'group by', 'group except', 'group all'.
309
312
  """
313
+
310
314
  op: str
311
315
  operand: Optional[AST] = None
312
316
  grouping_op: Optional[str] = None
@@ -334,6 +338,7 @@ class If(AST):
334
338
  """
335
339
  If: (condition, thenOp, elseOp)
336
340
  """
341
+
337
342
  condition: AST
338
343
  thenOp: AST
339
344
  elseOp: AST
@@ -358,6 +363,7 @@ class ComponentType(AST):
358
363
  """
359
364
  ComponentType: (data_type, role)
360
365
  """
366
+
361
367
  name: str
362
368
  data_type: Optional[Type[ScalarType]] = None
363
369
  role: Optional[Role] = None
@@ -400,8 +406,9 @@ class Argument(AST):
400
406
  """
401
407
  Argument: (name, type_, default)
402
408
  """
409
+
403
410
  name: str
404
- type_: ScalarType
411
+ type_: Type[ScalarType]
405
412
  default: Optional[AST]
406
413
 
407
414
 
@@ -423,6 +430,7 @@ class DefIdentifier(AST):
423
430
  """
424
431
  DefIdentifier: (value, kind)
425
432
  """
433
+
426
434
  value: str
427
435
  kind: str
428
436
 
@@ -432,6 +440,7 @@ class DPRIdentifier(AST):
432
440
  """
433
441
  DefIdentifier: (value, kind, alias)
434
442
  """
443
+
435
444
  value: str
436
445
  kind: str
437
446
  alias: Optional[str] = None
@@ -444,6 +453,7 @@ class HRBinOp(AST):
444
453
  HRBinOp: (left, op, right)
445
454
  op types: '+','-', '=', '>', '<', '>=', '<='.
446
455
  """
456
+
447
457
  left: DefIdentifier
448
458
  op: str
449
459
  right: DefIdentifier
@@ -529,4 +539,5 @@ class NoOp(AST):
529
539
  """
530
540
  NoOp: ()
531
541
  """
542
+
532
543
  pass
@@ -1,8 +1,9 @@
1
1
  import operator
2
2
  from decimal import Decimal
3
+ from typing import Union
3
4
 
4
5
 
5
- def decimal_add(a, b):
6
+ def decimal_add(a: Union[float, int], b: Union[float, int]) -> float:
6
7
  """
7
8
  Adds two numbers, if they are floats, converts them to Decimal and then to float
8
9
  :param a: first number
@@ -16,21 +17,21 @@ def decimal_add(a, b):
16
17
  return operator.add(a, b)
17
18
 
18
19
 
19
- def decimal_sub(a, b):
20
+ def decimal_sub(a: Union[float, int], b: Union[float, int]) -> float:
20
21
  if isinstance(a, float) and isinstance(b, float):
21
22
  decimal_value = Decimal(a) - Decimal(b)
22
23
  return float(decimal_value)
23
24
  return operator.sub(a, b)
24
25
 
25
26
 
26
- def decimal_mul(a, b):
27
+ def decimal_mul(a: Union[float, int], b: Union[float, int]) -> float:
27
28
  if isinstance(a, float) and isinstance(b, float):
28
29
  decimal_value = Decimal(a) * Decimal(b)
29
30
  return float(decimal_value)
30
31
  return operator.mul(a, b)
31
32
 
32
33
 
33
- def decimal_div(a, b):
34
+ def decimal_div(a: Union[float, int], b: Union[float, int]) -> float:
34
35
  if isinstance(a, float) and isinstance(b, float):
35
36
  decimal_value = Decimal(a) / Decimal(b)
36
37
  return float(decimal_value)