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.
/*
* Copyright (c) 2015. Qubole Inc
* Licensed 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 com.qubole.quark.fatjdbc.executor;
import org.apache.calcite.adapter.java.JavaTypeFactory;
import org.apache.calcite.avatica.AvaticaParameter;
import org.apache.calcite.avatica.AvaticaStatement;
import org.apache.calcite.avatica.ColumnMetaData;
import org.apache.calcite.avatica.Meta;
import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
import org.apache.calcite.linq4j.Ord;
import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rel.type.RelDataTypeFactoryImpl;
import org.apache.calcite.rel.type.RelDataTypeField;
import org.apache.calcite.rel.type.RelDataTypeFieldImpl;
import org.apache.calcite.rel.type.RelRecordType;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.util.Util;
import com.google.common.cache.Cache;
import com.google.common.collect.ImmutableList;
import com.qubole.quark.catalog.db.pojo.DataSource;
import com.qubole.quark.catalog.db.pojo.View;
import com.qubole.quark.ee.QuarkExecutor;
import com.qubole.quark.ee.QuarkExecutorFactory;
import com.qubole.quark.fatjdbc.QuarkConnectionImpl;
import com.qubole.quark.fatjdbc.QuarkJdbcStatement;
import com.qubole.quark.fatjdbc.QuarkMetaResultSet;
import com.qubole.quark.planner.parser.ParserResult;
import java.lang.reflect.Type;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
/**
* Created by amoghm on 3/4/16.
*/
public class PlanExecutor {
private final Meta.StatementHandle h;
private final QuarkConnectionImpl connection;
private final long maxRowCount;
private final Cache connectionCache;
public PlanExecutor(Meta.StatementHandle h,
QuarkConnectionImpl connection,
Cache connectionCache,
long maxRowCount) {
this.h = h;
this.connection = connection;
this.connectionCache = connectionCache;
this.maxRowCount = maxRowCount;
}
public QuarkMetaResultSet execute(ParserResult parserResult) throws Exception {
QuarkJdbcStatement stmt = connection.server.getStatement(h);
QuarkExecutor executor = QuarkExecutorFactory.getQuarkExecutor(parserResult.getKind(),
connection.parserFactory, connection.getProperties(), connectionCache);
Object result = executor.execute(parserResult);
if (result instanceof Integer) {
// Alter, Create, Drop DDL commands will either return id or 0
return QuarkMetaResultSet.count(h.connectionId, h.id, ((Integer) result).intValue());
} else if (result instanceof ArrayList) {
// Show DDL returns an arraylist
Class pojoType = getPojoType(parserResult.getParsedSql());
return getMetaResultSetFromIterator(
convertToIterator((ArrayList) result, pojoType),
connection, parserResult, "", connection.server.getStatement(h), h,
AvaticaStatement.DEFAULT_FETCH_SIZE, pojoType);
} else if (result instanceof ResultSet) {
// Querying JdbcDB
return QuarkMetaResultSet.create(h.connectionId, h.id, (ResultSet) result,
maxRowCount);
} else if (result instanceof Iterator) {
// Querying QuboleDB
return getMetaResultSetFromIterator((Iterator