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 Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets 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 io.druid.sql.avatica;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
import io.druid.concurrent.Execs;
import io.druid.java.util.common.ISE;
import io.druid.java.util.common.guava.Sequence;
import io.druid.java.util.common.guava.Sequences;
import io.druid.java.util.common.guava.Yielder;
import io.druid.java.util.common.guava.Yielders;
import io.druid.sql.calcite.planner.DruidPlanner;
import io.druid.sql.calcite.planner.PlannerFactory;
import io.druid.sql.calcite.planner.PlannerResult;
import io.druid.sql.calcite.rel.QueryMaker;
import org.apache.calcite.avatica.ColumnMetaData;
import org.apache.calcite.avatica.Meta;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeField;
import javax.annotation.concurrent.GuardedBy;
import java.io.Closeable;
import java.sql.DatabaseMetaData;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
/**
* Statement handle for {@link DruidMeta}. Thread-safe.
*/
public class DruidStatement implements Closeable
{
public static final long START_OFFSET = 0;
enum State
{
NEW,
PREPARED,
RUNNING,
DONE
}
private final String connectionId;
private final int statementId;
private final Map queryContext;
private final Runnable onClose;
private final Object lock = new Object();
/**
* Query metrics can only be used within a single thread. Because results can be paginated into multiple
* JDBC frames (each frame being processed by a potentially different thread), the thread that closes the yielder
* (resulting in a QueryMetrics emit() call) may not be the same thread that created the yielder (which initializes
* DefaultQueryMetrics with the current thread as the owner). Create and close the yielder with this
* single-thread executor to prevent this from happening.
*
* The thread owner check in DefaultQueryMetrics is more aggressive than needed for this specific JDBC case, since
* the JDBC frames are processed sequentially. If the thread owner check is changed/loosened to permit this use case,
* we would not need to use this executor.
*
* See discussion at:
* https://github.com/druid-io/druid/pull/4288
* https://github.com/druid-io/druid/pull/4415
*/
private final ExecutorService yielderOpenCloseExecutor;
private State state = State.NEW;
private String query;
private long maxRowCount;
private PlannerResult plannerResult;
private Meta.Signature signature;
private Yielder