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 com.hazelcast.shaded.org.apache.calcite.jdbc;
import com.hazelcast.shaded.org.apache.calcite.DataContext;
import com.hazelcast.shaded.org.apache.calcite.DataContexts;
import com.hazelcast.shaded.org.apache.calcite.adapter.java.JavaTypeFactory;
import com.hazelcast.shaded.org.apache.calcite.avatica.AvaticaConnection;
import com.hazelcast.shaded.org.apache.calcite.avatica.AvaticaFactory;
import com.hazelcast.shaded.org.apache.calcite.avatica.AvaticaSite;
import com.hazelcast.shaded.org.apache.calcite.avatica.AvaticaStatement;
import com.hazelcast.shaded.org.apache.calcite.avatica.Helper;
import com.hazelcast.shaded.org.apache.calcite.avatica.InternalProperty;
import com.hazelcast.shaded.org.apache.calcite.avatica.Meta;
import com.hazelcast.shaded.org.apache.calcite.avatica.MetaImpl;
import com.hazelcast.shaded.org.apache.calcite.avatica.NoSuchStatementException;
import com.hazelcast.shaded.org.apache.calcite.avatica.UnregisteredDriver;
import com.hazelcast.shaded.org.apache.calcite.avatica.remote.TypedValue;
import com.hazelcast.shaded.org.apache.calcite.config.CalciteConnectionConfig;
import com.hazelcast.shaded.org.apache.calcite.config.CalciteConnectionConfigImpl;
import com.hazelcast.shaded.org.apache.calcite.jdbc.CalcitePrepare.Context;
import com.hazelcast.shaded.org.apache.calcite.linq4j.BaseQueryable;
import com.hazelcast.shaded.org.apache.calcite.linq4j.Enumerable;
import com.hazelcast.shaded.org.apache.calcite.linq4j.Enumerator;
import com.hazelcast.shaded.org.apache.calcite.linq4j.Ord;
import com.hazelcast.shaded.org.apache.calcite.linq4j.QueryProvider;
import com.hazelcast.shaded.org.apache.calcite.linq4j.Queryable;
import com.hazelcast.shaded.org.apache.calcite.linq4j.tree.Expression;
import com.hazelcast.shaded.org.apache.calcite.linq4j.tree.Expressions;
import com.hazelcast.shaded.org.apache.calcite.materialize.Lattice;
import com.hazelcast.shaded.org.apache.calcite.materialize.MaterializationService;
import com.hazelcast.shaded.org.apache.calcite.plan.RelOptUtil;
import com.hazelcast.shaded.org.apache.calcite.prepare.CalciteCatalogReader;
import com.hazelcast.shaded.org.apache.calcite.rel.type.DelegatingTypeSystem;
import com.hazelcast.shaded.org.apache.calcite.rel.type.RelDataTypeSystem;
import com.hazelcast.shaded.org.apache.calcite.rel.type.TimeFrameSet;
import com.hazelcast.shaded.org.apache.calcite.rel.type.TimeFrames;
import com.hazelcast.shaded.org.apache.calcite.runtime.Hook;
import com.hazelcast.shaded.org.apache.calcite.schema.SchemaPlus;
import com.hazelcast.shaded.org.apache.calcite.schema.SchemaVersion;
import com.hazelcast.shaded.org.apache.calcite.schema.Schemas;
import com.hazelcast.shaded.org.apache.calcite.schema.impl.AbstractSchema;
import com.hazelcast.shaded.org.apache.calcite.schema.impl.LongSchemaVersion;
import com.hazelcast.shaded.org.apache.calcite.server.CalciteServer;
import com.hazelcast.shaded.org.apache.calcite.server.CalciteServerStatement;
import com.hazelcast.shaded.org.apache.calcite.sql.advise.SqlAdvisor;
import com.hazelcast.shaded.org.apache.calcite.sql.advise.SqlAdvisorValidator;
import com.hazelcast.shaded.org.apache.calcite.sql.fun.SqlStdOperatorTable;
import com.hazelcast.shaded.org.apache.calcite.sql.parser.SqlParser;
import com.hazelcast.shaded.org.apache.calcite.sql.validate.SqlValidator;
import com.hazelcast.shaded.org.apache.calcite.sql.validate.SqlValidatorWithHints;
import com.hazelcast.shaded.org.apache.calcite.tools.RelRunner;
import com.hazelcast.shaded.org.apache.calcite.util.BuiltInMethod;
import com.hazelcast.shaded.org.apache.calcite.util.Holder;
import com.hazelcast.shaded.org.apache.calcite.util.Util;
import com.hazelcast.shaded.com.google.common.base.Preconditions;
import com.hazelcast.shaded.com.google.common.collect.ImmutableList;
import com.hazelcast.shaded.com.google.common.collect.ImmutableMap;
import com.hazelcast.shaded.org.checkerframework.checker.nullness.qual.Nullable;
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.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import static com.hazelcast.shaded.org.apache.calcite.linq4j.Nullness.castNonNull;
import static java.util.Objects.requireNonNull;
/**
* 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 Supplier 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, @Nullable CalciteSchema rootSchema,
@Nullable JavaTypeFactory typeFactory) {
super(driver, factory, url, info);
CalciteConnectionConfig cfg = new CalciteConnectionConfigImpl(info);
this.prepareFactory = driver::createPrepare;
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;
}
};
}
this.typeFactory = new JavaTypeFactoryImpl(typeSystem);
}
this.rootSchema =
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;
}
@Override public CalciteConnectionConfig config() {
return new CalciteConnectionConfigImpl(info);
}
@Override 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 ->
prepareStatement_(CalcitePrepare.Query.of(rel),
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
getHoldability()));
}
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