vtlengine 1.0__py3-none-any.whl → 1.0.2__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 (56) hide show
  1. vtlengine/API/_InternalApi.py +159 -102
  2. vtlengine/API/__init__.py +110 -68
  3. vtlengine/AST/ASTConstructor.py +188 -98
  4. vtlengine/AST/ASTConstructorModules/Expr.py +402 -205
  5. vtlengine/AST/ASTConstructorModules/ExprComponents.py +248 -104
  6. vtlengine/AST/ASTConstructorModules/Terminals.py +158 -95
  7. vtlengine/AST/ASTEncoders.py +1 -1
  8. vtlengine/AST/ASTTemplate.py +24 -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/Vtl.g4 +49 -20
  13. vtlengine/AST/Grammar/VtlTokens.g4 +13 -1
  14. vtlengine/AST/Grammar/lexer.py +2012 -1312
  15. vtlengine/AST/Grammar/parser.py +7524 -4343
  16. vtlengine/AST/Grammar/tokens.py +140 -128
  17. vtlengine/AST/VtlVisitor.py +16 -5
  18. vtlengine/AST/__init__.py +41 -11
  19. vtlengine/DataTypes/NumericTypesHandling.py +5 -4
  20. vtlengine/DataTypes/TimeHandling.py +196 -301
  21. vtlengine/DataTypes/__init__.py +304 -218
  22. vtlengine/Exceptions/__init__.py +96 -27
  23. vtlengine/Exceptions/messages.py +149 -69
  24. vtlengine/Interpreter/__init__.py +817 -497
  25. vtlengine/Model/__init__.py +172 -121
  26. vtlengine/Operators/Aggregation.py +156 -95
  27. vtlengine/Operators/Analytic.py +167 -79
  28. vtlengine/Operators/Assignment.py +7 -4
  29. vtlengine/Operators/Boolean.py +27 -32
  30. vtlengine/Operators/CastOperator.py +177 -131
  31. vtlengine/Operators/Clause.py +137 -99
  32. vtlengine/Operators/Comparison.py +148 -117
  33. vtlengine/Operators/Conditional.py +290 -98
  34. vtlengine/Operators/General.py +68 -47
  35. vtlengine/Operators/HROperators.py +91 -72
  36. vtlengine/Operators/Join.py +217 -118
  37. vtlengine/Operators/Numeric.py +129 -46
  38. vtlengine/Operators/RoleSetter.py +16 -15
  39. vtlengine/Operators/Set.py +61 -36
  40. vtlengine/Operators/String.py +213 -139
  41. vtlengine/Operators/Time.py +467 -215
  42. vtlengine/Operators/Validation.py +117 -76
  43. vtlengine/Operators/__init__.py +340 -213
  44. vtlengine/Utils/__init__.py +232 -41
  45. vtlengine/__init__.py +1 -1
  46. vtlengine/files/output/__init__.py +15 -6
  47. vtlengine/files/output/_time_period_representation.py +10 -9
  48. vtlengine/files/parser/__init__.py +79 -52
  49. vtlengine/files/parser/_rfc_dialect.py +6 -5
  50. vtlengine/files/parser/_time_checking.py +48 -37
  51. vtlengine-1.0.2.dist-info/METADATA +245 -0
  52. vtlengine-1.0.2.dist-info/RECORD +58 -0
  53. {vtlengine-1.0.dist-info → vtlengine-1.0.2.dist-info}/WHEEL +1 -1
  54. vtlengine-1.0.dist-info/METADATA +0 -104
  55. vtlengine-1.0.dist-info/RECORD +0 -58
  56. {vtlengine-1.0.dist-info → vtlengine-1.0.2.dist-info}/LICENSE.md +0 -0
@@ -6,16 +6,31 @@ Description
6
6
  -----------
7
7
  Direct Acyclic Graph.
