org.apache.druid.sql.calcite.rule.DruidLogicalValuesRule 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 org.apache.druid.sql.calcite.rule;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import org.apache.calcite.plan.RelOptRule;
import org.apache.calcite.plan.RelOptRuleCall;
import org.apache.calcite.rel.logical.LogicalValues;
import org.apache.calcite.rex.RexLiteral;
import org.apache.druid.common.config.NullHandling;
import org.apache.druid.error.InvalidSqlInput;
import org.apache.druid.math.expr.ExpressionProcessing;
import org.apache.druid.query.InlineDataSource;
import org.apache.druid.segment.column.RowSignature;
import org.apache.druid.sql.calcite.planner.Calcites;
import org.apache.druid.sql.calcite.planner.PlannerContext;
import org.apache.druid.sql.calcite.rel.DruidQueryRel;
import org.apache.druid.sql.calcite.table.RowSignatures;
import javax.annotation.Nullable;
import java.util.List;
import java.util.stream.Collectors;
/**
* A {@link RelOptRule} that converts {@link LogicalValues} into {@link InlineDataSource}.
* This rule is used when the query directly reads in-memory tuples. For example, given a query of
* `SELECT 1 + 1`, the query planner will create {@link LogicalValues} that contains one tuple,
* which in turn containing one column of value 2.
*
* The query planner can sometimes reduce a regular query to a query that reads in-memory tuples.
* For example, `SELECT count(*) FROM foo WHERE 1 = 0` is reduced to `SELECT 0`. This rule will
* be used for this case as well.
*/
public class DruidLogicalValuesRule extends RelOptRule
{
private final PlannerContext plannerContext;
public DruidLogicalValuesRule(PlannerContext plannerContext)
{
super(operand(LogicalValues.class, any()));
this.plannerContext = plannerContext;
}
@Override
public void onMatch(RelOptRuleCall call)
{
final LogicalValues values = call.rel(0);
final List> tuples = values.getTuples();
final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy