http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRules.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRules.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRules.java deleted file mode 100644 index 29ee347..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRules.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.plan.RelOptRule; -import org.apache.calcite.util.trace.CalciteTrace; - -import org.slf4j.Logger; - -/** - * Rules and relational operators for the - * {@link EnumerableConvention enumerable calling convention}. - */ -public class EnumerableRules { - protected static final Logger LOGGER = CalciteTrace.getPlannerTracer(); - - public static final boolean BRIDGE_METHODS = true; - - public static final RelOptRule ENUMERABLE_JOIN_RULE = - new EnumerableJoinRule(); - - public static final RelOptRule ENUMERABLE_MERGE_JOIN_RULE = - new EnumerableMergeJoinRule(); - - public static final RelOptRule ENUMERABLE_SEMI_JOIN_RULE = - new EnumerableSemiJoinRule(); - - public static final RelOptRule ENUMERABLE_CORRELATE_RULE = - new EnumerableCorrelateRule(); - - private EnumerableRules() { - } - - public static final EnumerableProjectRule ENUMERABLE_PROJECT_RULE = - new EnumerableProjectRule(); - - public static final EnumerableFilterRule ENUMERABLE_FILTER_RULE = - new EnumerableFilterRule(); - - public static final EnumerableCalcRule ENUMERABLE_CALC_RULE = - new EnumerableCalcRule(); - - public static final EnumerableAggregateRule ENUMERABLE_AGGREGATE_RULE = - new EnumerableAggregateRule(); - - public static final EnumerableSortRule ENUMERABLE_SORT_RULE = - new EnumerableSortRule(); - - public static final EnumerableLimitRule ENUMERABLE_LIMIT_RULE = - new EnumerableLimitRule(); - - public static final EnumerableUnionRule ENUMERABLE_UNION_RULE = - new EnumerableUnionRule(); - - public static final EnumerableIntersectRule ENUMERABLE_INTERSECT_RULE = - new EnumerableIntersectRule(); - - public static final EnumerableMinusRule ENUMERABLE_MINUS_RULE = - new EnumerableMinusRule(); - - public static final EnumerableTableModifyRule - ENUMERABLE_TABLE_MODIFICATION_RULE = new EnumerableTableModifyRule(); - - public static final EnumerableValuesRule ENUMERABLE_VALUES_RULE = - new EnumerableValuesRule(); - - public static final EnumerableWindowRule ENUMERABLE_WINDOW_RULE = - new EnumerableWindowRule(); - - public static final EnumerableCollectRule ENUMERABLE_COLLECT_RULE = - new EnumerableCollectRule(); - - public static final EnumerableUncollectRule ENUMERABLE_UNCOLLECT_RULE = - new EnumerableUncollectRule(); - - public static final EnumerableFilterToCalcRule - ENUMERABLE_FILTER_TO_CALC_RULE = new EnumerableFilterToCalcRule(); - - public static final EnumerableProjectToCalcRule - ENUMERABLE_PROJECT_TO_CALC_RULE = new EnumerableProjectToCalcRule(); - - public static final EnumerableTableScanRule ENUMERABLE_TABLE_SCAN_RULE = - new EnumerableTableScanRule(); - - public static final EnumerableTableFunctionScanRule - ENUMERABLE_TABLE_FUNCTION_SCAN_RULE = new EnumerableTableFunctionScanRule(); -} - -// End EnumerableRules.java
http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSemiJoin.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSemiJoin.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSemiJoin.java deleted file mode 100644 index 0162c51..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSemiJoin.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.linq4j.tree.BlockBuilder; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; -import org.apache.calcite.plan.RelOptCluster; -import org.apache.calcite.plan.RelOptCost; -import org.apache.calcite.plan.RelOptPlanner; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.InvalidRelException; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.core.JoinInfo; -import org.apache.calcite.rel.core.JoinRelType; -import org.apache.calcite.rel.core.SemiJoin; -import org.apache.calcite.rel.metadata.RelMetadataQuery; -import org.apache.calcite.rex.RexNode; -import org.apache.calcite.util.BuiltInMethod; -import org.apache.calcite.util.ImmutableIntList; -import org.apache.calcite.util.Util; - -/** Implementation of {@link org.apache.calcite.rel.core.SemiJoin} in - * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */ -public class EnumerableSemiJoin extends SemiJoin implements EnumerableRel { - /** Creates an EnumerableSemiJoin. - * - * <p>Use {@link #create} unless you know what you're doing. */ - EnumerableSemiJoin( - RelOptCluster cluster, - RelTraitSet traits, - RelNode left, - RelNode right, - RexNode condition, - ImmutableIntList leftKeys, - ImmutableIntList rightKeys) - throws InvalidRelException { - super(cluster, traits, left, right, condition, leftKeys, rightKeys); - } - - /** Creates an EnumerableSemiJoin. */ - public static EnumerableSemiJoin create(RelNode left, RelNode right, RexNode condition, - ImmutableIntList leftKeys, ImmutableIntList rightKeys) { - final RelOptCluster cluster = left.getCluster(); - try { - return new EnumerableSemiJoin(cluster, - cluster.traitSetOf(EnumerableConvention.INSTANCE), left, - right, condition, leftKeys, rightKeys); - } catch (InvalidRelException e) { - // Semantic error not possible. Must be a bug. Convert to - // internal error. - throw new AssertionError(e); - } - } - - @Override public SemiJoin copy(RelTraitSet traitSet, RexNode condition, - RelNode left, RelNode right, JoinRelType joinType, - boolean semiJoinDone) { - assert joinType == JoinRelType.INNER; - final JoinInfo joinInfo = JoinInfo.of(left, right, condition); - assert joinInfo.isEqui(); - try { - return new EnumerableSemiJoin(getCluster(), traitSet, left, right, - condition, joinInfo.leftKeys, joinInfo.rightKeys); - } catch (InvalidRelException e) { - // Semantic error not possible. Must be a bug. Convert to - // internal error. - throw new AssertionError(e); - } - } - - @Override public RelOptCost computeSelfCost(RelOptPlanner planner, - RelMetadataQuery mq) { - double rowCount = mq.getRowCount(this); - - // Right-hand input is the "build", and hopefully small, input. - final double rightRowCount = right.estimateRowCount(mq); - final double leftRowCount = left.estimateRowCount(mq); - if (Double.isInfinite(leftRowCount)) { - rowCount = leftRowCount; - } else { - rowCount += Util.nLogN(leftRowCount); - } - if (Double.isInfinite(rightRowCount)) { - rowCount = rightRowCount; - } else { - rowCount += rightRowCount; - } - return planner.getCostFactory().makeCost(rowCount, 0, 0).multiplyBy(.01d); - } - - public Result implement(EnumerableRelImplementor implementor, Prefer pref) { - BlockBuilder builder = new BlockBuilder(); - final Result leftResult = - implementor.visitChild(this, 0, (EnumerableRel) left, pref); - Expression leftExpression = - builder.append( - "left", leftResult.block); - final Result rightResult = - implementor.visitChild(this, 1, (EnumerableRel) right, pref); - Expression rightExpression = - builder.append( - "right", rightResult.block); - final PhysType physType = leftResult.physType; - return implementor.result( - physType, - builder.append( - Expressions.call( - BuiltInMethod.SEMI_JOIN.method, - Expressions.list( - leftExpression, - rightExpression, - leftResult.physType.generateAccessor(leftKeys), - rightResult.physType.generateAccessor(rightKeys)))) - .toBlock()); - } -} - -// End EnumerableSemiJoin.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSemiJoinRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSemiJoinRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSemiJoinRule.java deleted file mode 100644 index 96f4be7..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSemiJoinRule.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.plan.Convention; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.convert.ConverterRule; -import org.apache.calcite.rel.core.SemiJoin; - -import java.util.ArrayList; -import java.util.List; - -/** Planner rule that converts a - * {@link org.apache.calcite.rel.core.SemiJoin} relational expression - * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */ -class EnumerableSemiJoinRule extends ConverterRule { - EnumerableSemiJoinRule() { - super(SemiJoin.class, Convention.NONE, EnumerableConvention.INSTANCE, - "EnumerableSemiJoinRule"); - } - - @Override public RelNode convert(RelNode rel) { - final SemiJoin semiJoin = (SemiJoin) rel; - final List<RelNode> newInputs = new ArrayList<>(); - for (RelNode input : semiJoin.getInputs()) { - if (!(input.getConvention() instanceof EnumerableConvention)) { - input = - convert(input, - input.getTraitSet().replace(EnumerableConvention.INSTANCE)); - } - newInputs.add(input); - } - return EnumerableSemiJoin.create(newInputs.get(0), newInputs.get(1), - semiJoin.getCondition(), semiJoin.leftKeys, semiJoin.rightKeys); - } -} - -// End EnumerableSemiJoinRule.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSort.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSort.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSort.java deleted file mode 100644 index 8046d64..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSort.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.linq4j.tree.BlockBuilder; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; -import org.apache.calcite.plan.RelOptCluster; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.RelCollation; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.core.Sort; -import org.apache.calcite.rex.RexNode; -import org.apache.calcite.util.BuiltInMethod; -import org.apache.calcite.util.Pair; - -/** Implementation of {@link org.apache.calcite.rel.core.Sort} in - * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */ -public class EnumerableSort extends Sort implements EnumerableRel { - /** - * Creates an EnumerableSort. - * - * <p>Use {@link #create} unless you know what you're doing. - */ - public EnumerableSort(RelOptCluster cluster, RelTraitSet traitSet, - RelNode input, RelCollation collation, RexNode offset, RexNode fetch) { - super(cluster, traitSet, input, collation, offset, fetch); - assert getConvention() instanceof EnumerableConvention; - assert getConvention() == input.getConvention(); - } - - /** Creates an EnumerableSort. */ - public static EnumerableSort create(RelNode child, RelCollation collation, - RexNode offset, RexNode fetch) { - final RelOptCluster cluster = child.getCluster(); - final RelTraitSet traitSet = - cluster.traitSetOf(EnumerableConvention.INSTANCE) - .replace(collation); - return new EnumerableSort(cluster, traitSet, child, collation, offset, - fetch); - } - - @Override public EnumerableSort copy( - RelTraitSet traitSet, - RelNode newInput, - RelCollation newCollation, - RexNode offset, - RexNode fetch) { - return new EnumerableSort(getCluster(), traitSet, newInput, newCollation, - offset, fetch); - } - - public Result implement(EnumerableRelImplementor implementor, Prefer pref) { - final BlockBuilder builder = new BlockBuilder(); - final EnumerableRel child = (EnumerableRel) getInput(); - final Result result = implementor.visitChild(this, 0, child, pref); - final PhysType physType = - PhysTypeImpl.of( - implementor.getTypeFactory(), - getRowType(), - result.format); - Expression childExp = - builder.append("child", result.block); - - PhysType inputPhysType = result.physType; - final Pair<Expression, Expression> pair = - inputPhysType.generateCollationKey( - collation.getFieldCollations()); - - builder.add( - Expressions.return_(null, - Expressions.call(childExp, - BuiltInMethod.ORDER_BY.method, - Expressions.list( - builder.append("keySelector", pair.left)) - .appendIfNotNull( - builder.appendIfNotNull("comparator", pair.right))))); - return implementor.result(physType, builder.toBlock()); - } -} - -// End EnumerableSort.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSortRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSortRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSortRule.java deleted file mode 100644 index eb3d737..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableSortRule.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.plan.Convention; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.convert.ConverterRule; -import org.apache.calcite.rel.core.Sort; - -/** - * Rule to convert an {@link org.apache.calcite.rel.core.Sort} to an - * {@link EnumerableSort}. - */ -class EnumerableSortRule extends ConverterRule { - EnumerableSortRule() { - super(Sort.class, Convention.NONE, EnumerableConvention.INSTANCE, - "EnumerableSortRule"); - } - - public RelNode convert(RelNode rel) { - final Sort sort = (Sort) rel; - if (sort.offset != null || sort.fetch != null) { - return null; - } - final RelNode input = sort.getInput(); - return EnumerableSort.create( - convert( - input, - input.getTraitSet().replace(EnumerableConvention.INSTANCE)), - sort.getCollation(), - null, - null); - } -} - -// End EnumerableSortRule.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableFunctionScan.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableFunctionScan.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableFunctionScan.java deleted file mode 100644 index 90892fa..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableFunctionScan.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.adapter.java.JavaTypeFactory; -import org.apache.calcite.linq4j.tree.BlockBuilder; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; -import org.apache.calcite.plan.RelOptCluster; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.core.TableFunctionScan; -import org.apache.calcite.rel.metadata.RelColumnMapping; -import org.apache.calcite.rel.type.RelDataType; -import org.apache.calcite.rex.RexCall; -import org.apache.calcite.rex.RexNode; -import org.apache.calcite.schema.QueryableTable; -import org.apache.calcite.schema.impl.TableFunctionImpl; -import org.apache.calcite.sql.validate.SqlUserDefinedTableFunction; -import org.apache.calcite.util.BuiltInMethod; - -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.util.List; -import java.util.Set; - -/** Implementation of {@link org.apache.calcite.rel.core.TableFunctionScan} in - * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */ -public class EnumerableTableFunctionScan extends TableFunctionScan - implements EnumerableRel { - - public EnumerableTableFunctionScan(RelOptCluster cluster, - RelTraitSet traits, List<RelNode> inputs, Type elementType, - RelDataType rowType, RexNode call, - Set<RelColumnMapping> columnMappings) { - super(cluster, traits, inputs, call, elementType, rowType, - columnMappings); - } - - @Override public EnumerableTableFunctionScan copy( - RelTraitSet traitSet, - List<RelNode> inputs, - RexNode rexCall, - Type elementType, - RelDataType rowType, - Set<RelColumnMapping> columnMappings) { - return new EnumerableTableFunctionScan(getCluster(), traitSet, inputs, - elementType, rowType, rexCall, columnMappings); - } - - public Result implement(EnumerableRelImplementor implementor, Prefer pref) { - BlockBuilder bb = new BlockBuilder(); - // Non-array user-specified types are not supported yet - final JavaRowFormat format; - boolean array = false; - if (getElementType() == null) { - format = JavaRowFormat.ARRAY; - } else if (rowType.getFieldCount() == 1 && isQueryable()) { - format = JavaRowFormat.SCALAR; - } else if (getElementType() instanceof Class - && Object[].class.isAssignableFrom((Class) getElementType())) { - array = true; - format = JavaRowFormat.ARRAY; - } else { - format = JavaRowFormat.CUSTOM; - } - final PhysType physType = - PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), format, - false); - RexToLixTranslator t = RexToLixTranslator.forAggregation( - (JavaTypeFactory) getCluster().getTypeFactory(), bb, null); - t = t.setCorrelates(implementor.allCorrelateVariables); - Expression translated = t.translate(getCall()); - if (array && rowType.getFieldCount() == 1) { - translated = - Expressions.call(null, BuiltInMethod.SLICE0.method, translated); - } - bb.add(Expressions.return_(null, translated)); - return implementor.result(physType, bb.toBlock()); - } - - private boolean isQueryable() { - if (!(getCall() instanceof RexCall)) { - return false; - } - final RexCall call = (RexCall) getCall(); - if (!(call.getOperator() instanceof SqlUserDefinedTableFunction)) { - return false; - } - final SqlUserDefinedTableFunction udtf = - (SqlUserDefinedTableFunction) call.getOperator(); - if (!(udtf.getFunction() instanceof TableFunctionImpl)) { - return false; - } - final TableFunctionImpl tableFunction = - (TableFunctionImpl) udtf.getFunction(); - final Method method = tableFunction.method; - return QueryableTable.class.isAssignableFrom(method.getReturnType()); - } -} - -// End EnumerableTableFunctionScan.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableFunctionScanRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableFunctionScanRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableFunctionScanRule.java deleted file mode 100644 index 5d06c18..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableFunctionScanRule.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.plan.Convention; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.convert.ConverterRule; -import org.apache.calcite.rel.logical.LogicalTableFunctionScan; - -/** Planner rule that converts a - * {@link org.apache.calcite.rel.logical.LogicalTableFunctionScan} - * relational expression - * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */ -public class EnumerableTableFunctionScanRule extends ConverterRule { - public EnumerableTableFunctionScanRule() { - super(LogicalTableFunctionScan.class, Convention.NONE, - EnumerableConvention.INSTANCE, "EnumerableTableFunctionScanRule"); - } - - @Override public RelNode convert(RelNode rel) { - final RelTraitSet traitSet = - rel.getTraitSet().replace(EnumerableConvention.INSTANCE); - LogicalTableFunctionScan tbl = (LogicalTableFunctionScan) rel; - return new EnumerableTableFunctionScan(rel.getCluster(), traitSet, - tbl.getInputs(), tbl.getElementType(), tbl.getRowType(), - tbl.getCall(), tbl.getColumnMappings()); - } -} - -// End EnumerableTableFunctionScanRule.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModify.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModify.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModify.java deleted file mode 100644 index 14ac0de..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModify.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.adapter.java.JavaTypeFactory; -import org.apache.calcite.linq4j.tree.BlockBuilder; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; -import org.apache.calcite.linq4j.tree.ParameterExpression; -import org.apache.calcite.linq4j.tree.Types; -import org.apache.calcite.plan.RelOptCluster; -import org.apache.calcite.plan.RelOptTable; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.prepare.Prepare; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.core.TableModify; -import org.apache.calcite.rex.RexNode; -import org.apache.calcite.schema.ModifiableTable; -import org.apache.calcite.util.BuiltInMethod; - -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** Implementation of {@link org.apache.calcite.rel.core.TableModify} in - * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */ -public class EnumerableTableModify extends TableModify - implements EnumerableRel { - public EnumerableTableModify(RelOptCluster cluster, RelTraitSet traits, - RelOptTable table, Prepare.CatalogReader catalogReader, RelNode child, - Operation operation, List<String> updateColumnList, - List<RexNode> sourceExpressionList, boolean flattened) { - super(cluster, traits, table, catalogReader, child, operation, - updateColumnList, sourceExpressionList, flattened); - assert child.getConvention() instanceof EnumerableConvention; - assert getConvention() instanceof EnumerableConvention; - final ModifiableTable modifiableTable = - table.unwrap(ModifiableTable.class); - if (modifiableTable == null) { - throw new AssertionError(); // TODO: user error in validator - } - } - - @Override public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) { - return new EnumerableTableModify( - getCluster(), - traitSet, - getTable(), - getCatalogReader(), - sole(inputs), - getOperation(), - getUpdateColumnList(), - getSourceExpressionList(), - isFlattened()); - } - - public Result implement(EnumerableRelImplementor implementor, Prefer pref) { - final BlockBuilder builder = new BlockBuilder(); - final Result result = implementor.visitChild( - this, 0, (EnumerableRel) getInput(), pref); - Expression childExp = - builder.append( - "child", result.block); - final ParameterExpression collectionParameter = - Expressions.parameter(Collection.class, - builder.newName("collection")); - final Expression expression = table.getExpression(ModifiableTable.class); - assert expression != null; // TODO: user error in validator - assert ModifiableTable.class.isAssignableFrom( - Types.toClass(expression.getType())) : expression.getType(); - builder.add( - Expressions.declare( - Modifier.FINAL, - collectionParameter, - Expressions.call( - expression, - BuiltInMethod.MODIFIABLE_TABLE_GET_MODIFIABLE_COLLECTION - .method))); - final Expression countParameter = - builder.append( - "count", - Expressions.call(collectionParameter, "size"), - false); - Expression convertedChildExp; - if (!getInput().getRowType().equals(getRowType())) { - final JavaTypeFactory typeFactory = - (JavaTypeFactory) getCluster().getTypeFactory(); - final JavaRowFormat format = EnumerableTableScan.deduceFormat(table); - PhysType physType = - PhysTypeImpl.of(typeFactory, table.getRowType(), format); - List<Expression> expressionList = new ArrayList<Expression>(); - final PhysType childPhysType = result.physType; - final ParameterExpression o_ = - Expressions.parameter(childPhysType.getJavaRowType(), "o"); - final int fieldCount = - childPhysType.getRowType().getFieldCount(); - for (int i = 0; i < fieldCount; i++) { - expressionList.add( - childPhysType.fieldReference(o_, i, physType.getJavaFieldType(i))); - } - convertedChildExp = - builder.append( - "convertedChild", - Expressions.call( - childExp, - BuiltInMethod.SELECT.method, - Expressions.lambda( - physType.record(expressionList), o_))); - } else { - convertedChildExp = childExp; - } - final Method method; - switch (getOperation()) { - case INSERT: - method = BuiltInMethod.INTO.method; - break; - case DELETE: - method = BuiltInMethod.REMOVE_ALL.method; - break; - default: - throw new AssertionError(getOperation()); - } - builder.add( - Expressions.statement( - Expressions.call( - convertedChildExp, method, collectionParameter))); - final Expression updatedCountParameter = - builder.append( - "updatedCount", - Expressions.call(collectionParameter, "size"), - false); - builder.add( - Expressions.return_( - null, - Expressions.call( - BuiltInMethod.SINGLETON_ENUMERABLE.method, - Expressions.convert_( - Expressions.condition( - Expressions.greaterThanOrEqual( - updatedCountParameter, countParameter), - Expressions.subtract( - updatedCountParameter, countParameter), - Expressions.subtract( - countParameter, updatedCountParameter)), - long.class)))); - final PhysType physType = - PhysTypeImpl.of( - implementor.getTypeFactory(), - getRowType(), - pref == Prefer.ARRAY - ? JavaRowFormat.ARRAY : JavaRowFormat.SCALAR); - return implementor.result(physType, builder.toBlock()); - } - -} - -// End EnumerableTableModify.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModifyRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModifyRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModifyRule.java deleted file mode 100644 index 321115f..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableModifyRule.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.plan.Convention; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.convert.ConverterRule; -import org.apache.calcite.rel.logical.LogicalTableModify; -import org.apache.calcite.schema.ModifiableTable; - -/** Planner rule that converts a - * {@link org.apache.calcite.rel.logical.LogicalTableModify} - * relational expression - * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */ -public class EnumerableTableModifyRule extends ConverterRule { - EnumerableTableModifyRule() { - super(LogicalTableModify.class, Convention.NONE, - EnumerableConvention.INSTANCE, "EnumerableTableModificationRule"); - } - - @Override public RelNode convert(RelNode rel) { - final LogicalTableModify modify = - (LogicalTableModify) rel; - final ModifiableTable modifiableTable = - modify.getTable().unwrap(ModifiableTable.class); - if (modifiableTable == null) { - return null; - } - final RelTraitSet traitSet = - modify.getTraitSet().replace(EnumerableConvention.INSTANCE); - return new EnumerableTableModify( - modify.getCluster(), traitSet, - modify.getTable(), - modify.getCatalogReader(), - convert(modify.getInput(), traitSet), - modify.getOperation(), - modify.getUpdateColumnList(), - modify.getSourceExpressionList(), - modify.isFlattened()); - } -} - -// End EnumerableTableModifyRule.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java deleted file mode 100644 index 3b4d8a1..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScan.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.adapter.java.JavaTypeFactory; -import org.apache.calcite.interpreter.Row; -import org.apache.calcite.linq4j.Enumerable; -import org.apache.calcite.linq4j.Queryable; -import org.apache.calcite.linq4j.function.Function1; -import org.apache.calcite.linq4j.tree.Blocks; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; -import org.apache.calcite.linq4j.tree.MethodCallExpression; -import org.apache.calcite.linq4j.tree.ParameterExpression; -import org.apache.calcite.linq4j.tree.Primitive; -import org.apache.calcite.linq4j.tree.Types; -import org.apache.calcite.plan.RelOptCluster; -import org.apache.calcite.plan.RelOptTable; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.RelCollation; -import org.apache.calcite.rel.RelCollationTraitDef; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.core.TableScan; -import org.apache.calcite.rel.type.RelDataType; -import org.apache.calcite.rel.type.RelDataTypeField; -import org.apache.calcite.schema.FilterableTable; -import org.apache.calcite.schema.ProjectableFilterableTable; -import org.apache.calcite.schema.QueryableTable; -import org.apache.calcite.schema.ScannableTable; -import org.apache.calcite.schema.StreamableTable; -import org.apache.calcite.schema.Table; -import org.apache.calcite.util.BuiltInMethod; - -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableList; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - -/** Implementation of {@link org.apache.calcite.rel.core.TableScan} in - * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */ -public class EnumerableTableScan - extends TableScan - implements EnumerableRel { - private final Class elementType; - - /** Creates an EnumerableTableScan. - * - * <p>Use {@link #create} unless you know what you are doing. */ - public EnumerableTableScan(RelOptCluster cluster, RelTraitSet traitSet, - RelOptTable table, Class elementType) { - super(cluster, traitSet, table); - assert getConvention() instanceof EnumerableConvention; - this.elementType = elementType; - } - - /** Creates an EnumerableTableScan. */ - public static EnumerableTableScan create(RelOptCluster cluster, - RelOptTable relOptTable) { - final Table table = relOptTable.unwrap(Table.class); - Class elementType = EnumerableTableScan.deduceElementType(table); - final RelTraitSet traitSet = - cluster.traitSetOf(EnumerableConvention.INSTANCE) - .replaceIfs(RelCollationTraitDef.INSTANCE, - new Supplier<List<RelCollation>>() { - public List<RelCollation> get() { - if (table != null) { - return table.getStatistic().getCollations(); - } - return ImmutableList.of(); - } - }); - return new EnumerableTableScan(cluster, traitSet, relOptTable, elementType); - } - - @Override public boolean equals(Object obj) { - return obj == this - || obj instanceof EnumerableTableScan - && table.equals(((EnumerableTableScan) obj).table); - } - - @Override public int hashCode() { - return table.hashCode(); - } - - /** Returns whether EnumerableTableScan can generate code to handle a - * particular variant of the Table SPI. */ - public static boolean canHandle(Table table) { - // FilterableTable and ProjectableFilterableTable cannot be handled in - // enumerable convention because they might reject filters and those filters - // would need to be handled dynamically. - return table instanceof QueryableTable - || table instanceof ScannableTable; - } - - public static Class deduceElementType(Table table) { - if (table instanceof QueryableTable) { - final QueryableTable queryableTable = (QueryableTable) table; - final Type type = queryableTable.getElementType(); - if (type instanceof Class) { - return (Class) type; - } else { - return Object[].class; - } - } else if (table instanceof ScannableTable - || table instanceof FilterableTable - || table instanceof ProjectableFilterableTable - || table instanceof StreamableTable) { - return Object[].class; - } else { - return Object.class; - } - } - - public static JavaRowFormat deduceFormat(RelOptTable table) { - final Class elementType = deduceElementType(table.unwrap(Table.class)); - return elementType == Object[].class - ? JavaRowFormat.ARRAY - : JavaRowFormat.CUSTOM; - } - - private Expression getExpression(PhysType physType) { - final Expression expression = table.getExpression(Queryable.class); - final Expression expression2 = toEnumerable(expression); - assert Types.isAssignableFrom(Enumerable.class, expression2.getType()); - return toRows(physType, expression2); - } - - private Expression toEnumerable(Expression expression) { - final Type type = expression.getType(); - if (Types.isArray(type)) { - if (Types.toClass(type).getComponentType().isPrimitive()) { - expression = - Expressions.call(BuiltInMethod.AS_LIST.method, expression); - } - return Expressions.call(BuiltInMethod.AS_ENUMERABLE.method, expression); - } else if (Types.isAssignableFrom(Iterable.class, type) - && !Types.isAssignableFrom(Enumerable.class, type)) { - return Expressions.call(BuiltInMethod.AS_ENUMERABLE2.method, - expression); - } else if (Types.isAssignableFrom(Queryable.class, type)) { - // Queryable extends Enumerable, but it's too "clever", so we call - // Queryable.asEnumerable so that operations such as take(int) will be - // evaluated directly. - return Expressions.call(expression, - BuiltInMethod.QUERYABLE_AS_ENUMERABLE.method); - } - return expression; - } - - private Expression toRows(PhysType physType, Expression expression) { - if (physType.getFormat() == JavaRowFormat.SCALAR - && Object[].class.isAssignableFrom(elementType) - && getRowType().getFieldCount() == 1 - && (table.unwrap(ScannableTable.class) != null - || table.unwrap(FilterableTable.class) != null - || table.unwrap(ProjectableFilterableTable.class) != null)) { - return Expressions.call(BuiltInMethod.SLICE0.method, expression); - } - JavaRowFormat oldFormat = format(); - if (physType.getFormat() == oldFormat && !hasCollectionField(rowType)) { - return expression; - } - final ParameterExpression row_ = - Expressions.parameter(elementType, "row"); - final int fieldCount = table.getRowType().getFieldCount(); - List<Expression> expressionList = new ArrayList<>(fieldCount); - for (int i = 0; i < fieldCount; i++) { - expressionList.add(fieldExpression(row_, i, physType, oldFormat)); - } - return Expressions.call(expression, - BuiltInMethod.SELECT.method, - Expressions.lambda(Function1.class, physType.record(expressionList), - row_)); - } - - private Expression fieldExpression(ParameterExpression row_, int i, - PhysType physType, JavaRowFormat format) { - final Expression e = - format.field(row_, i, null, physType.getJavaFieldType(i)); - final RelDataType relFieldType = - physType.getRowType().getFieldList().get(i).getType(); - switch (relFieldType.getSqlTypeName()) { - case ARRAY: - case MULTISET: - // We can't represent a multiset or array as a List<Employee>, because - // the consumer does not know the element type. - // The standard element type is List. - // We need to convert to a List<List>. - final JavaTypeFactory typeFactory = - (JavaTypeFactory) getCluster().getTypeFactory(); - final PhysType elementPhysType = PhysTypeImpl.of( - typeFactory, relFieldType.getComponentType(), JavaRowFormat.CUSTOM); - final MethodCallExpression e2 = - Expressions.call(BuiltInMethod.AS_ENUMERABLE2.method, e); - final RelDataType dummyType = this.rowType; - final Expression e3 = - elementPhysType.convertTo(e2, - PhysTypeImpl.of(typeFactory, dummyType, JavaRowFormat.LIST)); - return Expressions.call(e3, BuiltInMethod.ENUMERABLE_TO_LIST.method); - default: - return e; - } - } - - private JavaRowFormat format() { - int fieldCount = getRowType().getFieldCount(); - if (fieldCount == 0) { - return JavaRowFormat.LIST; - } - if (Object[].class.isAssignableFrom(elementType)) { - return fieldCount == 1 ? JavaRowFormat.SCALAR : JavaRowFormat.ARRAY; - } - if (Row.class.isAssignableFrom(elementType)) { - return JavaRowFormat.ROW; - } - if (fieldCount == 1 && (Object.class == elementType - || Primitive.is(elementType) - || Number.class.isAssignableFrom(elementType))) { - return JavaRowFormat.SCALAR; - } - return JavaRowFormat.CUSTOM; - } - - private boolean hasCollectionField(RelDataType rowType) { - for (RelDataTypeField field : rowType.getFieldList()) { - switch (field.getType().getSqlTypeName()) { - case ARRAY: - case MULTISET: - return true; - } - } - return false; - } - - @Override public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) { - return new EnumerableTableScan(getCluster(), traitSet, table, elementType); - } - - public Result implement(EnumerableRelImplementor implementor, Prefer pref) { - // Note that representation is ARRAY. This assumes that the table - // returns a Object[] for each record. Actually a Table<T> can - // return any type T. And, if it is a JdbcTable, we'd like to be - // able to generate alternate accessors that return e.g. synthetic - // records {T0 f0; T1 f1; ...} and don't box every primitive value. - final PhysType physType = - PhysTypeImpl.of( - implementor.getTypeFactory(), - getRowType(), - format()); - final Expression expression = getExpression(physType); - return implementor.result(physType, Blocks.toBlock(expression)); - } -} - -// End EnumerableTableScan.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScanRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScanRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScanRule.java deleted file mode 100644 index 416c01a..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableTableScanRule.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.plan.Convention; -import org.apache.calcite.plan.RelOptTable; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.convert.ConverterRule; -import org.apache.calcite.rel.logical.LogicalTableScan; -import org.apache.calcite.schema.Table; - -/** Planner rule that converts a - * {@link org.apache.calcite.rel.logical.LogicalTableFunctionScan} - * relational expression - * {@link EnumerableConvention enumerable calling convention}. */ -public class EnumerableTableScanRule extends ConverterRule { - public EnumerableTableScanRule() { - super(LogicalTableScan.class, Convention.NONE, - EnumerableConvention.INSTANCE, "EnumerableTableScanRule"); - } - - @Override public RelNode convert(RelNode rel) { - LogicalTableScan scan = (LogicalTableScan) rel; - final RelOptTable relOptTable = scan.getTable(); - final Table table = relOptTable.unwrap(Table.class); - if (!EnumerableTableScan.canHandle(table)) { - return null; - } - final Expression expression = relOptTable.getExpression(Object.class); - if (expression == null) { - return null; - } - return EnumerableTableScan.create(scan.getCluster(), relOptTable); - } -} - -// End EnumerableTableScanRule.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableThetaJoin.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableThetaJoin.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableThetaJoin.java deleted file mode 100644 index dc400ad..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableThetaJoin.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.linq4j.function.Predicate2; -import org.apache.calcite.linq4j.tree.BlockBuilder; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; -import org.apache.calcite.linq4j.tree.ParameterExpression; -import org.apache.calcite.plan.RelOptCluster; -import org.apache.calcite.plan.RelOptCost; -import org.apache.calcite.plan.RelOptPlanner; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.InvalidRelException; -import org.apache.calcite.rel.RelNode; -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.metadata.RelMetadataQuery; -import org.apache.calcite.rex.RexNode; -import org.apache.calcite.rex.RexProgramBuilder; -import org.apache.calcite.util.BuiltInMethod; -import org.apache.calcite.util.Pair; - -import com.google.common.collect.ImmutableList; - -import java.util.Set; - -/** Implementation of {@link org.apache.calcite.rel.core.Join} in - * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention} - * that allows conditions that are not just {@code =} (equals). */ -public class EnumerableThetaJoin extends Join implements EnumerableRel { - /** Creates an EnumerableThetaJoin. */ - protected EnumerableThetaJoin(RelOptCluster cluster, RelTraitSet traits, - RelNode left, RelNode right, RexNode condition, - Set<CorrelationId> variablesSet, JoinRelType joinType) - throws InvalidRelException { - super(cluster, traits, left, right, condition, variablesSet, joinType); - } - - @Deprecated // to be removed before 2.0 - protected EnumerableThetaJoin(RelOptCluster cluster, RelTraitSet traits, - RelNode left, RelNode right, RexNode condition, JoinRelType joinType, - Set<String> variablesStopped) throws InvalidRelException { - this(cluster, traits, left, right, condition, - CorrelationId.setOf(variablesStopped), joinType); - } - - @Override public EnumerableThetaJoin copy(RelTraitSet traitSet, - RexNode condition, RelNode left, RelNode right, JoinRelType joinType, - boolean semiJoinDone) { - try { - return new EnumerableThetaJoin(getCluster(), traitSet, left, right, - condition, variablesSet, joinType); - } catch (InvalidRelException e) { - // Semantic error not possible. Must be a bug. Convert to - // internal error. - throw new AssertionError(e); - } - } - - @Override public RelOptCost computeSelfCost(RelOptPlanner planner, - RelMetadataQuery mq) { - double rowCount = mq.getRowCount(this); - - // Joins can be flipped, and for many algorithms, both versions are viable - // and have the same cost. To make the results stable between versions of - // the planner, make one of the versions slightly more expensive. - switch (joinType) { - case RIGHT: - rowCount = addEpsilon(rowCount); - break; - default: - if (left.getId() > right.getId()) { - rowCount = addEpsilon(rowCount); - } - } - - final double rightRowCount = right.estimateRowCount(mq); - final double leftRowCount = left.estimateRowCount(mq); - if (Double.isInfinite(leftRowCount)) { - rowCount = leftRowCount; - } - if (Double.isInfinite(rightRowCount)) { - rowCount = rightRowCount; - } - return planner.getCostFactory().makeCost(rowCount, 0, 0); - } - - private double addEpsilon(double d) { - assert d >= 0d; - final double d0 = d; - if (d < 10) { - // For small d, adding 1 would change the value significantly. - d *= 1.001d; - if (d != d0) { - return d; - } - } - // For medium d, add 1. Keeps integral values integral. - ++d; - if (d != d0) { - return d; - } - // For large d, adding 1 might not change the value. Add .1%. - // If d is NaN, this still will probably not change the value. That's OK. - d *= 1.001d; - return d; - } - - public Result implement(EnumerableRelImplementor implementor, Prefer pref) { - final BlockBuilder builder = new BlockBuilder(); - final Result leftResult = - implementor.visitChild(this, 0, (EnumerableRel) left, pref); - Expression leftExpression = - builder.append("left", leftResult.block); - final Result rightResult = - implementor.visitChild(this, 1, (EnumerableRel) right, pref); - Expression rightExpression = - builder.append("right", rightResult.block); - final PhysType physType = - PhysTypeImpl.of(implementor.getTypeFactory(), - getRowType(), - pref.preferArray()); - final BlockBuilder builder2 = new BlockBuilder(); - return implementor.result( - physType, - builder.append( - Expressions.call(BuiltInMethod.THETA_JOIN.method, - leftExpression, - rightExpression, - predicate(implementor, - builder2, - leftResult.physType, - rightResult.physType, - condition), - EnumUtils.joinSelector(joinType, - physType, - ImmutableList.of(leftResult.physType, - rightResult.physType)), - Expressions.constant(joinType.generatesNullsOnLeft()), - Expressions.constant(joinType.generatesNullsOnRight()))) - .toBlock()); - } - - Expression predicate(EnumerableRelImplementor implementor, - BlockBuilder builder, PhysType leftPhysType, PhysType rightPhysType, - RexNode condition) { - final ParameterExpression left_ = - Expressions.parameter(leftPhysType.getJavaRowType(), "left"); - final ParameterExpression right_ = - Expressions.parameter(rightPhysType.getJavaRowType(), "right"); - final RexProgramBuilder program = - new RexProgramBuilder( - implementor.getTypeFactory().builder() - .addAll(left.getRowType().getFieldList()) - .addAll(right.getRowType().getFieldList()) - .build(), - getCluster().getRexBuilder()); - program.addCondition(condition); - builder.add( - Expressions.return_(null, - RexToLixTranslator.translateCondition(program.getProgram(), - implementor.getTypeFactory(), - builder, - new RexToLixTranslator.InputGetterImpl( - ImmutableList.of(Pair.of((Expression) left_, leftPhysType), - Pair.of((Expression) right_, rightPhysType))), - implementor.allCorrelateVariables))); - return Expressions.lambda(Predicate2.class, builder.toBlock(), left_, - right_); - } -} - -// End EnumerableThetaJoin.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollect.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollect.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollect.java deleted file mode 100644 index 9818622..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollect.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.linq4j.tree.BlockBuilder; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; -import org.apache.calcite.plan.RelOptCluster; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.core.Uncollect; -import org.apache.calcite.rel.type.RelDataType; -import org.apache.calcite.rel.type.RelDataTypeField; -import org.apache.calcite.runtime.SqlFunctions.FlatProductInputType; -import org.apache.calcite.sql.type.MapSqlType; -import org.apache.calcite.util.BuiltInMethod; - -import com.google.common.primitives.Ints; - -import java.util.ArrayList; -import java.util.List; - -/** Implementation of {@link org.apache.calcite.rel.core.Uncollect} in - * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */ -public class EnumerableUncollect extends Uncollect implements EnumerableRel { - @Deprecated // to be removed before 2.0 - public EnumerableUncollect(RelOptCluster cluster, RelTraitSet traitSet, - RelNode child) { - this(cluster, traitSet, child, false); - } - - /** Creates an EnumerableUncollect. - * - * <p>Use {@link #create} unless you know what you're doing. */ - public EnumerableUncollect(RelOptCluster cluster, RelTraitSet traitSet, - RelNode child, boolean withOrdinality) { - super(cluster, traitSet, child, withOrdinality); - assert getConvention() instanceof EnumerableConvention; - assert getConvention() == child.getConvention(); - } - - /** - * Creates an EnumerableUncollect. - * - * <p>Each field of the input relational expression must be an array or - * multiset. - * - * @param traitSet Trait set - * @param input Input relational expression - * @param withOrdinality Whether output should contain an ORDINALITY column - */ - public static EnumerableUncollect create(RelTraitSet traitSet, RelNode input, - boolean withOrdinality) { - final RelOptCluster cluster = input.getCluster(); - return new EnumerableUncollect(cluster, traitSet, input, withOrdinality); - } - - @Override public EnumerableUncollect copy(RelTraitSet traitSet, - RelNode newInput) { - return new EnumerableUncollect(getCluster(), traitSet, newInput, - withOrdinality); - } - - public Result implement(EnumerableRelImplementor implementor, Prefer pref) { - final BlockBuilder builder = new BlockBuilder(); - final EnumerableRel child = (EnumerableRel) getInput(); - final Result result = implementor.visitChild(this, 0, child, pref); - final PhysType physType = - PhysTypeImpl.of( - implementor.getTypeFactory(), - getRowType(), - JavaRowFormat.LIST); - - // final Enumerable<List<Employee>> child = <<child adapter>>; - // return child.selectMany(FLAT_PRODUCT); - final Expression child_ = - builder.append( - "child", result.block); - - final List<Integer> fieldCounts = new ArrayList<>(); - final List<FlatProductInputType> inputTypes = new ArrayList<>(); - - for (RelDataTypeField field : child.getRowType().getFieldList()) { - final RelDataType type = field.getType(); - if (type instanceof MapSqlType) { - fieldCounts.add(2); - inputTypes.add(FlatProductInputType.MAP); - } else { - final RelDataType elementType = type.getComponentType(); - if (elementType.isStruct()) { - fieldCounts.add(elementType.getFieldCount()); - inputTypes.add(FlatProductInputType.LIST); - } else { - fieldCounts.add(-1); - inputTypes.add(FlatProductInputType.SCALAR); - } - } - } - - final Expression lambda = - Expressions.call(BuiltInMethod.FLAT_PRODUCT.method, - Expressions.constant(Ints.toArray(fieldCounts)), - Expressions.constant(withOrdinality), - Expressions.constant( - inputTypes.toArray(new FlatProductInputType[inputTypes.size()]))); - builder.add( - Expressions.return_(null, - Expressions.call(child_, - BuiltInMethod.SELECT_MANY.method, - lambda))); - return implementor.result(physType, builder.toBlock()); - } - -} - -// End EnumerableUncollect.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollectRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollectRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollectRule.java deleted file mode 100644 index 2687b1e..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUncollectRule.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.plan.Convention; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.convert.ConverterRule; -import org.apache.calcite.rel.core.Uncollect; - -/** - * Rule to convert an {@link org.apache.calcite.rel.core.Uncollect} to an - * {@link EnumerableUncollect}. - */ -class EnumerableUncollectRule extends ConverterRule { - EnumerableUncollectRule() { - super(Uncollect.class, Convention.NONE, EnumerableConvention.INSTANCE, - "EnumerableUncollectRule"); - } - - public RelNode convert(RelNode rel) { - final Uncollect uncollect = (Uncollect) rel; - final RelTraitSet traitSet = - uncollect.getTraitSet().replace(EnumerableConvention.INSTANCE); - final RelNode input = uncollect.getInput(); - final RelNode newInput = convert(input, - input.getTraitSet().replace(EnumerableConvention.INSTANCE)); - return EnumerableUncollect.create(traitSet, newInput, - uncollect.withOrdinality); - } -} - -// End EnumerableUncollectRule.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUnion.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUnion.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUnion.java deleted file mode 100644 index 2df6550..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUnion.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.linq4j.Ord; -import org.apache.calcite.linq4j.tree.BlockBuilder; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; -import org.apache.calcite.plan.RelOptCluster; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.core.Union; -import org.apache.calcite.util.BuiltInMethod; - -import java.util.List; - -/** Implementation of {@link org.apache.calcite.rel.core.Union} in - * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */ -public class EnumerableUnion extends Union implements EnumerableRel { - public EnumerableUnion(RelOptCluster cluster, RelTraitSet traitSet, - List<RelNode> inputs, boolean all) { - super(cluster, traitSet, inputs, all); - } - - public EnumerableUnion copy(RelTraitSet traitSet, List<RelNode> inputs, - boolean all) { - return new EnumerableUnion(getCluster(), traitSet, inputs, all); - } - - public Result implement(EnumerableRelImplementor implementor, Prefer pref) { - final BlockBuilder builder = new BlockBuilder(); - Expression unionExp = null; - for (Ord<RelNode> ord : Ord.zip(inputs)) { - EnumerableRel input = (EnumerableRel) ord.e; - final Result result = implementor.visitChild(this, ord.i, input, pref); - Expression childExp = - builder.append( - "child" + ord.i, - result.block); - - if (unionExp == null) { - unionExp = childExp; - } else { - unionExp = all - ? Expressions.call(unionExp, BuiltInMethod.CONCAT.method, childExp) - : Expressions.call(unionExp, - BuiltInMethod.UNION.method, - Expressions.list(childExp) - .appendIfNotNull(result.physType.comparer())); - } - - // Once the first input has chosen its format, ask for the same for - // other inputs. - pref = pref.of(result.format); - } - - builder.add(unionExp); - final PhysType physType = - PhysTypeImpl.of( - implementor.getTypeFactory(), - getRowType(), - pref.prefer(JavaRowFormat.CUSTOM)); - return implementor.result(physType, builder.toBlock()); - } -} - -// End EnumerableUnion.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUnionRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUnionRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUnionRule.java deleted file mode 100644 index 42a97f1..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableUnionRule.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.plan.Convention; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.convert.ConverterRule; -import org.apache.calcite.rel.logical.LogicalUnion; - -/** - * Rule to convert an {@link org.apache.calcite.rel.logical.LogicalUnion} to an - * {@link EnumerableUnion}. - */ -class EnumerableUnionRule extends ConverterRule { - EnumerableUnionRule() { - super(LogicalUnion.class, Convention.NONE, EnumerableConvention.INSTANCE, - "EnumerableUnionRule"); - } - - public RelNode convert(RelNode rel) { - final LogicalUnion union = (LogicalUnion) rel; - final EnumerableConvention out = EnumerableConvention.INSTANCE; - final RelTraitSet traitSet = union.getTraitSet().replace(out); - return new EnumerableUnion(rel.getCluster(), traitSet, - convertList(union.getInputs(), out), union.all); - } -} - -// End EnumerableUnionRule.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValues.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValues.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValues.java deleted file mode 100644 index 6023c02..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValues.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.adapter.java.JavaTypeFactory; -import org.apache.calcite.linq4j.tree.BlockBuilder; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; -import org.apache.calcite.linq4j.tree.Primitive; -import org.apache.calcite.plan.RelOptCluster; -import org.apache.calcite.plan.RelTraitSet; -import org.apache.calcite.rel.RelCollation; -import org.apache.calcite.rel.RelCollationTraitDef; -import org.apache.calcite.rel.RelDistribution; -import org.apache.calcite.rel.RelDistributionTraitDef; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.core.Values; -import org.apache.calcite.rel.metadata.RelMdCollation; -import org.apache.calcite.rel.metadata.RelMdDistribution; -import org.apache.calcite.rel.metadata.RelMetadataQuery; -import org.apache.calcite.rel.type.RelDataType; -import org.apache.calcite.rel.type.RelDataTypeField; -import org.apache.calcite.rex.RexLiteral; -import org.apache.calcite.util.BuiltInMethod; -import org.apache.calcite.util.Pair; - -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableList; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - -/** Implementation of {@link org.apache.calcite.rel.core.Values} in - * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */ -public class EnumerableValues extends Values implements EnumerableRel { - /** Creates an EnumerableValues. */ - private EnumerableValues(RelOptCluster cluster, RelDataType rowType, - ImmutableList<ImmutableList<RexLiteral>> tuples, RelTraitSet traitSet) { - super(cluster, rowType, tuples, traitSet); - } - - /** Creates an EnumerableValues. */ - public static EnumerableValues create(RelOptCluster cluster, - final RelDataType rowType, - final ImmutableList<ImmutableList<RexLiteral>> tuples) { - final RelMetadataQuery mq = RelMetadataQuery.instance(); - final RelTraitSet traitSet = - cluster.traitSetOf(EnumerableConvention.INSTANCE) - .replaceIfs(RelCollationTraitDef.INSTANCE, - new Supplier<List<RelCollation>>() { - public List<RelCollation> get() { - return RelMdCollation.values(mq, rowType, tuples); - } - }) - .replaceIf(RelDistributionTraitDef.INSTANCE, - new Supplier<RelDistribution>() { - public RelDistribution get() { - return RelMdDistribution.values(rowType, tuples); - } - }); - return new EnumerableValues(cluster, rowType, tuples, traitSet); - } - - @Override public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) { - assert inputs.isEmpty(); - return create(getCluster(), rowType, tuples); - } - - public Result implement(EnumerableRelImplementor implementor, Prefer pref) { -/* - return Linq4j.asEnumerable( - new Object[][] { - new Object[] {1, 2}, - new Object[] {3, 4} - }); -*/ - final JavaTypeFactory typeFactory = - (JavaTypeFactory) getCluster().getTypeFactory(); - final BlockBuilder builder = new BlockBuilder(); - final PhysType physType = - PhysTypeImpl.of( - implementor.getTypeFactory(), - getRowType(), - pref.preferCustom()); - final Type rowClass = physType.getJavaRowType(); - - final List<Expression> expressions = new ArrayList<Expression>(); - final List<RelDataTypeField> fields = rowType.getFieldList(); - for (List<RexLiteral> tuple : tuples) { - final List<Expression> literals = new ArrayList<Expression>(); - for (Pair<RelDataTypeField, RexLiteral> pair - : Pair.zip(fields, tuple)) { - literals.add( - RexToLixTranslator.translateLiteral( - pair.right, - pair.left.getType(), - typeFactory, - RexImpTable.NullAs.NULL)); - } - expressions.add(physType.record(literals)); - } - builder.add( - Expressions.return_( - null, - Expressions.call( - BuiltInMethod.AS_ENUMERABLE.method, - Expressions.newArrayInit( - Primitive.box(rowClass), expressions)))); - return implementor.result(physType, builder.toBlock()); - } -} - -// End EnumerableValues.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValuesRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValuesRule.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValuesRule.java deleted file mode 100644 index 6e14bcc..0000000 --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableValuesRule.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.adapter.enumerable; - -import org.apache.calcite.plan.Convention; -import org.apache.calcite.rel.RelNode; -import org.apache.calcite.rel.convert.ConverterRule; -import org.apache.calcite.rel.logical.LogicalValues; - -/** Planner rule that converts a - * {@link org.apache.calcite.rel.logical.LogicalValues} - * relational expression - * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention enumerable calling convention}. */ -public class EnumerableValuesRule extends ConverterRule { - EnumerableValuesRule() { - super(LogicalValues.class, Convention.NONE, EnumerableConvention.INSTANCE, - "EnumerableValuesRule"); - } - - @Override public RelNode convert(RelNode rel) { - LogicalValues values = (LogicalValues) rel; - return EnumerableValues.create(values.getCluster(), values.getRowType(), - values.getTuples()); - } -} - -// End EnumerableValuesRule.java
