Package org.teiid.query.resolver.util
Class ResolverUtil
- java.lang.Object
-
- org.teiid.query.resolver.util.ResolverUtil
-
public class ResolverUtil extends Object
Utilities used during resolution
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ResolverUtil.ResolvedLookup
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static TempMetadataID
addTempGroup(TempMetadataAdapter metadata, GroupSymbol symbol, List<? extends Expression> symbols, boolean tempTable)
static TempMetadataID
addTempTable(TempMetadataAdapter metadata, GroupSymbol symbol, List<? extends Expression> symbols)
static boolean
canImplicitlyConvert(String fromType, String toType)
Gets whether there exists an implicit conversion from the source type to the target typestatic void
clearGroupInfo(GroupSymbol group, QueryMetadataInterface metadata)
static Constant
convertConstant(String sourceTypeName, String targetTypeName, Constant constant)
static Expression
convertExpression(Expression sourceExpression, String sourceTypeName, String targetTypeName, QueryMetadataInterface metadata, boolean forComparison)
Replaces a sourceExpression with a conversion of the source expression to the target type.static Expression
convertExpression(Expression sourceExpression, String targetTypeName, QueryMetadataInterface metadata)
Replaces a sourceExpression with a conversion of the source expression to the target type.static void
findKeyPreserved(FromClause clause, Set<GroupSymbol> keyPreservingGroups, QueryMetadataInterface metadata)
static void
findKeyPreserved(Query query, Set<GroupSymbol> keyPreservingGroups, QueryMetadataInterface metadata)
static List<GroupSymbol>
findMatchingGroups(String groupContext, Collection<GroupSymbol> groups, QueryMetadataInterface metadata)
static void
fullyQualifyElements(Command command)
This method will convert all elements in a command to their fully qualified name.static List
getAccessPatternElementsInGroups(QueryMetadataInterface metadata, Collection groups, boolean flatten)
When access patterns are flattened, they are an approximation the user may need to enter as criteria.static String
getCommonRuntimeType(String[] typeNames)
Gets the most specific type to which all the given types have an implicit conversion.static Function
getConversion(Expression sourceExpression, String sourceTypeName, String targetTypeName, boolean implicit, FunctionLibrary library)
IMPORTANT: source and target must be basic runtime typesstatic Expression
getDefault(ElementSymbol symbol, QueryMetadataInterface metadata)
Get the default value for the parameter, which could be null if the parameter is set to NULLABLE.static boolean
hasDefault(Object mid, QueryMetadataInterface metadata)
static boolean
nameMatchesGroup(String groupContext, String fullName)
static List<ElementSymbol>
resolveElementsInGroup(GroupSymbol group, QueryMetadataInterface metadata)
Returns the resolved elements in the given group.static void
resolveGroup(GroupSymbol symbol, QueryMetadataInterface metadata)
static void
resolveImplicitTempGroup(TempMetadataAdapter metadata, GroupSymbol symbol, List symbols)
static void
resolveLimit(Limit limit)
static ResolverUtil.ResolvedLookup
resolveLookup(Function lookup, QueryMetadataInterface metadata)
static void
resolveNullLiterals(List symbols)
Look for a null literal in the SELECT clause and set it's type to STRING.static void
resolveOrderBy(OrderBy orderBy, QueryCommand command, TempMetadataAdapter metadata)
Attempt to resolve the order by throws QueryResolverException if the symbol is not of SingleElementSymbol typestatic void
setDesiredType(List<DerivedColumn> passing, LanguageObject obj)
static void
setDesiredType(List<DerivedColumn> passing, LanguageObject obj, Class<?> type)
static void
setDesiredType(Expression expression, Class<?> targetType, LanguageObject surroundingExpression)
Utility to set the type of an expression if it is a Reference and has a null type.static void
setTypeIfNull(Expression symbol, Class<?> replacement)
-
-
-
Method Detail
-
getCommonRuntimeType
public static String getCommonRuntimeType(String[] typeNames)
Gets the most specific type to which all the given types have an implicit conversion. The method decides a common type as follows:- If one or more of the given types is a candidate, then this method will return the candidate that occurs first in the given array. This is why the order of the names in the array is important.
- Otherwise, if none of them is a candidate, this method will attempt to find a common type to which all of them can be implicitly converted.
- Otherwise this method is unable to find a common type to which all the given types can be implicitly converted, and therefore returns a null.
- Parameters:
typeNames
- an ordered array of unique type names.- Returns:
- a type name to which all the given types can be converted
-
canImplicitlyConvert
public static boolean canImplicitlyConvert(String fromType, String toType)
Gets whether there exists an implicit conversion from the source type to the target type- Parameters:
fromType
-toType
-- Returns:
- true if there exists an implicit conversion from the
fromType
to thetoType
.
-
convertExpression
public static Expression convertExpression(Expression sourceExpression, String targetTypeName, QueryMetadataInterface metadata) throws QueryResolverException
Replaces a sourceExpression with a conversion of the source expression to the target type. If the source type and target type are the same, this method does nothing.- Parameters:
sourceExpression
-targetTypeName
-- Returns:
- Throws:
QueryResolverException
-
convertExpression
public static Expression convertExpression(Expression sourceExpression, String sourceTypeName, String targetTypeName, QueryMetadataInterface metadata, boolean forComparison) throws QueryResolverException
Replaces a sourceExpression with a conversion of the source expression to the target type. If the source type and target type are the same, this method does nothing.- Parameters:
sourceExpression
-sourceTypeName
-targetTypeName
-forComparison
- if the conversion is for a comparison- Returns:
- Throws:
QueryResolverException
-
convertConstant
public static Constant convertConstant(String sourceTypeName, String targetTypeName, Constant constant)
-
getConversion
public static Function getConversion(Expression sourceExpression, String sourceTypeName, String targetTypeName, boolean implicit, FunctionLibrary library)
IMPORTANT: source and target must be basic runtime types- Parameters:
sourceExpression
-sourceTypeName
-targetTypeName
-implicit
-library
-- Returns:
-
setDesiredType
public static void setDesiredType(List<DerivedColumn> passing, LanguageObject obj) throws QueryResolverException
- Throws:
QueryResolverException
-
setDesiredType
public static void setDesiredType(List<DerivedColumn> passing, LanguageObject obj, Class<?> type) throws QueryResolverException
- Throws:
QueryResolverException
-
setDesiredType
public static void setDesiredType(Expression expression, Class<?> targetType, LanguageObject surroundingExpression) throws QueryResolverException
Utility to set the type of an expression if it is a Reference and has a null type.- Parameters:
expression
- the expression to testtargetType
- the target type, if the expression's type is null.- Throws:
QueryResolverException
- if unable to set the reference type to the target type.
-
resolveOrderBy
public static void resolveOrderBy(OrderBy orderBy, QueryCommand command, TempMetadataAdapter metadata) throws QueryResolverException, QueryMetadataException, TeiidComponentException
Attempt to resolve the order by throws QueryResolverException if the symbol is not of SingleElementSymbol type- Parameters:
orderBy
-- Throws:
QueryResolverException
QueryMetadataException
TeiidComponentException
-
getDefault
public static Expression getDefault(ElementSymbol symbol, QueryMetadataInterface metadata) throws TeiidComponentException, QueryMetadataException, QueryResolverException
Get the default value for the parameter, which could be null if the parameter is set to NULLABLE. If no default is available, a QueryResolverException will be thrown.- Parameters:
symbol
- ElementSymbol retrieved from metadata, fully-resolvedmetadata
- QueryMetadataInterface- Returns:
- expr param (if it is non-null) or default value (if there is one) or null Constant (if parameter is optional and therefore allows this)
- Throws:
QueryResolverException
- if expr is null, parameter is required and no default value is definedQueryMetadataException
- for error retrieving metadataTeiidComponentException
- Since:
- 4.3
-
hasDefault
public static boolean hasDefault(Object mid, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException
-
resolveElementsInGroup
public static List<ElementSymbol> resolveElementsInGroup(GroupSymbol group, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException
Returns the resolved elements in the given group. This method has the side effect of caching the resolved elements on the group object. The resolved elements may not contain non-selectable columns depending on the metadata first used for resolving.
-
clearGroupInfo
public static void clearGroupInfo(GroupSymbol group, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException
-
getAccessPatternElementsInGroups
public static List getAccessPatternElementsInGroups(QueryMetadataInterface metadata, Collection groups, boolean flatten) throws TeiidComponentException, QueryMetadataException
When access patterns are flattened, they are an approximation the user may need to enter as criteria.- Parameters:
metadata
-groups
-flatten
-- Returns:
- Throws:
TeiidComponentException
QueryMetadataException
-
resolveLimit
public static void resolveLimit(Limit limit) throws QueryResolverException
- Throws:
QueryResolverException
-
resolveImplicitTempGroup
public static void resolveImplicitTempGroup(TempMetadataAdapter metadata, GroupSymbol symbol, List symbols) throws TeiidComponentException, QueryResolverException
-
addTempGroup
public static TempMetadataID addTempGroup(TempMetadataAdapter metadata, GroupSymbol symbol, List<? extends Expression> symbols, boolean tempTable) throws QueryResolverException
- Throws:
QueryResolverException
-
addTempTable
public static TempMetadataID addTempTable(TempMetadataAdapter metadata, GroupSymbol symbol, List<? extends Expression> symbols) throws QueryResolverException
- Throws:
QueryResolverException
-
resolveNullLiterals
public static void resolveNullLiterals(List symbols)
Look for a null literal in the SELECT clause and set it's type to STRING. This ensures that the result set metadata retrieved for this query will be properly set to something other than the internal NullType. Added for defect 15437.- Parameters:
symbols
- The select clause symbols- Since:
- 4.2
-
setTypeIfNull
public static void setTypeIfNull(Expression symbol, Class<?> replacement)
-
findMatchingGroups
public static List<GroupSymbol> findMatchingGroups(String groupContext, Collection<GroupSymbol> groups, QueryMetadataInterface metadata) throws TeiidComponentException, QueryMetadataException
- Parameters:
groupContext
-groups
-metadata
-- Returns:
- the List of groups that match the given groupContext out of the supplied collection
- Throws:
TeiidComponentException
QueryMetadataException
-
resolveLookup
public static ResolverUtil.ResolvedLookup resolveLookup(Function lookup, QueryMetadataInterface metadata) throws QueryResolverException, TeiidComponentException
-
resolveGroup
public static void resolveGroup(GroupSymbol symbol, QueryMetadataInterface metadata) throws TeiidComponentException, QueryResolverException
-
findKeyPreserved
public static void findKeyPreserved(Query query, Set<GroupSymbol> keyPreservingGroups, QueryMetadataInterface metadata) throws TeiidComponentException, QueryMetadataException
-
findKeyPreserved
public static void findKeyPreserved(FromClause clause, Set<GroupSymbol> keyPreservingGroups, QueryMetadataInterface metadata) throws TeiidComponentException, QueryMetadataException
-
fullyQualifyElements
public static void fullyQualifyElements(Command command)
This method will convert all elements in a command to their fully qualified name.- Parameters:
command
- Command to convert
-
-