Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

45 check time period comparison #46

Merged
merged 18 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ pytest-cov = "^5.0.0"
line-profiler-pycharm = "^1.2.0"
sphinx = "^7.4"
sphinx-rtd-theme = "^2.0.0"
mypy = "^1.11.2"
mypy = "^1.14.1"
pandas-stubs = "^2.2.3.241009"
stubs = "^1.0.0"
toml = "^0.10.2"
ruff = "^0.7.1"
ruff = "^0.7.4"

[tool.ruff]
line-length = 100
Expand Down
4 changes: 2 additions & 2 deletions src/vtlengine/API/_InternalApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _load_single_datapoint(datapoint: Union[str, Path]) -> Dict[str, Any]:


def _load_datapoints_path(
datapoints: Union[Path, str, List[Union[str, Path]]]
datapoints: Union[Path, str, List[Union[str, Path]]],
) -> Dict[str, Dataset]:
"""
Returns a dict with the data given from a Path.
Expand Down Expand Up @@ -156,7 +156,7 @@ def _load_datastructure_single(data_structure: Union[Dict[str, Any], Path]) -> D


def load_datasets(
data_structure: Union[Dict[str, Any], Path, List[Union[Dict[str, Any], Path]]]
data_structure: Union[Dict[str, Any], Path, List[Union[Dict[str, Any], Path]]],
) -> Dict[str, Dataset]:
"""
Loads multiple datasets.
Expand Down
6 changes: 3 additions & 3 deletions src/vtlengine/AST/ASTConstructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def visitHierRuleSignature(self, ctx: Parser.HierRuleSignatureContext):
def visitValueDomainSignature(self, ctx: Parser.ValueDomainSignatureContext):
"""
valueDomainSignature: CONDITION IDENTIFIER (AS IDENTIFIER)? (',' IDENTIFIER (AS IDENTIFIER)?)* ;
""" # noqa E501
""" # noqa E501
# AST_ASTCONSTRUCTOR.7
ctx_list = list(ctx.getChildren())
component_nodes = [
Expand Down Expand Up @@ -459,7 +459,7 @@ def visitCodeItemRelation(self, ctx: Parser.CodeItemRelationContext):
codeItemRelation: ( WHEN expr THEN )? codeItemRef codeItemRelationClause (codeItemRelationClause)* ;
( WHEN exprComponent THEN )? codetemRef=valueDomainValue comparisonOperand? codeItemRelationClause (codeItemRelationClause)*

""" # noqa E501
""" # noqa E501

ctx_list = list(ctx.getChildren())

Expand Down Expand Up @@ -512,7 +512,7 @@ def visitCodeItemRelation(self, ctx: Parser.CodeItemRelationContext):
def visitCodeItemRelationClause(self, ctx: Parser.CodeItemRelationClauseContext):
"""
(opAdd=( PLUS | MINUS ))? rightCodeItem=valueDomainValue ( QLPAREN rightCondition=exprComponent QRPAREN )?
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())

expr = [expr for expr in ctx_list if isinstance(expr, Parser.ExprContext)]
Expand Down
66 changes: 24 additions & 42 deletions src/vtlengine/AST/ASTConstructorModules/Expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def visitExpr(self, ctx: Parser.ExprContext):
| constant # constantExpr
| varID # varIdExpr
;
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())
c = ctx_list[0]

Expand Down Expand Up @@ -121,7 +121,6 @@ def visitExpr(self, ctx: Parser.ExprContext):

# CASE WHEN expr THEN expr ELSE expr END # caseExpr
elif isinstance(c, TerminalNodeImpl) and (c.getSymbol().type == Parser.CASE):

if len(ctx_list) % 4 != 3:
raise ValueError("Syntax error.")

Expand Down Expand Up @@ -221,7 +220,6 @@ def visitMembershipExpr(self, ctx: Parser.MembershipExprContext):
return previous_node

def visitClauseExpr(self, ctx: Parser.ClauseExprContext):

ctx_list = list(ctx.getChildren())

dataset = self.visitExpr(ctx_list[0])
Expand Down Expand Up @@ -373,7 +371,7 @@ def visitJoinClause(self, ctx: Parser.JoinClauseContext):
def visitJoinClauseWithoutUsing(self, ctx: Parser.JoinClauseWithoutUsingContext):
"""
joinClause: joinClauseItem (COMMA joinClauseItem)* (USING componentID (COMMA componentID)*)? ;
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())

clause_nodes = []
Expand All @@ -388,7 +386,7 @@ def visitJoinClauseWithoutUsing(self, ctx: Parser.JoinClauseWithoutUsingContext)
def visitJoinBody(self, ctx: Parser.JoinBodyContext):
"""
joinBody: filterClause? (calcClause|joinApplyClause|aggrClause)? (keepOrDropClause)? renameClause?
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())