8
8
  """
9
+
9
10
  import copy
10
11
  from dataclasses import dataclass
11
12
  from typing import Any, Dict, Optional
12
13
 
13
14
  import networkx as nx
14
15
 
15
- from vtlengine.AST import AST, BinOp, VarID, Aggregation, Analytic, JoinOp, ParamOp, Operator, \
16
- Identifier, \
17
- DefIdentifier, Start, HRuleset, RegularAggregation, PersistentAssignment, Assignment, \
18
- DPRuleset
16
+ from vtlengine.AST import (
17
+ AST,
18
+ BinOp,
19
+ VarID,
20
+ Aggregation,
21
+ Analytic,
22
+ JoinOp,
23
+ ParamOp,
24
+ Operator,
25
+ Identifier,
26
+ DefIdentifier,
27
+ Start,
28
+ HRuleset,
29
+ RegularAggregation,
30
+ PersistentAssignment,
31
+ Assignment,
32
+ DPRuleset,
33
+ )
19
34
  from vtlengine.AST.ASTTemplate import ASTTemplate
20
35
  from vtlengine.AST.DAG._words import INSERT, DELETE, OUTPUTS, PERSISTENT, INPUTS, GLOBAL
21
36
  from vtlengine.AST.Grammar.tokens import AS, MEMBERSHIP, TO
@@ -116,9 +131,7 @@ class DAGAnalyzer(ASTTemplate):
116
131
 
117
132
  @classmethod
118
133
  def createDAG(cls, ast: AST):
119
- """
120
-
121
- """
134
+ """ """
122
135
  # Visit AST.
123
136
  dag = cls()
124
137
  dag.visit(ast)
@@ -142,17 +155,16 @@ class DAGAnalyzer(ASTTemplate):
142
155
  error_keys[aux_v1] = dag.dependencies[aux_v1]
143
156
  break
144
157
  raise Exception(
145
- 'Vtl Script contains Cycles, no DAG established.\nSuggestion {}, more_info:{}'.format(
146
- error, error_keys)) from None
158
+ "Vtl Script contains Cycles, no DAG established.\nSuggestion {}, "
159
+ "more_info:{}".format(error, error_keys)
160
+ ) from None
147
161
  except SemanticError as error:
148
162
  raise error
149
163
  except Exception as error:
150
- raise Exception('Error creating DAG.') from error
164
+ raise Exception("Error creating DAG.") from error
151
165
 
152
166
  def loadVertex(self):
153
- """
154
-
155
- """
167
+ """ """
156
168
  # For each vertex
157
169
  for key, statement in self.dependencies.items():
158
170
  output = statement[OUTPUTS] + statement[PERSISTENT]
@@ -164,9 +176,7 @@ class DAGAnalyzer(ASTTemplate):
164
176
  self.nov = len(self.vertex)
165
177
 
166
178
  def loadEdges(self):
167
- """
168
-
169
- """
179
+ """ """
170
180
  if len(self.vertex) != 0:
171
181
  countEdges = 0
172
182
  # For each vertex
@@ -182,9 +192,7 @@ class DAGAnalyzer(ASTTemplate):
182
192
  countEdges += 1
183
193
 
184
194
  def nx_topologicalSort(self):
185
- """
186
-
187
- """
195
+ """ """
188
196
  edges = list(self.edges.values())
189
197
  DAG = nx.DiGraph()
190
198
  DAG.add_nodes_from(self.vertex)
@@ -208,26 +216,23 @@ class DAGAnalyzer(ASTTemplate):
208
216
  non_repeated_outputs.append(statement.left.value)
209
217
 
210
218
  def sortAST(self, ast: AST):
211
- """
212
-
213
- """
219
+ """ """
214
220
  statements_nodes = ast.children
215
- HRuleStatements: list = [HRule for HRule in statements_nodes if
216
- isinstance(HRule, HRuleset)]
217
- DPRuleStatement: list = [DPRule for DPRule in statements_nodes if
218
- isinstance(DPRule, DPRuleset)]
221
+ HRuleStatements: list = [HRule for HRule in statements_nodes if isinstance(HRule, HRuleset)]
222
+ DPRuleStatement: list = [
223
+ DPRule for DPRule in statements_nodes if isinstance(DPRule, DPRuleset)
224
+ ]
219
225
  DOStatement: list = [DO for DO in statements_nodes if isinstance(DO, Operator)]
220
- MLStatements: list = [ML for ML in statements_nodes if
221
- not isinstance(ML, (HRuleset, DPRuleset, Operator))]
226
+ MLStatements: list = [
227
+ ML for ML in statements_nodes if not isinstance(ML, (HRuleset, DPRuleset, Operator))
228
+ ]
222
229
 
223
230
  intermediate = self.sort_elements(MLStatements)
224
231
  self.check_overwriting(intermediate)
225
232
  ast.children = HRuleStatements + DPRuleStatement + DOStatement + intermediate
226
233
 
227
234
  def statementStructure(self) -> dict:
228
- """
229
-
230
- """
235
+ """ """
231
236
  inputs = list(set(self.inputs))
232
237
  outputs = list(set(self.outputs))
233
238
  persistent = list(set(self.persistent))
@@ -267,9 +272,11 @@ class DAGAnalyzer(ASTTemplate):
267
272
 
268
273
  # Analyze inputs and outputs per each statement.
269
274
  self.dependencies[self.numberOfStatements] = copy.deepcopy(
270
- self.statementStructure())
275
+ self.statementStructure()
276
+ )
271
277
 
272
- # Count the number of statements in order to name the scope symbol table for each one.
278
+ # Count the number of statements in order to name the scope symbol table for
279
+ # each one.
273
280
  self.numberOfStatements += 1
274
281
 
275
282
  self.alias = []
@@ -376,8 +383,9 @@ class HRDAGAnalyzer(DAGAnalyzer):
376
383
  error_keys[aux_v1] = dag.dependencies[aux_v1]
377
384
  break
378
385
  raise Exception(
379
- f'Vtl Script contains Cycles, no DAG established.'
380
- f'\nSuggestion {error}, more_info:{error_keys}')
386
+ f"Vtl Script contains Cycles, no DAG established."
387
+ f"\nSuggestion {error}, more_info:{error_keys}"
388
+ )
381
389
 
382
390
  def visit_HRuleset(self, node: HRuleset) -> None:
383
391
  """
