>From Ali Alsuliman <[email protected]>: Ali Alsuliman has submitted this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18723 )
Change subject: [ASTERIXDB-3487][COMP] Fix inlining UDFs in UnaryExpr/IndexAccessor ...................................................................... [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]> --- A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/inline-in-expr/inline-in-expr.03.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/user-defined-functions/inline-in-expr/inline-in-expr.03.adm A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/inline-in-expr/inline-in-expr.01.ddl.sqlpp M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java M asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/AbstractInlineUdfsVisitor.java M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/inline-in-expr/inline-in-expr.02.update.sqlpp 7 files changed, 128 insertions(+), 4 deletions(-) Approvals: Murtadha Hubail: Looks good to me, approved Ali Alsuliman: Looks good to me, but someone else must approve Jenkins: Verified Anon. E. Moose #1000171: 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 dabe327..acbd13e 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 @@ } 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 0000000..d930fc9 --- /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 0000000..22cfcc1 --- /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 0000000..5ae85ea --- /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 0000000..145a6e3 --- /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 66e47ba..5840787 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -13060,6 +13060,11 @@ </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> <expected-error>Cannot find dataset TweetMessages in dataverse experiments nor an alias with name TweetMessages</expected-error> 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 52775d3..0fcdc99 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 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 @@ @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 @@ 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); -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18723 To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: neo Gerrit-Change-Id: I88c1bd5b67633a609117d80e1e427fd108e323d7 Gerrit-Change-Number: 18723 Gerrit-PatchSet: 3 Gerrit-Owner: Ali Alsuliman <[email protected]> Gerrit-Reviewer: Ali Alsuliman <[email protected]> Gerrit-Reviewer: Anon. E. Moose #1000171 Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Michael Blow <[email protected]> Gerrit-Reviewer: Murtadha Hubail <[email protected]> Gerrit-Reviewer: Peeyush Gupta <[email protected]> Gerrit-MessageType: merged
