This is an automated email from the ASF dual-hosted git repository. mblow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit 0bfdff274edafb709434166d027bb5e6336bde7f Author: Ali Alsuliman <[email protected]> AuthorDate: Mon Aug 19 20:01:13 2024 -0700 [ASTERIXDB-3487][COMP] Fix inlining UDFs in UnaryExpr/IndexAccessor - user model changes: no - storage format changes: no - interface changes: no Details: Fix inlining UDFs in UnaryExpr/IndexAccessor. Ext-ref: MB-63232 Change-Id: I88c1bd5b67633a609117d80e1e427fd108e323d7 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18688 (cherry picked from commit cda30085fa50f25f812436599701cfcdfdc1c54b) Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18723 Tested-by: Jenkins <[email protected]> Reviewed-by: Ali Alsuliman <[email protected]> Reviewed-by: Murtadha Hubail <[email protected]> --- .../translator/LangExpressionToPlanTranslator.java | 3 +- .../inline-in-expr/inline-in-expr.01.ddl.sqlpp | 37 ++++++++++++++++++++++ .../inline-in-expr/inline-in-expr.02.update.sqlpp | 22 +++++++++++++ .../inline-in-expr/inline-in-expr.03.query.sqlpp | 25 +++++++++++++++ .../inline-in-expr/inline-in-expr.03.adm | 1 + .../test/resources/runtimets/testsuite_sqlpp.xml | 5 +++ .../common/visitor/AbstractInlineUdfsVisitor.java | 15 +++++++-- 7 files changed, 104 insertions(+), 4 deletions(-) diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java index dabe327f7a..acbd13e37e 100644 --- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java +++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java @@ -940,7 +940,8 @@ abstract class LangExpressionToPlanTranslator } if (!function.isExternal()) { // all non-external UDFs should've been inlined by now - throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, sourceLoc, signature); + throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, sourceLoc, + "UDF not inlined: " + signature); } IFunctionInfo finfo = ExternalFunctionCompilerUtil.getExternalFunctionInfo(metadataProvider, function); AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(finfo, args); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/inline-in-expr/inline-in-expr.01.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/inline-in-expr/inline-in-expr.01.ddl.sqlpp new file mode 100644 index 0000000000..d930fc9efb --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/inline-in-expr/inline-in-expr.01.ddl.sqlpp @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Description : Test inlining of UDFs + */ + +drop dataverse experiments if exists; +create dataverse experiments; +use experiments; + +create function fun1(...) { + args[0] + args[1] +}; + +create function fun2(...) { + args[0] - args[1] +}; + +CREATE TYPE openType AS {id: int}; +CREATE DATASET ds(openType) primary key id; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/inline-in-expr/inline-in-expr.02.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/inline-in-expr/inline-in-expr.02.update.sqlpp new file mode 100644 index 0000000000..22cfcc1ffc --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/inline-in-expr/inline-in-expr.02.update.sqlpp @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use experiments; + +UPSERT INTO ds {"id": 1, "a": 1, "b": 2, "c": [10,20,30,40], "d": [100,200,300,400]}; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/inline-in-expr/inline-in-expr.03.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/inline-in-expr/inline-in-expr.03.query.sqlpp new file mode 100644 index 0000000000..5ae85ea176 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/inline-in-expr/inline-in-expr.03.query.sqlpp @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +USE experiments; + +SELECT -fun1(ds.a, ds.b) AS x1, +ds.c[fun1(ds.a, ds.b)] AS x2, +ds.d[-fun2(ds.a, ds.b)] AS x3 +FROM ds; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/user-defined-functions/inline-in-expr/inline-in-expr.03.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/user-defined-functions/inline-in-expr/inline-in-expr.03.adm new file mode 100644 index 0000000000..145a6e3271 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/user-defined-functions/inline-in-expr/inline-in-expr.03.adm @@ -0,0 +1 @@ +{ "x1": -3, "x2": 40, "x3": 200 } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml index 66e47ba308..58407871eb 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -13059,6 +13059,11 @@ </test-case> </test-group> <test-group name="user-defined-functions"> + <test-case FilePath="user-defined-functions"> + <compilation-unit name="inline-in-expr"> + <output-dir compare="Text">inline-in-expr</output-dir> + </compilation-unit> + </test-case> <test-case FilePath="user-defined-functions"> <compilation-unit name="bad-function-ddl-1"> <output-dir compare="Text">bad-function-ddl-1</output-dir> diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/AbstractInlineUdfsVisitor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/AbstractInlineUdfsVisitor.java index 52775d3645..0fcdc99dbf 100644 --- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/AbstractInlineUdfsVisitor.java +++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/AbstractInlineUdfsVisitor.java @@ -153,7 +153,14 @@ public abstract class AbstractInlineUdfsVisitor extends AbstractQueryExpressionV public Boolean visit(IndexAccessor fa, Void arg) throws CompilationException { Pair<Boolean, Expression> p = inlineUdfsAndViewsInExpr(fa.getExpr()); fa.setExpr(p.second); - return p.first; + boolean inlined = p.first; + Expression indexExpr = fa.getIndexExpr(); + if (indexExpr != null) { + Pair<Boolean, Expression> p2 = inlineUdfsAndViewsInExpr(indexExpr); + fa.setIndexExpr(p2.second); + inlined |= p2.first; + } + return inlined; } @Override @@ -250,7 +257,9 @@ public abstract class AbstractInlineUdfsVisitor extends AbstractQueryExpressionV @Override public Boolean visit(UnaryExpr u, Void arg) throws CompilationException { - return u.getExpr().accept(this, arg); + Pair<Boolean, Expression> p = inlineUdfsAndViewsInExpr(u.getExpr()); + u.setExpr(p.second); + return p.first; } @Override @@ -270,7 +279,7 @@ public abstract class AbstractInlineUdfsVisitor extends AbstractQueryExpressionV if (returnExpression != null) { Pair<Boolean, Expression> rewrittenReturnExpr = inlineUdfsAndViewsInExpr(returnExpression); insert.setReturnExpression(rewrittenReturnExpr.second); - changed |= rewrittenReturnExpr.first; + changed = rewrittenReturnExpr.first; } Pair<Boolean, Expression> rewrittenBodyExpression = inlineUdfsAndViewsInExpr(insert.getBody()); insert.setBody(rewrittenBodyExpression.second);
