use of org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo in project asterixdb by apache.
the class BuiltinFunctions method addPrivateFunction.
public static void addPrivateFunction(FunctionIdentifier fi, IResultTypeComputer typeComputer, boolean isFunctional) {
IFunctionInfo functionInfo = new FunctionInfo(fi, isFunctional);
builtinPrivateFunctionsSet.put(functionInfo, functionInfo);
funTypeComputer.put(functionInfo, typeComputer);
registeredFunctions.put(fi, functionInfo);
}
use of org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo in project asterixdb by apache.
the class ExternalFunctionCompilerUtil method getExternalFunctionInfo.
public static IFunctionInfo getExternalFunctionInfo(MetadataTransactionContext txnCtx, Function function) throws MetadataException {
String functionKind = function.getKind();
IFunctionInfo finfo = null;
if (FunctionKind.SCALAR.toString().equalsIgnoreCase(functionKind)) {
finfo = getScalarFunctionInfo(txnCtx, function);
} else if (FunctionKind.AGGREGATE.toString().equalsIgnoreCase(functionKind)) {
finfo = getAggregateFunctionInfo(txnCtx, function);
} else if (FunctionKind.STATEFUL.toString().equalsIgnoreCase(functionKind)) {
finfo = getStatefulFunctionInfo(txnCtx, function);
} else if (FunctionKind.UNNEST.toString().equalsIgnoreCase(functionKind)) {
finfo = getUnnestFunctionInfo(txnCtx, function);
}
return finfo;
}
use of org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo in project asterixdb by apache.
the class DisjunctivePredicateToJoinRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider();
if (metadataProvider.isBlockingOperatorDisabled()) {
return false;
}
SelectOperator select;
if ((select = asSelectOperator(opRef)) == null) {
return false;
}
AbstractFunctionCallExpression condEx;
if ((condEx = asFunctionCallExpression(select.getCondition(), AlgebricksBuiltinFunctions.OR)) == null) {
return false;
}
List<Mutable<ILogicalExpression>> args = condEx.getArguments();
VariableReferenceExpression varEx = null;
IAType valType = null;
HashSet<AsterixConstantValue> values = new HashSet<AsterixConstantValue>();
for (Mutable<ILogicalExpression> arg : args) {
AbstractFunctionCallExpression fctCall;
if ((fctCall = asFunctionCallExpression(arg, AlgebricksBuiltinFunctions.EQ)) == null) {
return false;
}
boolean haveConst = false;
boolean haveVar = false;
List<Mutable<ILogicalExpression>> fctArgs = fctCall.getArguments();
for (Mutable<ILogicalExpression> fctArg : fctArgs) {
final ILogicalExpression argExpr = fctArg.getValue();
switch(argExpr.getExpressionTag()) {
case CONSTANT:
haveConst = true;
AsterixConstantValue value = (AsterixConstantValue) ((ConstantExpression) argExpr).getValue();
if (valType == null) {
valType = value.getObject().getType();
} else if (!isCompatible(valType, value.getObject().getType())) {
return false;
}
values.add(value);
break;
case VARIABLE:
haveVar = true;
final VariableReferenceExpression varArg = (VariableReferenceExpression) argExpr;
if (varEx == null) {
varEx = varArg;
} else if (!varEx.getVariableReference().equals(varArg.getVariableReference())) {
return false;
}
break;
default:
return false;
}
}
if (!(haveVar && haveConst)) {
return false;
}
}
AOrderedList list = new AOrderedList(new AOrderedListType(valType, "orderedlist"));
for (AsterixConstantValue value : values) {
list.add(value.getObject());
}
EmptyTupleSourceOperator ets = new EmptyTupleSourceOperator();
context.computeAndSetTypeEnvironmentForOperator(ets);
ILogicalExpression cExp = new ConstantExpression(new AsterixConstantValue(list));
Mutable<ILogicalExpression> mutCExp = new MutableObject<>(cExp);
IFunctionInfo scanFctInfo = BuiltinFunctions.getAsterixFunctionInfo(BuiltinFunctions.SCAN_COLLECTION);
UnnestingFunctionCallExpression scanExp = new UnnestingFunctionCallExpression(scanFctInfo, mutCExp);
LogicalVariable scanVar = context.newVar();
UnnestOperator unn = new UnnestOperator(scanVar, new MutableObject<>(scanExp));
unn.getInputs().add(new MutableObject<>(ets));
context.computeAndSetTypeEnvironmentForOperator(unn);
IFunctionInfo eqFctInfo = BuiltinFunctions.getAsterixFunctionInfo(AlgebricksBuiltinFunctions.EQ);
AbstractFunctionCallExpression eqExp = new ScalarFunctionCallExpression(eqFctInfo);
eqExp.getArguments().add(new MutableObject<>(new VariableReferenceExpression(scanVar)));
eqExp.getArguments().add(new MutableObject<>(varEx.cloneExpression()));
eqExp.getAnnotations().put(IndexedNLJoinExpressionAnnotation.INSTANCE, IndexedNLJoinExpressionAnnotation.INSTANCE);
BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
// Broadcast the OR predicates branch.
bcast.setObject(BroadcastExpressionAnnotation.BroadcastSide.LEFT);
eqExp.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
InnerJoinOperator jOp = new InnerJoinOperator(new MutableObject<>(eqExp));
jOp.getInputs().add(new MutableObject<>(unn));
jOp.getInputs().add(select.getInputs().get(0));
opRef.setValue(jOp);
context.computeAndSetTypeEnvironmentForOperator(jOp);
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo in project asterixdb by apache.
the class FunctionMapUtil method isCoreAggregateFunction.
/**
* Whether a function signature is a SQL++ core aggregate function.
*
* @param fs,
* the function signature.
* @return true if the function signature is a SQL++ core aggregate,
* false otherwise.
*/
public static boolean isCoreAggregateFunction(FunctionSignature fs) {
String name = fs.getName().toLowerCase();
boolean coreAgg = name.startsWith(CORE_AGGREGATE_PREFIX);
boolean coreSqlAgg = name.startsWith(CORE_SQL_AGGREGATE_PREFIX);
if (!coreAgg && !coreSqlAgg) {
return false;
}
String internalName = coreAgg ? name.substring(CORE_AGGREGATE_PREFIX.length()) : (INTERNAL_SQL_AGGREGATE_PREFIX + name.substring(CORE_SQL_AGGREGATE_PREFIX.length()));
IFunctionInfo finfo = FunctionUtil.getFunctionInfo(new FunctionIdentifier(FunctionConstants.ASTERIX_NS, internalName, fs.getArity()));
if (finfo == null) {
return false;
}
return BuiltinFunctions.getAggregateFunction(finfo.getFunctionIdentifier()) != null;
}
Aggregations