@@ -1,9 +1,9 @@
1
1
  # DS analysis
2
- INSERT = 'insertion'
3
- DELETE = 'deletion'
4
- GLOBAL = 'global_inputs'
2
+ INSERT = "insertion"
3
+ DELETE = "deletion"
4
+ GLOBAL = "global_inputs"
5
5
 
6
6
  INPUTS = "inputs"
7
7
  OUTPUTS = "outputs"
8
8
  PERSISTENT = "persistent"
9
- STATEMENT_ = 'statement'
9
+ STATEMENT_ = "statement"
@@ -21,30 +21,33 @@ expr:
21
21
  | op=(PLUS|MINUS|NOT) right=expr # unaryExpr
22
22
  | left=expr op=(MUL|DIV) right=expr # arithmeticExpr
23
23
  | left=expr op=(PLUS|MINUS|CONCAT) right=expr # arithmeticExprOrConcat
24
- | left=expr op=comparisonOperand right=expr # comparisonExpr
24
+ | left=expr op=comparisonOperand right=expr # comparisonExpr
25
25
  | left=expr op=(IN|NOT_IN)(lists|valueDomainID) # inNotInExpr
26
26
  | left=expr op=AND right=expr # booleanExpr
27
27
  | left=expr op=(OR|XOR) right=expr # booleanExpr
28
28
  | IF conditionalExpr=expr THEN thenExpr=expr ELSE elseExpr=expr # ifExpr
29
+ | CASE (WHEN expr THEN expr)+ ELSE expr # caseExpr
29
30
  | constant # constantExpr
30
31
  | varID # varIdExpr
31
32
 
33
+
32
34
  ;
33
35
 
34
36
 
35
37
  exprComponent:
