Search in sources :

Example 1 with CompiledInsertStatement

use of org.apache.asterix.translator.CompiledStatements.CompiledInsertStatement in project asterixdb by apache.

the class LangExpressionToPlanTranslator method translateInsert.

private ILogicalOperator translateInsert(DatasetDataSource targetDatasource, Mutable<ILogicalExpression> varRef, List<Mutable<ILogicalExpression>> varRefsForLoading, List<Mutable<ILogicalExpression>> additionalFilteringExpressions, ILogicalOperator assign, ICompiledDmlStatement stmt) throws AlgebricksException {
    if (targetDatasource.getDataset().hasMetaPart()) {
        throw new AlgebricksException(targetDatasource.getDataset().getDatasetName() + ": insert into dataset is not supported on Datasets with Meta records");
    }
    // Adds the insert operator.
    InsertDeleteUpsertOperator insertOp = new InsertDeleteUpsertOperator(targetDatasource, varRef, varRefsForLoading, InsertDeleteUpsertOperator.Kind.INSERT, false);
    insertOp.setAdditionalFilteringExpressions(additionalFilteringExpressions);
    insertOp.getInputs().add(new MutableObject<>(assign));
    // Adds the commit operator.
    CompiledInsertStatement compiledInsert = (CompiledInsertStatement) stmt;
    Expression returnExpression = compiledInsert.getReturnExpression();
    ILogicalOperator rootOperator = new DelegateOperator(new CommitOperator(returnExpression == null ? true : false));
    rootOperator.getInputs().add(new MutableObject<>(insertOp));
    // Compiles the return expression.
    return processReturningExpression(rootOperator, insertOp, compiledInsert);
}
Also used : InsertDeleteUpsertOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.InsertDeleteUpsertOperator) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) AggregateFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression) Expression(org.apache.asterix.lang.common.base.Expression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) UnnestingFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression) DelegateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.DelegateOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) CommitOperator(org.apache.asterix.algebra.operators.CommitOperator) CompiledInsertStatement(org.apache.asterix.translator.CompiledStatements.CompiledInsertStatement)

Example 2 with CompiledInsertStatement

use of org.apache.asterix.translator.CompiledStatements.CompiledInsertStatement in project asterixdb by apache.

the class QueryTranslator method rewriteCompileInsertUpsert.

private JobSpecification rewriteCompileInsertUpsert(IClusterInfoCollector clusterInfoCollector, MetadataProvider metadataProvider, InsertStatement insertUpsert) throws RemoteException, AlgebricksException, ACIDException {
    // Insert/upsert statement rewriting (happens under the same ongoing metadata transaction)
    Pair<IReturningStatement, Integer> rewrittenResult = apiFramework.reWriteQuery(declaredFunctions, metadataProvider, insertUpsert, sessionOutput);
    InsertStatement rewrittenInsertUpsert = (InsertStatement) rewrittenResult.first;
    String dataverseName = getActiveDataverse(rewrittenInsertUpsert.getDataverseName());
    String datasetName = rewrittenInsertUpsert.getDatasetName().getValue();
    CompiledInsertStatement clfrqs;
    switch(insertUpsert.getKind()) {
        case Statement.Kind.INSERT:
            clfrqs = new CompiledInsertStatement(dataverseName, datasetName, rewrittenInsertUpsert.getQuery(), rewrittenInsertUpsert.getVarCounter(), rewrittenInsertUpsert.getVar(), rewrittenInsertUpsert.getReturnExpression());
            break;
        case Statement.Kind.UPSERT:
            clfrqs = new CompiledUpsertStatement(dataverseName, datasetName, rewrittenInsertUpsert.getQuery(), rewrittenInsertUpsert.getVarCounter(), rewrittenInsertUpsert.getVar(), rewrittenInsertUpsert.getReturnExpression());
            break;
        default:
            throw new AlgebricksException("Unsupported statement type " + rewrittenInsertUpsert.getKind());
    }
    // Insert/upsert statement compilation (happens under the same ongoing metadata transaction)
    return apiFramework.compileQuery(clusterInfoCollector, metadataProvider, rewrittenInsertUpsert.getQuery(), rewrittenResult.second, datasetName, sessionOutput, clfrqs);
}
Also used : CompiledUpsertStatement(org.apache.asterix.translator.CompiledStatements.CompiledUpsertStatement) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) IReturningStatement(org.apache.asterix.lang.common.base.IReturningStatement) CompiledInsertStatement(org.apache.asterix.translator.CompiledStatements.CompiledInsertStatement) InsertStatement(org.apache.asterix.lang.common.statement.InsertStatement) CompiledInsertStatement(org.apache.asterix.translator.CompiledStatements.CompiledInsertStatement)

Aggregations

CompiledInsertStatement (org.apache.asterix.translator.CompiledStatements.CompiledInsertStatement)2 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)2 CommitOperator (org.apache.asterix.algebra.operators.CommitOperator)1 Expression (org.apache.asterix.lang.common.base.Expression)1 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)1 IReturningStatement (org.apache.asterix.lang.common.base.IReturningStatement)1 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)1 InsertStatement (org.apache.asterix.lang.common.statement.InsertStatement)1 CompiledUpsertStatement (org.apache.asterix.translator.CompiledStatements.CompiledUpsertStatement)1 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)1 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)1 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)1 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)1 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)1 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)1 UnnestingFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression)1 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)1 DelegateOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.DelegateOperator)1 InsertDeleteUpsertOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.InsertDeleteUpsertOperator)1