Search in sources :

Example 1 with LocateFunctionModifier

use of org.teiid.translator.jdbc.LocateFunctionModifier in project teiid by teiid.

the class BaseDB2ExecutionFactory method start.

@Override
public void start() throws TranslatorException {
    super.start();
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CHAR, new AliasModifier("chr"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new AliasModifier("day"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce"));
    registerFunctionModifier(SourceSystemFunctions.LOCATE, new LocateFunctionModifier(getLanguageFactory()));
    registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new SubstringFunctionModifier());
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.MOD, new ModFunctionModifier("MOD", getLanguageFactory()));
    // add in type conversion
    ConvertModifier convertModifier = new ConvertModifier();
    // $NON-NLS-1$
    convertModifier.addTypeMapping("real", FunctionModifier.FLOAT);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("numeric(31,0)", FunctionModifier.BIGINTEGER);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("numeric(31,12)", FunctionModifier.BIGDECIMAL);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("blob", FunctionModifier.BLOB, FunctionModifier.OBJECT);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("clob", FunctionModifier.CLOB, FunctionModifier.XML);
    convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.TIMESTAMP, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return Arrays.asList("timestamp('1970-01-01', ", function.getParameters().get(0), ")");
        }
    });
    convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.TIMESTAMP, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return Arrays.asList("timestamp(", function.getParameters().get(0), ", '00:00:00')");
        }
    });
    // the next convert is not strictly necessary for db2, but it also works for derby
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.FLOAT, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return Arrays.asList("cast(double(", function.getParameters().get(0), ") as real)");
        }
    });
    // $NON-NLS-1$
    convertModifier.addTypeConversion(new NullHandlingFormatModifier("varchar"), FunctionModifier.STRING);
    // $NON-NLS-1$
    convertModifier.addTypeConversion(new NullHandlingFormatModifier("smallint"), FunctionModifier.BYTE, FunctionModifier.SHORT);
    // $NON-NLS-1$
    convertModifier.addTypeConversion(new NullHandlingFormatModifier("integer"), FunctionModifier.INTEGER);
    // $NON-NLS-1$
    convertModifier.addTypeConversion(new NullHandlingFormatModifier("bigint"), FunctionModifier.LONG);
    // $NON-NLS-1$
    convertModifier.addTypeConversion(new NullHandlingFormatModifier("double"), FunctionModifier.DOUBLE);
    // $NON-NLS-1$
    convertModifier.addTypeConversion(new NullHandlingFormatModifier("date"), FunctionModifier.DATE);
    // $NON-NLS-1$
    convertModifier.addTypeConversion(new NullHandlingFormatModifier("time"), FunctionModifier.TIME);
    // $NON-NLS-1$
    convertModifier.addTypeConversion(new NullHandlingFormatModifier("timestamp"), FunctionModifier.TIMESTAMP);
    convertModifier.addNumericBooleanConversions();
    registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
}
Also used : ModFunctionModifier(org.teiid.translator.jdbc.ModFunctionModifier) LocateFunctionModifier(org.teiid.translator.jdbc.LocateFunctionModifier) LocateFunctionModifier(org.teiid.translator.jdbc.LocateFunctionModifier) FunctionModifier(org.teiid.translator.jdbc.FunctionModifier) ModFunctionModifier(org.teiid.translator.jdbc.ModFunctionModifier) AliasModifier(org.teiid.translator.jdbc.AliasModifier) ArrayList(java.util.ArrayList) List(java.util.List) ConvertModifier(org.teiid.translator.jdbc.ConvertModifier)

Example 2 with LocateFunctionModifier

use of org.teiid.translator.jdbc.LocateFunctionModifier in project teiid by teiid.

the class MySQLExecutionFactory method start.

@Override
public void start() throws TranslatorException {
    super.start();
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.BITAND, new BitFunctionModifier("&", getLanguageFactory()));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.BITNOT, new BitFunctionModifier("~", getLanguageFactory()));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.BITOR, new BitFunctionModifier("|", getLanguageFactory()));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.BITXOR, new BitFunctionModifier("^", getLanguageFactory()));
    registerFunctionModifier(SourceSystemFunctions.LOCATE, new LocateFunctionModifier(getLanguageFactory()));
    registerFunctionModifier(SourceSystemFunctions.LPAD, new PadFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.RPAD, new PadFunctionModifier());
    // WEEKINYEAR assumes 4.1.1
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.WEEK, new AliasModifier("WEEKOFYEAR"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.ST_ASBINARY, new AliasModifier("AsWKB"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.ST_ASTEXT, new AliasModifier("AsWKT"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.ST_GEOMFROMWKB, new AliasModifier("GeomFromWKB"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.ST_GEOMFROMTEXT, new AliasModifier("GeomFromText"));
    // add in type conversion
    ConvertModifier convertModifier = new ConvertModifier();
    // $NON-NLS-1$
    convertModifier.addTypeMapping("signed", FunctionModifier.BOOLEAN, FunctionModifier.BYTE, FunctionModifier.SHORT, FunctionModifier.INTEGER, FunctionModifier.LONG);
    // char(n) assume 4.1 or later
    // $NON-NLS-1$
    convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("char", FunctionModifier.STRING);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("date", FunctionModifier.DATE);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("time", FunctionModifier.TIME);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("datetime", FunctionModifier.TIMESTAMP);
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.DATE, new ConvertModifier.FormatModifier("DATE"));
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIME, new ConvertModifier.FormatModifier("TIME"));
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIMESTAMP, new ConvertModifier.FormatModifier("TIMESTAMP"));
    // $NON-NLS-1$ //$NON-NLS-2$
    convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.STRING, new ConvertModifier.FormatModifier("date_format", "%Y-%m-%d"));
    // $NON-NLS-1$ //$NON-NLS-2$
    convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new ConvertModifier.FormatModifier("date_format", "%H:%i:%S"));
    // $NON-NLS-1$ //$NON-NLS-2$
    convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new ConvertModifier.FormatModifier("date_format", "%Y-%m-%d %H:%i:%S.%f"));
    convertModifier.addTypeConversion(new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return Arrays.asList("(", function.getParameters().get(0), " + 0.0)");
        }
    }, FunctionModifier.BIGDECIMAL, FunctionModifier.BIGINTEGER, FunctionModifier.FLOAT, FunctionModifier.DOUBLE);
    convertModifier.addNumericBooleanConversions();
    convertModifier.setWideningNumericImplicit(true);
    registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
    // $NON-NLS-1$ //$NON-NLS-2$
    addPushDownFunction("mysql", "SUBSTRING_INDEX", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.INTEGER);
}
Also used : LocateFunctionModifier(org.teiid.translator.jdbc.LocateFunctionModifier) FunctionModifier(org.teiid.translator.jdbc.FunctionModifier) LocateFunctionModifier(org.teiid.translator.jdbc.LocateFunctionModifier) AliasModifier(org.teiid.translator.jdbc.AliasModifier) ArrayList(java.util.ArrayList) List(java.util.List) ConvertModifier(org.teiid.translator.jdbc.ConvertModifier)

Example 3 with LocateFunctionModifier

use of org.teiid.translator.jdbc.LocateFunctionModifier in project teiid by teiid.

the class NetezzaExecutionFactory method start.

public void start() throws TranslatorException {
    super.start();
    // STRING FUNCTION MODIFIERS
    // //////////////////////////////////
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CHAR, new AliasModifier("chr"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("lower"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("upper"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.LOCATE, new LocateFunctionModifier(getLanguageFactory(), "INSTR", true));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CONCAT, new AliasModifier("||"));
    // /NUMERIC FUNCTION MODIFIERS
    // //////////////////////////////////
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CEILING, new AliasModifier("ceil"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.POWER, new AliasModifier("pow"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.LOG, new AliasModifier("LN"));
    // /BIT FUNCTION MODIFIERS
    // //////////////////////////////////
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.BITAND, new AliasModifier("int4and"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.BITNOT, new AliasModifier("int4not"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.BITOR, new AliasModifier("int4or"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.BITXOR, new AliasModifier("int4xor"));
    // DATE FUNCTION MODIFIERS
    // ////////////////////////////////////////
    registerFunctionModifier(SourceSystemFunctions.YEAR, new ExtractFunctionModifier());
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new ExtractModifier("DOY"));
    registerFunctionModifier(SourceSystemFunctions.QUARTER, new ExtractFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.MONTH, new ExtractFunctionModifier());
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new ExtractModifier("DAY"));
    registerFunctionModifier(SourceSystemFunctions.WEEK, new ExtractFunctionModifier());
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new ExtractModifier("DOW"));
    registerFunctionModifier(SourceSystemFunctions.HOUR, new ExtractFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.MINUTE, new ExtractFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.SECOND, new ExtractFunctionModifier());
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CURDATE, new AliasModifier("CURRENT_DATE"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CURTIME, new AliasModifier("CURRENT_TIME"));
    // SYSTEM FUNCTIONS
    // //////////////////////////////////
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("NVL"));
    // DATA TYPE CONVERSION
    // /////////////////////////////////////////
    ConvertModifier convertModifier = new ConvertModifier();
    // $NON-NLS-1$
    convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("byteint", FunctionModifier.BYTE);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("smallint", FunctionModifier.SHORT);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("bigint", FunctionModifier.LONG);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("numeric(38)", FunctionModifier.BIGINTEGER);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("numeric(38,18)", FunctionModifier.BIGDECIMAL);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("varchar(4000)", FunctionModifier.STRING);
    // convertModifier.addTypeMapping("nvarchar(5)", FunctionModifier.BOOLEAN);
    // /NO BOOLEAN, INTEGER, FLOAT, DATE, TIME, TIMESTAMP, as they are directly available in netezza
    // /NO NULL, CLOB, BLOB, OBJECT, XML
    // /BOOLEAN--BYTE, SHORT, INTEGER, LONG, FLOAT, DOUBLE, BIGINTEGER, BIGDECIMAL--AS IT DOESN'T WORK IMPLICITLY IN NETEZZA
    convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.INTEGER, new BooleanToNumericConversionModifier());
    convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.BYTE, new BooleanToNumericConversionModifier());
    convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.SHORT, new BooleanToNumericConversionModifier());
    convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.LONG, new BooleanToNumericConversionModifier());
    convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.FLOAT, new BooleanToNumericConversionModifier());
    convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.DOUBLE, new BooleanToNumericConversionModifier());
    convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.BIGINTEGER, new BooleanToNumericConversionModifier());
    convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.BIGDECIMAL, new BooleanToNumericConversionModifier());
    convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new BooleanToStringConversionModifier());
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.BOOLEAN, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            Expression stringValue = function.getParameters().get(0);
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            return Arrays.asList("CASE WHEN ", stringValue, " IN ('false', '0') THEN '0' WHEN ", stringValue, " IS NOT NULL THEN '1' END");
        }
    });
    convertModifier.addTypeConversion(new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            Expression stringValue = function.getParameters().get(0);
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            return Arrays.asList("CASE WHEN ", stringValue, " = 0 THEN '0' WHEN ", stringValue, " IS NOT NULL THEN '1' END");
        }
    }, FunctionModifier.BOOLEAN);
    // //////STRING TO DATATYPE CONVERSION OTHER THAN DATE/TIME
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.INTEGER, new CastModifier("integer"));
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.FLOAT, new CastModifier("float"));
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.DOUBLE, new CastModifier("double"));
    // /// STRING --> CHAR, BYTE, SHORT, LONG, BIGI, BIGD, BOOLEAN is taken care by Type Mapping
    // /// NO conversion support for NULL, CLOB, BLOB, OBJECT, XML
    // //STRING TO DATE/TIME CONVERSION////
    // ////////////////////////////////////
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.DATE, new ConvertModifier.FormatModifier("to_date", DATE_FORMAT));
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIME, new ConvertModifier.FormatModifier("to_timestamp", TIME_FORMAT));
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIMESTAMP, new ConvertModifier.FormatModifier("to_timestamp", TIMESTAMP_FORMAT));
    // ////DATE/TIME INTERNAL CONVERSION/////////
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new CastModifier("TIME"));
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.DATE, new CastModifier("DATE"));
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.TIMESTAMP, new CastModifier("TIMESTAMP"));
    // convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.TIMESTAMP, new CastModifier("TIMESTAMP")); //TIME --> TIMESTAMP --DOESN't WORK IN NETEZZA-NO FUNCTION SUPPORT
    // //DATE/TIME to STRING CONVERION////
    // ///////////////////////////////////
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", TIMESTAMP_FORMAT));
    // /NO NETEZAA FUNCTION for DATE, TIME to STRING
    convertModifier.setWideningNumericImplicit(true);
    registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
    if (sqlExtensionsInstalled) {
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_extract", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_extract", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.INTEGER);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_extract", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        addPushDownFunction("netezza", "regexp_extract_all", RUNTIME_NAMES.STRING + "[]", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        addPushDownFunction("netezza", "regexp_extract_all", RUNTIME_NAMES.STRING + "[]", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        addPushDownFunction("netezza", "regexp_extract_all", RUNTIME_NAMES.STRING + "[]", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        addPushDownFunction("netezza", "regexp_extract_all_sp", RUNTIME_NAMES.STRING + "[]", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        addPushDownFunction("netezza", "regexp_extract_all_sp", RUNTIME_NAMES.STRING + "[]", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        addPushDownFunction("netezza", "regexp_extract_all_sp", RUNTIME_NAMES.STRING + "[]", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_extract_sp", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.INTEGER);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_extract_sp", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_instr", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_instr", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.INTEGER);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_instr", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_like", RUNTIME_NAMES.BOOLEAN, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_like", RUNTIME_NAMES.BOOLEAN, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_like", RUNTIME_NAMES.BOOLEAN, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_match_count", RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_match_count", RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_match_count", RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_replace", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_replace", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.INTEGER);
        // $NON-NLS-1$ //$NON-NLS-2$
        addPushDownFunction("netezza", "regexp_replace", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.STRING);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        addPushDownFunction("netezza", "regexp_replace_sp", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING + "[]");
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        addPushDownFunction("netezza", "regexp_replace_sp", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING + "[]", RUNTIME_NAMES.INTEGER);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        addPushDownFunction("netezza", "regexp_replace_sp", RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING, RUNTIME_NAMES.STRING + "[]", RUNTIME_NAMES.INTEGER, RUNTIME_NAMES.STRING);
    }
}
Also used : LocateFunctionModifier(org.teiid.translator.jdbc.LocateFunctionModifier) ExtractFunctionModifier(org.teiid.translator.jdbc.ExtractFunctionModifier) ConvertModifier(org.teiid.translator.jdbc.ConvertModifier) Function(org.teiid.language.Function) Expression(org.teiid.language.Expression) LocateFunctionModifier(org.teiid.translator.jdbc.LocateFunctionModifier) FunctionModifier(org.teiid.translator.jdbc.FunctionModifier) ExtractFunctionModifier(org.teiid.translator.jdbc.ExtractFunctionModifier) AliasModifier(org.teiid.translator.jdbc.AliasModifier) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with LocateFunctionModifier

