vtlengine 1.0.2__py3-none-any.whl → 1.0.3__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.
- vtlengine/API/_InternalApi.py +12 -5
- vtlengine/API/__init__.py +8 -8
- vtlengine/AST/ASTConstructor.py +23 -43
- vtlengine/AST/ASTConstructorModules/Expr.py +69 -84
- vtlengine/AST/ASTConstructorModules/ExprComponents.py +47 -57
- vtlengine/AST/ASTConstructorModules/Terminals.py +28 -39
- vtlengine/AST/ASTTemplate.py +0 -1
- vtlengine/AST/DAG/__init__.py +12 -15
- vtlengine/AST/Grammar/tokens.py +2 -2
- vtlengine/AST/VtlVisitor.py +0 -1
- vtlengine/AST/__init__.py +2 -3
- vtlengine/DataTypes/TimeHandling.py +10 -7
- vtlengine/DataTypes/__init__.py +17 -24
- vtlengine/Exceptions/__init__.py +3 -5
- vtlengine/Exceptions/messages.py +68 -56
- vtlengine/Interpreter/__init__.py +82 -103
- vtlengine/Model/__init__.py +10 -12
- vtlengine/Operators/Aggregation.py +14 -14
- vtlengine/Operators/Analytic.py +3 -10
- vtlengine/Operators/Assignment.py +2 -3
- vtlengine/Operators/Boolean.py +5 -7
- vtlengine/Operators/CastOperator.py +12 -13
- vtlengine/Operators/Clause.py +11 -13
- vtlengine/Operators/Comparison.py +31 -17
- vtlengine/Operators/Conditional.py +48 -49
- vtlengine/Operators/General.py +4 -4
- vtlengine/Operators/HROperators.py +41 -34
- vtlengine/Operators/Join.py +18 -22
- vtlengine/Operators/Numeric.py +44 -45
- vtlengine/Operators/RoleSetter.py +6 -8
- vtlengine/Operators/Set.py +7 -12
- vtlengine/Operators/String.py +19 -27
- vtlengine/Operators/Time.py +298 -109
- vtlengine/Operators/Validation.py +4 -7
- vtlengine/Operators/__init__.py +38 -41
- vtlengine/Utils/__init__.py +133 -114
- vtlengine/__init__.py +1 -1
- vtlengine/files/output/__init__.py +2 -2
- vtlengine/files/output/_time_period_representation.py +0 -1
- vtlengine/files/parser/__init__.py +16 -18
- vtlengine/files/parser/_time_checking.py +1 -2
- {vtlengine-1.0.2.dist-info → vtlengine-1.0.3.dist-info}/METADATA +5 -2
- vtlengine-1.0.3.dist-info/RECORD +58 -0
- vtlengine-1.0.2.dist-info/RECORD +0 -58
- {vtlengine-1.0.2.dist-info → vtlengine-1.0.3.dist-info}/LICENSE.md +0 -0
- {vtlengine-1.0.2.dist-info → vtlengine-1.0.3.dist-info}/WHEEL +0 -0
vtlengine/API/_InternalApi.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import os
|
|
3
3
|
from pathlib import Path
|
|
4
|
-
from typing import
|
|
4
|
+
from typing import Any, Dict, List, Optional, Union
|
|
5
5
|
|
|
6
6
|
import pandas as pd
|
|
7
7
|
from s3fs import S3FileSystem # type: ignore[import-untyped]
|
|
@@ -9,9 +9,16 @@ from s3fs import S3FileSystem # type: ignore[import-untyped]
|
|
|
9
9
|
from vtlengine.AST import PersistentAssignment, Start
|
|
10
10
|
from vtlengine.DataTypes import SCALAR_TYPES
|
|
11
11
|
from vtlengine.Exceptions import check_key
|
|
12
|
-
from vtlengine.
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
from vtlengine.files.parser import _fill_dataset_empty_data, _validate_pandas
|
|
13
|
+
from vtlengine.Model import (
|
|
14
|
+
Component,
|
|
15
|
+
Dataset,
|
|
16
|
+
ExternalRoutine,
|
|
17
|
+
Role,
|
|
18
|
+
Role_keys,
|
|
19
|
+
Scalar,
|
|
20
|
+
ValueDomain,
|
|
21
|
+
)
|
|
15
22
|
|
|
16
23
|
base_path = Path(__file__).parent
|
|
17
24
|
filepath_VTL = base_path / "data" / "vtl"
|
|
@@ -212,7 +219,7 @@ def load_datasets_with_data(data_structures: Any, datapoints: Optional[Any] = No
|
|
|
212
219
|
return datasets, None
|
|
213
220
|
# Handling dictionary of paths
|
|
214
221
|
dict_datapoints = _load_datapoints_path(datapoints)
|
|
215
|
-
for dataset_name,
|
|
222
|
+
for dataset_name, _ in dict_datapoints.items():
|
|
216
223
|
if dataset_name not in datasets:
|
|
217
224
|
raise Exception(f"Not found dataset {dataset_name}")
|
|
218
225
|
|
vtlengine/API/__init__.py
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
|
-
from typing import Any,
|
|
2
|
+
from typing import Any, Dict, List, Optional, Union
|
|
3
3
|
|
|
4
4
|
import pandas as pd
|
|
5
5
|
from antlr4 import CommonTokenStream, InputStream # type: ignore[import-untyped]
|
|
6
6
|
from antlr4.error.ErrorListener import ErrorListener # type: ignore[import-untyped]
|
|
7
7
|
|
|
8
8
|
from vtlengine.API._InternalApi import (
|
|
9
|
-
|
|
9
|
+
_check_output_folder,
|
|
10
|
+
_return_only_persistent_datasets,
|
|
10
11
|
load_datasets,
|
|
11
|
-
load_value_domains,
|
|
12
|
-
load_external_routines,
|
|
13
12
|
load_datasets_with_data,
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
load_external_routines,
|
|
14
|
+
load_value_domains,
|
|
15
|
+
load_vtl,
|
|
16
16
|
)
|
|
17
17
|
from vtlengine.AST import Start
|
|
18
18
|
from vtlengine.AST.ASTConstructor import ASTVisitor
|
|
19
19
|
from vtlengine.AST.DAG import DAGAnalyzer
|
|
20
20
|
from vtlengine.AST.Grammar.lexer import Lexer
|
|
21
21
|
from vtlengine.AST.Grammar.parser import Parser
|
|
22
|
-
from vtlengine.Interpreter import InterpreterAnalyzer
|
|
23
22
|
from vtlengine.files.output._time_period_representation import (
|
|
24
|
-
format_time_period_external_representation,
|
|
25
23
|
TimePeriodRepresentation,
|
|
24
|
+
format_time_period_external_representation,
|
|
26
25
|
)
|
|
26
|
+
from vtlengine.Interpreter import InterpreterAnalyzer
|
|
27
27
|
|
|
28
28
|
pd.options.mode.chained_assignment = None
|
|
29
29
|
|
vtlengine/AST/ASTConstructor.py
CHANGED
|
@@ -10,18 +10,18 @@ Node Creator.
|
|
|
10
10
|
from antlr4.tree.Tree import TerminalNodeImpl
|
|
11
11
|
|
|
12
12
|
from vtlengine.AST import (
|
|
13
|
-
Start,
|
|
14
|
-
Assignment,
|
|
15
|
-
PersistentAssignment,
|
|
16
|
-
Operator,
|
|
17
13
|
Argument,
|
|
14
|
+
Assignment,
|
|
15
|
+
DefIdentifier,
|
|
16
|
+
DPRule,
|
|
18
17
|
DPRuleset,
|
|
19
18
|
HRBinOp,
|
|
20
|
-
DPRule,
|
|
21
|
-
HRuleset,
|
|
22
|
-
DefIdentifier,
|
|
23
19
|
HRule,
|
|
20
|
+
HRuleset,
|
|
24
21
|
HRUnOp,
|
|
22
|
+
Operator,
|
|
23
|
+
PersistentAssignment,
|
|
24
|
+
Start,
|
|
25
25
|
)
|
|
26
26
|
from vtlengine.AST.ASTConstructorModules.Expr import Expr
|
|
27
27
|
from vtlengine.AST.ASTConstructorModules.ExprComponents import ExprComp
|
|
@@ -30,8 +30,7 @@ from vtlengine.AST.ASTDataExchange import de_ruleset_elements
|
|
|
30
30
|
from vtlengine.AST.Grammar.parser import Parser
|
|
31
31
|
from vtlengine.AST.VtlVisitor import VtlVisitor
|
|
32
32
|
from vtlengine.Exceptions import SemanticError
|
|
33
|
-
from vtlengine.Model import
|
|
34
|
-
|
|
33
|
+
from vtlengine.Model import Component, Dataset, Scalar
|
|
35
34
|
|
|
36
35
|
# pylint: disable=unreachable,expression-not-assigned
|
|
37
36
|
# pylint: disable=assignment-from-no-return
|
|
@@ -280,19 +279,13 @@ class ASTVisitor(VtlVisitor):
|
|
|
280
279
|
for erCode_name in ctx_list
|
|
281
280
|
if isinstance(erCode_name, Parser.ErCodeContext)
|
|
282
281
|
]
|
|
283
|
-
if len(er_code) == 0
|
|
284
|
-
er_code = None
|
|
285
|
-
else:
|
|
286
|
-
er_code = er_code[0]
|
|
282
|
+
er_code = None if len(er_code) == 0 else er_code[0]
|
|
287
283
|
er_level = [
|
|
288
284
|
Terminals().visitErLevel(erLevel_name)
|
|
289
285
|
for erLevel_name in ctx_list
|
|
290
286
|
if isinstance(erLevel_name, Parser.ErLevelContext)
|
|
291
287
|
]
|
|
292
|
-
if len(er_level) == 0
|
|
293
|
-
er_level = None
|
|
294
|
-
else:
|
|
295
|
-
er_level = er_level[0]
|
|
288
|
+
er_level = None if len(er_level) == 0 else er_level[0]
|
|
296
289
|
|
|
297
290
|
return DPRule(name=rule_name, rule=rule_node, erCode=er_code, erLevel=er_level)
|
|
298
291
|
|
|
@@ -317,11 +310,7 @@ class ASTVisitor(VtlVisitor):
|
|
|
317
310
|
for element in ctx_list
|
|
318
311
|
if isinstance(element, Parser.ScalarItemContext)
|
|
319
312
|
]
|
|
320
|
-
|
|
321
|
-
if len(argument_default) == 0:
|
|
322
|
-
argument_default = None
|
|
323
|
-
else:
|
|
324
|
-
argument_default = argument_default[0]
|
|
313
|
+
argument_default = None if len(argument_default) == 0 else argument_default[0]
|
|
325
314
|
|
|
326
315
|
if isinstance(argument_type, (Dataset, Component, Scalar)):
|
|
327
316
|
argument_type.name = argument_name.value
|
|
@@ -375,10 +364,7 @@ class ASTVisitor(VtlVisitor):
|
|
|
375
364
|
if isinstance(valueDomain, TerminalNodeImpl)
|
|
376
365
|
and valueDomain.getSymbol().type == Parser.VALUE_DOMAIN
|
|
377
366
|
]
|
|
378
|
-
if len(value_domain) != 0
|
|
379
|
-
kind = "ValuedomainID"
|
|
380
|
-
else:
|
|
381
|
-
kind = "DatasetID"
|
|
367
|
+
kind = "ValuedomainID" if len(value_domain) != 0 else "DatasetID"
|
|
382
368
|
|
|
383
369
|
conditions = [
|
|
384
370
|
self.visitValueDomainSignature(vtlsig)
|
|
@@ -408,8 +394,8 @@ class ASTVisitor(VtlVisitor):
|
|
|
408
394
|
# TODO Support for valueDomainSignature.
|
|
409
395
|
def visitValueDomainSignature(self, ctx: Parser.ValueDomainSignatureContext):
|
|
410
396
|
"""
|
|
411
|
-
valueDomainSignature: CONDITION IDENTIFIER (AS IDENTIFIER)? (',' IDENTIFIER (AS IDENTIFIER)?)* ;
|
|
412
|
-
"""
|
|
397
|
+
valueDomainSignature: CONDITION IDENTIFIER (AS IDENTIFIER)? (',' IDENTIFIER (AS IDENTIFIER)?)* ;
|
|
398
|
+
""" # noqa E501
|
|
413
399
|
# AST_ASTCONSTRUCTOR.7
|
|
414
400
|
ctx_list = list(ctx.getChildren())
|
|
415
401
|
component_nodes = [
|
|
@@ -458,28 +444,22 @@ class ASTVisitor(VtlVisitor):
|
|
|
458
444
|
for erCode_name in ctx_list
|
|
459
445
|
if isinstance(erCode_name, Parser.ErCodeContext)
|
|
460
446
|
]
|
|
461
|
-
if len(er_code) == 0
|
|
462
|
-
er_code = None
|
|
463
|
-
else:
|
|
464
|
-
er_code = er_code[0]
|
|
447
|
+
er_code = None if len(er_code) == 0 else er_code[0]
|
|
465
448
|
er_level = [
|
|
466
449
|
Terminals().visitErLevel(erLevel_name)
|
|
467
450
|
for erLevel_name in ctx_list
|
|
468
451
|
if isinstance(erLevel_name, Parser.ErLevelContext)
|
|
469
452
|
]
|
|
470
|
-
if len(er_level) == 0
|
|
471
|
-
er_level = None
|
|
472
|
-
else:
|
|
473
|
-
er_level = er_level[0]
|
|
453
|
+
er_level = None if len(er_level) == 0 else er_level[0]
|
|
474
454
|
|
|
475
455
|
return HRule(name=rule_name, rule=rule_node, erCode=er_code, erLevel=er_level)
|
|
476
456
|
|
|
477
457
|
def visitCodeItemRelation(self, ctx: Parser.CodeItemRelationContext):
|
|
478
458
|
"""
|
|
479
|
-
codeItemRelation: ( WHEN expr THEN )? codeItemRef codeItemRelationClause (codeItemRelationClause)* ;
|
|
480
|
-
( WHEN exprComponent THEN )? codetemRef=valueDomainValue comparisonOperand? codeItemRelationClause (codeItemRelationClause)*
|
|
459
|
+
codeItemRelation: ( WHEN expr THEN )? codeItemRef codeItemRelationClause (codeItemRelationClause)* ;
|
|
460
|
+
( WHEN exprComponent THEN )? codetemRef=valueDomainValue comparisonOperand? codeItemRelationClause (codeItemRelationClause)*
|
|
481
461
|
|
|
482
|
-
"""
|
|
462
|
+
""" # noqa E501
|
|
483
463
|
|
|
484
464
|
ctx_list = list(ctx.getChildren())
|
|
485
465
|
|
|
@@ -531,8 +511,8 @@ class ASTVisitor(VtlVisitor):
|
|
|
531
511
|
|
|
532
512
|
def visitCodeItemRelationClause(self, ctx: Parser.CodeItemRelationClauseContext):
|
|
533
513
|
"""
|
|
534
|
-
(opAdd=( PLUS | MINUS ))? rightCodeItem=valueDomainValue ( QLPAREN rightCondition=exprComponent QRPAREN )?
|
|
535
|
-
"""
|
|
514
|
+
(opAdd=( PLUS | MINUS ))? rightCodeItem=valueDomainValue ( QLPAREN rightCondition=exprComponent QRPAREN )?
|
|
515
|
+
""" # noqa E501
|
|
536
516
|
ctx_list = list(ctx.getChildren())
|
|
537
517
|
|
|
538
518
|
expr = [expr for expr in ctx_list if isinstance(expr, Parser.ExprContext)]
|
|
@@ -552,13 +532,13 @@ class ASTVisitor(VtlVisitor):
|
|
|
552
532
|
|
|
553
533
|
code_item = DefIdentifier(value=value, kind="CodeItemID")
|
|
554
534
|
if right_condition:
|
|
555
|
-
|
|
535
|
+
code_item._right_condition = right_condition[0]
|
|
556
536
|
|
|
557
537
|
return HRBinOp(left=None, op=op, right=code_item)
|
|
558
538
|
else:
|
|
559
539
|
value = Terminals().visitValueDomainValue(ctx_list[0])
|
|
560
540
|
code_item = DefIdentifier(value=value, kind="CodeItemID")
|
|
561
541
|
if right_condition:
|
|
562
|
-
|
|
542
|
+
code_item._right_condition = right_condition[0]
|
|
563
543
|
|
|
564
544
|
return code_item
|
|
@@ -5,29 +5,29 @@ from typing import Any
|
|
|
5
5
|
from antlr4.tree.Tree import TerminalNodeImpl
|
|
6
6
|
|
|
7
7
|
from vtlengine.AST import (
|
|
8
|
-
|
|
8
|
+
ID,
|
|
9
|
+
Aggregation,
|
|
10
|
+
Analytic,
|
|
11
|
+
Assignment,
|
|
9
12
|
BinOp,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
JoinOp,
|
|
14
|
-
Identifier,
|
|
15
|
-
ParamOp,
|
|
13
|
+
Case,
|
|
14
|
+
CaseObj,
|
|
15
|
+
Constant,
|
|
16
16
|
EvalOp,
|
|
17
|
-
|
|
17
|
+
Identifier,
|
|
18
|
+
If,
|
|
19
|
+
JoinOp,
|
|
18
20
|
MulOp,
|
|
21
|
+
ParamConstant,
|
|
22
|
+
ParamOp,
|
|
19
23
|
RegularAggregation,
|
|
20
|
-
|
|
21
|
-
Aggregation,
|
|
22
|
-
ID,
|
|
24
|
+
RenameNode,
|
|
23
25
|
TimeAggregation,
|
|
24
|
-
|
|
26
|
+
UDOCall,
|
|
27
|
+
UnaryOp,
|
|
25
28
|
Validation,
|
|
26
|
-
Analytic,
|
|
27
|
-
Windowing,
|
|
28
29
|
VarID,
|
|
29
|
-
|
|
30
|
-
CaseObj,
|
|
30
|
+
Windowing,
|
|
31
31
|
)
|
|
32
32
|
from vtlengine.AST.ASTConstructorModules.ExprComponents import ExprComp
|
|
33
33
|
from vtlengine.AST.ASTConstructorModules.Terminals import Terminals
|
|
@@ -50,23 +50,23 @@ class Expr(VtlVisitor):
|
|
|
50
50
|
def visitExpr(self, ctx: Parser.ExprContext):
|
|
51
51
|
"""
|
|
52
52
|
expr:
|
|
53
|
-
LPAREN expr RPAREN # parenthesisExpr
|
|
54
|
-
| functions # functionsExpression
|
|
55
|
-
| dataset=expr QLPAREN clause=datasetClause QRPAREN # clauseExpr
|
|
56
|
-
| expr MEMBERSHIP simpleComponentId # membershipExpr
|
|
57
|
-
| op=(PLUS|MINUS|NOT) right=expr # unaryExpr
|
|
58
|
-
| left=expr op=(MUL|DIV) right=expr # arithmeticExpr
|
|
59
|
-
| left=expr op=(PLUS|MINUS|CONCAT) right=expr # arithmeticExprOrConcat
|
|
60
|
-
| left=expr op=comparisonOperand right=expr # comparisonExpr
|
|
61
|
-
| left=expr op=(IN|NOT_IN)(lists|valueDomainID) # inNotInExpr
|
|
62
|
-
| left=expr op=AND right=expr # booleanExpr
|
|
63
|
-
| left=expr op=(OR|XOR) right=expr # booleanExpr
|
|
64
|
-
| IF conditionalExpr=expr THEN thenExpr=expr ELSE elseExpr=expr # ifExpr
|
|
65
|
-
| CASE WHEN expr THEN expr ELSE expr END # caseExpr
|
|
66
|
-
| constant # constantExpr
|
|
67
|
-
| varID # varIdExpr
|
|
53
|
+
LPAREN expr RPAREN # parenthesisExpr
|
|
54
|
+
| functions # functionsExpression
|
|
55
|
+
| dataset=expr QLPAREN clause=datasetClause QRPAREN # clauseExpr
|
|
56
|
+
| expr MEMBERSHIP simpleComponentId # membershipExpr
|
|
57
|
+
| op=(PLUS|MINUS|NOT) right=expr # unaryExpr
|
|
58
|
+
| left=expr op=(MUL|DIV) right=expr # arithmeticExpr
|
|
59
|
+
| left=expr op=(PLUS|MINUS|CONCAT) right=expr # arithmeticExprOrConcat
|
|
60
|
+
| left=expr op=comparisonOperand right=expr # comparisonExpr
|
|
61
|
+
| left=expr op=(IN|NOT_IN)(lists|valueDomainID) # inNotInExpr
|
|
62
|
+
| left=expr op=AND right=expr # booleanExpr
|
|
63
|
+
| left=expr op=(OR|XOR) right=expr # booleanExpr
|
|
64
|
+
| IF conditionalExpr=expr THEN thenExpr=expr ELSE elseExpr=expr # ifExpr
|
|
65
|
+
| CASE WHEN expr THEN expr ELSE expr END # caseExpr
|
|
66
|
+
| constant # constantExpr
|
|
67
|
+
| varID # varIdExpr
|
|
68
68
|
;
|
|
69
|
-
"""
|
|
69
|
+
""" # noqa E501
|
|
70
70
|
ctx_list = list(ctx.getChildren())
|
|
71
71
|
c = ctx_list[0]
|
|
72
72
|
|
|
@@ -372,8 +372,8 @@ class Expr(VtlVisitor):
|
|
|
372
372
|
|
|
373
373
|
def visitJoinClauseWithoutUsing(self, ctx: Parser.JoinClauseWithoutUsingContext):
|
|
374
374
|
"""
|
|
375
|
-
joinClause: joinClauseItem (COMMA joinClauseItem)* (USING componentID (COMMA componentID)*)? ;
|
|
376
|
-
"""
|
|
375
|
+
joinClause: joinClauseItem (COMMA joinClauseItem)* (USING componentID (COMMA componentID)*)? ;
|
|
376
|
+
""" # noqa E501
|
|
377
377
|
ctx_list = list(ctx.getChildren())
|
|
378
378
|
|
|
379
379
|
clause_nodes = []
|
|
@@ -387,8 +387,8 @@ class Expr(VtlVisitor):
|
|
|
387
387
|
|
|
388
388
|
def visitJoinBody(self, ctx: Parser.JoinBodyContext):
|
|
389
389
|
"""
|
|
390
|
-
joinBody: filterClause? (calcClause|joinApplyClause|aggrClause)? (keepOrDropClause)? renameClause?
|
|
391
|
-
"""
|
|
390
|
+
joinBody: filterClause? (calcClause|joinApplyClause|aggrClause)? (keepOrDropClause)? renameClause?
|
|
391
|
+
""" # noqa E501
|
|
392
392
|
ctx_list = list(ctx.getChildren())
|
|
393
393
|
|
|
394
394
|
body_nodes = []
|
|
@@ -456,8 +456,8 @@ class Expr(VtlVisitor):
|
|
|
456
456
|
|
|
457
457
|
def visitEvalAtom(self, ctx: Parser.EvalAtomContext):
|
|
458
458
|
"""
|
|
459
|
-
| EVAL LPAREN routineName LPAREN (varID|scalarItem)? (COMMA (varID|scalarItem))* RPAREN (LANGUAGE STRING_CONSTANT)? (RETURNS evalDatasetType)? RPAREN
|
|
460
|
-
"""
|
|
459
|
+
| EVAL LPAREN routineName LPAREN (varID|scalarItem)? (COMMA (varID|scalarItem))* RPAREN (LANGUAGE STRING_CONSTANT)? (RETURNS evalDatasetType)? RPAREN # evalAtom
|
|
460
|
+
""" # noqa E501
|
|
461
461
|
ctx_list = list(ctx.getChildren())
|
|
462
462
|
|
|
463
463
|
routine_name = Terminals().visitRoutineName(ctx_list[2])
|
|
@@ -504,8 +504,8 @@ class Expr(VtlVisitor):
|
|
|
504
504
|
|
|
505
505
|
def visitCastExprDataset(self, ctx: Parser.CastExprDatasetContext):
|
|
506
506
|
"""
|
|
507
|
-
| CAST LPAREN expr COMMA (basicScalarType|valueDomainName) (COMMA STRING_CONSTANT)? RPAREN
|
|
508
|
-
"""
|
|
507
|
+
| CAST LPAREN expr COMMA (basicScalarType|valueDomainName) (COMMA STRING_CONSTANT)? RPAREN # castExprDataset
|
|
508
|
+
""" # noqa E501
|
|
509
509
|
ctx_list = list(ctx.getChildren())
|
|
510
510
|
c = ctx_list[0]
|
|
511
511
|
|
|
@@ -795,21 +795,15 @@ class Expr(VtlVisitor):
|
|
|
795
795
|
return self.visitTimeDiffAtom(ctx)
|
|
796
796
|
elif isinstance(ctx, Parser.DateAddAtomContext):
|
|
797
797
|
return self.visitTimeAddAtom(ctx)
|
|
798
|
-
elif isinstance(ctx, Parser.YearAtomContext
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
return self.visitTimeUnaryAtom(ctx)
|
|
808
|
-
elif isinstance(ctx, Parser.DayToMonthAtomContext):
|
|
809
|
-
return self.visitTimeUnaryAtom(ctx)
|
|
810
|
-
elif isinstance(ctx, Parser.YearTodayAtomContext):
|
|
811
|
-
return self.visitTimeUnaryAtom(ctx)
|
|
812
|
-
elif isinstance(ctx, Parser.MonthTodayAtomContext):
|
|
798
|
+
elif isinstance(ctx, (Parser.YearAtomContext,
|
|
799
|
+
Parser.MonthAtomContext,
|
|
800
|
+
Parser.DayOfMonthAtomContext,
|
|
801
|
+
Parser.DayOfYearAtomContext,
|
|
802
|
+
Parser.DayToYearAtomContext,
|
|
803
|
+
Parser.DayToMonthAtomContext,
|
|
804
|
+
Parser.YearTodayAtomContext,
|
|
805
|
+
Parser.MonthTodayAtomContext)):
|
|
806
|
+
|
|
813
807
|
return self.visitTimeUnaryAtom(ctx)
|
|
814
808
|
else:
|
|
815
809
|
raise NotImplementedError
|
|
@@ -883,8 +877,8 @@ class Expr(VtlVisitor):
|
|
|
883
877
|
|
|
884
878
|
def visitTimeAggAtom(self, ctx: Parser.TimeAggAtomContext):
|
|
885
879
|
"""
|
|
886
|
-
TIME_AGG LPAREN periodIndTo=STRING_CONSTANT (COMMA periodIndFrom=(STRING_CONSTANT| OPTIONAL ))? (COMMA op=optionalExpr)? (COMMA (FIRST|LAST))? RPAREN # timeAggAtom
|
|
887
|
-
"""
|
|
880
|
+
TIME_AGG LPAREN periodIndTo=STRING_CONSTANT (COMMA periodIndFrom=(STRING_CONSTANT| OPTIONAL ))? (COMMA op=optionalExpr)? (COMMA (FIRST|LAST))? RPAREN # timeAggAtom
|
|
881
|
+
""" # noqa E501
|
|
888
882
|
ctx_list = list(ctx.getChildren())
|
|
889
883
|
c = ctx_list[0]
|
|
890
884
|
|
|
@@ -902,10 +896,7 @@ class Expr(VtlVisitor):
|
|
|
902
896
|
and str_.getSymbol().type in [Parser.FIRST, Parser.LAST]
|
|
903
897
|
]
|
|
904
898
|
|
|
905
|
-
if len(conf) == 0
|
|
906
|
-
conf = None
|
|
907
|
-
else:
|
|
908
|
-
conf = conf[0]
|
|
899
|
+
conf = None if len(conf) == 0 else conf[0]
|
|
909
900
|
|
|
910
901
|
if ctx.op is not None:
|
|
911
902
|
operand_node = self.visitOptionalExpr(ctx.op)
|
|
@@ -994,10 +985,10 @@ class Expr(VtlVisitor):
|
|
|
994
985
|
|
|
995
986
|
def visitSetFunctions(self, ctx: Parser.SetFunctionsContext):
|
|
996
987
|
"""
|
|
997
|
-
setExpr: UNION LPAREN left=expr (COMMA expr)+ RPAREN # unionAtom
|
|
998
|
-
| INTERSECT LPAREN left=expr (COMMA expr)+ RPAREN # intersectAtom
|
|
999
|
-
| op=(SETDIFF|SYMDIFF) LPAREN left=expr COMMA right=expr RPAREN # setOrSYmDiffAtom
|
|
1000
|
-
"""
|
|
988
|
+
setExpr: UNION LPAREN left=expr (COMMA expr)+ RPAREN # unionAtom
|
|
989
|
+
| INTERSECT LPAREN left=expr (COMMA expr)+ RPAREN # intersectAtom
|
|
990
|
+
| op=(SETDIFF|SYMDIFF) LPAREN left=expr COMMA right=expr RPAREN # setOrSYmDiffAtom
|
|
991
|
+
""" # noqa E501
|
|
1001
992
|
if isinstance(ctx, Parser.UnionAtomContext):
|
|
1002
993
|
return self.visitUnionAtom(ctx)
|
|
1003
994
|
elif isinstance(ctx, Parser.IntersectAtomContext):
|
|
@@ -1039,8 +1030,8 @@ class Expr(VtlVisitor):
|
|
|
1039
1030
|
|
|
1040
1031
|
def visitHierarchyFunctions(self, ctx: Parser.HierarchyFunctionsContext):
|
|
1041
1032
|
"""
|
|
1042
|
-
HIERARCHY LPAREN op=expr COMMA hrName=IDENTIFIER (conditionClause)? (RULE ruleComponent=componentID)? (validationMode)? (inputModeHierarchy)? outputModeHierarchy? RPAREN
|
|
1043
|
-
"""
|
|
1033
|
+
HIERARCHY LPAREN op=expr COMMA hrName=IDENTIFIER (conditionClause)? (RULE ruleComponent=componentID)? (validationMode)? (inputModeHierarchy)? outputModeHierarchy? RPAREN
|
|
1034
|
+
""" # noqa E501
|
|
1044
1035
|
ctx_list = list(ctx.getChildren())
|
|
1045
1036
|
c = ctx_list[0]
|
|
1046
1037
|
|
|
@@ -1110,8 +1101,8 @@ class Expr(VtlVisitor):
|
|
|
1110
1101
|
|
|
1111
1102
|
def visitValidateDPruleset(self, ctx: Parser.ValidateDPrulesetContext):
|
|
1112
1103
|
"""
|
|
1113
|
-
validationDatapoint: CHECK_DATAPOINT '(' expr ',' IDENTIFIER (COMPONENTS componentID (',' componentID)*)? (INVALID|ALL_MEASURES|ALL)? ')' ;
|
|
1114
|
-
"""
|
|
1104
|
+
validationDatapoint: CHECK_DATAPOINT '(' expr ',' IDENTIFIER (COMPONENTS componentID (',' componentID)*)? (INVALID|ALL_MEASURES|ALL)? ')' ;
|
|
1105
|
+
""" # noqa E501
|
|
1115
1106
|
ctx_list = list(ctx.getChildren())
|
|
1116
1107
|
c = ctx_list[0]
|
|
1117
1108
|
|
|
@@ -1145,8 +1136,8 @@ class Expr(VtlVisitor):
|
|
|
1145
1136
|
# TODO Not fully implemented only basic usage available.
|
|
1146
1137
|
def visitValidateHRruleset(self, ctx: Parser.ValidateHRrulesetContext):
|
|
1147
1138
|
"""
|
|
1148
|
-
CHECK_HIERARCHY LPAREN op=expr COMMA hrName=IDENTIFIER conditionClause? (RULE componentID)? validationMode? inputMode? validationOutput? RPAREN
|
|
1149
|
-
"""
|
|
1139
|
+
CHECK_HIERARCHY LPAREN op=expr COMMA hrName=IDENTIFIER conditionClause? (RULE componentID)? validationMode? inputMode? validationOutput? RPAREN # validateHRruleset
|
|
1140
|
+
""" # noqa E501
|
|
1150
1141
|
|
|
1151
1142
|
ctx_list = list(ctx.getChildren())
|
|
1152
1143
|
c = ctx_list[0]
|
|
@@ -1207,8 +1198,8 @@ class Expr(VtlVisitor):
|
|
|
1207
1198
|
|
|
1208
1199
|
def visitValidationSimple(self, ctx: Parser.ValidationSimpleContext):
|
|
1209
1200
|
"""
|
|
1210
|
-
| CHECK LPAREN op=expr (codeErr=erCode)? (levelCode=erLevel)? imbalanceExpr? output=(INVALID|ALL)? RPAREN
|
|
1211
|
-
"""
|
|
1201
|
+
| CHECK LPAREN op=expr (codeErr=erCode)? (levelCode=erLevel)? imbalanceExpr? output=(INVALID|ALL)? RPAREN # validationSimple
|
|
1202
|
+
""" # noqa E501
|
|
1212
1203
|
ctx_list = list(ctx.getChildren())
|
|
1213
1204
|
c = ctx_list[0]
|
|
1214
1205
|
token = c.getSymbol()
|
|
@@ -1227,11 +1218,7 @@ class Expr(VtlVisitor):
|
|
|
1227
1218
|
inbalance_node = self.visitImbalanceExpr(param)
|
|
1228
1219
|
|
|
1229
1220
|
invalid = ctx_list[-2] if isinstance(ctx_list[-2], TerminalNodeImpl) else None
|
|
1230
|
-
|
|
1231
|
-
if invalid is None:
|
|
1232
|
-
invalid_value = False
|
|
1233
|
-
else:
|
|
1234
|
-
invalid_value = True if invalid.getSymbol().text == "invalid" else False
|
|
1221
|
+
invalid_value = False if invalid is None else invalid.getSymbol().text == "invalid"
|
|
1235
1222
|
|
|
1236
1223
|
return Validation(
|
|
1237
1224
|
op=token.text,
|
|
@@ -1291,7 +1278,7 @@ class Expr(VtlVisitor):
|
|
|
1291
1278
|
grouping_op, group_node = self.visitGroupingClause(groups[0])
|
|
1292
1279
|
if len(haves) != 0:
|
|
1293
1280
|
have_node, expr = self.visitHavingClause(haves[0])
|
|
1294
|
-
|
|
1281
|
+
have_node.expr = expr
|
|
1295
1282
|
|
|
1296
1283
|
return Aggregation(
|
|
1297
1284
|
op=op_node,
|
|
@@ -1368,9 +1355,7 @@ class Expr(VtlVisitor):
|
|
|
1368
1355
|
elif isinstance(c, Parser.OrderByClauseContext):
|
|
1369
1356
|
order_by = Terminals().visitOrderByClause(c)
|
|
1370
1357
|
continue
|
|
1371
|
-
elif isinstance(c, Parser.SignedIntegerContext)
|
|
1372
|
-
c, Parser.ScalarItemContext
|
|
1373
|
-
):
|
|
1358
|
+
elif isinstance(c, (Parser.SignedIntegerContext, Parser.ScalarItemContext)):
|
|
1374
1359
|
if params is None:
|
|
1375
1360
|
params = []
|
|
1376
1361
|
if isinstance(c, Parser.SignedIntegerContext):
|
|
@@ -1536,7 +1521,7 @@ class Expr(VtlVisitor):
|
|
|
1536
1521
|
right_node = ExprComp().visitAggregateFunctionsComponents(ctx_list[base_index + 2])
|
|
1537
1522
|
# Encoding the role information inside the Assignment for easiness and simplicity.
|
|
1538
1523
|
# Cannot find another way with less lines of code
|
|
1539
|
-
|
|
1524
|
+
left_node.role = role
|
|
1540
1525
|
|
|
1541
1526
|
return Assignment(left_node, op_node, right_node)
|
|
1542
1527
|
|
|
@@ -1563,7 +1548,7 @@ class Expr(VtlVisitor):
|
|
|
1563
1548
|
grouping_op, group_node = self.visitGroupingClause(groups[0])
|
|
1564
1549
|
if len(haves) > 0:
|
|
1565
1550
|
have_node, expr = self.visitHavingClause(haves[0])
|
|
1566
|
-
|
|
1551
|
+
have_node.expr = expr
|
|
1567
1552
|
for element in aggregate_nodes:
|
|
1568
1553
|
element.right = Aggregation(
|
|
1569
1554
|
op=element.right.op,
|