Search in sources :

Example 11 with Identifier

use of org.apache.asterix.lang.common.struct.Identifier in project asterixdb by apache.

the class QueryTranslator method prepareRunExternalRuntime.

// Prepares to run a program on external runtime.
protected void prepareRunExternalRuntime(MetadataProvider metadataProvider, IHyracksClientConnection hcc, RunStatement pregelixStmt, String dataverseNameFrom, String dataverseNameTo, String datasetNameFrom, String datasetNameTo, MetadataTransactionContext mdTxnCtx) throws Exception {
    // Validates the source/sink dataverses and datasets.
    Dataset fromDataset = metadataProvider.findDataset(dataverseNameFrom, datasetNameFrom);
    if (fromDataset == null) {
        throw new CompilationException("The source dataset " + datasetNameFrom + " in dataverse " + dataverseNameFrom + " could not be found for the Run command");
    }
    Dataset toDataset = metadataProvider.findDataset(dataverseNameTo, datasetNameTo);
    if (toDataset == null) {
        throw new CompilationException("The sink dataset " + datasetNameTo + " in dataverse " + dataverseNameTo + " could not be found for the Run command");
    }
    try {
        // Find the primary index of the sink dataset.
        Index toIndex = null;
        List<Index> indexes = MetadataManager.INSTANCE.getDatasetIndexes(mdTxnCtx, dataverseNameTo, pregelixStmt.getDatasetNameTo().getValue());
        for (Index index : indexes) {
            if (index.isPrimaryIndex()) {
                toIndex = index;
                break;
            }
        }
        if (toIndex == null) {
            throw new AlgebricksException("Tried to access non-existing dataset: " + datasetNameTo);
        }
        // Cleans up the sink dataset -- Drop and then Create.
        DropDatasetStatement dropStmt = new DropDatasetStatement(new Identifier(dataverseNameTo), pregelixStmt.getDatasetNameTo(), true);
        this.handleDatasetDropStatement(metadataProvider, dropStmt, hcc);
        IDatasetDetailsDecl idd = new InternalDetailsDecl(toIndex.getKeyFieldNames(), toIndex.getKeyFieldSourceIndicators(), false, null, toDataset.getDatasetDetails().isTemp());
        DatasetDecl createToDataset = new DatasetDecl(new Identifier(dataverseNameTo), pregelixStmt.getDatasetNameTo(), new Identifier(toDataset.getItemTypeDataverseName()), new Identifier(toDataset.getItemTypeName()), new Identifier(toDataset.getMetaItemTypeDataverseName()), new Identifier(toDataset.getMetaItemTypeName()), new Identifier(toDataset.getNodeGroupName()), toDataset.getCompactionPolicy(), toDataset.getCompactionPolicyProperties(), toDataset.getHints(), toDataset.getDatasetType(), idd, false);
        this.handleCreateDatasetStatement(metadataProvider, createToDataset, hcc);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, e.getMessage(), e);
        throw new AlgebricksException("Error cleaning the result dataset. This should not happen.");
    }
    // Flushes source dataset.
    FlushDatasetUtil.flushDataset(hcc, metadataProvider, dataverseNameFrom, datasetNameFrom, datasetNameFrom);
}
Also used : IDatasetDetailsDecl(org.apache.asterix.lang.common.statement.IDatasetDetailsDecl) InternalDetailsDecl(org.apache.asterix.lang.common.statement.InternalDetailsDecl) CompilationException(org.apache.asterix.common.exceptions.CompilationException) DatasetDecl(org.apache.asterix.lang.common.statement.DatasetDecl) Identifier(org.apache.asterix.lang.common.struct.Identifier) IHyracksDataset(org.apache.hyracks.api.dataset.IHyracksDataset) IDataset(org.apache.asterix.common.metadata.IDataset) Dataset(org.apache.asterix.metadata.entities.Dataset) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) DropDatasetStatement(org.apache.asterix.lang.common.statement.DropDatasetStatement) Index(org.apache.asterix.metadata.entities.Index) ACIDException(org.apache.asterix.common.exceptions.ACIDException) MetadataException(org.apache.asterix.metadata.MetadataException) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) CompilationException(org.apache.asterix.common.exceptions.CompilationException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) AsterixException(org.apache.asterix.common.exceptions.AsterixException)

Example 12 with Identifier

use of org.apache.asterix.lang.common.struct.Identifier in project asterixdb by apache.

