Skip to content
Permalink
Browse files
IGNITE-16214 Bump version up to 1.28.0 - Fixes #527.
Signed-off-by: zstan <stanilovsky@gmail.com>
  • Loading branch information
zstan committed Dec 28, 2021
1 parent ca29c42 commit 663be6e5d93efd4c88c92305ed40f10fe77dffe4
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 159 deletions.
@@ -67,6 +67,11 @@
<artifactId>calcite-linq4j</artifactId>
</dependency>

<dependency>
<groupId>org.immutables</groupId>
<artifactId>value-annotations</artifactId>
</dependency>

<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>commons-compiler</artifactId>
@@ -19,19 +19,18 @@

import java.util.Collections;
import java.util.Set;
import org.apache.calcite.plan.Convention;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.plan.RelOptRule;
import org.apache.calcite.plan.RelOptRuleCall;
import org.apache.calcite.plan.RelTrait;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.PhysicalNode;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.convert.ConverterRule;
import org.apache.calcite.rel.core.Correlate;
import org.apache.calcite.rel.core.CorrelationId;
import org.apache.calcite.rel.core.JoinRelType;
import org.apache.calcite.rel.core.RelFactories;
import org.apache.calcite.rel.logical.LogicalCorrelate;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteConvention;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteCorrelatedNestedLoopJoin;
import org.apache.ignite.internal.processors.query.calcite.trait.CorrelationTrait;
@@ -44,28 +43,20 @@
* logical operators if decorrelation is enabled, but in some cases query can't be decorrelated (when table function is used for example),
* this rule is required to support such cases.
*/
public class CorrelateToNestedLoopRule extends ConverterRule {
public static final RelOptRule INSTANCE = Config.DEFAULT.toRule();
public class CorrelateToNestedLoopRule extends AbstractIgniteConverterRule<LogicalCorrelate> {
public static final RelOptRule INSTANCE = new CorrelateToNestedLoopRule();

/**
* Constructor.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
public CorrelateToNestedLoopRule(Config cfg) {
super(cfg);
public CorrelateToNestedLoopRule() {
super(LogicalCorrelate.class, "CorrelateToNestedLoopRule");
}

/** {@inheritDoc} */
@Override
public RelNode convert(RelNode rel) {
throw new IllegalStateException("Should not be called");
}

/** {@inheritDoc} */
@Override
public void onMatch(RelOptRuleCall call) {
LogicalCorrelate rel = call.rel(0);

public PhysicalNode convert(RelOptPlanner planner, RelMetadataQuery mq, LogicalCorrelate rel) {
final RelOptCluster cluster = rel.getCluster();

final Set<CorrelationId> correlationIds = Collections.singleton(rel.getCorrelationId());
@@ -80,47 +71,26 @@ public void onMatch(RelOptRuleCall call) {
RelNode left = convert(rel.getLeft(), leftInTraits);
RelNode right = convert(rel.getRight(), rightInTraits);

call.transformTo(
new IgniteCorrelatedNestedLoopJoin(
cluster,
outTraits,
left,
right,
cluster.getRexBuilder().makeLiteral(true),
correlationIds,
rel.getJoinType()
)
return new IgniteCorrelatedNestedLoopJoin(
cluster,
outTraits,
left,
right,
cluster.getRexBuilder().makeLiteral(true),
correlationIds,
rel.getJoinType()
);
}

/**
* Config interface.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
@SuppressWarnings("ClassNameSameAsAncestorName")
public interface Config extends ConverterRule.Config {
Config DEFAULT = ConverterRule.Config.INSTANCE
.withDescription("CorrelateToNestedLoopRule")
.withRelBuilderFactory(RelFactories.LOGICAL_BUILDER)
.as(Config.class)
.withConversion(LogicalCorrelate.class, Convention.NONE, IgniteConvention.INSTANCE);

/**
* WithConversion.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
default Config withConversion(Class<? extends Correlate> clazz, RelTrait in, RelTrait out) {
return withInTrait(in)
.withOutTrait(out)
.withOperandSupplier(b ->
b.operand(clazz).predicate(CorrelateToNestedLoopRule::preMatch).convert(in))
.as(Config.class);
}
@Override public void onMatch(RelOptRuleCall call) {
Correlate join = call.rel(0);

/** {@inheritDoc} */
@Override
default CorrelateToNestedLoopRule toRule() {
return new CorrelateToNestedLoopRule(this);
if (preMatch(join)) {
super.onMatch(call);
}
}

@@ -21,27 +21,24 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.calcite.plan.Convention;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.plan.RelOptRule;
import org.apache.calcite.plan.RelOptRuleCall;
import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.plan.RelTrait;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.PhysicalNode;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.convert.ConverterRule;
import org.apache.calcite.rel.core.CorrelationId;
import org.apache.calcite.rel.core.Join;
import org.apache.calcite.rel.core.JoinRelType;
import org.apache.calcite.rel.core.RelFactories;
import org.apache.calcite.rel.logical.LogicalJoin;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
import org.apache.calcite.rex.RexBuilder;
import org.apache.calcite.rex.RexCorrelVariable;
import org.apache.calcite.rex.RexInputRef;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexShuttle;
import org.apache.calcite.tools.RelBuilder;
import org.apache.calcite.util.ImmutableBeans;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteConvention;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteCorrelatedNestedLoopJoin;
import org.apache.ignite.internal.processors.query.calcite.trait.CorrelationTrait;
@@ -51,36 +48,25 @@
* CorrelatedNestedLoopJoinRule.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
public class CorrelatedNestedLoopJoinRule extends ConverterRule {
public static final RelOptRule INSTANCE = Config.DEFAULT.toRule();
public class CorrelatedNestedLoopJoinRule extends AbstractIgniteConverterRule<LogicalJoin> {
public static final RelOptRule INSTANCE = new CorrelatedNestedLoopJoinRule(1);

public static final RelOptRule INSTANCE_BATCHED = Config.DEFAULT.withBatchSize(100).toRule();
/** TODO: https://issues.apache.org/jira/browse/IGNITE-14757 */
public static final RelOptRule INSTANCE_BATCHED = new CorrelatedNestedLoopJoinRule(100);

private final int batchSize;

/**
* Constructor.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
public CorrelatedNestedLoopJoinRule(Config cfg) {
super(cfg);

int batchSize = cfg.batchSize();
assert batchSize >= 0;
public CorrelatedNestedLoopJoinRule(int batchSize) {
super(LogicalJoin.class, "CorrelatedNestedLoopJoin");

this.batchSize = batchSize;
}

/** {@inheritDoc} */
@Override
public RelNode convert(RelNode rel) {
throw new IllegalStateException("Should not be called");
}

/** {@inheritDoc} */
@Override
public void onMatch(RelOptRuleCall call) {
Join rel = call.rel(0);
@Override protected PhysicalNode convert(RelOptPlanner planner, RelMetadataQuery mq, LogicalJoin rel) {
final int leftFieldCount = rel.getLeft().getRowType().getFieldCount();
final RelOptCluster cluster = rel.getCluster();
final RexBuilder rexBuilder = cluster.getRexBuilder();
@@ -89,21 +75,10 @@ public void onMatch(RelOptRuleCall call) {
final Set<CorrelationId> correlationIds = new HashSet<>();
final ArrayList<RexNode> corrVar = new ArrayList<>();

final Set<CorrelationId> corrIds = RelOptUtil.getVariablesUsed(rel.getRight());

// TODO: remove all near 'if' scope after https://issues.apache.org/jira/browse/CALCITE-4673 will be merged.
if (corrIds.size() > 1) {
CorrelationId corr0 = corrIds.iterator().next();
corrVar.add(rexBuilder.makeCorrel(rel.getLeft().getRowType(), corr0));
correlationIds.add(corr0);
}

if (corrVar.isEmpty()) {
for (int i = 0; i < batchSize; i++) {
CorrelationId correlationId = cluster.createCorrel();
correlationIds.add(correlationId);
corrVar.add(rexBuilder.makeCorrel(rel.getLeft().getRowType(), correlationId));
}
for (int i = 0; i < batchSize; i++) {
CorrelationId correlationId = cluster.createCorrel();
correlationIds.add(correlationId);
corrVar.add(rexBuilder.makeCorrel(rel.getLeft().getRowType(), correlationId));
}

// Generate first condition
@@ -157,55 +132,26 @@ public RexNode visitCorrelVariable(RexCorrelVariable variable) {
RelNode left = convert(rel.getLeft(), leftInTraits);
right = convert(right, rightInTraits);

call.transformTo(
new IgniteCorrelatedNestedLoopJoin(
cluster,
outTraits,
left,
right,
rel.getCondition(),
correlationIds,
joinType
)
return new IgniteCorrelatedNestedLoopJoin(
cluster,
outTraits,
left,
right,
rel.getCondition(),
correlationIds,
joinType
);
}

/**
* Config interface.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
@SuppressWarnings("ClassNameSameAsAncestorName")
public interface Config extends ConverterRule.Config {
Config DEFAULT = ConverterRule.Config.INSTANCE
.withDescription("CorrelatedNestedLoopJoin")
.withRelBuilderFactory(RelFactories.LOGICAL_BUILDER)
.as(Config.class)
.withConversion(LogicalJoin.class, Convention.NONE, IgniteConvention.INSTANCE)
.withBatchSize(1);

/** Description of the rule instance. */
@ImmutableBeans.Property
int batchSize();

/** Sets {@link #description()}. */
Config withBatchSize(int batchSize);

/**
* WithConversion.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
default Config withConversion(Class<? extends Join> clazz, RelTrait in, RelTrait out) {
return withInTrait(in)
.withOutTrait(out)
.withOperandSupplier(b ->
b.operand(clazz).predicate(CorrelatedNestedLoopJoinRule::preMatch).convert(in))
.as(Config.class);
}
@Override public void onMatch(RelOptRuleCall call) {
LogicalJoin join = call.rel(0);

/** {@inheritDoc} */
@Override
default CorrelatedNestedLoopJoinRule toRule() {
return new CorrelatedNestedLoopJoinRule(this);
if (preMatch(join)) {
super.onMatch(call);
}
}

@@ -19,20 +19,14 @@

import static org.apache.ignite.internal.util.CollectionUtils.nullOrEmpty;

import java.util.List;
import java.util.Set;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.plan.RelOptRule;
import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.rel.PhysicalNode;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.CorrelationId;
import org.apache.calcite.rel.logical.LogicalTableFunctionScan;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
import org.apache.calcite.rex.RexBuilder;
import org.apache.calcite.sql2rel.DeduplicateCorrelateVariables;
import org.apache.calcite.util.Util;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteConvention;
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteTableFunctionScan;
import org.apache.ignite.internal.processors.query.calcite.trait.CorrelationTrait;
@@ -61,23 +55,8 @@ protected PhysicalNode convert(RelOptPlanner planner, RelMetadataQuery mq, Logic
.replace(RewindabilityTrait.REWINDABLE)
.replace(IgniteDistributions.broadcast());

RexBuilder rexBuilder = rel.getCluster().getRexBuilder();

Set<CorrelationId> corrIds = RexUtils.extractCorrelationIds(rel.getCall());

// TODO: remove all near 'if' scope after https://issues.apache.org/jira/browse/CALCITE-4673 will be merged.
if (corrIds.size() > 1) {
final List<CorrelationId> correlNames = List.copyOf(corrIds);

RelNode rel0 = DeduplicateCorrelateVariables.go(rexBuilder, correlNames.get(0), Util.skip(correlNames), rel);

corrIds = RelOptUtil.getVariablesUsed(rel0);

assert corrIds.size() == 1 : "Multiple correlates are applied: " + corrIds;

rel = (LogicalTableFunctionScan) rel0;
}

if (!corrIds.isEmpty()) {
traitSet = traitSet.replace(CorrelationTrait.correlations(corrIds));
}
@@ -111,11 +111,11 @@ public void testSetOpAllRandom(SetOp setOp) throws Exception {
+ "SELECT * FROM random_tbl2 ";

assertPlan(sql, publicSchema, isInstanceOf(setOp.reduce).and(IgniteSetOp::all)
.and(hasChildThat(isInstanceOf(setOp.map)
.and(input(0, isTableScan("random_tbl1")))
.and(input(1, isTableScan("random_tbl2")))
))
);
.and(hasChildThat(isInstanceOf(setOp.map)
.and(input(0, isTableScan("random_tbl1")))
.and(input(1, isTableScan("random_tbl2")))
)),
"SingleIntersectConverterRule");
}

/**
@@ -70,9 +70,10 @@
<hamcrest.version>2.2</hamcrest.version>
<hamcrest.optional.version>2.0.0</hamcrest.optional.version>
<scalecube.version>2.6.12</scalecube.version>
<calcite.version>1.27.0</calcite.version>
<janino.version>3.1.4</janino.version>
<avatica.version>1.18.0</avatica.version>
<calcite.version>1.28.0</calcite.version>
<immutables.version>2.8.8</immutables.version>
<janino.version>3.1.6</janino.version>
<avatica.version>1.19.0</avatica.version>
<jsonpath.version>2.4.0</jsonpath.version>
<reflections.version>0.9.10</reflections.version>
<javassist.version>3.28.0-GA</javassist.version>
@@ -155,6 +156,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.immutables</groupId>
<artifactId>value-annotations</artifactId>
<version>${immutables.version}</version>
</dependency>

<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-cli-common</artifactId>

0 comments on commit 663be6e

Please sign in to comment.