Search in sources :

Example 1 with IReturningStatement

use of org.apache.asterix.lang.common.base.IReturningStatement 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

IReturningStatement (org.apache.asterix.lang.common.base.IReturningStatement)1 InsertStatement (org.apache.asterix.lang.common.statement.InsertStatement)1 CompiledInsertStatement (org.apache.asterix.translator.CompiledStatements.CompiledInsertStatement)1 CompiledUpsertStatement (org.apache.asterix.translator.CompiledStatements.CompiledUpsertStatement)1 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)1