org.teiid.query.resolver.util
Class ResolverUtil

java.lang.Object
  extended by org.teiid.query.resolver.util.ResolverUtil

public class ResolverUtil
extends java.lang.Object

Utilities used during resolution


Nested Class Summary
static class ResolverUtil.ResolvedLookup
           
 
Method Summary
static TempMetadataID addTempGroup(TempMetadataAdapter metadata, GroupSymbol symbol, java.util.List<? extends SingleElementSymbol> symbols, boolean tempTable)
           
static TempMetadataID addTempTable(TempMetadataAdapter metadata, GroupSymbol symbol, java.util.List<? extends SingleElementSymbol> symbols)
           
static boolean canImplicitlyConvert(java.lang.String fromType, java.lang.String toType)
          Gets whether there exists an implicit conversion from the source type to the target type
static Constant convertConstant(java.lang.String sourceTypeName, java.lang.String targetTypeName, Constant constant)
           
static Expression convertExpression(Expression sourceExpression, java.lang.String targetTypeName, QueryMetadataInterface metadata)
          Replaces a sourceExpression with a conversion of the source expression to the target type.
static Expression convertExpression(Expression sourceExpression, java.lang.String sourceTypeName, java.lang.String targetTypeName, QueryMetadataInterface metadata)
          Replaces a sourceExpression with a conversion of the source expression to the target type.
static void findKeyPreserved(FromClause clause, java.util.Set<GroupSymbol> keyPreservingGroups, QueryMetadataInterface metadata)
           
static void findKeyPreserved(Query query, java.util.Set<GroupSymbol> keyPreservingGroups, QueryMetadataInterface metadata)
           
static java.util.List<GroupSymbol> findMatchingGroups(java.lang.String groupContext, java.util.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 java.util.List getAccessPatternElementsInGroups(QueryMetadataInterface metadata, java.util.Collection groups, boolean flatten)
          When access patterns are flattened, they are an approximation the user may need to enter as criteria.
static java.lang.String getCommonType(java.lang.String[] typeNames)
          Gets the most specific type to which all the given types have an implicit conversion.
static Function getConversion(Expression sourceExpression, java.lang.String sourceTypeName, java.lang.String targetTypeName, boolean implicit, FunctionLibrary library)
           
static 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 nameMatchesGroup(java.lang.String groupContext, java.lang.String fullName)
           
static java.util.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, java.util.List symbols)
           
static void resolveLimit(Limit limit)
           
static ResolverUtil.ResolvedLookup resolveLookup(Function lookup, QueryMetadataInterface metadata)
           
static void resolveNullLiterals(java.util.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, QueryMetadataInterface metadata)
          Attempt to resolve the order by throws QueryResolverException if the symbol is not of SingleElementSymbol type
static void setDesiredType(Expression expression, java.lang.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(SingleElementSymbol symbol, java.lang.Class<?> replacement)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCommonType

public static java.lang.String getCommonType(java.lang.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:

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(java.lang.String fromType,
                                           java.lang.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 the toType.

convertExpression

public static Expression convertExpression(Expression sourceExpression,
                                           java.lang.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,
                                           java.lang.String sourceTypeName,
                                           java.lang.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 -
sourceTypeName -
targetTypeName -
Returns:
Throws:
QueryResolverException

convertConstant

public static Constant convertConstant(java.lang.String sourceTypeName,
                                       java.lang.String targetTypeName,
                                       Constant constant)

getConversion

public static Function getConversion(Expression sourceExpression,
                                     java.lang.String sourceTypeName,
                                     java.lang.String targetTypeName,
                                     boolean implicit,
                                     FunctionLibrary library)

setDesiredType

public static void setDesiredType(Expression expression,
                                  java.lang.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 test
targetType - 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,
                                  QueryMetadataInterface metadata)
                           throws QueryResolverException,
                                  QueryMetadataException,
                                  TeiidComponentException
Attempt to resolve the order by throws QueryResolverException if the symbol is not of SingleElementSymbol type

Parameters:
orderBy -
fromClauseGroups - groups of the FROM clause of the query (for resolving ambiguous unqualified element names), or empty List if a Set Query Order By is being resolved
knownElements - resolved elements from SELECT clause, which are only ones allowed to be in ORDER BY
metadata - QueryMetadataInterface
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-resolved
metadata - 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 defined
QueryMetadataException - for error retrieving metadata
TeiidComponentException
Since:
4.3

resolveElementsInGroup

public static java.util.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.

Throws:
QueryMetadataException
TeiidComponentException

getAccessPatternElementsInGroups

public static java.util.List getAccessPatternElementsInGroups(QueryMetadataInterface metadata,
                                                              java.util.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,
                                            java.util.List symbols)
                                     throws TeiidComponentException,
                                            QueryResolverException
Throws:
TeiidComponentException
QueryResolverException

addTempGroup

public static TempMetadataID addTempGroup(TempMetadataAdapter metadata,
                                          GroupSymbol symbol,
                                          java.util.List<? extends SingleElementSymbol> symbols,
                                          boolean tempTable)
                                   throws QueryResolverException
Throws:
QueryResolverException

addTempTable

public static TempMetadataID addTempTable(TempMetadataAdapter metadata,
                                          GroupSymbol symbol,
                                          java.util.List<? extends SingleElementSymbol> symbols)
                                   throws QueryResolverException
Throws:
QueryResolverException

resolveNullLiterals

public static void resolveNullLiterals(java.util.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:
select - The select clause
Since:
4.2

setTypeIfNull

public static void setTypeIfNull(SingleElementSymbol symbol,
                                 java.lang.Class<?> replacement)

findMatchingGroups

public static java.util.List<GroupSymbol> findMatchingGroups(java.lang.String groupContext,
                                                             java.util.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

nameMatchesGroup

public static boolean nameMatchesGroup(java.lang.String groupContext,
                                       java.lang.String fullName)

resolveLookup

public static ResolverUtil.ResolvedLookup resolveLookup(Function lookup,
                                                        QueryMetadataInterface metadata)
                                                 throws QueryResolverException,
                                                        TeiidComponentException
Throws:
QueryResolverException
TeiidComponentException

resolveGroup

public static void resolveGroup(GroupSymbol symbol,
                                QueryMetadataInterface metadata)
                         throws TeiidComponentException,
                                QueryResolverException
Throws:
TeiidComponentException
QueryResolverException

findKeyPreserved

public static void findKeyPreserved(Query query,
                                    java.util.Set<GroupSymbol> keyPreservingGroups,
                                    QueryMetadataInterface metadata)
                             throws TeiidComponentException,
                                    QueryMetadataException
Throws:
TeiidComponentException
QueryMetadataException

findKeyPreserved

public static void findKeyPreserved(FromClause clause,
                                    java.util.Set<GroupSymbol> keyPreservingGroups,
                                    QueryMetadataInterface metadata)
                             throws TeiidComponentException,
                                    QueryMetadataException
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


Copyright © 2011. All Rights Reserved.