use of org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier in project asterixdb by apache.
the class LangExpressionToPlanTranslator method createComparisonExpression.
protected AbstractFunctionCallExpression createComparisonExpression(OperatorType t) {
FunctionIdentifier fi = operatorTypeToFunctionIdentifier(t);
IFunctionInfo finfo = FunctionUtil.getFunctionInfo(fi);
return new ScalarFunctionCallExpression(finfo);
}
use of org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier in project asterixdb by apache.
the class LangExpressionToPlanTranslator method visit.
@Override
public Pair<ILogicalOperator, LogicalVariable> visit(ListConstructor lc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
FunctionIdentifier fid = (lc.getType() == ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR) ? BuiltinFunctions.ORDERED_LIST_CONSTRUCTOR : BuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR;
AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(fid));
LogicalVariable v1 = context.newVar();
AssignOperator a = new AssignOperator(v1, new MutableObject<>(f));
Mutable<ILogicalOperator> topOp = tupSource;
for (Expression expr : lc.getExprList()) {
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(expr, topOp);
f.getArguments().add(new MutableObject<>(eo.first));
topOp = eo.second;
}
a.getInputs().add(topOp);
return new Pair<>(a, v1);
}
use of org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier 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.hyracks.algebricks.core.algebra.functions.FunctionIdentifier in project asterixdb by apache.
the class ExtractFunctionsFromJoinConditionRule method assignFunctionExpressions.
private boolean assignFunctionExpressions(AbstractLogicalOperator joinOp, ILogicalExpression expr, IOptimizationContext context) throws AlgebricksException {
if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return false;
}
AbstractFunctionCallExpression fexp = (AbstractFunctionCallExpression) expr;
FunctionIdentifier fi = fexp.getFunctionIdentifier();
boolean modified = false;
if (fi.equals(AlgebricksBuiltinFunctions.AND) || fi.equals(AlgebricksBuiltinFunctions.OR) || processArgumentsToFunction(fi)) {
for (Mutable<ILogicalExpression> a : fexp.getArguments()) {
if (assignFunctionExpressions(joinOp, a.getValue(), context)) {
modified = true;
}
}
return modified;
} else if (AlgebricksBuiltinFunctions.isComparisonFunction(fi) || isComparisonFunction(fi)) {
for (Mutable<ILogicalExpression> exprRef : fexp.getArguments()) {
if (exprRef.getValue().getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
LogicalVariable newVar = context.newVar();
AssignOperator newAssign = new AssignOperator(newVar, new MutableObject<ILogicalExpression>(exprRef.getValue().cloneExpression()));
newAssign.setExecutionMode(joinOp.getExecutionMode());
// Place assign below joinOp.
List<LogicalVariable> used = new ArrayList<LogicalVariable>();
VariableUtilities.getUsedVariables(newAssign, used);
Mutable<ILogicalOperator> leftBranchRef = joinOp.getInputs().get(0);
ILogicalOperator leftBranch = leftBranchRef.getValue();
List<LogicalVariable> leftBranchVariables = new ArrayList<LogicalVariable>();
VariableUtilities.getLiveVariables(leftBranch, leftBranchVariables);
if (leftBranchVariables.containsAll(used)) {
// place assign on left branch
newAssign.getInputs().add(new MutableObject<ILogicalOperator>(leftBranch));
leftBranchRef.setValue(newAssign);
modified = true;
} else {
Mutable<ILogicalOperator> rightBranchRef = joinOp.getInputs().get(1);
ILogicalOperator rightBranch = rightBranchRef.getValue();
List<LogicalVariable> rightBranchVariables = new ArrayList<LogicalVariable>();
VariableUtilities.getLiveVariables(rightBranch, rightBranchVariables);
if (rightBranchVariables.containsAll(used)) {
// place assign on right branch
newAssign.getInputs().add(new MutableObject<ILogicalOperator>(rightBranch));
rightBranchRef.setValue(newAssign);
modified = true;
}
}
if (modified) {
// Replace original expr with variable reference.
exprRef.setValue(new VariableReferenceExpression(newVar));
context.computeAndSetTypeEnvironmentForOperator(newAssign);
context.computeAndSetTypeEnvironmentForOperator(joinOp);
}
}
}
return modified;
} else {
return false;
}
}
use of org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier in project asterixdb by apache.
the class FullTextContainsParameterCheckRule method checkParamter.
/**
* Check the correctness of the parameters of the ftcontains(). Also rearrange options as arguments.
* The expected form of ftcontains() is ftcontains(expression1, expression2, parameters as a record).
*/
private boolean checkParamter(ILogicalOperator op, Mutable<ILogicalExpression> exprRef, IOptimizationContext context) throws AlgebricksException {
ILogicalExpression expr = exprRef.getValue();
if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return false;
}
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
FunctionIdentifier fi = funcExpr.getFunctionIdentifier();
// Collects the correct number of arguments - it can be 2 if a user doesn't provide any option.
int numberOfCorrectArguments = 0;
String functionName = "";
if (fi == BuiltinFunctions.FULLTEXT_CONTAINS) {
numberOfCorrectArguments = FULLTEXT_QUERY_WITH_OPTION_NO_OF_ARGUMENTS;
functionName = BuiltinFunctions.FULLTEXT_CONTAINS.getName();
} else if (fi == BuiltinFunctions.FULLTEXT_CONTAINS_WO_OPTION) {
numberOfCorrectArguments = FULLTEXT_QUERY_WITHOUT_OPTION_NO_OF_ARGUMENTS;
functionName = BuiltinFunctions.FULLTEXT_CONTAINS_WO_OPTION.getName();
}
// If numberOfCorrectArguments is greater than zero, then this is a full-text search query.
if (numberOfCorrectArguments > 0) {
// Don't need to check this operator again.
context.addToDontApplySet(this, op);
List<Mutable<ILogicalExpression>> oldExprs = funcExpr.getArguments();
List<Mutable<ILogicalExpression>> newExprs = new ArrayList<>();
// The number of parameters should be three: exp1, exp2, and the option
if (oldExprs.size() != numberOfCorrectArguments) {
throw new AlgebricksException(functionName + " should have " + numberOfCorrectArguments + " parameters.");
}
// The last expression before the option needs to be copied first.
for (int i = 0; i <= LAST_EXPRESSION_POS_BEFORE_OPTION; i++) {
newExprs.add(new MutableObject<ILogicalExpression>((ILogicalExpression) oldExprs.get(i).getValue()));
}
// Sanity check for the types of the first two parameters
checkFirstAndSecondParamter(oldExprs, functionName);
// Checks and transforms the actual full-text parameters.
if (numberOfCorrectArguments == FULLTEXT_QUERY_WITH_OPTION_NO_OF_ARGUMENTS) {
checkValueForThirdParameter(oldExprs.get(2), newExprs);
} else {
// no option provided case: sets the default option here.
setDefaultValueForThirdParameter(newExprs);
}
// Resets the last argument.
funcExpr.getArguments().clear();
funcExpr.getArguments().addAll(newExprs);
return true;
}
return false;
}
Aggregations