body_nodes = []
Expand Down Expand Up @@ -457,7 +455,7 @@ def visitCallDataset(self, ctx: Parser.CallDatasetContext):
def visitEvalAtom(self, ctx: Parser.EvalAtomContext):
"""
| EVAL LPAREN routineName LPAREN (varID|scalarItem)? (COMMA (varID|scalarItem))* RPAREN (LANGUAGE STRING_CONSTANT)? (RETURNS evalDatasetType)? RPAREN # evalAtom
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())

routine_name = Terminals().visitRoutineName(ctx_list[2])
Expand Down Expand Up @@ -505,7 +503,7 @@ def visitEvalAtom(self, ctx: Parser.EvalAtomContext):
def visitCastExprDataset(self, ctx: Parser.CastExprDatasetContext):
"""
| CAST LPAREN expr COMMA (basicScalarType|valueDomainName) (COMMA STRING_CONSTANT)? RPAREN # castExprDataset
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())
c = ctx_list[0]

Expand Down Expand Up @@ -795,15 +793,19 @@ def visitTimeFunctions(self, ctx: Parser.TimeFunctionsContext):
return self.visitTimeDiffAtom(ctx)
elif isinstance(ctx, Parser.DateAddAtomContext):
return self.visitTimeAddAtom(ctx)
elif isinstance(ctx, (Parser.YearAtomContext,
Parser.MonthAtomContext,
Parser.DayOfMonthAtomContext,
Parser.DayOfYearAtomContext,
Parser.DayToYearAtomContext,
Parser.DayToMonthAtomContext,
Parser.YearTodayAtomContext,
Parser.MonthTodayAtomContext)):

elif isinstance(
ctx,
(
Parser.YearAtomContext,
Parser.MonthAtomContext,
Parser.DayOfMonthAtomContext,
Parser.DayOfYearAtomContext,
Parser.DayToYearAtomContext,
Parser.DayToMonthAtomContext,
Parser.YearTodayAtomContext,
Parser.MonthTodayAtomContext,
),
):
return self.visitTimeUnaryAtom(ctx)
else:
raise NotImplementedError
Expand All @@ -825,26 +827,6 @@ def visitTimeUnaryAtom(self, ctx: Any):

return UnaryOp(op=op, operand=operand_node[0])

# def visitPeriodAtom(self, ctx: Parser.PeriodAtomContext):
# """
# periodExpr: PERIOD_INDICATOR '(' expr? ')' ;
# """
# ctx_list = list(ctx.getChildren())
# c = ctx_list[0]
#
# op = c.getSymbol().text
# operand_node = [
# self.visitExpr(operand)
# for operand in ctx_list
# if isinstance(operand, Parser.ExprContext)
# ]
#
# if len(operand_node) == 0:
# # AST_ASTCONSTRUCTOR.15
# raise NotImplementedError
#
# return UnaryOp(op=op, operand=operand_node[0])

def visitTimeShiftAtom(self, ctx: Parser.TimeShiftAtomContext):
"""
timeShiftExpr: TIMESHIFT '(' expr ',' INTEGER_CONSTANT ')' ;
Expand Down Expand Up @@ -878,7 +860,7 @@ def visitFillTimeAtom(self, ctx: Parser.FillTimeAtomContext):
def visitTimeAggAtom(self, ctx: Parser.TimeAggAtomContext):
"""
TIME_AGG LPAREN periodIndTo=STRING_CONSTANT (COMMA periodIndFrom=(STRING_CONSTANT| OPTIONAL ))? (COMMA op=optionalExpr)? (COMMA (FIRST|LAST))? RPAREN # timeAggAtom
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())
c = ctx_list[0]

