Repository navigation
Implement Parameter Validation for PPL functions on Calcite - #3626
Merged
Merged
Conversation
Signed-off-by: Heng Qian <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
…hecking for non-operator registrated udf Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
yuancu
requested review from
GumpacG,
LantaoJin,
MaxKsyunz,
Swiddis,
YANG-DB,
Yury-Fridlyand,
acarbonetto,
anirudha,
dai-chen,
derek-ho,
forestmvey,
joshuali925,
kavithacm,
mengweieric,
noCharger,
penghuo,
ps48,
qianheng-aws,
seankao-az and
ykmr1224
as code owners
May 16, 2025 07:58
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
…ions - additionally fixed span type checker Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
… composition field of CompositeOperandTypeChecker via relection. May cause fatal errors if IllegalAccessException is thrown. Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
… checker) Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
penghuo
reviewed
May 28, 2025
| composition.name())); | ||
| } | ||
| } catch (IllegalAccessException e) { | ||
| LogManager.getLogger(PPLTypeChecker.class).error(e); |
Collaborator
Author
There was a problem hiding this comment.
As it was in an interface, I was hesitated in adding a static member logger to it. Therefore, I used LogManageer.getLogger().error(). It's also part of log4j.
Now this line is removed.
| @Test | ||
| public void testLowerWithIntegerType() { | ||
| String ppl = "source=EMP | eval lower_name = lower(EMPNO) | fields lower_name"; | ||
| Assert.assertThrows(Exception.class, () -> getRelNode(ppl)); |
Collaborator
There was a problem hiding this comment.
I also see VARCHAR in other test cases. for instance, testTimestampWithWrongArg, does this issue all solved?
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
LantaoJin
previously approved these changes
Jun 4, 2025
LantaoJin
left a comment
Member
There was a problem hiding this comment.
We could investigate how to leverage SqlNode validation later 3.1.0. Approved.
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
penghuo
approved these changes
Jun 5, 2025
LantaoJin
approved these changes
Jun 6, 2025
penghuo
pushed a commit
that referenced
this pull request
Jun 16, 2025
* Support type checker For PPL functions Signed-off-by: Heng Qian <[email protected]> * Implement type checkers for UDF Signed-off-by: Yuanchun Shen <[email protected]> * Implement composite type checker Signed-off-by: Yuanchun Shen <[email protected]> * Define type checkers for UDFs Signed-off-by: Yuanchun Shen <[email protected]> * Display expected signatures when type checking fails & support type checking for non-operator registrated udf Signed-off-by: Yuanchun Shen <[email protected]> * Add ITs for UDF type checking Signed-off-by: Yuanchun Shen <[email protected]> * Fix: correct CONV's operand types Signed-off-by: Yuanchun Shen <[email protected]> * Fix test parse IT Signed-off-by: Yuanchun Shen <[email protected]> * Remove unused code in UserDefinedFunctionUtils Signed-off-by: Yuanchun Shen <[email protected]> * Refactor: improve ITs, javadocs, type checkers Signed-off-by: Yuanchun Shen <[email protected]> * Improve javadoc for PPLTypeChecker Signed-off-by: Yuanchun Shen <[email protected]> * Return false at validation for mismatched operand count with expectations - additionally fixed span type checker Signed-off-by: Yuanchun Shen <[email protected]> * Add type checker for cidrmatch Signed-off-by: Yuanchun Shen <[email protected]> * Correct cidrmatch type checker Signed-off-by: Yuanchun Shen <[email protected]> * Fix compile error in CalcitePPLAbstractTest.java Signed-off-by: Yuanchun Shen <[email protected]> * Experiment: support type checking for built-in operators by accessing composition field of CompositeOperandTypeChecker via relection. May cause fatal errors if IllegalAccessException is thrown. Signed-off-by: Yuanchun Shen <[email protected]> * Check composition type for only calcite's built-in operators Signed-off-by: Yuanchun Shen <[email protected]> * Support parameter validation for comparabale operators Signed-off-by: Yuanchun Shen <[email protected]> * Support parameter validation for coalesce (by reusing comparable type checker) Signed-off-by: Yuanchun Shen <[email protected]> * Support parameter validation for substring Signed-off-by: Yuanchun Shen <[email protected]> * Support parameter validation for if Signed-off-by: Yuanchun Shen <[email protected]> * Support parameter validation for nullif, isempty, isblank Signed-off-by: Yuanchun Shen <[email protected]> * Align types in type check error information to actual types in PPL Signed-off-by: Yuanchun Shen <[email protected]> * Display PPL types when failing to resolve a function Signed-off-by: Yuanchun Shen <[email protected]> * Create type checker for geoip function Signed-off-by: Yuanchun Shen <[email protected]> * Define type checker for grok and item operators Signed-off-by: Yuanchun Shen <[email protected]> --------- Signed-off-by: Heng Qian <[email protected]> Signed-off-by: Yuanchun Shen <[email protected]> Co-authored-by: Heng Qian <[email protected]> Signed-off-by: xinyual <[email protected]>
This was referenced Jun 23, 2025
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implement parameter validations. It supports validations for
registerOperator(ABS, SqlStdOperatorTable.ABS)registerOperator(SHA2, PPLBuiltinOperators.SHA2);registerOperator). E.g.Besides, it support functions with signature overriddings. E.g.
timestamphas multiple signatures:This implementation is based on the PoC in #3562, where it explains why we can not directly adopt Calcite's built-in type checking mechanism for SQL and how our type checking works.
Issues Resolved
Resolves #3608
Implementation Notes
Classes related to type checking & their roles
UDFOperandMetadata: Created for compatibility withSqlUserDefinedFunction, which serves as the basis for implementing our UDFs. SinceSqlUserDefinedFunctiononly acceptsSqlOperandMetadataas its type checker, andSqlOperandMetadatais incompatible with Calcite's built-in operators,UDFOperandMetadatawas introduced. It acts as a wrapper around Calcite's operand type checkers, allowing us to reuse them. This ensures that type checkers can be utilized in the same way as Calcite's built-in operators for type checking.PPLTypeChecker: The type checker that does the real work. It retrieved acceptable types from Calcite's type checkers, and compare them with the actual ones.SqlOperandTypeChecker,ImplicitCastOperandTypeChecker,FamilyOperandTypeChecker, ...: Calcite's builtin type checkers. Cannot be directly used since it requires aSqlCallBinding:boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure).classDiagram class SqlOperandTypeChecker { <<interface>> +checkOperandTypes(SqlCallBinding, boolean) } class CompositeOperandTypeChecker { } class FamilyOperandTypeChecker { } class PPLTypeChecker { <<interface>> +checkOperandTypes(actualTypes) : boolean } class PPLFamilyTypeChecker { - families: List[SqlTypeFamily] } class PPLCompositeTypeChecker { - rules: List[FamilyOperandTypeChecker] } class UDFOperandMetadata { <<interface>> <<extends>> SqlOperandMetadata <<extends>> ImplicitCastOperandTypeChecker +getInnerTypeChecker() : SqlOperandTypeChecker } class SqlOperator { <<abstract>> - operandTypeChecker: SqlOperandTypeChecker + getOperandTypeChecker() : SqlOperandTypeChecker } class SqlUserDefinedFunction { +SqlUserDefinedFunction(SqlOperandMetadata, ...) } %% Relationships SqlOperandTypeChecker <|.. FamilyOperandTypeChecker SqlOperandTypeChecker <|.. CompositeOperandTypeChecker SqlOperator <|-- SqlUserDefinedFunction PPLTypeChecker <|.. PPLFamilyTypeChecker PPLTypeChecker <|.. PPLCompositeTypeChecker UDFOperandMetadata --> SqlUserDefinedFunction : feeds to constructor SqlOperator *-- SqlOperandTypeChecker: contains %% UDFOperandMetadata *-- SqlOperandTypeChecker PPLFamilyTypeChecker ..> FamilyOperandTypeChecker: wraps PPLCompositeTypeChecker ..> CompositeOperandTypeChecker: wrapsType checking for Calcite's built-in operators & for self-implemented UDFs
SqlOperandTypeChecker, then wrapped withPPLTypeCheckerwhich does the actual type checking with the expected param types in theSqlOperandTypeChecker.UDFOperandMetadatato create aSqlUderDefinedFunction, which implementsSqlOperator. Afterwards, the actual Calcite type checker can be retrieved and used in the same way as Calcite's built-in operators.register(funcName, FuncImp)interface, since there is noSqlOperatorinvolved, we directly pass aPPLTypeCheckerwhen creating aFuncImpinstance.Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.