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.calcite.jdbc;
import org.apache.calcite.DataContext;
import org.apache.calcite.adapter.java.JavaTypeFactory;
import org.apache.calcite.avatica.AvaticaConnection;
import org.apache.calcite.avatica.AvaticaFactory;
import org.apache.calcite.avatica.AvaticaSite;
import org.apache.calcite.avatica.AvaticaStatement;
import org.apache.calcite.avatica.Helper;
import org.apache.calcite.avatica.InternalProperty;
import org.apache.calcite.avatica.Meta;
import org.apache.calcite.avatica.MetaImpl;
import org.apache.calcite.avatica.NoSuchStatementException;
import org.apache.calcite.avatica.UnregisteredDriver;
import org.apache.calcite.avatica.remote.TypedValue;
import org.apache.calcite.config.CalciteConnectionConfig;
import org.apache.calcite.config.CalciteConnectionConfigImpl;
import org.apache.calcite.jdbc.CalcitePrepare.Context;
import org.apache.calcite.linq4j.BaseQueryable;
import org.apache.calcite.linq4j.Enumerable;
import org.apache.calcite.linq4j.Enumerator;
import org.apache.calcite.linq4j.Ord;
import org.apache.calcite.linq4j.QueryProvider;
import org.apache.calcite.linq4j.Queryable;
import org.apache.calcite.linq4j.function.Function0;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.Expressions;
import org.apache.calcite.materialize.Lattice;
import org.apache.calcite.materialize.MaterializationService;
import org.apache.calcite.prepare.CalciteCatalogReader;
import org.apache.calcite.rel.type.DelegatingTypeSystem;
import org.apache.calcite.rel.type.RelDataTypeSystem;
import org.apache.calcite.runtime.Hook;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.SchemaVersion;
import org.apache.calcite.schema.Schemas;
import org.apache.calcite.schema.impl.AbstractSchema;
import org.apache.calcite.schema.impl.LongSchemaVersion;
import org.apache.calcite.server.CalciteServer;
import org.apache.calcite.server.CalciteServerStatement;
import org.apache.calcite.sql.advise.SqlAdvisor;
import org.apache.calcite.sql.advise.SqlAdvisorValidator;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.validate.SqlConformanceEnum;
import org.apache.calcite.sql.validate.SqlValidatorWithHints;
import org.apache.calcite.tools.RelRunner;
import org.apache.calcite.util.BuiltInMethod;
import org.apache.calcite.util.Holder;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Implementation of JDBC connection
* in the Calcite engine.
*
*
Abstract to allow newer versions of JDBC to add methods.
*/
abstract class CalciteConnectionImpl
extends AvaticaConnection
implements CalciteConnection, QueryProvider {
public final JavaTypeFactory typeFactory;
final CalciteSchema rootSchema;
final Function0 prepareFactory;
final CalciteServer server = new CalciteServerImpl();
// must be package-protected
static final Trojan TROJAN = createTrojan();
/**
* Creates a CalciteConnectionImpl.
*
*
Not public; method is called only from the driver.
*
* @param driver Driver
* @param factory Factory for JDBC objects
* @param url Server URL
* @param info Other connection properties
* @param rootSchema Root schema, or null
* @param typeFactory Type factory, or null
*/
protected CalciteConnectionImpl(Driver driver, AvaticaFactory factory,
String url, Properties info, CalciteSchema rootSchema,
JavaTypeFactory typeFactory) {
super(driver, factory, url, info);
CalciteConnectionConfig cfg = new CalciteConnectionConfigImpl(info);
this.prepareFactory = driver.prepareFactory;
if (typeFactory != null) {
this.typeFactory = typeFactory;
} else {
RelDataTypeSystem typeSystem =
cfg.typeSystem(RelDataTypeSystem.class, RelDataTypeSystem.DEFAULT);
if (cfg.conformance().shouldConvertRaggedUnionTypesToVarying()) {
typeSystem =
new DelegatingTypeSystem(typeSystem) {
@Override public boolean
shouldConvertRaggedUnionTypesToVarying() {
return true;
}
};
cfg.typeSystem(RelDataTypeSystem.class, RelDataTypeSystem.DEFAULT);
}
this.typeFactory = new JavaTypeFactoryImpl(typeSystem);
}
this.rootSchema =
Objects.requireNonNull(rootSchema != null
? rootSchema
: CalciteSchema.createRootSchema(true));
Preconditions.checkArgument(this.rootSchema.isRoot(), "must be root schema");
this.properties.put(InternalProperty.CASE_SENSITIVE, cfg.caseSensitive());
this.properties.put(InternalProperty.UNQUOTED_CASING, cfg.unquotedCasing());
this.properties.put(InternalProperty.QUOTED_CASING, cfg.quotedCasing());
this.properties.put(InternalProperty.QUOTING, cfg.quoting());
}
CalciteMetaImpl meta() {
return (CalciteMetaImpl) meta;
}
public CalciteConnectionConfig config() {
return new CalciteConnectionConfigImpl(info);
}
public Context createPrepareContext() {
return new ContextImpl(this);
}
/** Called after the constructor has completed and the model has been
* loaded. */
void init() {
final MaterializationService service = MaterializationService.instance();
for (CalciteSchema.LatticeEntry e : Schemas.getLatticeEntries(rootSchema)) {
final Lattice lattice = e.getLattice();
for (Lattice.Tile tile : lattice.computeTiles()) {
service.defineTile(lattice, tile.bitSet(), tile.measures, e.schema,
true, true);
}
}
}
@Override public T unwrap(Class iface) throws SQLException {
if (iface == RelRunner.class) {
return iface.cast((RelRunner) rel -> {
try {
return prepareStatement_(CalcitePrepare.Query.of(rel),
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
getHoldability());
} catch (SQLException e) {
throw new RuntimeException(e);
}
});
}
return super.unwrap(iface);
}
@Override public CalciteStatement createStatement(int resultSetType,
int resultSetConcurrency, int resultSetHoldability) throws SQLException {
return (CalciteStatement) super.createStatement(resultSetType,
resultSetConcurrency, resultSetHoldability);
}
@Override public CalcitePreparedStatement prepareStatement(
String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
final CalcitePrepare.Query