use of org.teiid.translator.jdbc.LocateFunctionModifier in project teiid by teiid.

the class HanaExecutionFactory method start.

@Override
public void start() throws TranslatorException {
    super.start();
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("lower"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CEILING, new AliasModifier("ceil"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("lower"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CHAR, new AliasModifier("to_nvarchar"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("upper"));
    registerFunctionModifier(SourceSystemFunctions.LOG, new Log10FunctionModifier(getLanguageFactory()));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CEILING, new AliasModifier("ceil"));
    registerFunctionModifier(SourceSystemFunctions.LOG10, new Log10FunctionModifier(getLanguageFactory()));
    registerFunctionModifier(SourceSystemFunctions.LOCATE, new // $NON-NLS-1$
    LocateFunctionModifier(// $NON-NLS-1$
    getLanguageFactory(), // $NON-NLS-1$
    "locate", // $NON-NLS-1$
    true) {

        @Override
        public void modify(Function function) {
            super.modify(function);
            // If a start index was passed in, we convert to a substring on the search string since
            // HANA does not support the start index parameter in LOCATE().
            List<Expression> args = function.getParameters();
            if (args.size() > 2) {
                List<Expression> substringArgs = new ArrayList<Expression>();
                substringArgs.add(args.get(0));
                substringArgs.add(args.get(2));
                args.set(0, getLanguageFactory().createFunction(SourceSystemFunctions.SUBSTRING, substringArgs, null));
                args.remove(2);
            }
        }
    });
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CURDATE, new AliasModifier("current_date"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CURTIME, new AliasModifier("current_time"));
    // $NON-NLS-1$ //$NON-NLS-2$
    registerFunctionModifier(SourceSystemFunctions.WEEK, new TemplateFunctionModifier("cast(substring(isoweek(", 0, "), 7, 2) as integer)"));
    // $NON-NLS-1$ //$NON-NLS-2$
    registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new TemplateFunctionModifier("(MOD((WEEKDAY(", 0, ")+1),7)+1)"));
    // $NON-NLS-1$ //$NON-NLS-2$
    registerFunctionModifier(SourceSystemFunctions.DAYNAME, new TemplateFunctionModifier("initcap(lower(dayname(", 0, ")))"));
    // $NON-NLS-1$ //$NON-NLS-2$
    registerFunctionModifier(SourceSystemFunctions.QUARTER, new TemplateFunctionModifier("((month(", 0, ")+2)/3)"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.NOW, new AliasModifier("current_timestamp"));
    // spatial functions
    registerFunctionModifier(SourceSystemFunctions.ST_ASEWKT, new HanaSpatialFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.ST_ASBINARY, new HanaSpatialFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.ST_ASGEOJSON, new HanaSpatialFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.ST_ASTEXT, new HanaSpatialFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.ST_CONTAINS, new HanaSpatialFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.ST_CROSSES, new HanaSpatialFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.ST_DISTANCE, new HanaSpatialFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.ST_DISJOINT, new HanaSpatialFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.ST_EQUALS, new HanaSpatialFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.ST_INTERSECTS, new HanaSpatialFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.ST_SRID, new HanaSpatialFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.ST_GEOMFROMTEXT, new HanaSpatialFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.ST_OVERLAPS, new HanaSpatialFunctionModifier());
    registerFunctionModifier(SourceSystemFunctions.ST_TOUCHES, new HanaSpatialFunctionModifier());
    // ////////////////////////////////////////////////////////
    // TYPE CONVERION MODIFIERS////////////////////////////////
    // ////////////////////////////////////////////////////////
    ConvertModifier convertModifier = new ConvertModifier();
    // $NON-NLS-1$
    convertModifier.addTypeMapping("boolean", FunctionModifier.BOOLEAN);
    convertModifier.addTypeMapping(TINYINT_TYPE, FunctionModifier.BYTE);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("smallint", FunctionModifier.SHORT);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("integer", FunctionModifier.INTEGER);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("bigint", FunctionModifier.LONG, FunctionModifier.BIGINTEGER);
    // convertModifier.addTypeMapping("smalldecimal", FunctionModifier.FLOAT); //$NON-NLS-1$
    // $NON-NLS-1$
    convertModifier.addTypeMapping("decimal", FunctionModifier.BIGDECIMAL);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("float", FunctionModifier.FLOAT);
    // convertModifier.addTypeMapping("real", FunctionModifier.FLOAT); //$NON-NLS-1$
    // $NON-NLS-1$
    convertModifier.addTypeMapping("date", FunctionModifier.DATE);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("double", FunctionModifier.DOUBLE);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("time", FunctionModifier.TIME);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("timestamp", FunctionModifier.TIMESTAMP);
    // convertModifier.addTypeMapping("seconddate", FunctionModifier.TIMESTAMP); //$NON-NLS-1$
    // $NON-NLS-1$
    convertModifier.addTypeMapping("nvarchar", FunctionModifier.STRING);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("nvarchar(1)", FunctionModifier.CHAR);
    // convertModifier.addTypeMapping("alphanum", FunctionModifier.STRING); //$NON-NLS-1$
    // $NON-NLS-1$
    convertModifier.addTypeMapping("varbinary", FunctionModifier.VARBINARY);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("blob", FunctionModifier.BLOB);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("nclob", FunctionModifier.CLOB);
    // $NON-NLS-1$
    convertModifier.addTypeMapping("text", FunctionModifier.XML);
    // convertModifier.addTypeMapping("shorttext", FunctionModifier.STRING); //$NON-NLS-1$
    // $NON-NLS-1$
    convertModifier.addTypeMapping("st_geometry", FunctionModifier.GEOMETRY);
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.DATE, new ConvertModifier.FormatModifier("to_date", DATE_FORMAT));
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIME, new ConvertModifier.FormatModifier("to_time", TIME_FORMAT));
    // $NON-NLS-1$
    convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIMESTAMP, new ConvertModifier.FormatModifier("to_timestamp", DATETIME_FORMAT));
    convertModifier.setWideningNumericImplicit(true);
    convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            Expression trueValue = function.getParameters().get(0);
            Expression falseValue = trueValue;
            falseValue = new IsNull(falseValue, true);
            if (!(trueValue instanceof Predicate)) {
                trueValue = new Comparison(trueValue, new Literal(Boolean.TRUE, TypeFacility.RUNTIME_TYPES.BOOLEAN), Comparison.Operator.EQ);
            }
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            return Arrays.asList("CASE WHEN ", trueValue, " THEN 'true' WHEN ", falseValue, " THEN 'false' END");
        }
    });
    convertModifier.addSourceConversion(new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            ((Literal) function.getParameters().get(1)).setValue(TINYINT_TYPE);
            return null;
        }
    }, FunctionModifier.BOOLEAN);
    registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
    /*
    	 * Date/Time Pushdown functions
    	 */
    addPushDownFunction(HANA, ADD_DAYS, DATE, DATE, INTEGER);
    addPushDownFunction(HANA, ADD_MONTHS, DATE, DATE, INTEGER);
    addPushDownFunction(HANA, ADD_SECONDS, TIMESTAMP, TIMESTAMP, INTEGER);
    addPushDownFunction(HANA, ADD_WORKDAYS, DATE, DATE, INTEGER);
    addPushDownFunction(HANA, ADD_YEARS, DATE, DATE, INTEGER);
    addPushDownFunction(HANA, CURRENT_UTCDATE, DATE);
    addPushDownFunction(HANA, CURRENT_UTCTIME, TIME);
    addPushDownFunction(HANA, CURRENT_UTCTIMESTAMP, TIMESTAMP);
    addPushDownFunction(HANA, DAYS_BETWEEN, INTEGER, DATE, DATE);
    addPushDownFunction(HANA, ISOWEEK, STRING, DATE);
    addPushDownFunction(HANA, LAST_DAY, DATE, DATE);
    addPushDownFunction(HANA, LOCALTOUTC, TIMESTAMP, TIMESTAMP, STRING);
    addPushDownFunction(HANA, NANO100_BETWEEN, INTEGER, DATE, DATE);
    addPushDownFunction(HANA, NEXT_DAY, DATE, DATE);
    addPushDownFunction(HANA, SECONDS_BETWEEN, INTEGER, DATE, DATE);
    addPushDownFunction(HANA, WEEKDAY, INTEGER, DATE);
    addPushDownFunction(HANA, WORKDAYS_BETWEEN, DATE, INTEGER);
    /*
    	 * Numeric Pushdown functions
    	 */
    addPushDownFunction(HANA, COSH, INTEGER, FLOAT);
    addPushDownFunction(HANA, BITSET, STRING, VARBINARY, INTEGER, INTEGER);
    addPushDownFunction(HANA, BITUNSET, STRING, VARBINARY, INTEGER, INTEGER);
    addPushDownFunction(HANA, COSH, FLOAT, FLOAT);
    addPushDownFunction(HANA, HEXTOBIN, BLOB, STRING);
    addPushDownFunction(HANA, RAND, BLOB);
    addPushDownFunction(HANA, SINH, FLOAT, FLOAT);
    addPushDownFunction(HANA, TANH, FLOAT, FLOAT);
    addPushDownFunction(HANA, UMINUS, INTEGER, INTEGER);
}
Also used : ConvertModifier(org.teiid.translator.jdbc.ConvertModifier) TemplateFunctionModifier(org.teiid.translator.jdbc.TemplateFunctionModifier) TemplateFunctionModifier(org.teiid.translator.jdbc.TemplateFunctionModifier) LocateFunctionModifier(org.teiid.translator.jdbc.LocateFunctionModifier) FunctionModifier(org.teiid.translator.jdbc.FunctionModifier) AliasModifier(org.teiid.translator.jdbc.AliasModifier) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)4 List (java.util.List)4 AliasModifier (org.teiid.translator.jdbc.AliasModifier)4 ConvertModifier (org.teiid.translator.jdbc.ConvertModifier)4 FunctionModifier (org.teiid.translator.jdbc.FunctionModifier)4 LocateFunctionModifier (org.teiid.translator.jdbc.LocateFunctionModifier)4 Expression (org.teiid.language.Expression)1 Function (org.teiid.language.Function)1 ExtractFunctionModifier (org.teiid.translator.jdbc.ExtractFunctionModifier)1 ModFunctionModifier (org.teiid.translator.jdbc.ModFunctionModifier)1 TemplateFunctionModifier (org.teiid.translator.jdbc.TemplateFunctionModifier)1