vtlengine 1.4.0rc2__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.
Files changed (66) hide show
  1. vtlengine/API/_InternalApi.py +791 -0
  2. vtlengine/API/__init__.py +612 -0
  3. vtlengine/API/data/schema/external_routines_schema.json +34 -0
  4. vtlengine/API/data/schema/json_schema_2.1.json +116 -0
  5. vtlengine/API/data/schema/value_domain_schema.json +97 -0
  6. vtlengine/AST/ASTComment.py +57 -0
  7. vtlengine/AST/ASTConstructor.py +598 -0
  8. vtlengine/AST/ASTConstructorModules/Expr.py +1928 -0
  9. vtlengine/AST/ASTConstructorModules/ExprComponents.py +995 -0
  10. vtlengine/AST/ASTConstructorModules/Terminals.py +790 -0
  11. vtlengine/AST/ASTConstructorModules/__init__.py +50 -0
  12. vtlengine/AST/ASTDataExchange.py +10 -0
  13. vtlengine/AST/ASTEncoders.py +32 -0
  14. vtlengine/AST/ASTString.py +675 -0
  15. vtlengine/AST/ASTTemplate.py +558 -0
  16. vtlengine/AST/ASTVisitor.py +25 -0
  17. vtlengine/AST/DAG/__init__.py +479 -0
  18. vtlengine/AST/DAG/_words.py +10 -0
  19. vtlengine/AST/Grammar/Vtl.g4 +705 -0
  20. vtlengine/AST/Grammar/VtlTokens.g4 +409 -0
  21. vtlengine/AST/Grammar/__init__.py +0 -0
  22. vtlengine/AST/Grammar/lexer.py +2139 -0
  23. vtlengine/AST/Grammar/parser.py +16597 -0
  24. vtlengine/AST/Grammar/tokens.py +169 -0
  25. vtlengine/AST/VtlVisitor.py +824 -0
  26. vtlengine/AST/__init__.py +674 -0
  27. vtlengine/DataTypes/TimeHandling.py +562 -0
  28. vtlengine/DataTypes/__init__.py +863 -0
  29. vtlengine/DataTypes/_time_checking.py +135 -0
  30. vtlengine/Exceptions/__exception_file_generator.py +96 -0
  31. vtlengine/Exceptions/__init__.py +159 -0
  32. vtlengine/Exceptions/messages.py +1004 -0
  33. vtlengine/Interpreter/__init__.py +2048 -0
  34. vtlengine/Model/__init__.py +501 -0
  35. vtlengine/Operators/Aggregation.py +357 -0
  36. vtlengine/Operators/Analytic.py +455 -0
  37. vtlengine/Operators/Assignment.py +23 -0
  38. vtlengine/Operators/Boolean.py +106 -0
  39. vtlengine/Operators/CastOperator.py +451 -0
  40. vtlengine/Operators/Clause.py +366 -0
  41. vtlengine/Operators/Comparison.py +488 -0
  42. vtlengine/Operators/Conditional.py +495 -0
  43. vtlengine/Operators/General.py +191 -0
  44. vtlengine/Operators/HROperators.py +254 -0
  45. vtlengine/Operators/Join.py +447 -0
  46. vtlengine/Operators/Numeric.py +422 -0
  47. vtlengine/Operators/RoleSetter.py +77 -0
  48. vtlengine/Operators/Set.py +176 -0
  49. vtlengine/Operators/String.py +578 -0
  50. vtlengine/Operators/Time.py +1144 -0
  51. vtlengine/Operators/Validation.py +275 -0
  52. vtlengine/Operators/__init__.py +900 -0
  53. vtlengine/Utils/__Virtual_Assets.py +34 -0
  54. vtlengine/Utils/__init__.py +479 -0
  55. vtlengine/__extras_check.py +17 -0
  56. vtlengine/__init__.py +27 -0
  57. vtlengine/files/__init__.py +0 -0
  58. vtlengine/files/output/__init__.py +35 -0
  59. vtlengine/files/output/_time_period_representation.py +55 -0
  60. vtlengine/files/parser/__init__.py +240 -0
  61. vtlengine/files/parser/_rfc_dialect.py +22 -0
  62. vtlengine/py.typed +0 -0
  63. vtlengine-1.4.0rc2.dist-info/METADATA +89 -0
  64. vtlengine-1.4.0rc2.dist-info/RECORD +66 -0
  65. vtlengine-1.4.0rc2.dist-info/WHEEL +4 -0
  66. vtlengine-1.4.0rc2.dist-info/licenses/LICENSE.md +661 -0