36
- LPAREN exprComponent RPAREN # parenthesisExprComp
37
- | functionsComponents # functionsExpressionComp
38
- | op=(PLUS|MINUS|NOT) right=exprComponent # unaryExprComp
39
- | left=exprComponent op=(MUL|DIV) right=exprComponent # arithmeticExprComp
40
- | left=exprComponent op=(PLUS|MINUS|CONCAT) right=exprComponent # arithmeticExprOrConcatComp
41
- | left=exprComponent comparisonOperand right=exprComponent # comparisonExprComp
42
- | left=exprComponent op=(IN|NOT_IN)(lists|valueDomainID) # inNotInExprComp
43
- | left=exprComponent op=AND right=exprComponent # booleanExprComp
44
- | left=exprComponent op=(OR|XOR) right=exprComponent # booleanExprComp
45
- | IF conditionalExpr=exprComponent THEN thenExpr=exprComponent ELSE elseExpr=exprComponent # ifExprComp
46
- | constant # constantExprComp
47
- | componentID # compId
38
+ LPAREN exprComponent RPAREN # parenthesisExprComp
39
+ | functionsComponents # functionsExpressionComp
40
+ | op=(PLUS|MINUS|NOT) right=exprComponent # unaryExprComp
41
+ | left=exprComponent op=(MUL|DIV) right=exprComponent # arithmeticExprComp
42
+ | left=exprComponent op=(PLUS|MINUS|CONCAT) right=exprComponent # arithmeticExprOrConcatComp
43
+ | left=exprComponent comparisonOperand right=exprComponent # comparisonExprComp
44
+ | left=exprComponent op=(IN|NOT_IN)(lists|valueDomainID) # inNotInExprComp
45
+ | left=exprComponent op=AND right=exprComponent # booleanExprComp
46
+ | left=exprComponent op=(OR|XOR) right=exprComponent # booleanExprComp
47
+ | IF conditionalExpr=exprComponent THEN thenExpr=exprComponent ELSE elseExpr=exprComponent # ifExprComp
48
+ | CASE (WHEN exprComponent THEN exprComponent)+ ELSE exprComponent # caseExprComp
49
+ | constant # constantExprComp
50
+ | componentID # compId
48
51
  ;
49
52
 
50
53
  functionsComponents:
@@ -84,6 +87,7 @@ datasetClause:
84
87
  | calcClause
85
88
  | keepOrDropClause
86
89
  | pivotOrUnpivotClause
90
+ /* | customPivotClause */
87
91
  | subspaceClause
88
92
  ;
89
93
 
@@ -112,6 +116,10 @@ pivotOrUnpivotClause:
112
116
  op=(PIVOT|UNPIVOT) id_=componentID COMMA mea=componentID
113
117
  ;
114
118
 
119
+ customPivotClause:
120
+ CUSTOMPIVOT id_=componentID COMMA mea=componentID IN constant (COMMA constant)*
121
+ ;
122
+
115
123
  subspaceClause:
116
124
  SUBSPACE subspaceClauseItem (COMMA subspaceClauseItem)*
117
125
  ;
@@ -138,7 +146,7 @@ defOperators:
138
146
  /*---------------------------------------------------FUNCTIONS-------------------------------------------------*/
139
147
  genericOperators:
140
148
  operatorID LPAREN (parameter (COMMA parameter)*)? RPAREN # callDataset
141
- | EVAL LPAREN routineName LPAREN (varID|scalarItem)? (COMMA (varID|scalarItem))* RPAREN (LANGUAGE STRING_CONSTANT)? (RETURNS evalDatasetType)? RPAREN # evalAtom
149
+ | EVAL LPAREN routineName LPAREN (varID|scalarItem)? (COMMA (varID|scalarItem))* RPAREN (LANGUAGE STRING_CONSTANT)? (RETURNS evalDatasetType)? RPAREN # evalAtom
142
150
  | CAST LPAREN expr COMMA (basicScalarType|valueDomainName) (COMMA STRING_CONSTANT)? RPAREN # castExprDataset
143
151
  ;
144
152
 
@@ -149,6 +157,7 @@ genericOperatorsComponent:
149
157
 
150
158
  ;
151
159
 
160
+
152
161
  parameterComponent:
153
162
  exprComponent
154
163
  | OPTIONAL
