Dwrite opened a new pull request, #4877: URL: https://github.com/apache/calcite/pull/4877
Summary Currently, Apache Calcite fails with a RuntimeException during code generation or execution when a quantifier operator (such as SOME, ANY, or ALL) compares columns with mismatched types (e.g., VARCHAR vs SMALLINT), even when TypeCoercion is enabled. Problem When a query like SELECT dname > SOME(SELECT empno FROM emp) FROM dept is executed: The SqlValidator fails to inject a necessary CAST because the implicit type coercion rules for quantifier operators are not fully applied. During the optimization or code generation phase (e.g., in Enumerable convention), the engine attempts to resolve a comparison method (like gt) between raw String and short types. This results in a RuntimeException (e.g., while resolving method 'gt[class java.lang.String, short]') because no such method exists in SqlFunctions, or a NumberFormatException occurs if a blind cast is attempted at runtime. Solution This PR enhances TypeCoercionImpl to properly handle quantifier operators (SOME, ANY, ALL). It ensures that the SqlValidator identifies type mismatches between the left-hand side expression and the subquery result type. It leverages the default TypeCoercion rules to insert a CAST node, aligning the types before the comparison logic is generated. This aligns Calcite's behavior with other mainstream SQL engines (like MySQL and PostgreSQL) which support implicit conversion between numeric and string types in subqueries. Changes TypeCoercionImpl.java: Added/Updated logic to handle SqlKind.SOME, SqlKind.ANY, and SqlKind.ALL in the coercion flow. sub-query.iq: Added a regression test case to verify that a CAST is correctly inserted into the physical plan, preventing the runtime exception. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
