-
Notifications
You must be signed in to change notification settings - Fork 7
Fix/430 #443
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
base: develop
Are you sure you want to change the base?
Fix/430 #443
Conversation
…ply with the requirements of the VTL 2.1 specification. In addition, an error handling mechanism has been incorporated into all the aforementioned functions, providing both the cause and the statement that triggered the error in the event of a runtime failure
hadrienk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Miguel, very nice contribution thank you!
I took a first pass. There are a few important changes that we need to address.
Please don't hesitate to ask for clarifications if needed.
vtl-engine/src/test/java/fr/insee/vtl/engine/visitors/ClauseVisitorTest.java
Outdated
Show resolved
Hide resolved
vtl-engine/src/test/java/fr/insee/vtl/engine/visitors/ClauseVisitorTest.java
Show resolved
Hide resolved
| if (!availableColumns.contains(requested)) { | ||
| String errorMsg = | ||
| String.format( | ||
| "Error: column '%s' not found in dataset. Line %d, position %d. Statement: [%s]", | ||
| requested, line, charPosition, statement); | ||
| throw new VtlRuntimeException(new InvalidArgumentException(errorMsg, fromContext(ctx))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The VtlRuntimeException handles reporting the position so you don't have to do it yourself. See the fromContext(...) that returns a positionable for the particular ANTLR context.
| if (!availableColumns.contains(requested)) { | |
| String errorMsg = | |
| String.format( | |
| "Error: column '%s' not found in dataset. Line %d, position %d. Statement: [%s]", | |
| requested, line, charPosition, statement); | |
| throw new VtlRuntimeException(new InvalidArgumentException(errorMsg, fromContext(ctx))); | |
| if (!availableColumns.contains(requested)) { | |
| throw new VtlRuntimeException(new InvalidArgumentException(String.format("'%s' not found in dataset", requested), fromContext(ctx))); |
| // Error reporting context | ||
| final int line = ctx.getStart().getLine(); | ||
| final int charPosition = ctx.getStart().getCharPositionInLine(); | ||
| final String statement = ctx.getText(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Error reporting context | |
| final int line = ctx.getStart().getLine(); | |
| final int charPosition = ctx.getStart().getCharPositionInLine(); | |
| final String statement = ctx.getText(); |
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Outdated
Show resolved
Hide resolved
| .filter(identifiers::containsKey) | ||
| .collect(Collectors.toCollection(LinkedHashSet::new)); | ||
|
|
||
| if (!forbidden.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you are building the complete set of possible errors. While this is a very nice thing for the end user, this makes the implementation very complex. I suggest a simple fail fast approach for now. If we want to offer more that one error we should bake that in the VtlScritpException API.
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Outdated
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Outdated
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Outdated
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Outdated
Show resolved
Hide resolved
hadrienk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Miguel,
Do you think you could split this PR into the different PR of each area? Something like:
- Calc
- Keep/drop
- Rename
- Filter
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Outdated
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Outdated
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Outdated
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Outdated
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Outdated
Show resolved
Hide resolved
|
Hi hadrienk, Apologies for the delay in replying; I was involved in other priorities. To summarize the rationale behind the changes: Regarding your suggestion on ctx management, I did not fully understand the change. If you can provide a concrete example, I will adapt the code as you propose. I still believe error messages should explicitly include the fields and the VTL statement causing the runtime issue, otherwise the engine is not verbose enough for effective debugging. For the other minor points, I agree with your proposals. On splitting the PR into four (one per operator), I will not be able to take that on due to project changes. I can either complete this PR with the requested adjustments or leave the splitting for a colleague who may continue this work. |
…ply with the requirements of the VTL 2.1 specification. In addition, an error handling mechanism has been incorporated into all the aforementioned functions, providing both the cause and the statement that triggered the error in the event of a runtime failure Unitary tests adapted
# Conflicts: # vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java # vtl-engine/src/test/java/fr/insee/vtl/engine/visitors/ClauseVisitorTest.java # vtl-engine/src/test/java/fr/insee/vtl/engine/visitors/expression/ArithmeticExprTest.java # vtl-engine/src/test/java/fr/insee/vtl/engine/visitors/expression/ComparisonExprTest.java # vtl-engine/src/test/java/fr/insee/vtl/engine/visitors/expression/ConditionalExprTest.java # vtl-engine/src/test/java/fr/insee/vtl/engine/visitors/expression/UnaryExprTest.java # vtl-engine/src/test/java/fr/insee/vtl/engine/visitors/expression/functions/JoinFunctionsTest.java
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Show resolved
Hide resolved
vtl-engine/src/main/java/fr/insee/vtl/engine/visitors/ClauseVisitor.java
Show resolved
Hide resolved
Hi Miguel, no problem. Thanks for taking the time. The 'fromContext` method takes an ANTLR grammar object (token I think, reviewing from the phone). This contains all the information needed to construct an error message that is positioned. For instance, if a variable is not found, you can pass the actual variable 'context' to the exception and one will be able to position the error (lines and columns + text value). Therefore, adding the name of the variables and their position is redundant. There's still improvements to be made to the error system, but we can make improvements later as long as we pass the proper contextes. |
The following PR addresses the issues identified in issue #430 , which revealed execution problems and misalignments with the VTL 2.1 specification. In addition, an error-handling mechanism has been incorporated for the functions keep, rename, filter, and calc, in order to report both the cause of the error and the VTL statement that triggered it. Below is a detailed list of the main features included in this PR.
ClauseVisitor – Key Changes
General / Exceptions
KEEP/DROP
CALC
RENAME
Validates and errors on:
FILTER
UNITARY TESTS