@@ -176,13 +185,13 @@ stringOperatorsComponent:
176
185
  numericOperators:
177
186
  op=(CEIL | FLOOR | ABS | EXP | LN | SQRT) LPAREN expr RPAREN # unaryNumeric
178
187
  | op=(ROUND | TRUNC) LPAREN expr (COMMA optionalExpr)? RPAREN # unaryWithOptionalNumeric
179
- | op=(MOD | POWER|LOG) LPAREN left=expr COMMA right=expr RPAREN # binaryNumeric
188
+ | op=(MOD | POWER | LOG | RANDOM) LPAREN left=expr COMMA right=expr RPAREN # binaryNumeric
180
189
  ;
181
190
 
182
191
  numericOperatorsComponent:
183
- op=(CEIL | FLOOR | ABS | EXP | LN | SQRT) LPAREN exprComponent RPAREN # unaryNumericComponent
184
- | op=(ROUND | TRUNC) LPAREN exprComponent (COMMA optionalExprComponent)? RPAREN # unaryWithOptionalNumericComponent
185
- | op=(MOD | POWER | LOG) LPAREN left=exprComponent COMMA right=exprComponent RPAREN # binaryNumericComponent
192
+ op=(CEIL | FLOOR | ABS | EXP | LN | SQRT) LPAREN exprComponent RPAREN # unaryNumericComponent
193
+ | op=(ROUND | TRUNC) LPAREN exprComponent (COMMA optionalExprComponent)? RPAREN # unaryWithOptionalNumericComponent
194
+ | op=(MOD | POWER | LOG | RANDOM) LPAREN left=exprComponent COMMA right=exprComponent RPAREN # binaryNumericComponent
186
195
  ;
187
196
 
188
197
  comparisonOperators:
@@ -205,6 +214,16 @@ timeOperators:
205
214
  | TIMESHIFT LPAREN expr COMMA signedInteger RPAREN # timeShiftAtom
206
215
  | TIME_AGG LPAREN periodIndTo=STRING_CONSTANT (COMMA periodIndFrom=(STRING_CONSTANT| OPTIONAL ))? (COMMA op=optionalExpr)? (COMMA (FIRST|LAST))? RPAREN # timeAggAtom
207
216
  | CURRENT_DATE LPAREN RPAREN # currentDateAtom
217
+ | DATEDIFF LPAREN dateFrom=expr COMMA dateTo=expr RPAREN # dateDiffAtom
218
+ | DATEADD LPAREN op=expr COMMA shiftNumber=expr COMMA periodInd=expr RPAREN # dateAddAtom
219
+ | YEAR_OP LPAREN expr RPAREN # yearAtom
220
+ | MONTH_OP LPAREN expr RPAREN # monthAtom
221
+ | DAYOFMONTH LPAREN expr RPAREN # dayOfMonthAtom
222
+ | DAYOFYEAR LPAREN expr RPAREN # datOfYearAtom
223
+ | DAYTOYEAR LPAREN expr RPAREN # dayToYearAtom
224
+ | DAYTOMONTH LPAREN expr RPAREN # dayToMonthAtom
225
+ | YEARTODAY LPAREN expr RPAREN # yearTodayAtom
226
+ | MONTHTODAY LPAREN expr RPAREN # monthTodayAtom
208
227
  ;
209
228
 
210
229
  timeOperatorsComponent:
@@ -213,7 +232,17 @@ timeOperatorsComponent:
213
232
  | op=(FLOW_TO_STOCK | STOCK_TO_FLOW) LPAREN exprComponent RPAREN # flowAtomComponent
214
233
  | TIMESHIFT LPAREN exprComponent COMMA signedInteger RPAREN # timeShiftAtomComponent
215
234
  | TIME_AGG LPAREN periodIndTo=STRING_CONSTANT (COMMA periodIndFrom=(STRING_CONSTANT| OPTIONAL ))? (COMMA op=optionalExprComponent)? (COMMA (FIRST|LAST))? RPAREN # timeAggAtomComponent
