use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class SqlppQueryRewriter method inlineDeclaredUdfs.
protected void inlineDeclaredUdfs() throws CompilationException {
List<FunctionSignature> funIds = new ArrayList<FunctionSignature>();
for (FunctionDecl fdecl : declaredFunctions) {
funIds.add(fdecl.getSignature());
}
List<FunctionDecl> usedStoredFunctionDecls = new ArrayList<>();
for (Expression topLevelExpr : topExpr.getDirectlyEnclosedExpressions()) {
usedStoredFunctionDecls.addAll(FunctionUtil.retrieveUsedStoredFunctions(metadataProvider, topLevelExpr, funIds, null, expr -> getFunctionCalls(expr), func -> functionRepository.getFunctionDecl(func), signature -> FunctionMapUtil.normalizeBuiltinFunctionSignature(signature, false)));
}
declaredFunctions.addAll(usedStoredFunctionDecls);
if (!declaredFunctions.isEmpty()) {
SqlppInlineUdfsVisitor visitor = new SqlppInlineUdfsVisitor(context, new SqlppFunctionBodyRewriterFactory(), /* the rewriter for function bodies expressions*/
declaredFunctions, metadataProvider);
while (topExpr.accept(visitor, declaredFunctions)) {
// loop until no more changes
}
}
declaredFunctions.removeAll(usedStoredFunctionDecls);
}
use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class FunctionMapUtil method normalizedListInputFunctions.
/**
* Rewrites a variable-arg, user-surface function call into an internal, list-arg function.
*
* @param callExpr
* The input call expression.
* @return a new call expression that calls the corresponding AsterixDB internal function.
*/
public static CallExpr normalizedListInputFunctions(CallExpr callExpr) {
FunctionSignature fs = callExpr.getFunctionSignature();
String internalFuncName = LIST_INPUT_FUNCTION_MAP.get(fs.getName().toLowerCase());
if (internalFuncName == null) {
return callExpr;
}
callExpr.setFunctionSignature(new FunctionSignature(FunctionConstants.ASTERIX_NS, internalFuncName, 1));
callExpr.setExprList(new ArrayList<>(Collections.singletonList(new ListConstructor(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR, callExpr.getExprList()))));
return callExpr;
}
use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class ExpressionTypeComputer method getTypeForFunction.
private IAType getTypeForFunction(AbstractFunctionCallExpression expr, IVariableTypeEnvironment env, IMetadataProvider<?, ?> mp) throws AlgebricksException {
FunctionIdentifier fi = expr.getFunctionIdentifier();
// Note: built-in functions + udfs
IResultTypeComputer rtc;
FunctionSignature signature = new FunctionSignature(fi.getNamespace(), fi.getName(), fi.getArity());
if (BuiltinFunctions.isBuiltinCompilerFunction(signature, true)) {
rtc = BuiltinFunctions.getResultTypeComputer(fi);
} else {
rtc = ((ExternalFunctionInfo) expr.getFunctionInfo()).getResultTypeComputer();
}
if (rtc == null) {
throw new AlgebricksException("Type computer missing for " + fi);
}
return rtc.computeType(expr, env, mp);
}
use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class FunctionSignatures method get.
public FunctionSignature get(String dataverse, String name, int arity) {
FunctionSignature fid = new FunctionSignature(dataverse, name, arity);
FunctionExpressionMap possibleFD = functionMap.get(fid);
if (possibleFD == null) {
return null;
} else {
return possibleFD.get(arity);
}
}
use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class FeedConnectionTupleTranslator method createFeedConnFromRecord.
private FeedConnection createFeedConnFromRecord(ARecord feedConnRecord) {
String dataverseName = ((AString) feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_DATAVERSE_NAME_FIELD_INDEX)).getStringValue();
String feedName = ((AString) feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_FEED_NAME_FIELD_INDEX)).getStringValue();
String datasetName = ((AString) feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_DATASET_NAME_FIELD_INDEX)).getStringValue();
String outputType = ((AString) feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_OUTPUT_TYPE_INDEX)).getStringValue();
String policyName = ((AString) feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_POLICY_FIELD_INDEX)).getStringValue();
ArrayList<FunctionSignature> appliedFunctions = null;
Object o = feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_APPLIED_FUNCTIONS_FIELD_INDEX);
IACursor cursor;
if (!(o instanceof ANull) && !(o instanceof AMissing)) {
appliedFunctions = new ArrayList<>();
FunctionSignature functionSignature;
cursor = ((AUnorderedList) feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_APPLIED_FUNCTIONS_FIELD_INDEX)).getCursor();
while (cursor.next()) {
//TODO: allow different arity
functionSignature = new FunctionSignature(dataverseName, ((AString) cursor.get()).getStringValue(), 1);
appliedFunctions.add(functionSignature);
}
}
return new FeedConnection(dataverseName, feedName, datasetName, appliedFunctions, policyName, outputType);
}
Aggregations