Expand Down Expand Up @@ -988,7 +970,7 @@ def visitSetFunctions(self, ctx: Parser.SetFunctionsContext):
setExpr: UNION LPAREN left=expr (COMMA expr)+ RPAREN # unionAtom
| INTERSECT LPAREN left=expr (COMMA expr)+ RPAREN # intersectAtom
| op=(SETDIFF|SYMDIFF) LPAREN left=expr COMMA right=expr RPAREN # setOrSYmDiffAtom
""" # noqa E501
""" # noqa E501
if isinstance(ctx, Parser.UnionAtomContext):
return self.visitUnionAtom(ctx)
elif isinstance(ctx, Parser.IntersectAtomContext):
Expand Down Expand Up @@ -1031,7 +1013,7 @@ def visitSetOrSYmDiffAtom(self, ctx: Parser.SetOrSYmDiffAtomContext):
def visitHierarchyFunctions(self, ctx: Parser.HierarchyFunctionsContext):
"""
HIERARCHY LPAREN op=expr COMMA hrName=IDENTIFIER (conditionClause)? (RULE ruleComponent=componentID)? (validationMode)? (inputModeHierarchy)? outputModeHierarchy? RPAREN
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())
c = ctx_list[0]

Expand Down Expand Up @@ -1102,7 +1084,7 @@ def visitValidationFunctions(self, ctx: Parser.ValidationFunctionsContext):
def visitValidateDPruleset(self, ctx: Parser.ValidateDPrulesetContext):
"""
validationDatapoint: CHECK_DATAPOINT '(' expr ',' IDENTIFIER (COMPONENTS componentID (',' componentID)*)? (INVALID|ALL_MEASURES|ALL)? ')' ;
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())
c = ctx_list[0]

Expand Down Expand Up @@ -1137,7 +1119,7 @@ def visitValidateDPruleset(self, ctx: Parser.ValidateDPrulesetContext):
def visitValidateHRruleset(self, ctx: Parser.ValidateHRrulesetContext):
"""
CHECK_HIERARCHY LPAREN op=expr COMMA hrName=IDENTIFIER conditionClause? (RULE componentID)? validationMode? inputMode? validationOutput? RPAREN # validateHRruleset
""" # noqa E501
""" # noqa E501

ctx_list = list(ctx.getChildren())
c = ctx_list[0]
Expand Down Expand Up @@ -1199,7 +1181,7 @@ def visitValidateHRruleset(self, ctx: Parser.ValidateHRrulesetContext):
def visitValidationSimple(self, ctx: Parser.ValidationSimpleContext):
"""
| CHECK LPAREN op=expr (codeErr=erCode)? (levelCode=erLevel)? imbalanceExpr? output=(INVALID|ALL)? RPAREN # validationSimple
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())
c = ctx_list[0]
token = c.getSymbol()
Expand Down
35 changes: 18 additions & 17 deletions src/vtlengine/AST/ASTConstructorModules/ExprComponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def visitExprComponent(self, ctx: Parser.ExprComponentContext):
| constant # constantExprComp
| componentID # compId
;
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())
c = ctx_list[0]

Expand Down Expand Up @@ -280,7 +280,7 @@ def visitGenericFunctionsComponents(self, ctx: Parser.GenericFunctionsComponents
def visitCallComponent(self, ctx: Parser.CallComponentContext):
"""
callFunction: operatorID LPAREN (parameterComponent (COMMA parameterComponent)*)? RPAREN # callComponent
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())
c = ctx_list[0]

Expand All @@ -296,7 +296,7 @@ def visitCallComponent(self, ctx: Parser.CallComponentContext):
def visitEvalAtomComponent(self, ctx: Parser.EvalAtomComponentContext):
"""
| EVAL LPAREN routineName LPAREN (componentID|scalarItem)? (COMMA (componentID|scalarItem))* RPAREN (LANGUAGE STRING_CONSTANT)? (RETURNS outputParameterTypeComponent)? RPAREN # evalAtomComponent
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())

routine_name = Terminals().visitRoutineName(ctx_list[2])
Expand Down Expand Up @@ -347,7 +347,7 @@ def visitEvalAtomComponent(self, ctx: Parser.EvalAtomComponentContext):
def visitCastExprComponent(self, ctx: Parser.CastExprComponentContext):
"""
| CAST LPAREN exprComponent COMMA (basicScalarType|valueDomainName) (COMMA STRING_CONSTANT)? RPAREN # castExprComponent
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())
c = ctx_list[0]

Expand Down Expand Up @@ -391,7 +391,6 @@ def visitCastExprComponent(self, ctx: Parser.CastExprComponentContext):
raise NotImplementedError

def visitParameterComponent(self, ctx: Parser.ParameterComponentContext):

ctx_list = list(ctx.getChildren())
c = ctx_list[0]

Expand Down Expand Up @@ -582,16 +581,19 @@ def visitTimeFunctionsComponents(self, ctx: Parser.TimeFunctionsComponentsContex
return self.visitDateDiffAtomComponent(ctx)
elif isinstance(ctx, Parser.DateAddAtomComponentContext):
return self.visitDateAddAtomComponentContext(ctx)
elif (isinstance(ctx, (
Parser.YearAtomComponentContext,
Parser.MonthAtomComponentContext,
Parser.DayOfMonthAtomComponentContext,
Parser.DayOfYearAtomComponentContext,
Parser.DayToYearAtomComponentContext,
Parser.DayToMonthAtomComponentContext,
Parser.YearToDayAtomComponentContext,
Parser.MonthToDayAtomComponentContext
))):
elif isinstance(
ctx,
(
Parser.YearAtomComponentContext,
Parser.MonthAtomComponentContext,
Parser.DayOfMonthAtomComponentContext,
Parser.DayOfYearAtomComponentContext,
Parser.DayToYearAtomComponentContext,
Parser.DayToMonthAtomComponentContext,
Parser.YearToDayAtomComponentContext,
Parser.MonthToDayAtomComponentContext,
),
):
return self.visitTimeUnaryAtomComponent(ctx)
else:
raise NotImplementedError
Expand Down Expand Up @@ -650,7 +652,7 @@ def visitTimeAggAtomComponent(self, ctx: Parser.TimeAggAtomComponentContext):
"""
TIME_AGG LPAREN periodIndTo=STRING_CONSTANT (COMMA periodIndFrom=(STRING_CONSTANT| OPTIONAL ))?
(COMMA op=optionalExprComponent)? (COMMA (FIRST|LAST))? RPAREN # timeAggAtomComponent;
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())
c = ctx_list[0]

