public class SqlValidatorUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
SqlValidatorUtil.DeepCopier
Deprecated.
|
(package private) static class |
SqlValidatorUtil.GroupAnalyzer
Builds a list of GROUP BY expressions.
|
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 | Constructor and Description |
---|---|
private |
SqlValidatorUtil() |
Modifier and Type | Method and Description |
---|---|
static SqlNode |
addAlias(SqlNode expr,
java.lang.String alias)
Converts an expression "expr" into "expr AS alias".
|
private static void |
addFields(java.util.List<RelDataTypeField> fieldList,
java.util.List<RelDataType> typeList,
java.util.List<java.lang.String> nameList,
java.util.Set<java.lang.String> uniqueNames) |
private static ImmutableBitSet |
analyzeGroupExpr(SqlValidatorScope scope,
SqlValidatorUtil.GroupAnalyzer groupAnalyzer,
SqlNode groupExpr)
Analyzes a component of a tuple in a GROUPING SETS clause.
|
static void |
analyzeGroupItem(SqlValidatorScope scope,
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.
|
private static java.util.List<ImmutableBitSet> |
analyzeGroupTuple(SqlValidatorScope scope,
SqlValidatorUtil.GroupAnalyzer groupAnalyzer,
java.util.List<SqlNode> operandList)
Analyzes a tuple in a GROUPING SETS clause.
|
static void |
checkCharsetAndCollateConsistentIfCharType(RelDataType type) |
(package private) static void |
checkIdentifierListForDuplicates(java.util.List<SqlNode> columnList,
SqlValidatorImpl.ValidationErrorFunction validationErrorFunction)
Checks that there are no duplicates in a list of
SqlIdentifier . |
private static java.util.List<SqlValidatorNamespace> |
children(SqlValidatorScope scope) |
(package private) static boolean |
containsMonotonic(SelectScope scope,
SqlNodeList nodes)
Returns whether any of the given expressions are sorted.
|
static boolean |
containsMonotonic(SqlValidatorScope scope)
Returns whether there are any input columns that are sorted.
|
private static void |
convertGroupSet(SqlValidatorScope scope,
SqlValidatorUtil.GroupAnalyzer groupAnalyzer,
com.google.common.collect.ImmutableList.Builder<ImmutableBitSet> builder,
SqlNode groupExpr)
Analyzes a GROUPING SETS item in a GROUP BY clause.
|
static RelDataType |
createJoinType(RelDataTypeFactory typeFactory,
RelDataType leftType,
RelDataType rightType,
java.util.List<java.lang.String> fieldNameList,
java.util.List<RelDataTypeField> systemFieldList)
Returns the type the row which results when two relations are joined.
|
static RelDataType |
createTypeFromProjection(RelDataType type,
java.util.List<java.lang.String> columnNameList,
RelDataTypeFactory typeFactory,
boolean caseSensitive) |
static com.google.common.collect.ImmutableList<ImmutableBitSet> |
cube(java.util.List<ImmutableBitSet> bitSets)
Computes the cube of bit sets.
|
static RelDataType |
deriveJoinRowType(RelDataType leftType,
RelDataType rightType,
JoinRelType joinType,
RelDataTypeFactory typeFactory,
java.util.List<java.lang.String> fieldNameList,
java.util.List<RelDataTypeField> systemFieldList)
Derives the type of a join relational expression.
|
static java.util.List<java.lang.String> |
deriveNaturalJoinColumnList(SqlNameMatcher nameMatcher,
RelDataType leftRowType,
RelDataType rightRowType)
Derives the list of column names suitable for NATURAL JOIN.
|
static java.lang.String |
getAlias(SqlNode node,
int ordinal)
Derives an alias for a node, and invents a mangled identifier if it
cannot.
|
static AggregatingSelectScope |
getEnclosingAggregateSelectScope(SqlValidatorScope scope) |
static SelectScope |
getEnclosingSelectScope(SqlValidatorScope scope) |
static java.util.List<RelDataTypeField> |
getExtendedColumns(RelDataTypeFactory typeFactory,
SqlValidatorTable table,
SqlNodeList extendedColumns)
Gets a list of extended columns with field indices to the underlying table.
|
static com.google.common.collect.ImmutableMap<java.lang.Integer,RelDataTypeField> |
getIndexToFieldMap(java.util.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,
java.util.Map<java.lang.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 RelOptTable |
getRelOptTable(SqlValidatorNamespace namespace,
Prepare.CatalogReader catalogReader,
java.lang.String datasetName,
boolean[] usedDataset)
Converts a
SqlValidatorScope into a RelOptTable . |
private static RelOptTable |
getRelOptTable(TableNamespace tableNamespace,
Prepare.CatalogReader catalogReader,
java.lang.String datasetName,
boolean[] usedDataset,
java.util.List<RelDataTypeField> extendedFields) |
static CalciteSchema |
getSchema(CalciteSchema rootSchema,
java.lang.Iterable<java.lang.String> schemaPath,
SqlNameMatcher nameMatcher)
Finds and returns
CalciteSchema nested to the given rootSchema
with specified schemaPath. |
static void |
getSchemaObjectMonikers(SqlValidatorCatalogReader catalogReader,
java.util.List<java.lang.String> names,
java.util.List<SqlMoniker> hints) |
static CalciteSchema.TableEntry |
getTableEntry(SqlValidatorCatalogReader catalogReader,
java.util.List<java.lang.String> names)
Finds a
CalciteSchema.TableEntry in a
given catalog reader whose table has the given name, possibly qualified. |
private static CalciteSchema.TableEntry |
getTableEntryFrom(CalciteSchema schema,
java.lang.String name,
boolean caseSensitive) |
static RelDataTypeField |
getTargetField(RelDataType rowType,
RelDataTypeFactory typeFactory,
SqlIdentifier id,
SqlValidatorCatalogReader catalogReader,
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,
java.util.List<java.lang.String> names)
Resolves a multi-part identifier such as "SCHEMA.EMP.EMPNO" to a
namespace.
|
static RelDataTypeField |
lookupField(boolean caseSensitive,
RelDataType rowType,
java.lang.String columnName)
Deprecated.
|
private static int |
lookupGroupExpr(SqlValidatorUtil.GroupAnalyzer groupAnalyzer,
SqlNode expr) |
static SqlOperator |
lookupSqlFunctionByID(SqlOperatorTable opTab,
SqlIdentifier funName,
SqlFunctionCategory funcType)
Lookup sql function by sql identifier and function category.
|
static java.util.Map<java.lang.String,java.lang.Integer> |
mapNameToIndex(java.util.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,
SqlConformance conformance)
Factory method for
SqlValidator . |
private static java.util.List<Pair<SqlIdentifier,SqlDataTypeSpec>> |
pairs(SqlNodeList extendedColumns)
Converts a list of extended columns
(of the form [name0, type0, name1, type1, ...])
into a list of (name, type) pairs.
|
static com.google.common.collect.ImmutableList<ImmutableBitSet> |
rollup(java.util.List<ImmutableBitSet> bitSets)
Computes the rollup of bit sets.
|
static java.util.List<java.lang.String> |
uniquify(java.util.List<java.lang.String> nameList)
Deprecated.
|
static java.util.List<java.lang.String> |
uniquify(java.util.List<java.lang.String> nameList,
boolean caseSensitive)
Makes sure that the names in a list are unique.
|
static java.util.List<java.lang.String> |
uniquify(java.util.List<java.lang.String> nameList,
SqlValidatorUtil.Suggester suggester)
Deprecated.
|
static java.util.List<java.lang.String> |
uniquify(java.util.List<java.lang.String> nameList,
SqlValidatorUtil.Suggester suggester,
boolean caseSensitive)
Makes sure that the names in a list are unique.
|
static java.lang.String |
uniquify(java.lang.String name,
java.util.Set<java.lang.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.
|
public static final SqlValidatorUtil.Suggester EXPR_SUGGESTER
public static final SqlValidatorUtil.Suggester F_SUGGESTER
public static final SqlValidatorUtil.Suggester ATTEMPT_SUGGESTER
public static RelOptTable getRelOptTable(SqlValidatorNamespace namespace, Prepare.CatalogReader catalogReader, java.lang.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 nullprivate static RelOptTable getRelOptTable(TableNamespace tableNamespace, Prepare.CatalogReader catalogReader, java.lang.String datasetName, boolean[] usedDataset, java.util.List<RelDataTypeField> extendedFields)
public static java.util.List<RelDataTypeField> getExtendedColumns(RelDataTypeFactory typeFactory, SqlValidatorTable table, SqlNodeList extendedColumns)
private static java.util.List<Pair<SqlIdentifier,SqlDataTypeSpec>> pairs(SqlNodeList extendedColumns)
public static com.google.common.collect.ImmutableMap<java.lang.Integer,RelDataTypeField> getIndexToFieldMap(java.util.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, java.util.Map<java.lang.Integer,RelDataTypeField> indexToField)
sourceRowType
- The source upon which to ordinate the bit set.indexToField
- The map of ordinals to target fields.public static java.util.Map<java.lang.String,java.lang.Integer> mapNameToIndex(java.util.List<RelDataTypeField> fields)
@Deprecated public static RelDataTypeField lookupField(boolean caseSensitive, RelDataType rowType, java.lang.String columnName)
public static void checkCharsetAndCollateConsistentIfCharType(RelDataType type)
static void checkIdentifierListForDuplicates(java.util.List<SqlNode> columnList, SqlValidatorImpl.ValidationErrorFunction validationErrorFunction)
SqlIdentifier
.public static SqlNode addAlias(SqlNode expr, java.lang.String alias)
public static java.lang.String getAlias(SqlNode node, int ordinal)
Examples:
public static SqlValidatorWithHints newValidator(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, SqlConformance conformance)
SqlValidator
.@Deprecated public static SqlValidatorWithHints newValidator(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory)
SqlValidator
, with default conformance.public static java.lang.String uniquify(java.lang.String name, java.util.Set<java.lang.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 java.util.List<java.lang.String> uniquify(java.util.List<java.lang.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 java.util.List<java.lang.String> uniquify(java.util.List<java.lang.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 java.util.List<java.lang.String> uniquify(java.util.List<java.lang.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 java.util.List<java.lang.String> uniquify(java.util.List<java.lang.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, RelDataType rightType, JoinRelType joinType, RelDataTypeFactory typeFactory, java.util.List<java.lang.String> fieldNameList, java.util.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, RelDataType rightType, java.util.List<java.lang.String> fieldNameList, java.util.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
nullprivate static void addFields(java.util.List<RelDataTypeField> fieldList, java.util.List<RelDataType> typeList, java.util.List<java.lang.String> nameList, java.util.Set<java.lang.String> uniqueNames)
public static RelDataTypeField getTargetField(RelDataType rowType, RelDataTypeFactory typeFactory, SqlIdentifier id, SqlValidatorCatalogReader catalogReader, 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, java.util.List<java.lang.String> names)
public static void getSchemaObjectMonikers(SqlValidatorCatalogReader catalogReader, java.util.List<java.lang.String> names, java.util.List<SqlMoniker> hints)
public static SelectScope getEnclosingSelectScope(SqlValidatorScope scope)
public static AggregatingSelectScope getEnclosingAggregateSelectScope(SqlValidatorScope scope)
public static java.util.List<java.lang.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, java.util.List<java.lang.String> columnNameList, RelDataTypeFactory typeFactory, boolean caseSensitive)
public static void analyzeGroupItem(SqlValidatorScope scope, 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.
private static void convertGroupSet(SqlValidatorScope scope, SqlValidatorUtil.GroupAnalyzer groupAnalyzer, com.google.common.collect.ImmutableList.Builder<ImmutableBitSet> builder, SqlNode groupExpr)
private static java.util.List<ImmutableBitSet> analyzeGroupTuple(SqlValidatorScope scope, SqlValidatorUtil.GroupAnalyzer groupAnalyzer, java.util.List<SqlNode> operandList)
For example, in GROUP BY GROUPING SETS ((a, b), a, c)
,
(a, b)
is a tuple.
Gathers into groupExprs
the set of distinct expressions being
grouped, and returns a bitmap indicating which expressions this tuple
is grouping.
private static ImmutableBitSet analyzeGroupExpr(SqlValidatorScope scope, SqlValidatorUtil.GroupAnalyzer groupAnalyzer, SqlNode groupExpr)
private static int lookupGroupExpr(SqlValidatorUtil.GroupAnalyzer groupAnalyzer, SqlNode expr)
public static com.google.common.collect.ImmutableList<ImmutableBitSet> rollup(java.util.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(java.util.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, java.util.List<java.lang.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 CalciteSchema getSchema(CalciteSchema rootSchema, java.lang.Iterable<java.lang.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 matcherprivate static CalciteSchema.TableEntry getTableEntryFrom(CalciteSchema schema, java.lang.String name, boolean caseSensitive)
public 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.)
private static java.util.List<SqlValidatorNamespace> children(SqlValidatorScope scope)
static boolean containsMonotonic(SelectScope scope, SqlNodeList nodes)
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 SqlOperator lookupSqlFunctionByID(SqlOperatorTable opTab, SqlIdentifier funName, SqlFunctionCategory funcType)
opTab
- operator table to look upfunName
- function namefuncType
- function categoryCopyright © 2012–2019 The Apache Software Foundation. All rights reserved.