Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C2364200B99 for ; Wed, 21 Sep 2016 03:21:59 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C095D160AC9; Wed, 21 Sep 2016 01:21:59 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 58D14160AC5 for ; Wed, 21 Sep 2016 03:21:58 +0200 (CEST) Received: (qmail 72885 invoked by uid 500); 21 Sep 2016 01:21:57 -0000 Mailing-List: contact notifications-help@asterixdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@asterixdb.apache.org Delivered-To: mailing list notifications@asterixdb.apache.org Received: (qmail 72876 invoked by uid 99); 21 Sep 2016 01:21:57 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Sep 2016 01:21:57 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 2107D1805DB for ; Wed, 21 Sep 2016 01:21:57 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.919 X-Spam-Level: X-Spam-Status: No, score=0.919 tagged_above=-999 required=6.31 tests=[SPF_FAIL=0.919] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id Wul4R5KLW8Wp for ; Wed, 21 Sep 2016 01:21:52 +0000 (UTC) Received: from unhygienix.ics.uci.edu (unhygienix.ics.uci.edu [128.195.14.130]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with ESMTP id 624FA5F177 for ; Wed, 21 Sep 2016 01:21:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by unhygienix.ics.uci.edu (Postfix) with ESMTP id DF959241DB9; Tue, 20 Sep 2016 18:21:51 -0700 (PDT) Date: Tue, 20 Sep 2016 18:21:51 -0700 From: "Yingyi Bu (Code Review)" Message-ID: Reply-To: buyingyi@gmail.com X-Gerrit-MessageType: newchange Subject: Change in asterixdb[master]: ASTERIXDB-1652: fix dataverse.function(...) to check the exi... X-Gerrit-Change-Id: I7779db56f540fdd645bb85c769baeaa37f620a0d X-Gerrit-ChangeURL: X-Gerrit-Commit: d94292d098c2381bf33d31473ab1d2f8e79531f1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Disposition: inline User-Agent: Gerrit/2.8.4 To: undisclosed-recipients:; archived-at: Wed, 21 Sep 2016 01:21:59 -0000 Yingyi Bu has uploaded a new change for review. https://asterix-gerrit.ics.uci.edu/1192 Change subject: ASTERIXDB-1652: fix dataverse.function(...) to check the existence of the dataverse. ...................................................................... ASTERIXDB-1652: fix dataverse.function(...) to check the existence of the dataverse. Change-Id: I7779db56f540fdd645bb85c769baeaa37f620a0d --- M asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/binary_null/binary_null.1.query.sqlpp M asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/int64_missing/int64_missing.1.query.sqlpp M asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/int64_null/int64_null.1.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/query-ASTERIXDB-1652/query-ASTERIXDB-1652.1.query.sqlpp M asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/comparison/binary_null/binary_null.1.ast M asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/comparison/int64_null/int64_null.1.ast M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml M asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlQueryRewriter.java M asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java M asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java M asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java 11 files changed, 143 insertions(+), 136 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/92/1192/1 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/binary_null/binary_null.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/binary_null/binary_null.1.query.sqlpp index 6b7441e..0377995 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/binary_null/binary_null.1.query.sqlpp +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/binary_null/binary_null.1.query.sqlpp @@ -18,4 +18,4 @@ */ -{'result1':(test.hex('AA') > null),'result2':(null >= test.hex('AA')),'result3':(test.hex('AA') < null),'result4':(null <= test.hex('AA')),'result5':(test.hex('AA') = null),'result6':(null != test.hex('AA'))}; +{'result1':(hex('AA') > null),'result2':(null >= hex('AA')),'result3':(hex('AA') < null),'result4':(null <= hex('AA')),'result5':(hex('AA') = null),'result6':(null != hex('AA'))}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/int64_missing/int64_missing.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/int64_missing/int64_missing.1.query.sqlpp index 320ef99..74e25a7 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/int64_missing/int64_missing.1.query.sqlpp +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/int64_missing/int64_missing.1.query.sqlpp @@ -18,4 +18,4 @@ */ -{'result1':(test.int64('3') > missing),'result2':(missing >= test.int64('3')),'result3':(test.int64('3') < missing),'result4':(missing <= test.int64('3')),'result5':(test.int64('3') = missing),'result6':(missing != test.int64('3'))}; +{'result1':(int64('3') > missing),'result2':(missing >= int64('3')),'result3':(int64('3') < missing),'result4':(missing <= int64('3')),'result5':(int64('3') = missing),'result6':(missing != int64('3'))}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/int64_null/int64_null.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/int64_null/int64_null.1.query.sqlpp index 2af586e..a6a2163 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/int64_null/int64_null.1.query.sqlpp +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/int64_null/int64_null.1.query.sqlpp @@ -17,4 +17,4 @@ * under the License. */ -{'result1':(test.int64('3') > null),'result2':(null >= test.int64('3')),'result3':(test.int64('3') < null),'result4':(null <= test.int64('3')),'result5':(test.int64('3') = null),'result6':(null != test.int64('3'))}; +{'result1':(int64('3') > null),'result2':(null >= int64('3')),'result3':(int64('3') < null),'result4':(null <= int64('3')),'result5':(int64('3') = null),'result6':(null != int64('3'))}; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/query-ASTERIXDB-1652/query-ASTERIXDB-1652.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/query-ASTERIXDB-1652/query-ASTERIXDB-1652.1.query.sqlpp new file mode 100644 index 0000000..650889c --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/user-defined-functions/query-ASTERIXDB-1652/query-ASTERIXDB-1652.1.query.sqlpp @@ -0,0 +1,20 @@ +/* + * 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. + */ + +test.length("test"); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/comparison/binary_null/binary_null.1.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/comparison/binary_null/binary_null.1.ast index 3df4327..ee79f0c 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/comparison/binary_null/binary_null.1.ast +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/comparison/binary_null/binary_null.1.ast @@ -4,7 +4,7 @@ LiteralExpr [STRING] [result1] : OperatorExpr [ - FunctionCall test.hex@1[ + FunctionCall null.hex@1[ LiteralExpr [STRING] [AA] ] > @@ -17,7 +17,7 @@ OperatorExpr [ LiteralExpr [NULL] >= - FunctionCall test.hex@1[ + FunctionCall null.hex@1[ LiteralExpr [STRING] [AA] ] ] @@ -26,7 +26,7 @@ LiteralExpr [STRING] [result3] : OperatorExpr [ - FunctionCall test.hex@1[ + FunctionCall null.hex@1[ LiteralExpr [STRING] [AA] ] < @@ -39,7 +39,7 @@ OperatorExpr [ LiteralExpr [NULL] <= - FunctionCall test.hex@1[ + FunctionCall null.hex@1[ LiteralExpr [STRING] [AA] ] ] @@ -48,7 +48,7 @@ LiteralExpr [STRING] [result5] : OperatorExpr [ - FunctionCall test.hex@1[ + FunctionCall null.hex@1[ LiteralExpr [STRING] [AA] ] = @@ -61,7 +61,7 @@ OperatorExpr [ LiteralExpr [NULL] != - FunctionCall test.hex@1[ + FunctionCall null.hex@1[ LiteralExpr [STRING] [AA] ] ] diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/comparison/int64_null/int64_null.1.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/comparison/int64_null/int64_null.1.ast index d1a8791..0866ec0 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/comparison/int64_null/int64_null.1.ast +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/comparison/int64_null/int64_null.1.ast @@ -4,7 +4,7 @@ LiteralExpr [STRING] [result1] : OperatorExpr [ - FunctionCall test.int64@1[ + FunctionCall null.int64@1[ LiteralExpr [STRING] [3] ] > @@ -17,7 +17,7 @@ OperatorExpr [ LiteralExpr [NULL] >= - FunctionCall test.int64@1[ + FunctionCall null.int64@1[ LiteralExpr [STRING] [3] ] ] @@ -26,7 +26,7 @@ LiteralExpr [STRING] [result3] : OperatorExpr [ - FunctionCall test.int64@1[ + FunctionCall null.int64@1[ LiteralExpr [STRING] [3] ] < @@ -39,7 +39,7 @@ OperatorExpr [ LiteralExpr [NULL] <= - FunctionCall test.int64@1[ + FunctionCall null.int64@1[ LiteralExpr [STRING] [3] ] ] @@ -48,7 +48,7 @@ LiteralExpr [STRING] [result5] : OperatorExpr [ - FunctionCall test.int64@1[ + FunctionCall null.int64@1[ LiteralExpr [STRING] [3] ] = @@ -61,7 +61,7 @@ OperatorExpr [ LiteralExpr [NULL] != - FunctionCall test.int64@1[ + FunctionCall null.int64@1[ LiteralExpr [STRING] [3] ] ] 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 a2bc4ce..a2687b0 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -7002,6 +7002,12 @@ + + Dataverse test cannot be found for function call test.length! + query-issue218-2 + + + query-issue218-2 diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlQueryRewriter.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlQueryRewriter.java index 5edc521..84625db 100644 --- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlQueryRewriter.java +++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlQueryRewriter.java @@ -34,8 +34,8 @@ import org.apache.asterix.lang.aql.visitor.base.IAQLVisitor; import org.apache.asterix.lang.common.base.Clause; import org.apache.asterix.lang.common.base.Expression; -import org.apache.asterix.lang.common.base.Expression.Kind; import org.apache.asterix.lang.common.base.IQueryRewriter; +import org.apache.asterix.lang.common.base.Expression.Kind; import org.apache.asterix.lang.common.clause.GroupbyClause; import org.apache.asterix.lang.common.clause.LetClause; import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair; @@ -46,11 +46,7 @@ import org.apache.asterix.lang.common.struct.VarIdentifier; import org.apache.asterix.lang.common.util.FunctionUtil; import org.apache.asterix.lang.common.visitor.GatherFunctionCallsVisitor; -import org.apache.asterix.metadata.MetadataManager; -import org.apache.asterix.metadata.MetadataTransactionContext; import org.apache.asterix.metadata.declared.AqlMetadataProvider; -import org.apache.asterix.metadata.entities.Function; -import org.apache.asterix.om.functions.AsterixBuiltinFunctions; class AqlQueryRewriter implements IQueryRewriter { @@ -58,7 +54,6 @@ private Query topExpr; private List declaredFunctions; private LangRewritingContext context; - private MetadataTransactionContext mdTxnCtx; private AqlMetadataProvider metadataProvider; private void setup(List declaredFunctions, Query topExpr, AqlMetadataProvider metadataProvider, @@ -66,7 +61,6 @@ this.topExpr = topExpr; this.context = context; this.declaredFunctions = declaredFunctions; - this.mdTxnCtx = metadataProvider.getMetadataTxnContext(); this.metadataProvider = metadataProvider; } @@ -109,7 +103,8 @@ } List otherFDecls = new ArrayList(); - buildOtherUdfs(topExpr.getBody(), otherFDecls, funIds); + FunctionUtil.buildInternalUdfs(metadataProvider, topExpr.getBody(), otherFDecls, funIds, + expr -> getFunctionCalls(expr), func -> functionParser.getFunctionDecl(func), null); declaredFunctions.addAll(otherFDecls); if (!declaredFunctions.isEmpty()) { AQLInlineUdfsVisitor visitor = @@ -119,58 +114,6 @@ } } declaredFunctions.removeAll(otherFDecls); - } - - private void buildOtherUdfs(Expression expression, List functionDecls, - List declaredFunctions) throws AsterixException { - if (expression == null) { - return; - } - String value = metadataProvider.getConfig().get(FunctionUtil.IMPORT_PRIVATE_FUNCTIONS); - boolean includePrivateFunctions = (value != null) ? Boolean.valueOf(value.toLowerCase()) : false; - Set functionCalls = getFunctionCalls(expression); - for (FunctionSignature signature : functionCalls) { - - if (declaredFunctions != null && declaredFunctions.contains(signature)) { - continue; - } - - Function function = lookupUserDefinedFunctionDecl(signature); - if (function == null) { - if (AsterixBuiltinFunctions.isBuiltinCompilerFunction(signature, includePrivateFunctions)) { - continue; - } - StringBuilder messageBuilder = new StringBuilder(); - if (functionDecls.size() > 0) { - messageBuilder.append("function " + functionDecls.get(functionDecls.size() - 1).getSignature() - + " depends upon function " + signature + " which is undefined"); - } else { - messageBuilder.append("function " + signature + " is undefined "); - } - throw new AsterixException(messageBuilder.toString()); - } - - if (function.getLanguage().equalsIgnoreCase(Function.LANGUAGE_AQL)) { - FunctionDecl functionDecl = functionParser.getFunctionDecl(function); - if (functionDecl != null) { - if (functionDecls.contains(functionDecl)) { - throw new AsterixException( - "Recursive invocation " + functionDecls.get(functionDecls.size() - 1).getSignature() - + " <==> " + functionDecl.getSignature()); - } - functionDecls.add(functionDecl); - buildOtherUdfs(functionDecl.getFuncBody(), functionDecls, declaredFunctions); - } - } - } - - } - - private Function lookupUserDefinedFunctionDecl(FunctionSignature signature) throws AsterixException { - if (signature.getNamespace() == null) { - return null; - } - return MetadataManager.INSTANCE.getFunction(mdTxnCtx, signature); } private Set getFunctionCalls(Expression expression) throws AsterixException { diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java index acd40d7..cfe5857 100644 --- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java +++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java @@ -19,7 +19,18 @@ package org.apache.asterix.lang.common.util; +import java.util.List; +import java.util.Set; + +import org.apache.asterix.common.exceptions.AsterixException; +import org.apache.asterix.common.functions.FunctionConstants; import org.apache.asterix.common.functions.FunctionSignature; +import org.apache.asterix.lang.common.base.Expression; +import org.apache.asterix.lang.common.statement.FunctionDecl; +import org.apache.asterix.metadata.MetadataManager; +import org.apache.asterix.metadata.MetadataTransactionContext; +import org.apache.asterix.metadata.declared.AqlMetadataProvider; +import org.apache.asterix.metadata.entities.Function; import org.apache.asterix.om.functions.AsterixBuiltinFunctions; import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; import org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo; @@ -36,4 +47,82 @@ return getFunctionInfo(new FunctionIdentifier(fs.getNamespace(), fs.getName(), fs.getArity())); } + @FunctionalInterface + public interface IFunctionCollector { + Set getFunctionCalls(Expression expression) throws AsterixException; + } + + @FunctionalInterface + public interface IFunctionParser { + FunctionDecl getFunctionDecl(Function function) throws AsterixException; + } + + @FunctionalInterface + public interface IFunctionNormalizer { + FunctionSignature normalizeBuiltinFunctionSignature(FunctionSignature fs) throws AsterixException; + } + + public static void buildInternalUdfs(AqlMetadataProvider metadataProvider, Expression expression, + List functionDecls, List declaredFunctions, + IFunctionCollector functionCollector, IFunctionParser functionParser, + IFunctionNormalizer functionNormalizer) throws AsterixException { + if (expression == null) { + return; + } + String value = metadataProvider.getConfig().get(FunctionUtil.IMPORT_PRIVATE_FUNCTIONS); + boolean includePrivateFunctions = (value != null) ? Boolean.valueOf(value.toLowerCase()) : false; + Set functionCalls = functionCollector.getFunctionCalls(expression); + for (FunctionSignature signature : functionCalls) { + if (declaredFunctions != null && declaredFunctions.contains(signature)) { + continue; + } + String dataverseName = signature.getNamespace() == null ? metadataProvider.getDefaultDataverseName() + : signature.getNamespace(); + if (metadataProvider.findDataverse(dataverseName) == null + && !dataverseName.equals(FunctionConstants.ASTERIX_NS)) { + throw new AsterixException("Dataverse " + dataverseName + " cannot be found for function call " + + dataverseName + "." + signature.getName() + "!"); + } + Function function = lookupUserDefinedFunctionDecl(metadataProvider.getMetadataTxnContext(), signature); + if (function == null) { + FunctionSignature normalizedSignature = functionNormalizer == null ? signature + : functionNormalizer.normalizeBuiltinFunctionSignature(signature); + if (AsterixBuiltinFunctions.isBuiltinCompilerFunction(normalizedSignature, includePrivateFunctions)) { + continue; + } + StringBuilder messageBuilder = new StringBuilder(); + if (functionDecls.size() > 0) { + messageBuilder.append("function " + functionDecls.get(functionDecls.size() - 1).getSignature() + + " depends upon function " + signature + " which is undefined"); + } else { + messageBuilder.append("function " + signature + " is undefined "); + } + throw new AsterixException(messageBuilder.toString()); + } + + if (function.getLanguage().equalsIgnoreCase(Function.LANGUAGE_AQL)) { + FunctionDecl functionDecl = functionParser.getFunctionDecl(function); + if (functionDecl != null) { + if (functionDecls.contains(functionDecl)) { + throw new AsterixException( + "Recursive invocation " + functionDecls.get(functionDecls.size() - 1).getSignature() + + " <==> " + functionDecl.getSignature()); + } + functionDecls.add(functionDecl); + buildInternalUdfs(metadataProvider, functionDecl.getFuncBody(), functionDecls, declaredFunctions, + functionCollector, functionParser, functionNormalizer); + } + } + } + + } + + private static Function lookupUserDefinedFunctionDecl(MetadataTransactionContext mdTxnCtx, + FunctionSignature signature) throws AsterixException { + if (signature.getNamespace() == null) { + return null; + } + return MetadataManager.INSTANCE.getFunction(mdTxnCtx, signature); + } + } diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java index dd79969..d9c6260 100644 --- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java +++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java @@ -65,11 +65,8 @@ import org.apache.asterix.lang.sqlpp.struct.SetOperationRight; import org.apache.asterix.lang.sqlpp.util.FunctionMapUtil; import org.apache.asterix.lang.sqlpp.visitor.base.ISqlppVisitor; -import org.apache.asterix.metadata.MetadataManager; import org.apache.asterix.metadata.MetadataTransactionContext; import org.apache.asterix.metadata.declared.AqlMetadataProvider; -import org.apache.asterix.metadata.entities.Function; -import org.apache.asterix.om.functions.AsterixBuiltinFunctions; class SqlppQueryRewriter implements IQueryRewriter { private static final String INLINE_WITH = "inline_with"; @@ -260,7 +257,9 @@ } List otherFDecls = new ArrayList(); - buildOtherUdfs(topExpr.getBody(), otherFDecls, funIds); + FunctionUtil.buildInternalUdfs(metadataProvider, topExpr.getBody(), otherFDecls, funIds, + expr -> getFunctionCalls(expr), func -> functionRepository.getFunctionDecl(func), + signature -> FunctionMapUtil.normalizeBuiltinFunctionSignature(signature, false)); declaredFunctions.addAll(otherFDecls); if (!declaredFunctions.isEmpty()) { SqlppInlineUdfsVisitor visitor = new SqlppInlineUdfsVisitor(context, @@ -271,60 +270,6 @@ } } declaredFunctions.removeAll(otherFDecls); - } - - protected void buildOtherUdfs(Expression expression, List functionDecls, - List declaredFunctions) throws AsterixException { - if (expression == null) { - return; - } - String value = metadataProvider.getConfig().get(FunctionUtil.IMPORT_PRIVATE_FUNCTIONS); - boolean includePrivateFunctions = (value != null) ? Boolean.valueOf(value.toLowerCase()) : false; - Set functionCalls = getFunctionCalls(expression); - for (FunctionSignature signature : functionCalls) { - - if (declaredFunctions != null && declaredFunctions.contains(signature)) { - continue; - } - - Function function = lookupUserDefinedFunctionDecl(signature); - if (function == null) { - FunctionSignature normalizedSignature = - FunctionMapUtil.normalizeBuiltinFunctionSignature(signature, false); - if (AsterixBuiltinFunctions.isBuiltinCompilerFunction(normalizedSignature, includePrivateFunctions)) { - continue; - } - StringBuilder messageBuilder = new StringBuilder(); - if (functionDecls.size() > 0) { - messageBuilder.append("function " + functionDecls.get(functionDecls.size() - 1).getSignature() - + " depends upon function " + signature + " which is undefined"); - } else { - messageBuilder.append("function " + signature + " is undefined "); - } - throw new AsterixException(messageBuilder.toString()); - } - - if (function.getLanguage().equalsIgnoreCase(Function.LANGUAGE_AQL)) { - FunctionDecl functionDecl = functionRepository.getFunctionDecl(function); - if (functionDecl != null) { - if (functionDecls.contains(functionDecl)) { - throw new AsterixException( - "Recursive invocation " + functionDecls.get(functionDecls.size() - 1).getSignature() - + " <==> " + functionDecl.getSignature()); - } - functionDecls.add(functionDecl); - buildOtherUdfs(functionDecl.getFuncBody(), functionDecls, declaredFunctions); - } - } - } - - } - - private Function lookupUserDefinedFunctionDecl(FunctionSignature signature) throws AsterixException { - if (signature.getNamespace() == null) { - return null; - } - return MetadataManager.INSTANCE.getFunction(mdTxnCtx, signature); } private Set getFunctionCalls(Expression expression) throws AsterixException { diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java index 41a843f..29087ba 100644 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java @@ -26,10 +26,10 @@ import java.util.Map; import org.apache.asterix.common.config.AsterixStorageProperties; +import org.apache.asterix.common.config.GlobalConfig; import org.apache.asterix.common.config.DatasetConfig.DatasetType; import org.apache.asterix.common.config.DatasetConfig.ExternalFilePendingOp; import org.apache.asterix.common.config.DatasetConfig.IndexType; -import org.apache.asterix.common.config.GlobalConfig; import org.apache.asterix.common.context.AsterixVirtualBufferCacheProvider; import org.apache.asterix.common.context.ITransactionSubsystemProvider; import org.apache.asterix.common.context.TransactionSubsystemProvider; @@ -42,8 +42,8 @@ import org.apache.asterix.common.ioopcallbacks.LSMInvertedIndexIOOperationCallbackFactory; import org.apache.asterix.common.ioopcallbacks.LSMRTreeIOOperationCallbackFactory; import org.apache.asterix.common.library.ILibraryManager; -import org.apache.asterix.common.transactions.IRecoveryManager.ResourceType; import org.apache.asterix.common.transactions.JobId; +import org.apache.asterix.common.transactions.IRecoveryManager.ResourceType; import org.apache.asterix.common.utils.StoragePathUtil; import org.apache.asterix.dataflow.data.nontagged.valueproviders.AqlPrimitiveValueProviderFactory; import org.apache.asterix.external.adapter.factory.LookupAdapterFactory; @@ -92,8 +92,8 @@ import org.apache.asterix.runtime.operators.AsterixLSMInvertedIndexUpsertOperatorDescriptor; import org.apache.asterix.runtime.operators.AsterixLSMTreeUpsertOperatorDescriptor; import org.apache.asterix.runtime.util.AsterixAppContextInfo; -import org.apache.asterix.runtime.util.ClusterStateManager; import org.apache.asterix.runtime.util.AsterixRuntimeComponentsProvider; +import org.apache.asterix.runtime.util.ClusterStateManager; import org.apache.asterix.transaction.management.opcallbacks.LockThenSearchOperationCallbackFactory; import org.apache.asterix.transaction.management.opcallbacks.PrimaryIndexInstantSearchOperationCallbackFactory; import org.apache.asterix.transaction.management.opcallbacks.PrimaryIndexModificationOperationCallbackFactory; @@ -417,6 +417,10 @@ return format; } + public Dataverse findDataverse(String dataverseName) throws AsterixException { + return MetadataManager.INSTANCE.getDataverse(mdTxnCtx, dataverseName); + } + public Triple buildFeedIntakeRuntime( JobSpecification jobSpec, Feed primaryFeed, FeedPolicyAccessor policyAccessor) throws Exception { Triple factoryOutput; -- To view, visit https://asterix-gerrit.ics.uci.edu/1192 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7779db56f540fdd645bb85c769baeaa37f620a0d Gerrit-PatchSet: 1 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Yingyi Bu