use of org.apache.asterix.lang.common.literal.StringLiteral in project asterixdb by apache.
the class SqlppDeleteRewriteVisitor method visit.
@Override
public Void visit(DeleteStatement deleteStmt, Void visitArg) {
List<Expression> arguments = new ArrayList<>();
Identifier dataverseName = deleteStmt.getDataverseName();
Identifier datasetName = deleteStmt.getDatasetName();
String arg = dataverseName == null ? datasetName.getValue() : dataverseName.getValue() + "." + datasetName.getValue();
LiteralExpr argumentLiteral = new LiteralExpr(new StringLiteral(arg));
arguments.add(argumentLiteral);
CallExpr callExpression = new CallExpr(new FunctionSignature(FunctionConstants.ASTERIX_NS, "dataset", 1), arguments);
// From clause.
VariableExpr var = deleteStmt.getVariableExpr();
FromTerm fromTerm = new FromTerm(callExpression, var, null, null);
@SuppressWarnings("unchecked") FromClause fromClause = new FromClause(Collections.singletonList(fromTerm));
// Where clause.
WhereClause whereClause = null;
Expression condition = deleteStmt.getCondition();
if (condition != null) {
whereClause = new WhereClause(condition);
}
// Select clause.
VariableExpr returnExpr = new VariableExpr(var.getVar());
returnExpr.setIsNewVar(false);
SelectElement selectElement = new SelectElement(returnExpr);
SelectClause selectClause = new SelectClause(selectElement, null, false);
// Construct the select expression.
SelectBlock selectBlock = new SelectBlock(selectClause, fromClause, null, whereClause, null, null, null);
SelectSetOperation selectSetOperation = new SelectSetOperation(new SetOperationInput(selectBlock, null), null);
SelectExpression selectExpression = new SelectExpression(null, selectSetOperation, null, null, false);
Query query = new Query(false, false, selectExpression, 0);
query.setBody(selectExpression);
// return the delete statement.
deleteStmt.setQuery(query);
return null;
}
use of org.apache.asterix.lang.common.literal.StringLiteral in project asterixdb by apache.
the class SqlppExpressionToPlanTranslator method generateReturnExpr.
// Generates the return expression for a select clause.
private Expression generateReturnExpr(SelectClause selectClause, SelectBlock selectBlock) {
SelectRegular selectRegular = selectClause.getSelectRegular();
List<FieldBinding> fieldBindings = new ArrayList<>();
List<Projection> projections = selectRegular.getProjections();
for (Projection projection : projections) {
if (projection.star()) {
if (selectBlock.hasGroupbyClause()) {
fieldBindings.addAll(getGroupBindings(selectBlock.getGroupbyClause()));
} else if (selectBlock.hasFromClause()) {
fieldBindings.addAll(getFromBindings(selectBlock.getFromClause()));
}
} else {
fieldBindings.add(new FieldBinding(new LiteralExpr(new StringLiteral(projection.getName())), projection.getExpression()));
}
}
return new RecordConstructor(fieldBindings);
}
use of org.apache.asterix.lang.common.literal.StringLiteral in project asterixdb by apache.
the class LangExpressionToPlanTranslator method visit.
@Override
public Pair<ILogicalOperator, LogicalVariable> visit(GroupbyClause gc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
Mutable<ILogicalOperator> topOp = tupSource;
if (gc.hasGroupVar()) {
List<Pair<Expression, Identifier>> groupFieldList = gc.getGroupFieldList();
List<Mutable<ILogicalExpression>> groupRecordConstructorArgList = new ArrayList<>();
for (Pair<Expression, Identifier> groupField : groupFieldList) {
ILogicalExpression groupFieldNameExpr = langExprToAlgExpression(new LiteralExpr(new StringLiteral(groupField.second.getValue())), topOp).first;
groupRecordConstructorArgList.add(new MutableObject<>(groupFieldNameExpr));
ILogicalExpression groupFieldExpr = langExprToAlgExpression(groupField.first, topOp).first;
groupRecordConstructorArgList.add(new MutableObject<>(groupFieldExpr));
}
LogicalVariable groupVar = context.newVarFromExpression(gc.getGroupVar());
AssignOperator groupVarAssignOp = new AssignOperator(groupVar, new MutableObject<>(new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR), groupRecordConstructorArgList)));
groupVarAssignOp.getInputs().add(topOp);
topOp = new MutableObject<>(groupVarAssignOp);
}
GroupByOperator gOp = new GroupByOperator();
for (GbyVariableExpressionPair ve : gc.getGbyPairList()) {
VariableExpr vexpr = ve.getVar();
LogicalVariable v = vexpr == null ? context.newVar() : context.newVarFromExpression(vexpr);
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(ve.getExpr(), topOp);
gOp.addGbyExpression(v, eo.first);
topOp = eo.second;
}
for (GbyVariableExpressionPair ve : gc.getDecorPairList()) {
VariableExpr vexpr = ve.getVar();
LogicalVariable v = vexpr == null ? context.newVar() : context.newVarFromExpression(vexpr);
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(ve.getExpr(), topOp);
gOp.addDecorExpression(v, eo.first);
topOp = eo.second;
}
gOp.getInputs().add(topOp);
for (Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) {
Pair<ILogicalExpression, Mutable<ILogicalOperator>> listifyInput = langExprToAlgExpression(entry.getKey(), new MutableObject<>(new NestedTupleSourceOperator(new MutableObject<>(gOp))));
List<Mutable<ILogicalExpression>> flArgs = new ArrayList<>(1);
flArgs.add(new MutableObject<>(listifyInput.first));
AggregateFunctionCallExpression fListify = BuiltinFunctions.makeAggregateFunctionExpression(BuiltinFunctions.LISTIFY, flArgs);
LogicalVariable aggVar = context.newVar();
AggregateOperator agg = new AggregateOperator(mkSingletonArrayList(aggVar), mkSingletonArrayList(new MutableObject<>(fListify)));
agg.getInputs().add(listifyInput.second);
ILogicalPlan plan = new ALogicalPlanImpl(new MutableObject<>(agg));
gOp.getNestedPlans().add(plan);
// Hide the variable that was part of the "with", replacing it with
// the one bound by the aggregation op.
context.setVar(entry.getValue(), aggVar);
}
gOp.setGroupAll(gc.isGroupAll());
gOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY, gc.hasHashGroupByHint());
return new Pair<>(gOp, null);
}
use of org.apache.asterix.lang.common.literal.StringLiteral in project asterixdb by apache.
the class VariableCheckAndRewriteVisitor method wrapWithDatasetFunction.
private Expression wrapWithDatasetFunction(String dataverseName, String datasetName) throws CompilationException {
String fullyQualifiedName = dataverseName == null ? datasetName : dataverseName + "." + datasetName;
List<Expression> argList = new ArrayList<>();
argList.add(new LiteralExpr(new StringLiteral(fullyQualifiedName)));
return new CallExpr(datasetFunction, argList);
}
use of org.apache.asterix.lang.common.literal.StringLiteral in project asterixdb by apache.
the class AbstractSqlppExpressionScopingVisitor method wrapWithResolveFunction.
// Rewrites for an undefined variable reference, which potentially could be a syntatic sugar.
protected Expression wrapWithResolveFunction(VariableExpr expr, Set<VariableExpr> liveVars) throws CompilationException {
List<Expression> argList = new ArrayList<>();
//Ignore the parser-generated prefix "$" for a dataset.
String varName = SqlppVariableUtil.toUserDefinedVariableName(expr.getVar().getValue()).getValue();
argList.add(new LiteralExpr(new StringLiteral(varName)));
argList.addAll(liveVars);
return new CallExpr(resolveFunction, argList);
}
Aggregations