com.hazelcast.org.apache.calcite.rel.logical.LogicalValues Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.org.apache.calcite.rel.logical;
import com.hazelcast.org.apache.calcite.plan.Convention;
import com.hazelcast.org.apache.calcite.plan.RelOptCluster;
import com.hazelcast.org.apache.calcite.plan.RelTraitSet;
import com.hazelcast.org.apache.calcite.rel.RelCollationTraitDef;
import com.hazelcast.org.apache.calcite.rel.RelDistributionTraitDef;
import com.hazelcast.org.apache.calcite.rel.RelInput;
import com.hazelcast.org.apache.calcite.rel.RelNode;
import com.hazelcast.org.apache.calcite.rel.RelShuttle;
import com.hazelcast.org.apache.calcite.rel.core.Values;
import com.hazelcast.org.apache.calcite.rel.hint.RelHint;
import com.hazelcast.org.apache.calcite.rel.metadata.RelMdCollation;
import com.hazelcast.org.apache.calcite.rel.metadata.RelMdDistribution;
import com.hazelcast.org.apache.calcite.rel.metadata.RelMetadataQuery;
import com.hazelcast.org.apache.calcite.rel.type.RelDataType;
import com.hazelcast.org.apache.calcite.rex.RexLiteral;
import com.hazelcast.org.apache.calcite.sql.type.SqlTypeName;
import com.hazelcast.com.google.common.collect.ImmutableList;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
/**
* Sub-class of {@link com.hazelcast.org.apache.calcite.rel.core.Values}
* not targeted at any particular engine or calling convention.
*/
public class LogicalValues extends Values {
//~ Constructors -----------------------------------------------------------
/**
* Creates a LogicalValues.
*
* Use {@link #create} unless you know what you're doing.
*
* @param cluster Cluster that this relational expression belongs to
* @param hints Hints for this node
* @param rowType Row type for tuples produced by this rel
* @param tuples 2-dimensional array of tuple values to be produced; outer
* list contains tuples; each inner list is one tuple; all
* tuples must be of same length, conforming to rowType
*/
public LogicalValues(
RelOptCluster cluster,
RelTraitSet traitSet,
List hints,
RelDataType rowType,
ImmutableList> tuples) {
super(cluster, hints, rowType, tuples, traitSet);
}
/**
* Creates a LogicalValues.
*
* Use {@link #create} unless you know what you're doing.
*
* @param cluster Cluster that this relational expression belongs to
* @param rowType Row type for tuples produced by this rel
* @param tuples 2-dimensional array of tuple values to be produced; outer
* list contains tuples; each inner list is one tuple; all
* tuples must be of same length, conforming to rowType
*/
public LogicalValues(
RelOptCluster cluster,
RelTraitSet traitSet,
RelDataType rowType,
ImmutableList> tuples) {
this(cluster, traitSet, Collections.emptyList(), rowType, tuples);
}
@Deprecated // to be removed before 2.0
public LogicalValues(
RelOptCluster cluster,
RelDataType rowType,
ImmutableList> tuples) {
this(cluster, cluster.traitSetOf(Convention.NONE), rowType, tuples);
}
/**
* Creates a LogicalValues by parsing serialized output.
*/
public LogicalValues(RelInput input) {
super(input);
}
/** Creates a LogicalValues. */
public static LogicalValues create(RelOptCluster cluster,
final RelDataType rowType,
final ImmutableList> tuples) {
final RelMetadataQuery mq = cluster.getMetadataQuery();
final RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE)
.replaceIfs(RelCollationTraitDef.INSTANCE,
() -> RelMdCollation.values(mq, rowType, tuples))
.replaceIf(RelDistributionTraitDef.INSTANCE,
() -> RelMdDistribution.values(rowType, tuples));
return new LogicalValues(cluster, traitSet, rowType, tuples);
}
@Override public RelNode copy(RelTraitSet traitSet, List inputs) {
assert traitSet.containsIfApplicable(Convention.NONE);
assert inputs.isEmpty();
return new LogicalValues(getCluster(), traitSet, getRowType(), tuples);
}
/** Creates a LogicalValues that outputs no rows of a given row type. */
public static LogicalValues createEmpty(RelOptCluster cluster,
RelDataType rowType) {
return create(cluster, rowType,
ImmutableList.of());
}
/** Creates a LogicalValues that outputs one row and one column. */
public static LogicalValues createOneRow(RelOptCluster cluster) {
final RelDataType rowType =
cluster.getTypeFactory().builder()
.add("ZERO", SqlTypeName.INTEGER).nullable(false)
.build();
final ImmutableList> tuples =
ImmutableList.of(
ImmutableList.of(
cluster.getRexBuilder().makeExactLiteral(BigDecimal.ZERO,
rowType.getFieldList().get(0).getType())));
return create(cluster, rowType, tuples);
}
@Override public RelNode accept(RelShuttle shuttle) {
return shuttle.visit(this);
}
@Override public RelNode withHints(List hintList) {
return new LogicalValues(getCluster(), traitSet, hintList, getRowType(), tuples);
}
}