use of io.prestosql.sql.builder.functioncall.functions.FunctionCallRewriter in project hetu-core by openlookeng.
the class TestFunctionWriterManagerGroup method setUp.
@BeforeTest
public void setUp() {
String connectorName = "jdbc_connector";
String versionName = "default";
Map<String, FunctionCallRewriter> functionCallRewriterMap = new HashMap<>();
functionCallRewriterMap.put(VarbinaryLiteralFunctionCallRewriterForUt.INNER_FUNC_VARBINARY_LITERAL, new VarbinaryLiteralFunctionCallRewriterForUt());
functionCallRewriterMap.put(UnsupportedFunctionCallRewriterForUt.UNSUPPORTED_FUNCTION_NAME_TEST, new UnsupportedFunctionCallRewriterForUt(connectorName));
DefaultUdfRewriteConfigSupplier defaultUdfRewriteConfigSupplier = new DefaultUdfRewriteConfigSupplier(Test_UDF_REWRITE_PATTERNS);
DefaultConnectorConfigFunctionRewriter defaultConnectorConfigFunctionRewriter = new DefaultConnectorConfigFunctionRewriter(connectorName, defaultUdfRewriteConfigSupplier);
setFunctionWriterManager(connectorName, versionName, functionCallRewriterMap, defaultConnectorConfigFunctionRewriter);
FunctionWriterManager functionWriterManager2 = FunctionWriterManagerGroup.newFunctionWriterManagerInstance(connectorName, versionName, functionCallRewriterMap, defaultConnectorConfigFunctionRewriter);
assertEquals(functionWriterManager1.toString(), functionWriterManager2.toString());
}
use of io.prestosql.sql.builder.functioncall.functions.FunctionCallRewriter in project hetu-core by openlookeng.
the class HanaRowExpressionConverter method getInjectFunctionCallRewritersDefault.
private Map<String, FunctionCallRewriter> getInjectFunctionCallRewritersDefault(HanaConfig hanaConfig) {
// add the user define function re-writer
Map<String, FunctionCallRewriter> functionCallRewriters = new HashMap<>(Collections.emptyMap());
// 1. the base function re-writers all connector can use
FromBase64CallRewriter fromBase64CallRewriter = new FromBase64CallRewriter();
functionCallRewriters.put(FromBase64CallRewriter.INNER_FUNC_FROM_BASE64, fromBase64CallRewriter);
// 2. the specific user define function re-writers
FunctionCallRewriter varbinaryLiteralFunctionCallRewriter = new VarbinaryLiteralFunctionCallRewriter();
functionCallRewriters.put(VarbinaryLiteralFunctionCallRewriter.INNER_FUNC_VARBINARY_LITERAL, varbinaryLiteralFunctionCallRewriter);
FunctionCallRewriter unSupportedFunctionCallRewriter = new HanaUnsupportedFunctionCallRewriter(HanaConstants.CONNECTOR_NAME);
functionCallRewriters.put(HanaUnsupportedFunctionCallRewriter.INNER_FUNC_INTERVAL_LITERAL_DAY2SEC, unSupportedFunctionCallRewriter);
functionCallRewriters.put(HanaUnsupportedFunctionCallRewriter.INNER_FUNC_INTERVAL_LITERAL_YEAR2MONTH, unSupportedFunctionCallRewriter);
functionCallRewriters.put(HanaUnsupportedFunctionCallRewriter.INNER_FUNC_TIME_WITH_TZ_LITERAL, unSupportedFunctionCallRewriter);
FunctionCallRewriter dateTimeFunctionCallRewriter = new DateTimeFunctionCallRewriter(hanaConfig);
functionCallRewriters.put(DateTimeFunctionCallRewriter.INNER_FUNC_TIME_LITERAL, dateTimeFunctionCallRewriter);
functionCallRewriters.put(DateTimeFunctionCallRewriter.INNER_FUNC_TIMESTAMP_LITERAL, dateTimeFunctionCallRewriter);
FunctionCallRewriter dateAddFunctionCallRewrite = new DateAddFunctionCallRewrite();
functionCallRewriters.put(DateAddFunctionCallRewrite.BUILD_IN_FUNC_DATE_ADD, dateAddFunctionCallRewrite);
FunctionCallRewriter buildInDirectMapFunctionCallRewriter = new BuildInDirectMapFunctionCallRewriter();
functionCallRewriters.put(BuildInDirectMapFunctionCallRewriter.BUIDLIN_AGGR_FUNC_SUM, buildInDirectMapFunctionCallRewriter);
functionCallRewriters.put(BuildInDirectMapFunctionCallRewriter.BUILDIN_AGGR_FUNC_AVG, buildInDirectMapFunctionCallRewriter);
functionCallRewriters.put(BuildInDirectMapFunctionCallRewriter.BUILDIN_AGGR_FUNC_COUNT, buildInDirectMapFunctionCallRewriter);
functionCallRewriters.put(BuildInDirectMapFunctionCallRewriter.BUILDIN_AGGR_FUNC_MAX, buildInDirectMapFunctionCallRewriter);
functionCallRewriters.put(BuildInDirectMapFunctionCallRewriter.BUILDIN_AGGR_FUNC_MIN, buildInDirectMapFunctionCallRewriter);
FunctionCallRewriter arrayConstructorCallRewriter = new ArrayConstructorCallRewriter();
functionCallRewriters.put(ArrayConstructorCallRewriter.INNER_FUNC_ARRAY_CONSTRUCTOR, arrayConstructorCallRewriter);
return functionCallRewriters;
}
use of io.prestosql.sql.builder.functioncall.functions.FunctionCallRewriter in project hetu-core by openlookeng.
the class FunctionWriterManager method getFunctionRewriteResult.
/**
* Get the function rewrite name if not support, throw UnsupportedOperationException
*
* @param name QualifiedName
* @param isDistinct isDistinct
* @param argumentsList argumentsList
* @param orderBy order by
* @param filter filter
* @param window windows
* @return String rewrite result, it can be empty in an optional Object for not support function
*/
// CHECKSTYLE:OFF:ParameterNumber
// inherit api(io.prestosql.spi.sql.SqlQueryWriter.functionCall), can't change it
public final String getFunctionRewriteResult(QualifiedName name, boolean isDistinct, List<String> argumentsList, Optional<String> orderBy, Optional<String> filter, Optional<String> window) {
// CHECKSTYLE:ON:ParameterNumber
FunctionCallArgsPackage functionCallArgsPackage = new FunctionCallArgsPackage(name, isDistinct, argumentsList, orderBy, filter, window);
FunctionCallRewriter functionCallRewriter;
String functionSignature = this.argsFunction.apply(functionCallArgsPackage);
functionCallRewriter = rewriteFunctionMap.getOrDefault(functionSignature, null);
Optional<String> result = Optional.empty();
if (functionCallRewriter != null) {
result = Optional.ofNullable(functionCallRewriter.rewriteFunctionCall(functionCallArgsPackage));
}
if (!result.isPresent()) {
// connector config
if (connectorConfigFunctionRewriter != null) {
result = Optional.ofNullable(connectorConfigFunctionRewriter.rewriteFunctionCall(functionCallArgsPackage));
}
}
if (result.isPresent()) {
return result.get();
} else {
String exceptionStr = connectorName + " Connector does not support function call of " + FunctionCallArgsPackage.defaultBuildFunctionSignature(functionCallArgsPackage);
throw new UnsupportedOperationException(exceptionStr);
}
}
use of io.prestosql.sql.builder.functioncall.functions.FunctionCallRewriter in project hetu-core by openlookeng.
the class ClickHouseRowExpressionConverter method getInjectFunctionCallRewritersDefault.
private Map<String, FunctionCallRewriter> getInjectFunctionCallRewritersDefault(ClickHouseConfig clickHouseConfig) {
// add the user define function re-writer
Map<String, FunctionCallRewriter> functionCallRewriters = new HashMap<>(Collections.emptyMap());
// 1. the base function re-writers all connector can use
FromBase64CallRewriter fromBase64CallRewriter = new FromBase64CallRewriter();
functionCallRewriters.put(FromBase64CallRewriter.INNER_FUNC_FROM_BASE64, fromBase64CallRewriter);
// 2. the specific user define function re-writers
FunctionCallRewriter unSupportedFunctionCallRewriter = new ClickHouseUnsupportedFunctionCallRewriter(ClickHouseConstants.CONNECTOR_NAME);
functionCallRewriters.put(ClickHouseUnsupportedFunctionCallRewriter.INNER_FUNC_INTERVAL_LITERAL_DAY2SEC, unSupportedFunctionCallRewriter);
functionCallRewriters.put(ClickHouseUnsupportedFunctionCallRewriter.INNER_FUNC_INTERVAL_LITERAL_YEAR2MONTH, unSupportedFunctionCallRewriter);
functionCallRewriters.put(ClickHouseUnsupportedFunctionCallRewriter.INNER_FUNC_TIME_WITH_TZ_LITERAL, unSupportedFunctionCallRewriter);
FunctionCallRewriter buildInDirectMapFunctionCallRewriter = new BuildInDirectMapFunctionCallRewriter();
functionCallRewriters.put(BuildInDirectMapFunctionCallRewriter.BUIDLIN_AGGR_FUNC_SUM, buildInDirectMapFunctionCallRewriter);
functionCallRewriters.put(BuildInDirectMapFunctionCallRewriter.BUILDIN_AGGR_FUNC_AVG, buildInDirectMapFunctionCallRewriter);
functionCallRewriters.put(BuildInDirectMapFunctionCallRewriter.BUILDIN_AGGR_FUNC_COUNT, buildInDirectMapFunctionCallRewriter);
functionCallRewriters.put(BuildInDirectMapFunctionCallRewriter.BUILDIN_AGGR_FUNC_MAX, buildInDirectMapFunctionCallRewriter);
functionCallRewriters.put(BuildInDirectMapFunctionCallRewriter.BUILDIN_AGGR_FUNC_MIN, buildInDirectMapFunctionCallRewriter);
FunctionCallRewriter dateParseFunctionCallRewriter = new DateParseFunctionCallRewriter();
functionCallRewriters.put(DateParseFunctionCallRewriter.BUILD_IN_FUNC_DATE_PARSE, dateParseFunctionCallRewriter);
return functionCallRewriters;
}
Aggregations