216
- | CURRENT_DATE LPAREN RPAREN # currentDateAtomComponent
235
+ | CURRENT_DATE LPAREN RPAREN # currentDateAtomComponent
236
+ | DATEDIFF LPAREN dateFrom=exprComponent COMMA dateTo=exprComponent RPAREN # dateDiffAtomComponent
237
+ | DATEADD LPAREN op=exprComponent COMMA shiftNumber=exprComponent COMMA periodInd=exprComponent RPAREN # dateAddAtomComponent
238
+ | YEAR_OP LPAREN exprComponent RPAREN # yearAtomComponent
239
+ | MONTH_OP LPAREN exprComponent RPAREN # monthAtomComponent
240
+ | DAYOFMONTH LPAREN exprComponent RPAREN # dayOfMonthAtomComponent
241
+ | DAYOFYEAR LPAREN exprComponent RPAREN # datOfYearAtomComponent
242
+ | DAYTOYEAR LPAREN exprComponent RPAREN # dayToYearAtomComponent
243
+ | DAYTOMONTH LPAREN exprComponent RPAREN # dayToMonthAtomComponent
244
+ | YEARTODAY LPAREN exprComponent RPAREN # yearTodayAtomComponent
245
+ | MONTHTODAY LPAREN exprComponent RPAREN # monthTodayAtomComponent
217
246
  ;
218
247
 
219
248
  setOperators:
@@ -284,7 +313,7 @@ aggrOperatorsGrouping:
284
313
  | FIRST_VALUE
285
314
  | LAST_VALUE)
286
315
  LPAREN expr OVER LPAREN (partition=partitionByClause? orderBy=orderByClause? windowing=windowingClause?)RPAREN RPAREN #anSimpleFunction
287
- | op=(LAG |LEAD) LPAREN expr (COMMA offet=signedInteger(COMMA defaultValue=scalarItem)?)? OVER LPAREN (partition=partitionByClause? orderBy=orderByClause) RPAREN RPAREN # lagOrLeadAn
316
+ | op=(LAG |LEAD) LPAREN expr (COMMA offset=signedInteger(COMMA defaultValue=scalarItem)?)? OVER LPAREN (partition=partitionByClause? orderBy=orderByClause) RPAREN RPAREN # lagOrLeadAn
288
317
  | op=RATIO_TO_REPORT LPAREN expr OVER LPAREN (partition=partitionByClause) RPAREN RPAREN # ratioToReportAn
289
318
  ;
290
319
 
@@ -28,11 +28,22 @@ lexer grammar VtlTokens;
28
28
  MEMBERSHIP : '#';
29
29
  EVAL : 'eval';
30
30
  IF : 'if';
31
+ CASE : 'case';
31
32
  THEN : 'then';
32
33
  ELSE : 'else';
33
34
  USING : 'using';
34
35
  WITH : 'with';
35
36
  CURRENT_DATE : 'current_date';
37
+ DATEDIFF : 'datediff';
38
+ DATEADD : 'dateadd';
39
+ YEAR_OP : 'year';
40
+ MONTH_OP : 'month';
41
+ DAYOFMONTH : 'dayofmonth';
42
+ DAYOFYEAR : 'dayofyear';
43
+ DAYTOYEAR : 'daytoyear';
44
+ DAYTOMONTH : 'daytomonth';
45
+ YEARTODAY : 'yeartoday';
46
+ MONTHTODAY : 'monthtoday';
36
47
  ON : 'on';
37
48
  DROP : 'drop';
38
49
  KEEP : 'keep';
@@ -54,6 +65,7 @@ lexer grammar VtlTokens;
54
65
  DIFF : 'diff';
55
66
  SYMDIFF : 'symdiff';
56
67
  INTERSECT : 'intersect';
68
+ RANDOM : 'random';
57
69
  KEYS : 'keys';
58
70
  INTYEAR : 'intyear';
59
71
  INTMONTH : 'intmonth';
@@ -394,4 +406,4 @@ FREQUENCY
394
406
  | 'M'
395
407
  | 'W'
396
408
  | 'D'
397
- ;*/
409
+ ;*/