Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import org.apache.calcite.jdbc.CalciteSchemaBuilder;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.pinot.broker.api.AccessControl;
import org.apache.pinot.broker.api.RequesterIdentity;
import org.apache.pinot.broker.broker.AccessControlFactory;
import org.apache.pinot.broker.querylog.QueryLogger;
import org.apache.pinot.broker.queryquota.QueryQuotaManager;
import org.apache.pinot.broker.routing.BrokerRoutingManager;
import org.apache.pinot.calcite.jdbc.CalciteSchemaBuilder;
import org.apache.pinot.common.config.provider.TableCache;
import org.apache.pinot.common.exception.QueryException;
import org.apache.pinot.common.metrics.BrokerMeter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import org.apache.calcite.jdbc.CalciteSchemaBuilder;
import org.apache.calcite.sql.SqlNode;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.helix.model.InstanceConfig;
import org.apache.pinot.calcite.jdbc.CalciteSchemaBuilder;
import org.apache.pinot.common.Utils;
import org.apache.pinot.common.exception.QueryException;
import org.apache.pinot.common.response.ProcessingException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.calcite.jdbc;
package org.apache.pinot.calcite.jdbc;

import java.util.List;
import java.util.Map;
import org.apache.calcite.jdbc.CalciteSchema;
import org.apache.calcite.schema.Function;
import org.apache.calcite.schema.Schema;
import org.apache.calcite.schema.SchemaPlus;
Expand All @@ -28,26 +29,14 @@