the class CloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(GroupbyClause gc, VariableSubstitutionEnvironment env) throws CompilationException {
    VariableSubstitutionEnvironment newSubs = env;
    List<GbyVariableExpressionPair> newGbyList = VariableCloneAndSubstitutionUtil.substInVarExprPair(context, gc.getGbyPairList(), newSubs, this);
    List<GbyVariableExpressionPair> newDecorList = gc.hasDecorList() ? VariableCloneAndSubstitutionUtil.substInVarExprPair(context, gc.getDecorPairList(), newSubs, this) : new ArrayList<>();
    VariableExpr newGroupVar = null;
    if (gc.hasGroupVar()) {
        newGroupVar = generateNewVariable(context, gc.getGroupVar());
    }
    Map<Expression, VariableExpr> newWithMap = new HashMap<>();
    if (gc.hasWithMap()) {
        for (Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) {
            Expression newKeyVar = (Expression) entry.getKey().accept(this, env).first;
            VariableExpr newValueVar = generateNewVariable(context, entry.getValue());
            newWithMap.put(newKeyVar, newValueVar);
        }
    }
    List<Pair<Expression, Identifier>> newGroupFieldList = new ArrayList<>();
    if (gc.hasGroupFieldList()) {
        for (Pair<Expression, Identifier> varId : gc.getGroupFieldList()) {
            Expression newExpr = (Expression) varId.first.accept(this, env).first;
            newGroupFieldList.add(new Pair<>(newExpr, varId.second));
        }
    }
    GroupbyClause newGroup = new GroupbyClause(newGbyList, newDecorList, newWithMap, newGroupVar, newGroupFieldList, gc.hasHashGroupByHint(), gc.isGroupAll());
    return new Pair<>(newGroup, newSubs);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) Identifier(org.apache.asterix.lang.common.struct.Identifier) VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) GroupbyClause(org.apache.asterix.lang.common.clause.GroupbyClause) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) Expression(org.apache.asterix.lang.common.base.Expression) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 13 with Identifier

use of org.apache.asterix.lang.common.struct.Identifier in project asterixdb by apache.

the class FormatPrintVisitor method printDelimitedIdentifiers.

protected void printDelimitedIdentifiers(List<Identifier> ids, String delimiter) {
    int index = 0;
    int size = ids.size();
    for (Identifier id : ids) {
        out.print(normalize(id.getValue()));
        if (++index < size) {
            out.print(delimiter);
        }
    }
}
Also used : Identifier(org.apache.asterix.lang.common.struct.Identifier)

Example 14 with Identifier

use of org.apache.asterix.lang.common.struct.Identifier in project asterixdb by apache.

the class Scope method getLiveVariables.

public Set<VariableExpr> getLiveVariables() {
    Set<VariableExpr> vars = new HashSet<VariableExpr>();
    Iterator<Identifier> identifierIterator = liveSymbols();
    while (identifierIterator.hasNext()) {
        Identifier identifier = identifierIterator.next();
        if (identifier instanceof VarIdentifier) {
            vars.add(new VariableExpr((VarIdentifier) identifier));
        }
    }
    return vars;
}
Also used : VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) Identifier(org.apache.asterix.lang.common.struct.Identifier) VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) HashSet(java.util.HashSet)

Example 15 with Identifier

use of org.apache.asterix.lang.common.struct.Identifier in project asterixdb by apache.

the class ClauseComparator method printDelimitedIdentifiers.

@Override
protected void printDelimitedIdentifiers(List<Identifier> ids, String delimiter) {
    int index = 0;
    int size = ids.size();
    for (Identifier id : ids) {
        String idStr = id.getValue();
        if (idStr.startsWith("$")) {
            id = new Identifier(idStr.substring(1));
        }
        out.print(id);
        if (++index < size) {
            out.print(delimiter);
        }
    }
}
Also used : Identifier(org.apache.asterix.lang.common.struct.Identifier) VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier)

Aggregations

Identifier (org.apache.asterix.lang.common.struct.Identifier)20 ArrayList (java.util.ArrayList)10 Expression (org.apache.asterix.lang.common.base.Expression)8 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)8 VarIdentifier (org.apache.asterix.lang.common.struct.VarIdentifier)8 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)6 AsterixException (org.apache.asterix.common.exceptions.AsterixException)5 CompilationException (org.apache.asterix.common.exceptions.CompilationException)5 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)5 IOException (java.io.IOException)4 RemoteException (java.rmi.RemoteException)4 HashMap (java.util.HashMap)4 ACIDException (org.apache.asterix.common.exceptions.ACIDException)4 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)4 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)4 MetadataException (org.apache.asterix.metadata.MetadataException)4 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)4 Pair (org.apache.hyracks.algebricks.common.utils.Pair)4 FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)4 IDataset (org.apache.asterix.common.metadata.IDataset)3