Expand Down Expand Up @@ -825,7 +827,6 @@ def visitCountAggrComp(self, ctx: Parser.CountAggrCompContext):
"""

def visitAnalyticFunctionsComponents(self, ctx: Parser.AnalyticFunctionsComponentsContext):

if isinstance(ctx, Parser.AnSimpleFunctionComponentContext):
return self.visitAnSimpleFunctionComponent(ctx)
elif isinstance(ctx, Parser.LagOrLeadAnComponentContext):
Expand Down
16 changes: 9 additions & 7 deletions src/vtlengine/AST/ASTConstructorModules/Terminals.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def visitVarID(self, ctx: Parser.VarIDContext):
return var_id_node

def visitVarIdExpr(self, ctx: Parser.VarIdExprContext):

if isinstance(ctx.children[0], Parser.VarIDContext):
return self.visitVarID(ctx.children[0])

Expand Down Expand Up @@ -381,7 +380,7 @@ def visitDpRuleset(self, ctx: Parser.DpRulesetContext):
| DATAPOINT_ON_VD (GLPAREN valueDomainName (MUL valueDomainName)* GRPAREN )? # dataPointVd
| DATAPOINT_ON_VAR (GLPAREN varID (MUL varID)* GRPAREN )? # dataPointVar
;
""" # noqa E501
""" # noqa E501
# AST_ASTCONSTRUCTOR.54
raise NotImplementedError

Expand All @@ -391,7 +390,7 @@ def visitHrRuleset(self, ctx: Parser.HrRulesetContext):
| HIERARCHICAL_ON_VD ( GLPAREN vdName=IDENTIFIER (LPAREN valueDomainName (MUL valueDomainName)* RPAREN)? GRPAREN )? # hrRulesetVdType
| HIERARCHICAL_ON_VAR ( GLPAREN varName=varID (LPAREN varID (MUL varID)* RPAREN)? GRPAREN )? # hrRulesetVarType
;
""" # noqa E501
""" # noqa E501
# AST_ASTCONSTRUCTOR.55
raise NotImplementedError

Expand Down Expand Up @@ -483,7 +482,6 @@ def visitOutputParameterTypeComponent(self, ctx: Parser.OutputParameterTypeCompo
raise NotImplementedError

def visitScalarItem(self, ctx: Parser.ScalarItemContext):

ctx_list = list(ctx.getChildren())
c = ctx_list[0]

Expand All @@ -497,7 +495,7 @@ def visitScalarItem(self, ctx: Parser.ScalarItemContext):
def visitScalarWithCast(self, ctx: Parser.ScalarWithCastContext):
"""
| CAST LPAREN constant COMMA (basicScalarType) (COMMA STRING_CONSTANT)? RPAREN #scalarWithCast # noqa E501
""" # noqa E501
""" # noqa E501
ctx_list = list(ctx.getChildren())
c = ctx_list[0]

Expand Down Expand Up @@ -672,8 +670,12 @@ def visitWindowingClause(self, ctx: Parser.WindowingClauseContext):
first = num_rows_1 # unbounded (default value)
second = num_rows_2 # current data point (default value)

if (mode_2 == "preceding" and mode_1 == "preceding" and num_rows_1 == -1
and num_rows_2 == -1): # preceding and preceding (error)
if (
mode_2 == "preceding"
and mode_1 == "preceding"
and num_rows_1 == -1
and num_rows_2 == -1
): # preceding and preceding (error)
raise Exception(
f"Cannot have 2 preceding clauses with unbounded in analytic clause, "
f"line {ctx_list[3].start.line}"
Expand Down
Loading
Loading