Skip to content

Use Java built-in functions to create failure function #24792

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

Merged
merged 1 commit into from
May 21, 2025

Conversation

pdabre12
Copy link
Contributor

@pdabre12 pdabre12 commented Mar 24, 2025

Description

When sidecar is enabled, the coordinator is unable to create a failure function. Use Java functions to create a failure function.

Motivation and Context

When the sidecar is used for query analysis, the default namespace is switched to reflect the different set of functions used in Velox. While eventually we wish to use Velox for both expression evaluation and also as a registry of functions, the former is taking a long time due to refactoring in Velox. In the meantime, we need function evaluation over C++ namespaces to work properly, which means we need to use the Java functions for now. This is a stopgap solution until function evaluation in Velox works end to end. (copied from #25135)

Eg:
java.lang.AssertionError: Execution of 'actual' query failed: SELECT IF(true, 0/0, 1)

Caused by: java.lang.RuntimeException: Error getting ScalarFunctionImplementation for handle: native.default.json_parse(varchar):1
	at com.facebook.presto.tests.AbstractTestingPrestoClient.execute(AbstractTestingPrestoClient.java:126)
	at com.facebook.presto.tests.DistributedQueryRunner.execute(DistributedQueryRunner.java:852)
	at com.facebook.presto.tests.DistributedQueryRunner.execute(DistributedQueryRunner.java:820)
	at com.facebook.presto.tests.QueryAssertions.assertQuery(QueryAssertions.java:176)
	... 31 more
Caused by: com.facebook.presto.spi.PrestoException: Error getting ScalarFunctionImplementation for handle: native.default.json_parse(varchar):1
	at com.facebook.presto.functionNamespace.AbstractSqlInvokedFunctionNamespaceManager.convertToPrestoException(AbstractSqlInvokedFunctionNamespaceManager.java:255)
	at com.facebook.presto.functionNamespace.AbstractSqlInvokedFunctionNamespaceManager.getScalarFunctionImplementation(AbstractSqlInvokedFunctionNamespaceManager.java:231)
	at com.facebook.presto.metadata.FunctionAndTypeManager.getScalarFunctionImplementation(FunctionAndTypeManager.java:607)
	at com.facebook.presto.metadata.FunctionAndTypeManager.getJavaScalarFunctionImplementation(FunctionAndTypeManager.java:640)
	at com.facebook.presto.sql.InterpretedFunctionInvoker.invoke(InterpretedFunctionInvoker.java:60)
	at com.facebook.presto.sql.InterpretedFunctionInvoker.invoke(InterpretedFunctionInvoker.java:55)
	at com.facebook.presto.sql.planner.RowExpressionInterpreter$Visitor.createFailureFunction(RowExpressionInterpreter.java:727)
	at com.facebook.presto.sql.planner.RowExpressionInterpreter$Visitor.processWithExceptionHandling(RowExpressionInterpreter.java:717)
	at com.facebook.presto.sql.planner.RowExpressionInterpreter$Visitor.visitSpecialForm(RowExpressionInterpreter.java:367)
	at com.facebook.presto.spi.relation.SpecialFormExpression.accept(SpecialFormExpression.java:127)
	at com.facebook.presto.sql.planner.RowExpressionInterpreter.optimize(RowExpressionInterpreter.java:191)
	at com.facebook.presto.sql.planner.RowExpressionInterpreter.optimize(RowExpressionInterpreter.java:182)
	at com.facebook.presto.sql.relational.RowExpressionOptimizer.optimize(RowExpressionOptimizer.java:49)
	at com.facebook.presto.sql.planner.iterative.rule.SimplifyRowExpressions$Rewriter.rewrite(SimplifyRowExpressions.java:72)
	at com.facebook.presto.sql.planner.iterative.rule.SimplifyRowExpressions$Rewriter.rewrite(SimplifyRowExpressions.java:64)
	at com.facebook.presto.sql.planner.iterative.rule.RowExpressionRewriteRuleSet$ProjectRowExpressionRewrite.apply(RowExpressionRewriteRuleSet.java:176)
	at com.facebook.presto.sql.planner.iterative.rule.RowExpressionRewriteRuleSet$ProjectRowExpressionRewrite.apply(RowExpressionRewriteRuleSet.java:155)
	at com.facebook.presto.sql.planner.iterative.IterativeOptimizer.transform(IterativeOptimizer.java:237)
	at com.facebook.presto.sql.planner.iterative.IterativeOptimizer.exploreNode(IterativeOptimizer.java:189)
	at com.facebook.presto.sql.planner.iterative.IterativeOptimizer.exploreGroup(IterativeOptimizer.java:151)
	at com.facebook.presto.sql.planner.iterative.IterativeOptimizer.exploreChildren(IterativeOptimizer.java:281)
	at com.facebook.presto.sql.planner.iterative.IterativeOptimizer.exploreGroup(IterativeOptimizer.java:153)
	at com.facebook.presto.sql.planner.iterative.IterativeOptimizer.exploreChildren(IterativeOptimizer.java:281)
	at com.facebook.presto.sql.planner.iterative.IterativeOptimizer.exploreGroup(IterativeOptimizer.java:153)
	at com.facebook.presto.sql.planner.iterative.IterativeOptimizer.exploreChildren(IterativeOptimizer.java:281)
	at com.facebook.presto.sql.planner.iterative.IterativeOptimizer.exploreGroup(IterativeOptimizer.java:153)
	at com.facebook.presto.sql.planner.iterative.IterativeOptimizer.exploreChildren(IterativeOptimizer.java:281)
	at com.facebook.presto.sql.planner.iterative.IterativeOptimizer.exploreGroup(IterativeOptimizer.java:153)
	at com.facebook.presto.sql.planner.iterative.IterativeOptimizer.optimize(IterativeOptimizer.java:138)
	at com.facebook.presto.sql.Optimizer.validateAndOptimizePlan(Optimizer.java:112)
	at com.facebook.presto.execution.SqlQueryExecution.lambda$doCreateLogicalPlanAndOptimize$5(SqlQueryExecution.java:589)
	at com.facebook.presto.common.RuntimeStats.recordWallAndCpuTime(RuntimeStats.java:158)
	at com.facebook.presto.execution.SqlQueryExecution.doCreateLogicalPlanAndOptimize(SqlQueryExecution.java:587)
	at com.facebook.presto.common.RuntimeStats.recordWallAndCpuTime(RuntimeStats.java:158)
	at com.facebook.presto.execution.SqlQueryExecution.createLogicalPlanAndOptimize(SqlQueryExecution.java:558)
	at com.facebook.presto.execution.SqlQueryExecution.start(SqlQueryExecution.java:486)
	at com.facebook.presto.$gen.Presto_null__testversion____20250521_201034_5.run(Unknown Source)
	at com.facebook.presto.execution.SqlQueryManager.createQuery(SqlQueryManager.java:320)
	at com.facebook.presto.dispatcher.LocalDispatchQuery.lambda$startExecution$8(LocalDispatchQuery.java:210)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Presto coordinator can not resolve implementation of CPP UDF functions

Another example would be whenever window queries encounter invalid frames, we create a failure function, which is failing too.

Impact

No impact

Test Plan

Test cases included

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

== RELEASE NOTES ==

Prestissimo (Native Execution)
* Replace using native functions with Java functions for creating failure functions when native execution is enabled.

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Mar 24, 2025
@pdabre12 pdabre12 changed the title Use built-in functions in function invoker Use Java built-in functions in function invoker Mar 25, 2025
@pdabre12 pdabre12 marked this pull request as ready for review March 25, 2025 19:40
@pdabre12 pdabre12 requested a review from presto-oss March 25, 2025 19:40
@prestodb-ci prestodb-ci requested review from a team, Dilli-Babu-Godari and namya28 and removed request for a team March 25, 2025 19:40
@pdabre12
Copy link
Contributor Author

@rschlussel @jaystarshot
Can you please take a look? Thanks.

@pdabre12 pdabre12 force-pushed the fix-failing-window-functions branch from d6a1294 to ece0b6f Compare May 21, 2025 19:42
@pdabre12 pdabre12 requested a review from a team as a code owner May 21, 2025 19:42
@pdabre12 pdabre12 changed the title Use Java built-in functions in function invoker Use Java built-in functions to create failure function May 21, 2025
@pdabre12 pdabre12 force-pushed the fix-failing-window-functions branch 2 times, most recently from 42f5a66 to 82c3b72 Compare May 21, 2025 20:42
@pdabre12 pdabre12 force-pushed the fix-failing-window-functions branch from 82c3b72 to 3a02c78 Compare May 21, 2025 20:43
@pdabre12
Copy link
Contributor Author

@tdcmeehan Can you please take a look?

@pdabre12 pdabre12 merged commit 675e65e into prestodb:master May 21, 2025
105 checks passed
@pdabre12 pdabre12 deleted the fix-failing-window-functions branch May 21, 2025 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
from:IBM PR from IBM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants