io.trino.sql.analyzer.ExpressionAnalysis Maven / Gradle / Ivy
/*
* 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 io.trino.sql.analyzer;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import io.trino.spi.type.Type;
import io.trino.sql.tree.ExistsPredicate;
import io.trino.sql.tree.Expression;
import io.trino.sql.tree.FunctionCall;
import io.trino.sql.tree.InPredicate;
import io.trino.sql.tree.NodeRef;
import io.trino.sql.tree.QuantifiedComparisonExpression;
import io.trino.sql.tree.SubqueryExpression;
import java.util.Map;
import java.util.Set;
import static java.util.Objects.requireNonNull;
public class ExpressionAnalysis
{
private final Map, Type> expressionTypes;
private final Map, Type> expressionCoercions;
private final Set> typeOnlyCoercions;
private final Map, ResolvedField> columnReferences;
private final Set> subqueryInPredicates;
private final Set> subqueries;
private final Set> existsSubqueries;
private final Set> quantifiedComparisons;
private final Set> windowFunctions;
public ExpressionAnalysis(
Map, Type> expressionTypes,
Map, Type> expressionCoercions,
Set> subqueryInPredicates,
Set> subqueries,
Set> existsSubqueries,
Map, ResolvedField> columnReferences,
Set> typeOnlyCoercions,
Set> quantifiedComparisons,
Set> windowFunctions)
{
this.expressionTypes = ImmutableMap.copyOf(requireNonNull(expressionTypes, "expressionTypes is null"));
this.expressionCoercions = ImmutableMap.copyOf(requireNonNull(expressionCoercions, "expressionCoercions is null"));
this.typeOnlyCoercions = ImmutableSet.copyOf(requireNonNull(typeOnlyCoercions, "typeOnlyCoercions is null"));
this.columnReferences = ImmutableMap.copyOf(requireNonNull(columnReferences, "columnReferences is null"));
this.subqueryInPredicates = ImmutableSet.copyOf(requireNonNull(subqueryInPredicates, "subqueryInPredicates is null"));
this.subqueries = ImmutableSet.copyOf(requireNonNull(subqueries, "subqueries is null"));
this.existsSubqueries = ImmutableSet.copyOf(requireNonNull(existsSubqueries, "existsSubqueries is null"));
this.quantifiedComparisons = ImmutableSet.copyOf(requireNonNull(quantifiedComparisons, "quantifiedComparisons is null"));
this.windowFunctions = ImmutableSet.copyOf(requireNonNull(windowFunctions, "windowFunctions is null"));
}
public Type getType(Expression expression)
{
return expressionTypes.get(NodeRef.of(expression));
}
public Map, Type> getExpressionTypes()
{
return expressionTypes;
}
public Type getCoercion(Expression expression)
{
return expressionCoercions.get(NodeRef.of(expression));
}
public boolean isTypeOnlyCoercion(Expression expression)
{
return typeOnlyCoercions.contains(NodeRef.of(expression));
}
public boolean isColumnReference(Expression node)
{
return columnReferences.containsKey(NodeRef.of(node));
}
public Set> getSubqueryInPredicates()
{
return subqueryInPredicates;
}
public Set> getSubqueries()
{
return subqueries;
}
public Set> getExistsSubqueries()
{
return existsSubqueries;
}
public Set> getQuantifiedComparisons()
{
return quantifiedComparisons;
}
public Set> getWindowFunctions()
{
return windowFunctions;
}
}