/**
* This class is used to create a {@link CalciteSchema} with a given {@link Schema} as the root.
*
* <p>This class resides in calcite.jdbc namespace because there's no complex logic we have in terms of catalog-based
* schema construct. We instead create a {@link SimpleCalciteSchema} that's package protected.
*/
public class CalciteSchemaBuilder {

private CalciteSchemaBuilder() {
// do not instantiate.
}

/**
* Creates a {@link CalciteSchema} with a given {@link Schema} as the root.
*
* <p>Calcite creates two layer of abstraction, the {@link CalciteSchema} is use internally for planner and
* {@link Schema} is user-facing with overrides. In our case we don't have a complex internal wrapper extension
* so we only reuse the package protected {@link SimpleCalciteSchema}.
*
* <p>If there's need to extend this feature for planner functionalities we should create our own extension to the
* {@link CalciteSchema}.
*
* @param root schema to use as a root schema
* @return calcite schema with given schema as the root
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.calcite.prepare;
package org.apache.pinot.calcite.prepare;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
Expand All @@ -35,6 +35,9 @@
import org.apache.calcite.linq4j.function.Hints;
import org.apache.calcite.model.ModelHandler;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.prepare.CalciteCatalogReader;
import org.apache.calcite.prepare.Prepare;
import org.apache.calcite.prepare.RelOptTableImpl;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rel.type.RelDataTypeFactoryImpl;
Expand Down Expand Up @@ -78,16 +81,15 @@


/**
* ============================================================================
* THIS CLASS IS COPIED FROM Calcite's {@link org.apache.calcite.prepare.CalciteCatalogReader} and modified the
* case sensitivity of Function lookup. which is ALWAYS case-insensitive regardless of conventions on
* column/table identifier.
* ============================================================================
* ==============================================================================================================
* THIS CLASS IS COPIED FROM Calcite's {@link CalciteCatalogReader} and modified the case sensitivity of Function
* lookup, which is ALWAYS case-insensitive regardless of conventions on column/table identifier.
* ==============================================================================================================
*
* Pinot's implementation of {@link org.apache.calcite.prepare.Prepare.CatalogReader}
* and also {@link org.apache.calcite.sql.SqlOperatorTable} based on tables and
* Pinot's implementation of {@link Prepare.CatalogReader} and also {@link SqlOperatorTable} based on tables and
* functions defined schemas.
*/
//@formatter:off
public class PinotCalciteCatalogReader implements Prepare.CatalogReader {
protected final CalciteSchema _rootSchema;
protected final RelDataTypeFactory _typeFactory;
Expand Down Expand Up @@ -463,3 +465,4 @@ private static RelDataType toSql(RelDataTypeFactory typeFactory,
return null;
}
}
//@formatter:on
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.calcite.rel.hint;
package org.apache.pinot.calcite.rel.hint;

import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.hint.RelHint;
import org.apache.pinot.query.planner.logical.LiteralHintUtils;


/**
* {@code PinotHintOptions} specified the supported hint options by Pinot based a particular type of relation node.
*
* <p>for each {@link org.apache.calcite.rel.RelNode} type we support an option hint name.</p>
* <p>for each {@link RelNode} type we support an option hint name.</p>
* <p>for each option hint name there's a corresponding {@link RelHint} that supported only key-value option stored
* in {@link RelHint#kvOptions}</p>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.calcite.rel.hint;
package org.apache.pinot.calcite.rel.hint;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.calcite.rel.hint.HintPredicates;
import org.apache.calcite.rel.hint.HintStrategyTable;
import org.apache.calcite.rel.hint.RelHint;
import org.apache.pinot.spi.utils.BooleanUtils;


/**
* Default hint strategy set for Pinot query.
*/
public class PinotHintStrategyTable {

private PinotHintStrategyTable() {
// do not instantiate.
}

public static final HintStrategyTable PINOT_HINT_STRATEGY_TABLE = HintStrategyTable.builder()
.hintStrategy(PinotHintOptions.INTERNAL_AGG_OPTIONS, HintPredicates.AGGREGATE)
.hintStrategy(PinotHintOptions.AGGREGATE_HINT_OPTIONS, HintPredicates.AGGREGATE)
.hintStrategy(PinotHintOptions.JOIN_HINT_OPTIONS, HintPredicates.JOIN)
.hintStrategy(PinotHintOptions.TABLE_HINT_OPTIONS, HintPredicates.TABLE_SCAN)
.build();
public static final HintStrategyTable PINOT_HINT_STRATEGY_TABLE =
HintStrategyTable.builder().hintStrategy(PinotHintOptions.INTERNAL_AGG_OPTIONS, HintPredicates.AGGREGATE)
.hintStrategy(PinotHintOptions.AGGREGATE_HINT_OPTIONS, HintPredicates.AGGREGATE)
.hintStrategy(PinotHintOptions.JOIN_HINT_OPTIONS, HintPredicates.JOIN)
.hintStrategy(PinotHintOptions.TABLE_HINT_OPTIONS, HintPredicates.TABLE_SCAN).build();

/**
* Check if a hint-able {@link org.apache.calcite.rel.RelNode} contains a specific {@link RelHint} by name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.calcite.rel.logical;
package org.apache.pinot.calcite.rel.logical;

import org.apache.calcite.plan.Convention;
import org.apache.calcite.plan.RelOptCluster;
Expand All @@ -36,16 +36,14 @@
public class PinotLogicalExchange extends Exchange {
private final PinotRelExchangeType _exchangeType;

private PinotLogicalExchange(RelOptCluster cluster, RelTraitSet traitSet,
RelNode input, RelDistribution distribution, PinotRelExchangeType exchangeType) {
private PinotLogicalExchange(RelOptCluster cluster, RelTraitSet traitSet, RelNode input, RelDistribution distribution,
PinotRelExchangeType exchangeType) {
super(cluster, traitSet, input, distribution);
_exchangeType = exchangeType;
assert traitSet.containsIfApplicable(Convention.NONE);
}


public static PinotLogicalExchange create(RelNode input,
RelDistribution distribution) {
public static PinotLogicalExchange create(RelNode input, RelDistribution distribution) {
return create(input, distribution, PinotRelExchangeType.getDefaultExchangeType());
}

Expand All @@ -56,22 +54,19 @@ public static PinotLogicalExchange create(RelNode input,
* @param distribution Distribution specification
* @param exchangeType RelExchangeType specification
*/
public static PinotLogicalExchange create(RelNode input,
RelDistribution distribution, PinotRelExchangeType exchangeType) {
public static PinotLogicalExchange create(RelNode input, RelDistribution distribution,
PinotRelExchangeType exchangeType) {
RelOptCluster cluster = input.getCluster();
distribution = RelDistributionTraitDef.INSTANCE.canonize(distribution);
RelTraitSet traitSet =
input.getTraitSet().replace(Convention.NONE).replace(distribution);
RelTraitSet traitSet = input.getTraitSet().replace(Convention.NONE).replace(distribution);
return new PinotLogicalExchange(cluster, traitSet, input, distribution, exchangeType);
}

//~ Methods ----------------------------------------------------------------

@Override
public Exchange copy(RelTraitSet traitSet, RelNode newInput,
RelDistribution newDistribution) {
return new PinotLogicalExchange(getCluster(), traitSet, newInput,
newDistribution, _exchangeType);
public Exchange copy(RelTraitSet traitSet, RelNode newInput, RelDistribution newDistribution) {
return new PinotLogicalExchange(getCluster(), traitSet, newInput, newDistribution, _exchangeType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.calcite.rel.logical;
package org.apache.pinot.calcite.rel.logical;

import org.apache.calcite.plan.Convention;
import org.apache.calcite.plan.RelOptCluster;
Expand Down Expand Up @@ -46,9 +46,9 @@ public class PinotLogicalSortExchange extends SortExchange {
protected final boolean _isSortOnReceiver;
protected final PinotRelExchangeType _exchangeType;

private PinotLogicalSortExchange(RelOptCluster cluster, RelTraitSet traitSet,
RelNode input, RelDistribution distribution, PinotRelExchangeType exchangeType, RelCollation collation,
boolean isSortOnSender, boolean isSortOnReceiver) {
private PinotLogicalSortExchange(RelOptCluster cluster, RelTraitSet traitSet, RelNode input,
RelDistribution distribution, PinotRelExchangeType exchangeType, RelCollation collation, boolean isSortOnSender,
boolean isSortOnReceiver) {
super(cluster, traitSet, input, distribution, collation);
_exchangeType = exchangeType;
_isSortOnSender = isSortOnSender;
Expand All @@ -65,12 +65,8 @@ public PinotLogicalSortExchange(RelInput input) {
_isSortOnReceiver = true;
}

public static PinotLogicalSortExchange create(
RelNode input,
RelDistribution distribution,
RelCollation collation,
boolean isSortOnSender,
boolean isSortOnReceiver) {
public static PinotLogicalSortExchange create(RelNode input, RelDistribution distribution, RelCollation collation,
boolean isSortOnSender, boolean isSortOnReceiver) {
return create(input, distribution, PinotRelExchangeType.getDefaultExchangeType(), collation, isSortOnSender,
isSortOnReceiver);
}
Expand All @@ -85,36 +81,29 @@ public static PinotLogicalSortExchange create(
* @param isSortOnSender whether to sort on the sender
* @param isSortOnReceiver whether to sort on receiver
*/
public static PinotLogicalSortExchange create(
RelNode input,
RelDistribution distribution,
PinotRelExchangeType exchangeType,
RelCollation collation,
boolean isSortOnSender,
boolean isSortOnReceiver) {
public static PinotLogicalSortExchange create(RelNode input, RelDistribution distribution,
PinotRelExchangeType exchangeType, RelCollation collation, boolean isSortOnSender, boolean isSortOnReceiver) {
RelOptCluster cluster = input.getCluster();
collation = RelCollationTraitDef.INSTANCE.canonize(collation);
distribution = RelDistributionTraitDef.INSTANCE.canonize(distribution);
RelTraitSet traitSet =
input.getTraitSet().replace(Convention.NONE).replace(distribution).replace(collation);
return new PinotLogicalSortExchange(cluster, traitSet, input, distribution, exchangeType,
collation, isSortOnSender, isSortOnReceiver);
RelTraitSet traitSet = input.getTraitSet().replace(Convention.NONE).replace(distribution).replace(collation);
return new PinotLogicalSortExchange(cluster, traitSet, input, distribution, exchangeType, collation, isSortOnSender,
isSortOnReceiver);
}

//~ Methods ----------------------------------------------------------------

@Override
public SortExchange copy(RelTraitSet traitSet, RelNode newInput,
RelDistribution newDistribution, RelCollation newCollation) {
return new PinotLogicalSortExchange(this.getCluster(), traitSet, newInput,
newDistribution, _exchangeType, newCollation, _isSortOnSender, _isSortOnReceiver);
public SortExchange copy(RelTraitSet traitSet, RelNode newInput, RelDistribution newDistribution,
RelCollation newCollation) {
return new PinotLogicalSortExchange(this.getCluster(), traitSet, newInput, newDistribution, _exchangeType,
newCollation, _isSortOnSender, _isSortOnReceiver);
}

@Override
public RelWriter explainTerms(RelWriter pw) {
RelWriter relWriter = super.explainTerms(pw)
.item("isSortOnSender", _isSortOnSender)
.item("isSortOnReceiver", _isSortOnReceiver);
RelWriter relWriter =
super.explainTerms(pw).item("isSortOnSender", _isSortOnSender).item("isSortOnReceiver", _isSortOnReceiver);
if (_exchangeType != PinotRelExchangeType.getDefaultExchangeType()) {
relWriter.item("relExchangeType", _exchangeType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.calcite.rel.logical;
package org.apache.pinot.calcite.rel.logical;

/** Type of exchange. */
public enum PinotRelExchangeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.calcite.rel.rules;

// NOTE: this file was generated using Calcite's code generator, but instead of pulling in all
// the dependencies for codegen we just manually generate it and check it in. If active development
// on this needs to happen, re-generate it using Calcite's generator.

// CHECKSTYLE:OFF
package org.apache.pinot.calcite.rel.rules;

import com.google.common.base.MoreObjects;
import java.util.ArrayList;
Expand All @@ -35,10 +29,16 @@


/**
* NOTE: this file was generated using Calcite's code generator, but instead of pulling in all
* the dependencies for codegen we just manually generate it and check it in. If active development
* on this needs to happen, re-generate it using Calcite's generator.
*
* {@code ImmutableSortExchangeCopyRule} contains immutable implementation classes generated from
* abstract value types defined as nested inside {@link SortExchangeCopyRule}.
* @see ImmutableSortExchangeCopyRule.Config
*/
// CHECKSTYLE:OFF
//@formatter:off
@SuppressWarnings({"all"})
final class ImmutableSortExchangeCopyRule {
private ImmutableSortExchangeCopyRule() {
Expand Down Expand Up @@ -412,3 +412,4 @@ public ImmutableSortExchangeCopyRule.Config build() {
}
}
}
//@formatter:on
Loading