Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.druid.sql;
import com.google.common.annotations.VisibleForTesting;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.druid.error.DruidException;
import org.apache.druid.error.InvalidSqlInput;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.query.QueryException;
import org.apache.druid.query.QueryInterruptedException;
import org.apache.druid.server.QueryResponse;
import org.apache.druid.server.security.ResourceAction;
import org.apache.druid.sql.SqlLifecycleManager.Cancelable;
import org.apache.druid.sql.calcite.planner.DruidPlanner;
import org.apache.druid.sql.calcite.planner.PlannerResult;
import org.apache.druid.sql.calcite.planner.PrepareResult;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* Lifecycle for direct SQL statement execution, which means that the query
* is planned and executed in a single step, with no "prepare" step.
* Callers need call only:
*
*
{@link #execute()} to execute the query. The caller must close
* the returned {@code Sequence}.
*
{@link #close()} to report metrics, or {@link #closeQuietly()}
* otherwise.
*
*
* The {@link #cancel()} method may be called from any thread and cancels
* the query.
*
* All other methods are optional and are generally for introspection.
*
* The class supports two threading models. In the simple case, the same
* thread creates this object and executes the query. In the split model,
* a request thread creates this object and plans the query. A separate
* response thread consumes results and performs any desired logging, etc.
* The object is transferred between threads, with no overlapping access.
*
* As statement holds no resources and need not be called. Only the
* {@code Sequence} returned from {@link #execute()} need be closed.
*
* Use this class for tests and JDBC execution. Use the HTTP variant,
* {@link HttpStatement} for HTTP requests.
*/
public class DirectStatement extends AbstractStatement implements Cancelable
{
private static final Logger log = new Logger(DirectStatement.class);
/**
* Represents the execution plan for a query with the ability to run
* that plan (once).
*/
public class ResultSet implements Cancelable
{
private final PlannerResult plannerResult;
public ResultSet(PlannerResult plannerResult)
{
this.plannerResult = plannerResult;
}
public SqlQueryPlus query()
{
return queryPlus;
}
/**
* Convenience method for the split plan/run case to ensure that the statement
* can, in fact, be run.
*/
public boolean runnable()
{
return plannerResult != null && plannerResult.runnable();
}
/**
* Do the actual execute step which allows subclasses to wrap the sequence,
* as is sometimes needed for testing.
*/
public QueryResponse