Search in sources :

Example 1 with IExtensionStatement

use of org.apache.asterix.algebra.extension.IExtensionStatement in project asterixdb by apache.

the class QueryTranslator method compileAndExecute.

@Override
public void compileAndExecute(IHyracksClientConnection hcc, IHyracksDataset hdc, ResultDelivery resultDelivery, ResultMetadata outMetadata, Stats stats, String clientContextId, IStatementExecutorContext ctx) throws Exception {
    int resultSetIdCounter = 0;
    FileSplit outputFile = null;
    IAWriterFactory writerFactory = PrinterBasedWriterFactory.INSTANCE;
    IResultSerializerFactoryProvider resultSerializerFactoryProvider = ResultSerializerFactoryProvider.INSTANCE;
    Map<String, String> config = new HashMap<>();
    /* Since the system runs a large number of threads, when HTTP requests don't return, it becomes difficult to
         * find the thread running the request to determine where it has stopped.
         * Setting the thread name helps make that easier
         */
    String threadName = Thread.currentThread().getName();
    Thread.currentThread().setName(QueryTranslator.class.getSimpleName());
    try {
        for (Statement stmt : statements) {
            if (sessionConfig.is(SessionConfig.FORMAT_HTML)) {
                sessionOutput.out().println(ApiServlet.HTML_STATEMENT_SEPARATOR);
            }
            validateOperation(appCtx, activeDataverse, stmt);
            // Rewrite the statement's AST.
            rewriteStatement(stmt);
            MetadataProvider metadataProvider = new MetadataProvider(appCtx, activeDataverse, componentProvider);
            metadataProvider.setWriterFactory(writerFactory);
            metadataProvider.setResultSerializerFactoryProvider(resultSerializerFactoryProvider);
            metadataProvider.setOutputFile(outputFile);
            metadataProvider.setConfig(config);
            switch(stmt.getKind()) {
                case Statement.Kind.SET:
                    handleSetStatement(stmt, config);
                    break;
                case Statement.Kind.DATAVERSE_DECL:
                    activeDataverse = handleUseDataverseStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.CREATE_DATAVERSE:
                    handleCreateDataverseStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.DATASET_DECL:
                    handleCreateDatasetStatement(metadataProvider, stmt, hcc);
                    break;
                case Statement.Kind.CREATE_INDEX:
                    handleCreateIndexStatement(metadataProvider, stmt, hcc);
                    break;
                case Statement.Kind.TYPE_DECL:
                    handleCreateTypeStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.NODEGROUP_DECL:
                    handleCreateNodeGroupStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.DATAVERSE_DROP:
                    handleDataverseDropStatement(metadataProvider, stmt, hcc);
                    break;
                case Statement.Kind.DATASET_DROP:
                    handleDatasetDropStatement(metadataProvider, stmt, hcc);
                    break;
                case Statement.Kind.INDEX_DROP:
                    handleIndexDropStatement(metadataProvider, stmt, hcc);
                    break;
                case Statement.Kind.TYPE_DROP:
                    handleTypeDropStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.NODEGROUP_DROP:
                    handleNodegroupDropStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.CREATE_FUNCTION:
                    handleCreateFunctionStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.FUNCTION_DROP:
                    handleFunctionDropStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.LOAD:
                    handleLoadStatement(metadataProvider, stmt, hcc);
                    break;
                case Statement.Kind.INSERT:
                case Statement.Kind.UPSERT:
                    if (((InsertStatement) stmt).getReturnExpression() != null) {
                        metadataProvider.setResultSetId(new ResultSetId(resultSetIdCounter++));
                        metadataProvider.setResultAsyncMode(resultDelivery == ResultDelivery.ASYNC || resultDelivery == ResultDelivery.DEFERRED);
                    }
                    handleInsertUpsertStatement(metadataProvider, stmt, hcc, hdc, resultDelivery, outMetadata, stats, false, clientContextId, ctx);
                    break;
                case Statement.Kind.DELETE:
                    handleDeleteStatement(metadataProvider, stmt, hcc, false);
                    break;
                case Statement.Kind.CREATE_FEED:
                    handleCreateFeedStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.DROP_FEED:
                    handleDropFeedStatement(metadataProvider, stmt, hcc);
                    break;
                case Statement.Kind.DROP_FEED_POLICY:
                    handleDropFeedPolicyStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.CONNECT_FEED:
                    handleConnectFeedStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.DISCONNECT_FEED:
                    handleDisconnectFeedStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.START_FEED:
                    handleStartFeedStatement(metadataProvider, stmt, hcc);
                    break;
                case Statement.Kind.STOP_FEED:
                    handleStopFeedStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.CREATE_FEED_POLICY:
                    handleCreateFeedPolicyStatement(metadataProvider, stmt);
                    break;
                case Statement.Kind.QUERY:
                    metadataProvider.setResultSetId(new ResultSetId(resultSetIdCounter++));
                    metadataProvider.setResultAsyncMode(resultDelivery == ResultDelivery.ASYNC || resultDelivery == ResultDelivery.DEFERRED);
                    handleQuery(metadataProvider, (Query) stmt, hcc, hdc, resultDelivery, outMetadata, stats, clientContextId, ctx);
                    break;
                case Statement.Kind.COMPACT:
                    handleCompactStatement(metadataProvider, stmt, hcc);
                    break;
                case Statement.Kind.EXTERNAL_DATASET_REFRESH:
                    handleExternalDatasetRefreshStatement(metadataProvider, stmt, hcc);
                    break;
                case Statement.Kind.WRITE:
                    Pair<IAWriterFactory, FileSplit> result = handleWriteStatement(stmt);
                    writerFactory = (result.first != null) ? result.first : writerFactory;
                    outputFile = result.second;
                    break;
                case Statement.Kind.RUN:
                    handleRunStatement(metadataProvider, stmt, hcc);
                    break;
                case Statement.Kind.FUNCTION_DECL:
                    // No op
                    break;
                case Statement.Kind.EXTENSION:
                    ((IExtensionStatement) stmt).handle(this, metadataProvider, hcc, hdc, resultDelivery, stats, resultSetIdCounter);
                    break;
                default:
                    throw new CompilationException("Unknown function");
            }
        }
    } finally {
        Thread.currentThread().setName(threadName);
    }
}
Also used : IExtensionStatement(org.apache.asterix.algebra.extension.IExtensionStatement) CompilationException(org.apache.asterix.common.exceptions.CompilationException) HashMap(java.util.HashMap) IResultSerializerFactoryProvider(org.apache.hyracks.algebricks.data.IResultSerializerFactoryProvider) StopFeedStatement(org.apache.asterix.lang.common.statement.StopFeedStatement) FunctionDropStatement(org.apache.asterix.lang.common.statement.FunctionDropStatement) LoadStatement(org.apache.asterix.lang.common.statement.LoadStatement) CompiledInsertStatement(org.apache.asterix.translator.CompiledStatements.CompiledInsertStatement) CreateDataverseStatement(org.apache.asterix.lang.common.statement.CreateDataverseStatement) InsertStatement(org.apache.asterix.lang.common.statement.InsertStatement) CompiledLoadFromFileStatement(org.apache.asterix.translator.CompiledStatements.CompiledLoadFromFileStatement) CreateFeedPolicyStatement(org.apache.asterix.lang.common.statement.CreateFeedPolicyStatement) CreateIndexStatement(org.apache.asterix.lang.common.statement.CreateIndexStatement) RunStatement(org.apache.asterix.lang.common.statement.RunStatement) IExtensionStatement(org.apache.asterix.algebra.extension.IExtensionStatement) FeedPolicyDropStatement(org.apache.asterix.lang.common.statement.FeedPolicyDropStatement) Statement(org.apache.asterix.lang.common.base.Statement) DisconnectFeedStatement(org.apache.asterix.lang.common.statement.DisconnectFeedStatement) CompiledDeleteStatement(org.apache.asterix.translator.CompiledStatements.CompiledDeleteStatement) CreateFeedStatement(org.apache.asterix.lang.common.statement.CreateFeedStatement) DeleteStatement(org.apache.asterix.lang.common.statement.DeleteStatement) DataverseDropStatement(org.apache.asterix.lang.common.statement.DataverseDropStatement) TypeDropStatement(org.apache.asterix.lang.common.statement.TypeDropStatement) CompactStatement(org.apache.asterix.lang.common.statement.CompactStatement) StartFeedStatement(org.apache.asterix.lang.common.statement.StartFeedStatement) NodeGroupDropStatement(org.apache.asterix.lang.common.statement.NodeGroupDropStatement) RefreshExternalDatasetStatement(org.apache.asterix.lang.common.statement.RefreshExternalDatasetStatement) SetStatement(org.apache.asterix.lang.common.statement.SetStatement) CompiledUpsertStatement(org.apache.asterix.translator.CompiledStatements.CompiledUpsertStatement) ConnectFeedStatement(org.apache.asterix.lang.common.statement.ConnectFeedStatement) ICompiledDmlStatement(org.apache.asterix.translator.CompiledStatements.ICompiledDmlStatement) IndexDropStatement(org.apache.asterix.lang.common.statement.IndexDropStatement) CreateFunctionStatement(org.apache.asterix.lang.common.statement.CreateFunctionStatement) WriteStatement(org.apache.asterix.lang.common.statement.WriteStatement) IReturningStatement(org.apache.asterix.lang.common.base.IReturningStatement) DropDatasetStatement(org.apache.asterix.lang.common.statement.DropDatasetStatement) FeedDropStatement(org.apache.asterix.lang.common.statement.FeedDropStatement) FileSplit(org.apache.hyracks.api.io.FileSplit) UnmanagedFileSplit(org.apache.hyracks.api.io.UnmanagedFileSplit) DatasetNodegroupCardinalityHint(org.apache.asterix.metadata.dataset.hints.DatasetHints.DatasetNodegroupCardinalityHint) AlgebricksAbsolutePartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint) MetadataProvider(org.apache.asterix.metadata.declared.MetadataProvider) ResultSetId(org.apache.hyracks.api.dataset.ResultSetId) IAWriterFactory(org.apache.hyracks.algebricks.data.IAWriterFactory)

