Search in sources :

Example 1 with FunctionCallRewriter

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());
}
Also used : FunctionCallRewriter(io.prestosql.sql.builder.functioncall.functions.FunctionCallRewriter) HashMap(java.util.HashMap) UnsupportedFunctionCallRewriterForUt(io.prestosql.sql.builder.functioncall.base.UnsupportedFunctionCallRewriterForUt) DefaultConnectorConfigFunctionRewriter(io.prestosql.sql.builder.functioncall.functions.config.DefaultConnectorConfigFunctionRewriter) DefaultUdfRewriteConfigSupplier(io.prestosql.configmanager.DefaultUdfRewriteConfigSupplier) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with FunctionCallRewriter

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;
}
Also used : DateTimeFunctionCallRewriter(io.hetu.core.plugin.hana.rewrite.functioncall.DateTimeFunctionCallRewriter) FunctionCallRewriter(io.prestosql.sql.builder.functioncall.functions.FunctionCallRewriter) BuildInDirectMapFunctionCallRewriter(io.hetu.core.plugin.hana.rewrite.functioncall.BuildInDirectMapFunctionCallRewriter) VarbinaryLiteralFunctionCallRewriter(io.hetu.core.plugin.hana.rewrite.functioncall.VarbinaryLiteralFunctionCallRewriter) HanaUnsupportedFunctionCallRewriter(io.hetu.core.plugin.hana.rewrite.functioncall.HanaUnsupportedFunctionCallRewriter) ArrayConstructorCallRewriter(io.hetu.core.plugin.hana.rewrite.functioncall.ArrayConstructorCallRewriter) DateTimeFunctionCallRewriter(io.hetu.core.plugin.hana.rewrite.functioncall.DateTimeFunctionCallRewriter) DateAddFunctionCallRewrite(io.hetu.core.plugin.hana.rewrite.functioncall.DateAddFunctionCallRewrite) VarbinaryLiteralFunctionCallRewriter(io.hetu.core.plugin.hana.rewrite.functioncall.VarbinaryLiteralFunctionCallRewriter) HashMap(java.util.HashMap) FromBase64CallRewriter(io.prestosql.sql.builder.functioncall.functions.base.FromBase64CallRewriter) HanaUnsupportedFunctionCallRewriter(io.hetu.core.plugin.hana.rewrite.functioncall.HanaUnsupportedFunctionCallRewriter) BuildInDirectMapFunctionCallRewriter(io.hetu.core.plugin.hana.rewrite.functioncall.BuildInDirectMapFunctionCallRewriter)

Example 3 with FunctionCallRewriter

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);
    }
}
Also used : FunctionCallRewriter(io.prestosql.sql.builder.functioncall.functions.FunctionCallRewriter)

Example 4 with FunctionCallRewriter

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;
}
Also used : DateParseFunctionCallRewriter(io.hetu.core.plugin.clickhouse.rewrite.functioncall.DateParseFunctionCallRewriter) FunctionCallRewriter(io.prestosql.sql.builder.functioncall.functions.FunctionCallRewriter) ClickHouseUnsupportedFunctionCallRewriter(io.hetu.core.plugin.clickhouse.rewrite.ClickHouseUnsupportedFunctionCallRewriter) BuildInDirectMapFunctionCallRewriter(io.hetu.core.plugin.clickhouse.rewrite.BuildInDirectMapFunctionCallRewriter) DateParseFunctionCallRewriter(io.hetu.core.plugin.clickhouse.rewrite.functioncall.DateParseFunctionCallRewriter) HashMap(java.util.HashMap) FromBase64CallRewriter(io.prestosql.sql.builder.functioncall.functions.base.FromBase64CallRewriter) BuildInDirectMapFunctionCallRewriter(io.hetu.core.plugin.clickhouse.rewrite.BuildInDirectMapFunctionCallRewriter) ClickHouseUnsupportedFunctionCallRewriter(io.hetu.core.plugin.clickhouse.rewrite.ClickHouseUnsupportedFunctionCallRewriter)

Aggregations

FunctionCallRewriter (io.prestosql.sql.builder.functioncall.functions.FunctionCallRewriter)4 HashMap (java.util.HashMap)3 FromBase64CallRewriter (io.prestosql.sql.builder.functioncall.functions.base.FromBase64CallRewriter)2 BuildInDirectMapFunctionCallRewriter (io.hetu.core.plugin.clickhouse.rewrite.BuildInDirectMapFunctionCallRewriter)1 ClickHouseUnsupportedFunctionCallRewriter (io.hetu.core.plugin.clickhouse.rewrite.ClickHouseUnsupportedFunctionCallRewriter)1 DateParseFunctionCallRewriter (io.hetu.core.plugin.clickhouse.rewrite.functioncall.DateParseFunctionCallRewriter)1 ArrayConstructorCallRewriter (io.hetu.core.plugin.hana.rewrite.functioncall.ArrayConstructorCallRewriter)1 BuildInDirectMapFunctionCallRewriter (io.hetu.core.plugin.hana.rewrite.functioncall.BuildInDirectMapFunctionCallRewriter)1 DateAddFunctionCallRewrite (io.hetu.core.plugin.hana.rewrite.functioncall.DateAddFunctionCallRewrite)1 DateTimeFunctionCallRewriter (io.hetu.core.plugin.hana.rewrite.functioncall.DateTimeFunctionCallRewriter)1 HanaUnsupportedFunctionCallRewriter (io.hetu.core.plugin.hana.rewrite.functioncall.HanaUnsupportedFunctionCallRewriter)1 VarbinaryLiteralFunctionCallRewriter (io.hetu.core.plugin.hana.rewrite.functioncall.VarbinaryLiteralFunctionCallRewriter)1 DefaultUdfRewriteConfigSupplier (io.prestosql.configmanager.DefaultUdfRewriteConfigSupplier)1 UnsupportedFunctionCallRewriterForUt (io.prestosql.sql.builder.functioncall.base.UnsupportedFunctionCallRewriterForUt)1 DefaultConnectorConfigFunctionRewriter (io.prestosql.sql.builder.functioncall.functions.config.DefaultConnectorConfigFunctionRewriter)1 BeforeTest (org.testng.annotations.BeforeTest)1