com.facebook.presto.jdbc.internal.spi.plan.ValuesNode Maven / Gradle / Ivy
The newest version!
/*
* Licensed 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.facebook.presto.jdbc.internal.spi.plan;
import com.facebook.presto.jdbc.internal.spi.SourceLocation;
import com.facebook.presto.jdbc.internal.spi.relation.RowExpression;
import com.facebook.presto.jdbc.internal.spi.relation.VariableReferenceExpression;
import com.facebook.presto.jdbc.internal.jackson.annotation.JsonCreator;
import com.facebook.presto.jdbc.internal.jackson.annotation.JsonProperty;
import com.facebook.presto.jdbc.internal.javax.annotation.concurrent.Immutable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static java.lang.String.format;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;
@Immutable
public final class ValuesNode
extends PlanNode
{
private final List outputVariables;
private final List> rows;
// valuesNodeLabel is to record the original table information if the ValuesNode is converted from a table scan.
// Only used in query plan print, does not affect execution.
private final Optional valuesNodeLabel;
@JsonCreator
public ValuesNode(
@JsonProperty("location") Optional sourceLocation,
@JsonProperty("id") PlanNodeId id,
@JsonProperty("outputVariables") List outputVariables,
@JsonProperty("rows") List> rows,
@JsonProperty("valuesNodeLabel") Optional valuesNodeLabel)
{
this(sourceLocation, id, Optional.empty(), outputVariables, rows, valuesNodeLabel);
}
public ValuesNode(
Optional sourceLocation,
PlanNodeId id,
Optional statsEquivalentPlanNode,
List outputVariables,
List> rows,
Optional valuesNodeLabel)
{
super(sourceLocation, id, statsEquivalentPlanNode);
this.outputVariables = immutableListCopyOf(outputVariables);
this.rows = immutableListCopyOf(requireNonNull(rows, "lists is null").stream().map(ValuesNode::immutableListCopyOf).collect(Collectors.toList()));
for (List row : rows) {
if (!(row.size() == outputVariables.size() || row.isEmpty())) {
throw new IllegalArgumentException(format("Expected row to have %s values, but row has %s values", outputVariables.size(), row.size()));
}
}
this.valuesNodeLabel = valuesNodeLabel;
}
public Optional getValuesNodeLabel()
{
return valuesNodeLabel;
}
@JsonProperty
public List> getRows()
{
return rows;
}
@Override
public LogicalProperties computeLogicalProperties(LogicalPropertiesProvider logicalPropertiesProvider)
{
requireNonNull(logicalPropertiesProvider, "logicalPropertiesProvider cannot be null.");
return logicalPropertiesProvider.getValuesProperties(this);
}
@Override
@JsonProperty
public List getOutputVariables()
{
return outputVariables;
}
@Override
public List getSources()
{
return emptyList();
}
@Override
public R accept(PlanVisitor visitor, C context)
{
return visitor.visitValues(this, context);
}
@Override
public PlanNode assignStatsEquivalentPlanNode(Optional statsEquivalentPlanNode)
{
return new ValuesNode(getSourceLocation(), getId(), statsEquivalentPlanNode, outputVariables, rows, valuesNodeLabel);
}
@Override
public PlanNode replaceChildren(List newChildren)
{
if (!newChildren.isEmpty()) {
throw new IllegalArgumentException("newChildren is not empty");
}
return this;
}
private static List immutableListCopyOf(List list)
{
return unmodifiableList(new ArrayList<>(requireNonNull(list, "list is null")));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy