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.avatica;
import com.google.common.base.Preconditions;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import org.apache.calcite.avatica.Meta;
import org.apache.druid.java.util.common.IAE;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.concurrent.Execs;
import org.apache.druid.java.util.common.guava.Yielder;
import org.apache.druid.java.util.common.guava.Yielders;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.sql.DirectStatement;
import java.io.Closeable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* Druid's server-side representation of a JDBC result set. At most one
* can be open per statement (standard or prepared). The implementation
* is based on Druid's own {@link DirectStatement} class. Even if result
* set is for a {@code PreparedStatement}, the result set itself uses
* a Druid {@code DirectStatement} which includes the parameter values
* given for the execution. This allows Druid's planner to use the "query
* optimized" form of parameter substitution: we replan the query for
* each execution with the parameter values.
*
* Avatica returns results in {@link Meta.Frame} objects as batches of
* rows. The result set uses the {@code TYPE_FORWARD_ONLY} execution model:
* the application can only read results sequentially, the application
* can't jump around or read backwards. As a result, the enclosing
* statement closes the result set at EOF to release resources early.
*
* Thread safe, but only when accessed sequentially by different request
* threads: not designed for concurrent access as JDBC does not support
* concurrent actions on the same result set.
*/
public class DruidJdbcResultSet implements Closeable
{
private static final Logger LOG = new Logger(DruidJdbcResultSet.class);
/**
* Asynchronous result fetcher. JDBC operates via REST, which is subject to
* a timeout if a query takes too long to respond. Fortunately, JDBC uses a
* batched API, and is perfectly happy to get an empty batch. This class
* runs in a separate thread to fetch a batch. If the fetch takes too long,
* the JDBC request thread will time out waiting, will return an empty batch
* to the client, and will remember the fetch for use in the next fetch
* request. The result is that the time it takes to produce results for long
* running queries is decoupled from the HTTP timeout.
*/
public static class ResultFetcher implements Callable
{
private final int limit;
private int batchSize;
private int offset;
private Yielder