@@ -0,0 +1,674 @@
1
+ """
2
+ AST.AST.py
3
+ ==========
4
+
5
+ Description
6
+ -----------
7
+ Basic AST nodes.
8
+ """
9
+
10
+ from dataclasses import dataclass
11
+ from typing import Any, Dict, List, Optional, Type, Union
12
+
13
+ from vtlengine.DataTypes import ScalarType
14
+ from vtlengine.Model import Dataset, Role
15
+
16
+
17
+ @dataclass
18
+ class AST:
19
+ """
20
+ AST: (children)
21
+ """
22
+
23
+ line_start: int
24
+ column_start: int
25
+ line_stop: int
26
+ column_stop: int
27
+
28
+ @classmethod
29
+ def __all_annotations(cls) -> Dict[str, Any]:
30
+ class_attributes = {}
31
+ for c in cls.__mro__:
32
+ if "__annotations__" in c.__dict__:
33
+ class_attributes.update(c.__annotations__)
34
+ return dict(reversed(list(class_attributes.items())))
35
+
36
+ def __str__(self) -> str:
37
+ """Returns a human-friendly description."""
38
+ out = []
39
+ name = self.__class__.__name__
40
+ for k in self.__all_annotations():
41
+ v = self.__getattribute__(k)
42
+ if v:
43
+ out.append(f"{k}={str(v)}")
44
+ return f"<{name}({', '.join(out)})>"
45
+
46
+ def toJSON(self):
47
+ base = {"class_name": self.__class__.__name__}
48
+ for k in self.__all_annotations():
49
+ v = self.__getattribute__(k)
50
+ base[k] = v
51
+ return base
52
+
53
+ __repr__ = __str__
54
+
55
+ def ast_equality(self, other):
56
+ if not isinstance(other, self.__class__):
57
+ return False
58
+ for k in self.__all_annotations():
59
+ if (
60
+ getattr(self, k) != getattr(other, k)
61
+ and k not in AST.__annotations__
62
+ and k != "children" # We do not want to compare the children order here
63
+ ):
64
+ return False
65
+ return True
66
+
67
+ __eq__ = ast_equality
68
+
69
+
70
+ @dataclass
71
+ class Comment(AST):
72
+ """
73
+ Comment: (value)
74
+ """
75
+
76
+ value: str
77
+ __eq__ = AST.ast_equality
78
+
79
+
80
+ @dataclass
81
+ class Start(AST):
82
+ """
83
+ Start: (children)
84
+ """
85
+
86
+ children: List[AST]
87
+
88
+ __eq__ = AST.ast_equality
89
+
90
+
91
+ @dataclass
92
+ class Assignment(AST):
93
+ """
94
+ Assignment: (left, op, right)
95
+ """
96
+
97
+ left: AST
98
+ op: str
99
+ right: AST
100
+
101
+ __eq__ = AST.ast_equality
102
+
103
+
104
+ @dataclass
105
+ class PersistentAssignment(Assignment):
106
+ """
107
+ PersistentAssignment: (left, op, right)
108
+ """
109
+
110
+ pass
111
+
112
+
113
+ @dataclass
114
+ class VarID(AST):
115
+ """
116
+ VarID: (value)
117
+ The Var node is constructed out of ID token.
118
+ Could be: DATASET or a COMPONENT.
119
+ """
120
+
121
+ value: str
122
+
123
+ __eq__ = AST.ast_equality
124
+
125
+
126
+ @dataclass
127
+ class UnaryOp(AST):
128
+ """
129
+ UnaryOp: (op, operand)
130
+ op types: "+", "-", CEIL, FLOOR, ABS, EXP, LN, SQRT, LEN, TRIM, LTRIM, RTRIM, UPCASE, LCASE,
131
+ ISNULL, FLOW_TO_STOCK, STOCK_TO_FLOW, SUM, AVG, COUNT, MEDIAN, MAX,
132
+ RANK, STDDEV_POP, STDDEV_SAMP , VAR_POP, VAR_SAMP
133
+ """
134
+
135
+ op: str
136
+ operand: AST
137
+
138
+ __eq__ = AST.ast_equality
139
+
140
+
141
+ @dataclass
142
+ class BinOp(AST):
143
+ """
144
+ BinOp: (left, op, right)
145
+ op types: "+", "-", "*", "/",MOD, MEMBERSHIP, PIVOT, UNPIVOT, LOG,
146
+ POWER, CHARSET_MATCH, NVL, MOD
147
+ """
148
+
149
+ left: AST
150
+ op: str
151
+ right: AST
152
+
153
+ __eq__ = AST.ast_equality
154
+
155
+
156
+ @dataclass
157
+ class MulOp(AST):
158
+ """
159
+ MulOp: (op, children)
160
+ op types: BETWEEN, GROUP BY, GROUP EXCEPT, GROUP ALL
161
+ """
162
+
163
+ op: str
164
+ children: List[AST]
165
+
166
+ __eq__ = AST.ast_equality
167
+
168
+
169
+ @dataclass
170
+ class ParamOp(AST):
171
+ """
172
+ ParamOp: (op, children, params)
173
+
174
+ op types: ROUND, TRUNC, SUBSTR, INSTR, REPLACE
175
+ """
176
+
177
+ op: str
178
+ children: List[AST]
179
+ params: List[AST]
180
+
181
+ __eq__ = AST.ast_equality
182
+
183
+
184
+ @dataclass
185
+ class UDOCall(AST):
186
+ op: str
187
+ params: List[AST]
188
+
189
+ __eq__ = AST.ast_equality
190
+
191
+
192
+ @dataclass
193
+ class JoinOp(AST):
194
+ """
195
+ JoinOp: (op, clauses, using)
196
+
197
+ op types: INNER_JOIN, LEFT_JOIN, FULL_JOIN, CROSS_JOIN.
198
+ clauses types:
199
+ body types:
200
+ """
201
+
202
+ op: str
203
+ clauses: List[AST]
204
+ using: Optional[List[str]]
205
+ isLast: bool = False
206
+
207
+ __eq__ = AST.ast_equality
208
+
209
+
210
+ @dataclass
211
+ class Constant(AST):
212
+ """
213
+ Constant: (type, value)
214
+
215
+ types: INTEGER_CONSTANT, FLOAT_CONSTANT, BOOLEAN_CONSTANT,
216
+ STRING_CONSTANT, NULL_CONSTANT
217
+ """
218
+
219
+ type_: str
220
+ value: Optional[Union[str, int, float, bool]]
221
+
222
+ __eq__ = AST.ast_equality
223
+
224
+
225
+ @dataclass
226
+ class ParamConstant(Constant):
227
+ """
228
+ Constant: (type, value)
229
+
230
+ types: ALL
231
+ """
232
+
233
+ type_: str
234
+ value: str
235
+
236
+ __eq__ = AST.ast_equality
237
+
238
+
239
+ @dataclass
240
+ class Identifier(AST):
241
+ """
242
+ Identifier: (value)
243
+ """
244
+
245
+ value: str
246
+ kind: str
247
+
248
+ __eq__ = AST.ast_equality
249
+
250
+
251
+ @dataclass
252
+ class ID(AST):
253
+ """
254
+ ID: (type, value)
255
+
256
+ for a general purpose Terminal nodes Node
257
+ """
258
+
259
+ type_: str
260
+ value: str
261
+
262
+ __eq__ = AST.ast_equality
263
+
264
+
265
+ @dataclass
266
+ class Collection(AST):
267
+ """
268
+ Collection: (name, type, children)
269
+
270
+ types: Sets and ValueDomains
271
+ """
272
+
273
+ name: str
274
+ type: str
275
+ children: List[AST]
276
+ kind: str = "Set"
277
+
278
+ __eq__ = AST.ast_equality
279
+
280
+
281
+ @dataclass
282
+ class Windowing(AST):
283
+ """
284
+ Windowing: (type, first, second, first_mode, second_mode)
285
+
286
+ type: RANGE, ROWS, GROUPS
287
+ first: int
288
+ second: int
289
+ first_mode: int
290
+ second_mode: int
291
+ """
292
+
293
+ type_: str
294
+ start: Union[int, str]
295
+ start_mode: str
296
+ stop: Union[int, str]
297
+ stop_mode: str
298
+
299
+ __eq__ = AST.ast_equality
300
+
301
+
302
+ @dataclass
303
+ class OrderBy(AST):
304
+ component: str
305
+ order: str
306
+
307
+ def __post_init__(self):
308
+ if self.order not in ["asc", "desc"]:
309
+ raise ValueError(f"Invalid order: {self.order}")
310
+
311
+ __eq__ = AST.ast_equality
312
+
313
+
314
+ @dataclass
315
+ class Analytic(AST):
316
+ """
317
+ Analytic: (op, operand, partition_by, order_by, params)
318
+
319
+ op: SUM, AVG, COUNT, MEDIAN, MIN, MAX, STDDEV_POP, STDDEV_SAMP, VAR_POP, VAR_SAMP,
320
+ FIRST_VALUE, LAST_VALUE, LAG, LEAD, RATIO_TO_REPORT
321
+
322
+ partition_by: List of components.
323
+ order_by: List of components + mode (ASC, DESC).
324
+ params: Windowing clause (no need to validate them) or Scalar Item in LAG/LEAD.
325
+ """
326
+
327
+ op: str
328
+ operand: Optional[AST]
329
+ window: Optional[Windowing] = None
330
+ params: Optional[List[int]] = None
331
+ partition_by: Optional[List[str]] = None
332
+ order_by: Optional[List[OrderBy]] = None
333
+
334
+ def __post_init__(self):
335
+ if self.partition_by is None and self.order_by is None:
336
+ raise ValueError("Partition by or order by must be provided on Analytic.")
337
+
338
+ __eq__ = AST.ast_equality
339
+
340
+
341
+ @dataclass
342
+ class RegularAggregation(AST):
343
+ """
344
+ RegularAggregation: (dataset, op, children)
345
+
346
+ op types: FILTER, CALC, KEEP, DROP, RENAME, SUBSPACE
347
+ """
348
+
349
+ op: str
350
+ children: List[AST]
351
+ dataset: Optional[AST] = None
352
+ isLast: bool = False
353
+
354
+ __eq__ = AST.ast_equality
355
+
356
+
357
+ @dataclass
358
+ class RenameNode(AST):
359
+ """
360
+ RenameNode: (old_name, new_name)
361
+ """
362
+
363
+ old_name: str
364
+ new_name: str
365
+
366
+ __eq__ = AST.ast_equality
367
+
368
+
369
+ @dataclass
370
+ class Aggregation(AST):
371
+ """
372
+ Aggregation: (op, operand, grouping_op, grouping)
373
+
374
+ op types: AGGREGATE, SUM, AVG , COUNT, MEDIAN, MIN, MAX, STDDEV_POP, STDDEV_SAMP,
375
+ VAR_POP, VAR_SAMP
376
+
377
+ grouping types: 'group by', 'group except', 'group all'.
378
+ """
379
+
380
+ op: str
381
+ operand: Optional[AST] = None
382
+ grouping_op: Optional[str] = None
383
+ grouping: Optional[List[AST]] = None
384
+ having_clause: Optional[AST] = None
385
+
386
+ __eq__ = AST.ast_equality
387
+
388
+
389
+ @dataclass
390
+ class TimeAggregation(AST):
391
+ """
392
+ TimeAggregation: (op, operand, params, conf)
393
+
394
+ op types: TIME_AGG
395
+ """
396
+
397
+ op: str
398
+ period_to: str
399
+ period_from: Optional[str] = None
400
+ operand: Optional[AST] = None
401
+ conf: Optional[str] = None
402
+
403
+ __eq__ = AST.ast_equality
404
+
405
+
406
+ @dataclass
407
+ class If(AST):
408
+ """
409
+ If: (condition, thenOp, elseOp)
410
+ """
411
+
412
+ condition: AST
413
+ thenOp: AST
414
+ elseOp: AST
415
+
416
+ __eq__ = AST.ast_equality
417
+
418
+
419
+ @dataclass
420
+ class CaseObj(AST):
421
+ condition: AST
422
+ thenOp: AST
423
+
424
+
425
+ @dataclass
426
+ class Case(AST):
427
+ """
428
+ Case: (condition, thenOp, elseOp)
429
+ """
430
+
431
+ cases: List[CaseObj]
432
+ elseOp: AST
433
+
434
+ __eq__ = AST.ast_equality
435
+
436
+
437
+ @dataclass
438
+ class Validation(AST):
439
+ """
440
+ Validation: (op, validation, error_code, error_level, imbalance, invalid)
441
+ """
442
+
443
+ op: str
444
+ validation: str
445
+ error_code: Optional[str]
446
+ error_level: Optional[Union[int, str]]
447
+ imbalance: Optional[AST]
448
+ invalid: bool
449
+
450
+ __eq__ = AST.ast_equality
451
+
452
+
453
+ @dataclass
454
+ class ComponentType(AST):
455
+ """
456
+ ComponentType: (data_type, role)
457
+ """
458
+
459
+ name: str
460
+ data_type: Optional[Type[ScalarType]] = None
461
+ role: Optional[Role] = None
462
+
463
+ __eq__ = AST.ast_equality
464
+
465
+
466
+ @dataclass
467
+ class ASTScalarType(AST):
468
+ data_type: Type[ScalarType]
469
+
470
+
471
+ @dataclass
472
+ class DatasetType(AST):
473
+ """
474
+ DatasetType: (name, components)
475
+ """
476
+
477
+ components: List[ComponentType]
478
+
479
+ __eq__ = AST.ast_equality
480
+
481
+
482
+ @dataclass
483
+ class Types(AST):
484
+ """
485
+ Types: (name, kind, type_, constraints, nullable)
486
+
487
+ kind:
488
+ - basicScalarType
489
+ - STRING, INTEGER, NUMBER, BOOLEAN, DATE, TIME_PERIOD, DURATION, SCALAR, TIME.
490
+ -
491
+ """
492
+
493
+ kind: str
494
+ type_: str
495
+ constraints: List[AST]
496
+ nullable: Optional[bool]
497
+ name: Optional[str] = None
498
+
499
+ __eq__ = AST.ast_equality
500
+
501
+
502
+ @dataclass
503
+ class Argument(AST):
504
+ """
505
+ Argument: (name, type_, default)
506
+ """
507
+
508
+ name: str
509
+ type_: Type[ScalarType]
510
+ default: Optional[AST]
511
+
512
+ __eq__ = AST.ast_equality
513
+
514
+
515
+ @dataclass
516
+ class Operator(AST):
517
+ """
518
+ Operator: (operator, parameters, outputType, expression)
519
+ """
520
+
521
+ op: str
522
+ parameters: List[Argument]
523
+ output_type: str
524
+ expression: AST
525
+
526
+ __eq__ = AST.ast_equality
527
+
528
+
529
+ # TODO: Is this class necessary?
530
+ @dataclass
531
+ class DefIdentifier(AST):
532
+ """
533
+ DefIdentifier: (value, kind)
534
+ """
535
+
536
+ value: str
537
+ kind: str
538
+
539
+ __eq__ = AST.ast_equality
540
+
541
+
542
+ @dataclass
543
+ class DPRIdentifier(AST):
544
+ """
545
+ DefIdentifier: (value, kind, alias)
546
+ """
547
+
548
+ value: str
549
+ kind: str
550
+ alias: Optional[str] = None
551
+
552
+ __eq__ = AST.ast_equality
553
+
554
+
555
+ # TODO: Are HRBinOp and HRUnOp necessary?
556
+ @dataclass
557
+ class HRBinOp(AST):
558
+ """
559
+ HRBinOp: (left, op, right)
560
+ op types: '+','-', '=', '>', '<', '>=', '<='.
561
+ """
562
+
563
+ left: DefIdentifier
564
+ op: str
565
+ right: DefIdentifier
566
+
567
+ __eq__ = AST.ast_equality
568
+
569
+
570
+ @dataclass
571
+ class HRUnOp(AST):
572
+ """
573
+ HRUnOp: (op, operand)
574
+ op types: '+','-'.
575
+ """
576
+
577
+ op: str
578
+ operand: DefIdentifier
579
+
580
+ __eq__ = AST.ast_equality
581
+
582
+
583
+ # TODO: Unify HRule and DPRule?
584
+ @dataclass
585
+ class HRule(AST):
586
+ """
587
+ HRule: (name, rule, erCode, erLevel)
588
+ """
589
+
590
+ name: Optional[str]
591
+ rule: HRBinOp
592
+ erCode: Optional[str]
593
+ erLevel: Optional[Union[int, str]]
594
+
595
+ __eq__ = AST.ast_equality
596
+
597
+
598
+ @dataclass
599
+ class DPRule(AST):
600
+ """
601
+ DPRule: (name, rule, erCode, erLevel)
602
+ """
603
+
604
+ name: Optional[str]
605
+ rule: HRBinOp
606
+ erCode: Optional[str]
607
+ erLevel: Optional[Union[int, str]]
608
+
609
+ __eq__ = AST.ast_equality
610
+
611
+
612
+ # TODO: Unify HRuleset and DPRuleset?
613
+ @dataclass
614
+ class HRuleset(AST):
615
+ """
616
+ HRuleset: (name, element, rules)
617
+ """
618
+
619
+ name: str
620
+ signature_type: str
621
+ element: Union[DefIdentifier, List[DefIdentifier]]
622
+ rules: List[HRule]
623
+
624
+ __eq__ = AST.ast_equality
625
+
626
+
627
+ @dataclass
628
+ class DPRuleset(AST):
629
+ """
630
+ DPRuleset: (name, element, rules)
631
+ """
632
+
633
+ name: str
634
+ signature_type: str
635
+ params: Union[DefIdentifier, list]
636
+ rules: List[DPRule]
637
+
638
+ __eq__ = AST.ast_equality
639
+
640
+
641
+ @dataclass
642
+ class EvalOp(AST):
643
+ """
644
+ EvalOp: (name, children, output, language)
645
+
646
+ op types:
647
+ """
648
+
649
+ name: str
650
+ operands: List[AST]
651
+ output: Optional[Dataset]
652
+ language: Optional[str]
653
+
654
+ __eq__ = AST.ast_equality
655
+
656
+
657
+ @dataclass
658
+ class NoOp(AST):
659
+ """
660
+ NoOp: ()
661
+ """
662
+
663
+ pass
664
+
665
+
666
+ @dataclass
667
+ class ParFunction(AST):
668
+ """
669
+ ParFunction: (operand)
670
+ """
671
+
672
+ operand: AST
673
+
674
+ __eq__ = AST.ast_equality