use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.
the class LangExpressionToPlanTranslator method visit.
@Override
public Pair<ILogicalOperator, LogicalVariable> visit(RecordConstructor rc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR));
LogicalVariable v1 = context.newVar();
AssignOperator a = new AssignOperator(v1, new MutableObject<>(f));
Mutable<ILogicalOperator> topOp = tupSource;
for (FieldBinding fb : rc.getFbList()) {
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = langExprToAlgExpression(fb.getLeftExpr(), topOp);
f.getArguments().add(new MutableObject<>(eo1.first));
topOp = eo1.second;
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = langExprToAlgExpression(fb.getRightExpr(), topOp);
f.getArguments().add(new MutableObject<>(eo2.first));
topOp = eo2.second;
}
a.getInputs().add(topOp);
return new Pair<>(a, v1);
}
use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.
the class SqlppExpressionToPlanTranslator method generateUnnestForBinaryCorrelateRightBranch.
private Pair<ILogicalOperator, LogicalVariable> generateUnnestForBinaryCorrelateRightBranch(AbstractBinaryCorrelateClause binaryCorrelate, Mutable<ILogicalOperator> inputOpRef, boolean innerUnnest) throws CompilationException {
LogicalVariable rightVar = context.newVarFromExpression(binaryCorrelate.getRightVariable());
Expression rightExpr = binaryCorrelate.getRightExpression();
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(rightExpr, inputOpRef);
ILogicalOperator unnestOp;
if (binaryCorrelate.hasPositionalVariable()) {
LogicalVariable pVar = context.newVarFromExpression(binaryCorrelate.getPositionalVariable());
// We set the positional variable type as BIGINT type.
unnestOp = innerUnnest ? new UnnestOperator(rightVar, new MutableObject<>(makeUnnestExpression(eo.first)), pVar, BuiltinType.AINT64, new PositionWriter()) : new LeftOuterUnnestOperator(rightVar, new MutableObject<>(makeUnnestExpression(eo.first)), pVar, BuiltinType.AINT64, new PositionWriter());
} else {
unnestOp = innerUnnest ? new UnnestOperator(rightVar, new MutableObject<>(makeUnnestExpression(eo.first))) : new LeftOuterUnnestOperator(rightVar, new MutableObject<>(makeUnnestExpression(eo.first)));
}
unnestOp.getInputs().add(eo.second);
return new Pair<>(unnestOp, rightVar);
}
use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.
the class SqlppExpressionToPlanTranslator method processSelectClause.
// Generates the return expression for a select clause.
private Pair<ILogicalOperator, LogicalVariable> processSelectClause(SelectBlock selectBlock, Mutable<ILogicalOperator> tupSrc) throws CompilationException {
SelectClause selectClause = selectBlock.getSelectClause();
Expression returnExpr;
if (selectClause.selectElement()) {
returnExpr = selectClause.getSelectElement().getExpression();
} else {
returnExpr = generateReturnExpr(selectClause, selectBlock);
}
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(returnExpr, tupSrc);
LogicalVariable returnVar;
ILogicalOperator returnOperator;
if (returnExpr.getKind() == Kind.VARIABLE_EXPRESSION) {
VariableExpr varExpr = (VariableExpr) returnExpr;
returnOperator = eo.second.getValue();
returnVar = context.getVar(varExpr.getVar().getId());
} else {
returnVar = context.newVar();
returnOperator = new AssignOperator(returnVar, new MutableObject<ILogicalExpression>(eo.first));
returnOperator.getInputs().add(eo.second);
}
if (selectClause.distinct()) {
DistinctOperator distinctOperator = new DistinctOperator(mkSingletonArrayList(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(returnVar))));
distinctOperator.getInputs().add(new MutableObject<ILogicalOperator>(returnOperator));
return new Pair<>(distinctOperator, returnVar);
} else {
return new Pair<>(returnOperator, returnVar);
}
}
use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.
the class StaticTypeCastUtil method injectCastToRelaxType.
private static boolean injectCastToRelaxType(Mutable<ILogicalExpression> expRef, IAType inputFieldType, IVariableTypeEnvironment env) throws AlgebricksException {
ILogicalExpression argExpr = expRef.getValue();
List<LogicalVariable> parameterVars = new ArrayList<LogicalVariable>();
argExpr.getUsedVariables(parameterVars);
// we need to handle open fields recursively by their default
// types
// for list, their item type is any
// for record, their
boolean castInjected = false;
if (argExpr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL || argExpr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
IAType reqFieldType = inputFieldType;
// do not enforce nested type in the case of no-used variables
switch(inputFieldType.getTypeTag()) {
case OBJECT:
reqFieldType = DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE;
break;
case ARRAY:
reqFieldType = DefaultOpenFieldType.NESTED_OPEN_AORDERED_LIST_TYPE;
break;
case MULTISET:
reqFieldType = DefaultOpenFieldType.NESTED_OPEN_AUNORDERED_LIST_TYPE;
break;
default:
break;
}
// do not enforce nested type in the case of no-used variables
if (!inputFieldType.equals(reqFieldType) && !parameterVars.isEmpty()) {
//inject dynamic type casting
injectCastFunction(FunctionUtil.getFunctionInfo(BuiltinFunctions.CAST_TYPE), reqFieldType, inputFieldType, expRef, argExpr);
castInjected = true;
}
//recursively rewrite function arguments
if (argExpr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL && TypeCastUtils.getRequiredType((AbstractFunctionCallExpression) argExpr) == null && reqFieldType != null) {
if (castInjected) {
//rewrite the arg expression inside the dynamic cast
ScalarFunctionCallExpression argFunc = (ScalarFunctionCallExpression) argExpr;
rewriteFuncExpr(argFunc, inputFieldType, inputFieldType, env);
} else {
//rewrite arg
ScalarFunctionCallExpression argFunc = (ScalarFunctionCallExpression) argExpr;
rewriteFuncExpr(argFunc, reqFieldType, inputFieldType, env);
}
}
}
return castInjected;
}
use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.
the class SqlppExpressionToPlanTranslator method visit.
@Override
public Pair<ILogicalOperator, LogicalVariable> visit(Query q, Mutable<ILogicalOperator> tupSource) throws CompilationException {
Expression queryBody = q.getBody();
if (queryBody.getKind() == Kind.SELECT_EXPRESSION) {
SelectExpression selectExpr = (SelectExpression) queryBody;
if (q.isTopLevel()) {
selectExpr.setSubquery(false);
}
return queryBody.accept(this, tupSource);
} else {
LogicalVariable var = context.newVar();
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(queryBody, tupSource);
AssignOperator assignOp = new AssignOperator(var, new MutableObject<ILogicalExpression>(eo.first));
assignOp.getInputs().add(eo.second);
ProjectOperator projectOp = new ProjectOperator(var);
projectOp.getInputs().add(new MutableObject<ILogicalOperator>(assignOp));
return new Pair<>(projectOp, var);
}
}
Aggregations