use of org.apache.asterix.lang.common.struct.Identifier in project asterixdb by apache.
the class FeedOperations method getConnectionJob.
private static JobSpecification getConnectionJob(SessionOutput sessionOutput, MetadataProvider metadataProvider, FeedConnection feedConnection, String[] locations, ILangCompilationProvider compilationProvider, IStorageComponentProvider storageComponentProvider, DefaultStatementExecutorFactory qtFactory, IHyracksClientConnection hcc) throws AlgebricksException, RemoteException, ACIDException {
DataverseDecl dataverseDecl = new DataverseDecl(new Identifier(feedConnection.getDataverseName()));
FeedConnectionRequest fcr = new FeedConnectionRequest(FeedRuntimeType.INTAKE, feedConnection.getAppliedFunctions(), feedConnection.getDatasetName(), feedConnection.getPolicyName(), feedConnection.getFeedId());
SubscribeFeedStatement subscribeStmt = new SubscribeFeedStatement(locations, fcr);
subscribeStmt.initialize(metadataProvider.getMetadataTxnContext());
List<Statement> statements = new ArrayList<>();
statements.add(dataverseDecl);
statements.add(subscribeStmt);
IStatementExecutor translator = qtFactory.create(metadataProvider.getApplicationContext(), statements, sessionOutput, compilationProvider, storageComponentProvider);
// configure the metadata provider
metadataProvider.getConfig().put(FunctionUtil.IMPORT_PRIVATE_FUNCTIONS, "" + Boolean.TRUE);
metadataProvider.getConfig().put(FeedActivityDetails.FEED_POLICY_NAME, "" + subscribeStmt.getPolicy());
metadataProvider.getConfig().put(FeedActivityDetails.COLLECT_LOCATIONS, StringUtils.join(subscribeStmt.getLocations(), ','));
CompiledStatements.CompiledSubscribeFeedStatement csfs = new CompiledStatements.CompiledSubscribeFeedStatement(subscribeStmt.getSubscriptionRequest(), subscribeStmt.getVarCounter());
return translator.rewriteCompileQuery(hcc, metadataProvider, subscribeStmt.getQuery(), csfs);
}
use of org.apache.asterix.lang.common.struct.Identifier 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.struct.Identifier in project asterixdb by apache.
the class SqlppAstPrintVisitor method visit.
@Override
public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
if (gc.isGroupAll()) {
out.println(skip(step) + "Group All");
return null;
}
out.println(skip(step) + "Groupby");
for (GbyVariableExpressionPair pair : gc.getGbyPairList()) {
if (pair.getVar() != null) {
pair.getVar().accept(this, step + 1);
out.println(skip(step + 1) + ":=");
}
pair.getExpr().accept(this, step + 1);
}
if (gc.hasGroupVar()) {
out.print(skip(step + 1) + "GROUP AS ");
gc.getGroupVar().accept(this, 0);
if (gc.hasGroupFieldList()) {
out.println(skip(step + 1) + "(");
for (Pair<Expression, Identifier> field : gc.getGroupFieldList()) {
out.print(skip(step + 2) + field.second + ":=");
field.first.accept(this, 0);
}
out.println(skip(step + 1) + ")");
}
}
out.println();
return null;
}
use of org.apache.asterix.lang.common.struct.Identifier in project asterixdb by apache.
the class DeepCopyVisitor method visit.
@Override
public GroupbyClause visit(GroupbyClause gc, Void arg) throws CompilationException {
List<GbyVariableExpressionPair> gbyPairList = new ArrayList<>();
List<GbyVariableExpressionPair> decorPairList = new ArrayList<>();
Map<Expression, VariableExpr> withVarMap = new HashMap<>();
VariableExpr groupVarExpr = null;
List<Pair<Expression, Identifier>> groupFieldList = new ArrayList<>();
for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) {
VariableExpr var = gbyVarExpr.getVar();
gbyPairList.add(new GbyVariableExpressionPair(var == null ? null : (VariableExpr) var.accept(this, arg), (Expression) gbyVarExpr.getExpr().accept(this, arg)));
}
for (GbyVariableExpressionPair gbyVarExpr : gc.getDecorPairList()) {
VariableExpr var = gbyVarExpr.getVar();
decorPairList.add(new GbyVariableExpressionPair(var == null ? null : (VariableExpr) var.accept(this, arg), (Expression) gbyVarExpr.getExpr().accept(this, arg)));
}
for (Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) {
withVarMap.put((Expression) entry.getKey().accept(this, arg), (VariableExpr) entry.getValue().accept(this, arg));
}
if (gc.hasGroupVar()) {
groupVarExpr = (VariableExpr) gc.getGroupVar().accept(this, arg);
}
for (Pair<Expression, Identifier> field : gc.getGroupFieldList()) {
groupFieldList.add(new Pair<>((Expression) field.first.accept(this, arg), field.second));
}
return new GroupbyClause(gbyPairList, decorPairList, withVarMap, groupVarExpr, groupFieldList, gc.hasHashGroupByHint(), gc.isGroupAll());
}
use of org.apache.asterix.lang.common.struct.Identifier in project asterixdb by apache.
the class FormatPrintVisitor method visit.
@Override
public Void visit(DatasetDecl dd, Integer step) throws CompilationException {
if (dd.getDatasetType() == DatasetType.INTERNAL) {
String temp = dd.getDatasetDetailsDecl().isTemp() ? "temporary" : "";
out.print(skip(step) + "create " + temp + datasetSymbol + generateFullName(dd.getDataverse(), dd.getName()) + generateIfNotExists(dd.getIfNotExists()) + "(" + dd.getQualifiedTypeName() + ")" + " primary key ");
printDelimitedKeys(((InternalDetailsDecl) dd.getDatasetDetailsDecl()).getPartitioningExprs(), ",");
if (((InternalDetailsDecl) dd.getDatasetDetailsDecl()).isAutogenerated()) {
out.print(" autogenerated ");
}
} else if (dd.getDatasetType() == DatasetType.EXTERNAL) {
out.print(skip(step) + "create external " + datasetSymbol + generateFullName(dd.getDataverse(), dd.getName()) + "(" + dd.getQualifiedTypeName() + ")" + generateIfNotExists(dd.getIfNotExists()));
ExternalDetailsDecl externalDetails = (ExternalDetailsDecl) dd.getDatasetDetailsDecl();
out.print(" using " + revertStringToQuoted(externalDetails.getAdapter()));
printConfiguration(externalDetails.getProperties());
}
Identifier nodeGroupName = dd.getNodegroupName();
if (nodeGroupName != null) {
out.print(" on " + nodeGroupName.getValue());
}
Map<String, String> hints = dd.getHints();
if (dd.getHints().size() > 0) {
out.print(" hints ");
printProperties(hints);
}
if (dd.getCompactionPolicy() != null) {
out.print(" using compaction policy " + revertStringToQuoted(dd.getCompactionPolicy()));
Map<String, String> compactionPolicyProperties = dd.getCompactionPolicyProperties();
if (compactionPolicyProperties != null && compactionPolicyProperties.size() > 0) {
printConfiguration(compactionPolicyProperties);
}
}
if (dd.getDatasetType() == DatasetType.INTERNAL) {
List<String> filterField = ((InternalDetailsDecl) dd.getDatasetDetailsDecl()).getFilterField();
if (filterField != null && filterField.size() > 0) {
out.print(" with filter on ");
printNestField(filterField);
}
}
out.println(SEMICOLON);
out.println();
return null;
}
Aggregations