Aggregations

HashMap (java.util.HashMap)1 IExtensionStatement (org.apache.asterix.algebra.extension.IExtensionStatement)1 CompilationException (org.apache.asterix.common.exceptions.CompilationException)1 IReturningStatement (org.apache.asterix.lang.common.base.IReturningStatement)1 Statement (org.apache.asterix.lang.common.base.Statement)1 CompactStatement (org.apache.asterix.lang.common.statement.CompactStatement)1 ConnectFeedStatement (org.apache.asterix.lang.common.statement.ConnectFeedStatement)1 CreateDataverseStatement (org.apache.asterix.lang.common.statement.CreateDataverseStatement)1 CreateFeedPolicyStatement (org.apache.asterix.lang.common.statement.CreateFeedPolicyStatement)1 CreateFeedStatement (org.apache.asterix.lang.common.statement.CreateFeedStatement)1 CreateFunctionStatement (org.apache.asterix.lang.common.statement.CreateFunctionStatement)1 CreateIndexStatement (org.apache.asterix.lang.common.statement.CreateIndexStatement)1 DataverseDropStatement (org.apache.asterix.lang.common.statement.DataverseDropStatement)1 DeleteStatement (org.apache.asterix.lang.common.statement.DeleteStatement)1 DisconnectFeedStatement (org.apache.asterix.lang.common.statement.DisconnectFeedStatement)1 DropDatasetStatement (org.apache.asterix.lang.common.statement.DropDatasetStatement)1 FeedDropStatement (org.apache.asterix.lang.common.statement.FeedDropStatement)1 FeedPolicyDropStatement (org.apache.asterix.lang.common.statement.FeedPolicyDropStatement)1 FunctionDropStatement (org.apache.asterix.lang.common.statement.FunctionDropStatement)1 IndexDropStatement (org.apache.asterix.lang.common.statement.IndexDropStatement)1