public class SqlValidatorUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
SqlValidatorUtil.DeepCopier
Deprecated.
|
static class |
SqlValidatorUtil.FlatAggregate
Flattens any FILTER, WITHIN DISTINCT, WITHIN GROUP surrounding a call to
an aggregate function.
|
static interface |
SqlValidatorUtil.Suggester
Suggests candidates for unique names, given the number of attempts so far
and the number of expressions in the project list.
|
| Modifier and Type | Field and Description |
|---|---|
static SqlValidatorUtil.Suggester |
ATTEMPT_SUGGESTER |
static SqlValidatorUtil.Suggester |
EXPR_SUGGESTER |
static SqlValidatorUtil.Suggester |
F_SUGGESTER |
| Modifier and Type | Method and Description |
|---|---|
static SqlNode |
addAlias(SqlNode expr,
String alias)
Converts an expression "expr" into "expr AS alias".
|
static void |
analyzeGroupItem(SqlValidatorScope scope,
org.apache.calcite.sql.validate.SqlValidatorUtil.GroupAnalyzer groupAnalyzer,
com.google.common.collect.ImmutableList.Builder<com.google.common.collect.ImmutableList<ImmutableBitSet>> topBuilder,
SqlNode groupExpr)
Analyzes an expression in a GROUP BY clause.
|
static void |
checkCharsetAndCollateConsistentIfCharType(RelDataType type) |
static boolean |
containsMonotonic(SqlValidatorScope scope)
Returns whether there are any input columns that are sorted.
|
static RelDataType |
createJoinType(RelDataTypeFactory typeFactory,
RelDataType leftType,
@Nullable RelDataType rightType,
@Nullable List<String> fieldNameList,
List<RelDataTypeField> systemFieldList)
Returns the type the row which results when two relations are joined.
|
static CalciteCatalogReader |
createSingleTableCatalogReader(boolean caseSensitive,
String tableName,
RelDataTypeFactory typeFactory,
RelDataType rowType)
Creates a catalog reader that contains a single
Table with temporary table name
and specified rowType. |
static RelDataType |
createTypeFromProjection(RelDataType type,
List<String> columnNameList,
RelDataTypeFactory typeFactory,
boolean caseSensitive) |
static com.google.common.collect.ImmutableList<ImmutableBitSet> |
cube(List<ImmutableBitSet> bitSets)
Computes the cube of bit sets.
|
static RelDataType |
deriveJoinRowType(RelDataType leftType,
@Nullable RelDataType rightType,
JoinRelType joinType,
RelDataTypeFactory typeFactory,
@Nullable List<String> fieldNameList,
List<RelDataTypeField> systemFieldList)
Derives the type of a join relational expression.
|
static List<String> |
deriveNaturalJoinColumnList(SqlNameMatcher nameMatcher,
RelDataType leftRowType,
RelDataType rightRowType)
Derives the list of column names suitable for NATURAL JOIN.
|
static SqlValidatorUtil.FlatAggregate |
flatten(SqlCall call)
Flattens an aggregate call.
|
static @Nullable String |
getAlias(SqlNode node,
int ordinal)
Derives an alias for a node, and invents a mangled identifier if it
cannot.
|
static @Nullable AggregatingSelectScope |
getEnclosingAggregateSelectScope(SqlValidatorScope scope) |
static @Nullable SelectScope |
getEnclosingSelectScope(@Nullable SqlValidatorScope scope) |
static List<RelDataTypeField> |
getExtendedColumns(@Nullable SqlValidator validator,
SqlValidatorTable table,
SqlNodeList extendedColumns)
Gets a list of extended columns with field indices to the underlying table.
|
static com.google.common.collect.ImmutableMap<Integer,RelDataTypeField> |
getIndexToFieldMap(List<RelDataTypeField> sourceFields,
RelDataType targetFields)
Gets a map of indexes from the source to fields in the target for the
intersecting set of source and target fields.
|
static ImmutableBitSet |
getOrdinalBitSet(RelDataType sourceRowType,
Map<Integer,RelDataTypeField> indexToField)
Gets the bit-set to the column ordinals in the source for columns that
intersect in the target.
|
static ImmutableBitSet |
getOrdinalBitSet(RelDataType sourceRowType,
RelDataType targetRowType)
Gets the bit-set to the column ordinals in the source for columns that intersect in the target.
|
static @Nullable RelOptTable |
getRelOptTable(SqlValidatorNamespace namespace,
Prepare.CatalogReader catalogReader,
@Nullable String datasetName,
boolean[] usedDataset)
Converts a
SqlValidatorScope into a RelOptTable. |
static @Nullable CalciteSchema |
getSchema(CalciteSchema rootSchema,
Iterable<String> schemaPath,
SqlNameMatcher nameMatcher)
Finds and returns
CalciteSchema nested to the given rootSchema
with specified schemaPath. |
static void |
getSchemaObjectMonikers(SqlValidatorCatalogReader catalogReader,
List<String> names,
List<SqlMoniker> hints) |
static CalciteSchema.TableEntry |
getTableEntry(SqlValidatorCatalogReader catalogReader,
List<String> names)
Finds a
CalciteSchema.TableEntry in a
given catalog reader whose table has the given name, possibly qualified. |
static @Nullable RelDataTypeField |
getTargetField(RelDataType rowType,
RelDataTypeFactory typeFactory,
SqlIdentifier id,
SqlValidatorCatalogReader catalogReader,
@Nullable RelOptTable table)
Resolve a target column name in the target table.
|
static CalciteSchema.TypeEntry |
getTypeEntry(CalciteSchema rootSchema,
SqlIdentifier typeName)
Finds a
CalciteSchema.TypeEntry in a
given schema whose type has the given name, possibly qualified. |
static SqlValidatorNamespace |
lookup(SqlValidatorScope scope,
List<String> names)
Resolves a multi-part identifier such as "SCHEMA.EMP.EMPNO" to a
namespace.
|
static @Nullable RelDataTypeField |
lookupField(boolean caseSensitive,
RelDataType rowType,
String columnName)
Deprecated.
|
static @Nullable SqlOperator |
lookupSqlFunctionByID(SqlOperatorTable opTab,
SqlIdentifier funName,
@Nullable SqlFunctionCategory funcType)
Lookup sql function by sql identifier and function category.
|
static Map<String,Integer> |
mapNameToIndex(List<RelDataTypeField> fields)
Returns a map from field names to indexes.
|
static SqlValidatorWithHints |
newValidator(SqlOperatorTable opTab,
SqlValidatorCatalogReader catalogReader,
RelDataTypeFactory typeFactory)
Deprecated.
|
static SqlValidatorWithHints |
newValidator(SqlOperatorTable opTab,
SqlValidatorCatalogReader catalogReader,
RelDataTypeFactory typeFactory,
SqlValidator.Config config)
Factory method for
SqlValidator. |
static com.google.common.collect.ImmutableList<ImmutableBitSet> |
rollup(List<ImmutableBitSet> bitSets)
Computes the rollup of bit sets.
|
static List<String> |
uniquify(List<? extends String> nameList,
SqlValidatorUtil.Suggester suggester,
boolean caseSensitive)
Makes sure that the names in a list are unique.
|
static List<String> |
uniquify(List<String> nameList)
Deprecated.
|
static List<String> |
uniquify(List<String> nameList,
boolean caseSensitive)
Makes sure that the names in a list are unique.
|
static List<String> |
uniquify(List<String> nameList,
SqlValidatorUtil.Suggester suggester)
Deprecated.
|
static String |
uniquify(@Nullable String name,
Set<String> usedNames,
SqlValidatorUtil.Suggester suggester)
Makes a name distinct from other names which have already been used, adds
it to the list, and returns it.
|
static Pair<SqlNode,RelDataType> |
validateExprWithRowType(boolean caseSensitive,
SqlOperatorTable operatorTable,
RelDataTypeFactory typeFactory,
RelDataType rowType,
SqlNode expr)
Validate the sql node with specified base table row type.
|
public static final SqlValidatorUtil.Suggester EXPR_SUGGESTER
public static final SqlValidatorUtil.Suggester F_SUGGESTER
public static final SqlValidatorUtil.Suggester ATTEMPT_SUGGESTER
public static @Nullable RelOptTable getRelOptTable(SqlValidatorNamespace namespace, Prepare.CatalogReader catalogReader, @Nullable String datasetName, boolean[] usedDataset)
SqlValidatorScope into a RelOptTable. This is
only possible if the scope represents an identifier, such as "sales.emp".
Otherwise, returns null.namespace - NamespacecatalogReader - SchemadatasetName - Name of sample dataset to substitute, or null to use
the regular tableusedDataset - Output parameter which is set to true if a sample
dataset is found; may be nullpublic static List<RelDataTypeField> getExtendedColumns(@Nullable SqlValidator validator, SqlValidatorTable table, SqlNodeList extendedColumns)
public static com.google.common.collect.ImmutableMap<Integer,RelDataTypeField> getIndexToFieldMap(List<RelDataTypeField> sourceFields, RelDataType targetFields)
sourceFields - The source of column names that determine indexestargetFields - The target fields to be indexedpublic static ImmutableBitSet getOrdinalBitSet(RelDataType sourceRowType, RelDataType targetRowType)
sourceRowType - The source upon which to ordinate the bit set.targetRowType - The target to overlay on the source to create the bit set.public static ImmutableBitSet getOrdinalBitSet(RelDataType sourceRowType, Map<Integer,RelDataTypeField> indexToField)
sourceRowType - The source upon which to ordinate the bit set.indexToField - The map of ordinals to target fields.public static Map<String,Integer> mapNameToIndex(List<RelDataTypeField> fields)
@Deprecated public static @Nullable RelDataTypeField lookupField(boolean caseSensitive, RelDataType rowType, String columnName)
public static void checkCharsetAndCollateConsistentIfCharType(RelDataType type)
public static SqlNode addAlias(SqlNode expr, String alias)
public static @Nullable String getAlias(SqlNode node, int ordinal)
Examples:
public static SqlValidatorWithHints newValidator(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, SqlValidator.Config config)
SqlValidator.@Deprecated public static SqlValidatorWithHints newValidator(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory)
SqlValidator, with default conformance.public static String uniquify(@Nullable String name, Set<String> usedNames, SqlValidatorUtil.Suggester suggester)
name - Suggested name, may not be uniqueusedNames - Collection of names already usedsuggester - Base for name when input name is null@Deprecated public static List<String> uniquify(List<String> nameList)
Does not modify the input list. Returns the input list if the strings are unique, otherwise allocates a new list. Deprecated in favor of caseSensitive aware version.
nameList - List of strings@Deprecated public static List<String> uniquify(List<String> nameList, SqlValidatorUtil.Suggester suggester)
uniquify(List, Suggester, boolean)Does not modify the input list. Returns the input list if the strings are unique, otherwise allocates a new list.
nameList - List of stringssuggester - How to generate new names if duplicate names are foundpublic static List<String> uniquify(List<String> nameList, boolean caseSensitive)
Does not modify the input list. Returns the input list if the strings are unique, otherwise allocates a new list.
nameList - List of stringscaseSensitive - Whether upper and lower case names are considered
distinctpublic static List<String> uniquify(List<? extends String> nameList, SqlValidatorUtil.Suggester suggester, boolean caseSensitive)
Does not modify the input list. Returns the input list if the strings are unique, otherwise allocates a new list.
nameList - List of stringssuggester - How to generate new names if duplicate names are foundcaseSensitive - Whether upper and lower case names are considered
distinctpublic static RelDataType deriveJoinRowType(RelDataType leftType, @Nullable RelDataType rightType, JoinRelType joinType, RelDataTypeFactory typeFactory, @Nullable List<String> fieldNameList, List<RelDataTypeField> systemFieldList)
leftType - Row type of left input to joinrightType - Row type of right input to joinjoinType - Type of jointypeFactory - Type factoryfieldNameList - List of names of fields; if null, field names are
inherited and made uniquesystemFieldList - List of system fields that will be prefixed to
output row type; typically empty but must not be
nullpublic static RelDataType createJoinType(RelDataTypeFactory typeFactory, RelDataType leftType, @Nullable RelDataType rightType, @Nullable List<String> fieldNameList, List<RelDataTypeField> systemFieldList)
The resulting row type consists of the system fields (if any), followed by the fields of the left type, followed by the fields of the right type. The field name list, if present, overrides the original names of the fields.
typeFactory - Type factoryleftType - Type of left input to joinrightType - Type of right input to join, or null for semi-joinfieldNameList - If not null, overrides the original names of the
fieldssystemFieldList - List of system fields that will be prefixed to
output row type; typically empty but must not be
nullpublic static @Nullable RelDataTypeField getTargetField(RelDataType rowType, RelDataTypeFactory typeFactory, SqlIdentifier id, SqlValidatorCatalogReader catalogReader, @Nullable RelOptTable table)
rowType - the target row typeid - the target column identifiertable - the target table or null if it is not a RelOptTable instancepublic static SqlValidatorNamespace lookup(SqlValidatorScope scope, List<String> names)
public static void getSchemaObjectMonikers(SqlValidatorCatalogReader catalogReader, List<String> names, List<SqlMoniker> hints)
public static @Nullable SelectScope getEnclosingSelectScope(@Nullable SqlValidatorScope scope)
public static @Nullable AggregatingSelectScope getEnclosingAggregateSelectScope(SqlValidatorScope scope)
public static List<String> deriveNaturalJoinColumnList(SqlNameMatcher nameMatcher, RelDataType leftRowType, RelDataType rightRowType)
nameMatcher - Whether matches are case-sensitiveleftRowType - Row type of left input to the joinrightRowType - Row type of right input to the joinpublic static RelDataType createTypeFromProjection(RelDataType type, List<String> columnNameList, RelDataTypeFactory typeFactory, boolean caseSensitive)
public static void analyzeGroupItem(SqlValidatorScope scope, org.apache.calcite.sql.validate.SqlValidatorUtil.GroupAnalyzer groupAnalyzer, com.google.common.collect.ImmutableList.Builder<com.google.common.collect.ImmutableList<ImmutableBitSet>> topBuilder, SqlNode groupExpr)
It may be an expression, an empty list (), or a call to
GROUPING SETS, CUBE, ROLLUP,
TUMBLE, HOP or SESSION.
Each group item produces a list of group sets, which are written to
topBuilder. To find the grouping sets of the query, we will take
the cartesian product of the group sets.
public static com.google.common.collect.ImmutableList<ImmutableBitSet> rollup(List<ImmutableBitSet> bitSets)
For example, rollup({0}, {1})
returns ({0, 1}, {0}, {}).
Bit sets are not necessarily singletons:
rollup({0, 2}, {3, 5})
returns ({0, 2, 3, 5}, {0, 2}, {}).
public static com.google.common.collect.ImmutableList<ImmutableBitSet> cube(List<ImmutableBitSet> bitSets)
For example, rollup({0}, {1})
returns ({0, 1}, {0}, {}).
Bit sets are not necessarily singletons:
rollup({0, 2}, {3, 5})
returns ({0, 2, 3, 5}, {0, 2}, {}).
public static CalciteSchema.TypeEntry getTypeEntry(CalciteSchema rootSchema, SqlIdentifier typeName)
CalciteSchema.TypeEntry in a
given schema whose type has the given name, possibly qualified.rootSchema - root schematypeName - name of the type, may be qualified or fully-qualifiedpublic static CalciteSchema.TableEntry getTableEntry(SqlValidatorCatalogReader catalogReader, List<String> names)
CalciteSchema.TableEntry in a
given catalog reader whose table has the given name, possibly qualified.
Uses the case-sensitivity policy of the specified catalog reader.
If not found, returns null.
catalogReader - accessor to the table metadatanames - Name of table, may be qualified or fully-qualifiedpublic static @Nullable CalciteSchema getSchema(CalciteSchema rootSchema, Iterable<String> schemaPath, SqlNameMatcher nameMatcher)
CalciteSchema nested to the given rootSchema
with specified schemaPath.
Uses the case-sensitivity policy of specified nameMatcher.
If not found, returns null.
rootSchema - root schemaschemaPath - full schema path of required schemanameMatcher - name matcherpublic static boolean containsMonotonic(SqlValidatorScope scope)
If so, it can be the default ORDER BY clause for a WINDOW specification. (This is an extension to the SQL standard for streaming.)
public static @Nullable SqlOperator lookupSqlFunctionByID(SqlOperatorTable opTab, SqlIdentifier funName, @Nullable SqlFunctionCategory funcType)
opTab - operator table to look upfunName - function namefuncType - function categorypublic static Pair<SqlNode,RelDataType> validateExprWithRowType(boolean caseSensitive, SqlOperatorTable operatorTable, RelDataTypeFactory typeFactory, RelDataType rowType, SqlNode expr)
caseSensitive - whether to match the catalog case-sensitivelyoperatorTable - operator tabletypeFactory - type factoryrowType - the table row type that has fields referenced by the expressionexpr - the expression to validatepublic static CalciteCatalogReader createSingleTableCatalogReader(boolean caseSensitive, String tableName, RelDataTypeFactory typeFactory, RelDataType rowType)
Table with temporary table name
and specified rowType.
Make this method public so that other systems can also use it.
caseSensitive - whether to match case sensitivelytableName - table name to register withtypeFactory - type factoryrowType - table row typeCalciteCatalogReader instancepublic static SqlValidatorUtil.FlatAggregate flatten(SqlCall call)
Copyright © 2012-2022 Apache Software Foundation. All Rights Reserved.