Class LocateFunctionModifier
- java.lang.Object
-
- org.teiid.translator.jdbc.FunctionModifier
-
- org.teiid.translator.jdbc.AliasModifier
-
- org.teiid.translator.jdbc.LocateFunctionModifier
-
- Direct Known Subclasses:
LocateFunctionModifier
public class LocateFunctionModifier extends AliasModifier
A modifier class that can be used to translate the scalar functionlocate(search_string, source_string)
andlocate(search_string, source_string, start_index)
to a function or expression that can be used at the data source.If the default implementation is used, a function name of LOCATE will be used for the function name.
If the default implementation is used, the expression will not be modified if:
locate(search_string, source_string)
is usedlocate(search_string, source_string, start_index)
is used andstart_index
is a literal integer greater then 0- the default function parameter order is used or unspecified
If the default implementation is used, the expression will be modified if:
locate(search_string, source_string, start_index)
is used andstart_index
is a literal integer less then 1locate(search_string, source_string, start_index)
is used andstart_index
is not a literal integer- the function parameter order is something other than the default
If the default implementation is used and the expression is modified, it is modified to ensure that any literal integer value less than 1 is made equal to 1 and any non literal value is wrapped by a searched case expression to ensure that a value of less then 1 will be equal to 1 and the parameter order matches that of what the data source expects.
For example:
locate('a', 'abcdef')
-->LOCATE('a', 'abcdef')
locate('a', 'abcdef', 2)
-->LOCATE('a', 'abcdef', 2)
locate('a', 'abcdef', 0)
-->LOCATE('a', 'abcdef', 1)
locate('a', 'abcdef', intCol)
-->LOCATE('a', 'abcdef', CASE WHEN intCol < 1 THEN 1 ELSE intCol END)
- Since:
- 6.2
-
-
Field Summary
Fields Modifier and Type Field Description static String
LOCATE
-
Fields inherited from class org.teiid.translator.jdbc.AliasModifier
alias
-
-
Constructor Summary
Constructors Constructor Description LocateFunctionModifier(LanguageFactory langFactory)
Translates the scalar function LOCATE() to a source specific scalar function or expression.LocateFunctionModifier(LanguageFactory langFactory, String functionName, boolean sourceStringFirst)
Translates the scalar function LOCATE() to a source specific scalar function or expression.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected LanguageFactory
getLanguageFactory()
Get the instance ofLanguageFactory
set during construction.void
modify(Function function)
Returns a version offunction
suitable for executing at the data source.-
Methods inherited from class org.teiid.translator.jdbc.AliasModifier
translate
-
Methods inherited from class org.teiid.translator.jdbc.FunctionModifier
getCode
-
-
-
-
Field Detail
-
LOCATE
public static String LOCATE
-
-
Constructor Detail
-
LocateFunctionModifier
public LocateFunctionModifier(LanguageFactory langFactory)
Translates the scalar function LOCATE() to a source specific scalar function or expression.- Parameters:
langFactory
- the language factory associated with translation
-
LocateFunctionModifier
public LocateFunctionModifier(LanguageFactory langFactory, String functionName, boolean sourceStringFirst)
Translates the scalar function LOCATE() to a source specific scalar function or expression.- Parameters:
langFactory
- the language factory associated with translationfunctionName
- the function name or alias to be used instead of LOCATEsourceStringFirst
-
-
-
Method Detail
-
modify
public void modify(Function function)
Returns a version offunction
suitable for executing at the data source.For example:
locate('a', 'abcdefg') ---> LOCATE('a', 'abcdefg')
locate('a', 'abcdefg', 1) ---> LOCATE('a', 'abcdefg', 1)
locate('a', 'abcdefg', 1) ---> INSTR('abcdefg', 'a', 1)
locate('a', 'abcdefg', -5) ---> INSTR('abcdefg', 'a', 1)
locate('a', 'abcdefg', 1) ---> FINDSTR('a', 'abcdefg', 1)
locate('a', 'abcdefg', myCol) ---> LOCATE('a', 'abcdefg', CASE WHEN myCol < 1 THEN 1 ELSE myCol END)
- Overrides:
modify
in classAliasModifier
- Parameters:
function
- the LOCATE function that may need to be modified
-
getLanguageFactory
protected LanguageFactory getLanguageFactory()
Get the instance ofLanguageFactory
set during construction.- Returns:
- the
ILanguageFactory
instance
-
-