Search in sources :

Example 1 with FunctionModifier

use of org.teiid.translator.jdbc.FunctionModifier 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 FunctionModifier

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

the class DB2ExecutionFactory method start.

@Override
public void start() throws TranslatorException {
    super.start();
    registerFunctionModifier(SourceSystemFunctions.TRIM, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            List<Expression> p = function.getParameters();
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            return Arrays.asList("STRIP(", p.get(2), ", ", ((Literal) p.get(0)).getValue(), ", ", p.get(1), ")");
        }
    });
    registerFunctionModifier(SourceSystemFunctions.WEEK, new AliasModifier(WEEK_ISO));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    addPushDownFunction("db2", "substr", "string", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.INTEGER);
}
Also used : Function(org.teiid.language.Function) FunctionModifier(org.teiid.translator.jdbc.FunctionModifier) Literal(org.teiid.language.Literal) AliasModifier(org.teiid.translator.jdbc.AliasModifier) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with FunctionModifier

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

the class InterSystemsCacheExecutionFactory method start.

@Override
public void start() throws TranslatorException {
    super.start();
    // $NON-NLS-1$
    convert.addTypeMapping("tinyint", FunctionModifier.BYTE);
    // $NON-NLS-1$
    convert.addTypeMapping("smallint", FunctionModifier.SHORT);
    // $NON-NLS-1$
    convert.addTypeMapping("integer", FunctionModifier.INTEGER);
    // $NON-NLS-1$
    convert.addTypeMapping("bigint", FunctionModifier.LONG);
    // $NON-NLS-1$
    convert.addTypeMapping("decimal(38,19)", FunctionModifier.BIGDECIMAL);
    // $NON-NLS-1$
    convert.addTypeMapping("decimal(19,0)", FunctionModifier.BIGINTEGER);
    // $NON-NLS-1$
    convert.addTypeMapping("character", FunctionModifier.CHAR);
    // $NON-NLS-1$
    convert.addTypeMapping("varchar(4000)", FunctionModifier.STRING);
    // $NON-NLS-1$
    convert.addTypeMapping("date", FunctionModifier.DATE);
    // $NON-NLS-1$
    convert.addTypeMapping("time", FunctionModifier.TIME);
    // $NON-NLS-1$
    convert.addTypeMapping("timestamp", FunctionModifier.TIMESTAMP);
    convert.addNumericBooleanConversions();
    registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("nvl"));
    registerFunctionModifier(SourceSystemFunctions.CONCAT, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.ACOS, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.ASIN, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.ATAN, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.COS, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.COT, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.CURDATE, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.CURTIME, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.DAYNAME, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.EXP, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.HOUR, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.LOG, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.LOG10, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.LEFT, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.MINUTE, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.MONTH, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.MONTHNAME, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.MOD, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.NOW, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.PI, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.QUARTER, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.RIGHT, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.SIN, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.SECOND, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.SQRT, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.TAN, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.TRUNCATE, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.WEEK, new EscapeSyntaxModifier());
    registerFunctionModifier(SourceSystemFunctions.DIVIDE_OP, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            if (function.getType() == TypeFacility.RUNTIME_TYPES.INTEGER || function.getType() == TypeFacility.RUNTIME_TYPES.LONG) {
                Function result = ConvertModifier.createConvertFunction(getLanguageFactory(), function, TypeFacility.getDataTypeName(function.getType()));
                function.setType(TypeFacility.RUNTIME_TYPES.BIG_DECIMAL);
                return Arrays.asList(result);
            }
            return null;
        }
    });
    // $NON-NLS-1$
    addPushDownFunction(INTER_CACHE, "CHARACTER_LENGTH", INTEGER, STRING);
    // $NON-NLS-1$
    addPushDownFunction(INTER_CACHE, "CHAR_LENGTH", INTEGER, STRING);
    // $NON-NLS-1$
    addPushDownFunction(INTER_CACHE, "CHARINDEX", INTEGER, STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(INTER_CACHE, "CHARINDEX", INTEGER, STRING, STRING, INTEGER);
    // $NON-NLS-1$
    addPushDownFunction(INTER_CACHE, "INSTR", INTEGER, STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(INTER_CACHE, "INSTR", INTEGER, STRING, STRING, INTEGER);
    // $NON-NLS-1$
    addPushDownFunction(INTER_CACHE, "IS_NUMERIC", INTEGER, STRING);
    // $NON-NLS-1$
    addPushDownFunction(INTER_CACHE, "REPLICATE", STRING, STRING, INTEGER);
    // $NON-NLS-1$
    addPushDownFunction(INTER_CACHE, "REVERSE", STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(INTER_CACHE, "STUFF", STRING, STRING, STRING, INTEGER, STRING);
    // $NON-NLS-1$
    addPushDownFunction(INTER_CACHE, "TRIM", STRING, STRING);
}
Also used : Function(org.teiid.language.Function) FunctionModifier(org.teiid.translator.jdbc.FunctionModifier) AliasModifier(org.teiid.translator.jdbc.AliasModifier) EscapeSyntaxModifier(org.teiid.translator.jdbc.EscapeSyntaxModifier) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with FunctionModifier

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

the class MySQL5ExecutionFactory method start.

@Override
public void start() throws TranslatorException {
    super.start();
    registerFunctionModifier(SourceSystemFunctions.CHAR, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            // $NON-NLS-1$ //$NON-NLS-2$
            return Arrays.asList("char(", function.getParameters().get(0), " USING ASCII)");
        }
    });
    registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            Literal intervalType = (Literal) function.getParameters().get(0);
            String interval = ((String) intervalType.getValue()).toUpperCase();
            if (interval.equals(NonReserved.SQL_TSI_FRAC_SECOND)) {
                // $NON-NLS-1$
                intervalType.setValue("MICROSECOND");
                Expression[] args = new Expression[] { function.getParameters().get(1), getLanguageFactory().createLiteral(1000, TypeFacility.RUNTIME_TYPES.INTEGER) };
                // $NON-NLS-1$
                function.getParameters().set(1, getLanguageFactory().createFunction("/", args, TypeFacility.RUNTIME_TYPES.INTEGER));
            }
            return null;
        }
    });
    // $NON-NLS-1$ //$NON-NLS-2$
    addPushDownFunction("mysql", "timestampdiff", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.TIMESTAMP, TypeFacility.RUNTIME_NAMES.TIMESTAMP);
    registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            Literal intervalType = (Literal) function.getParameters().get(0);
            String interval = ((String) intervalType.getValue()).toUpperCase();
            if (interval.equals(NonReserved.SQL_TSI_FRAC_SECOND)) {
                // $NON-NLS-1$
                intervalType.setValue("MICROSECOND");
                // $NON-NLS-1$
                return Arrays.asList(function, " * 1000");
            }
            return null;
        }
    });
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.ST_SRID, new AliasModifier("SRID"));
}
Also used : Function(org.teiid.language.Function) FunctionModifier(org.teiid.translator.jdbc.FunctionModifier) Literal(org.teiid.language.Literal) AliasModifier(org.teiid.translator.jdbc.AliasModifier) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with FunctionModifier

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

the class SolrSQLHierarchyVistor method visit.

@Override
public void visit(Function obj) {
    FunctionModifier funcModifier = this.ef.getFunctionModifiers().get(obj.getName());
    if (funcModifier != null) {
        funcModifier.translate(obj);
    }
    StringBuilder sb = new StringBuilder();
    visitNodes(obj.getParameters());
    for (int i = 0; i < obj.getParameters().size(); i++) {
        sb.insert(0, this.onGoingExpression.pop());
        if (i < obj.getParameters().size() - 1) {
            sb.insert(0, Tokens.COMMA);
        }
    }
    sb.insert(0, Tokens.LPAREN);
    sb.insert(0, obj.getName());
    sb.append(Tokens.RPAREN);
    this.onGoingExpression.push(sb.toString());
}
Also used : FunctionModifier(org.teiid.translator.jdbc.FunctionModifier)

Aggregations

FunctionModifier (org.teiid.translator.jdbc.FunctionModifier)20 ArrayList (java.util.ArrayList)19 List (java.util.List)19 AliasModifier (org.teiid.translator.jdbc.AliasModifier)17 Function (org.teiid.language.Function)12 ConvertModifier (org.teiid.translator.jdbc.ConvertModifier)6 ModFunctionModifier (org.teiid.translator.jdbc.ModFunctionModifier)5 Expression (org.teiid.language.Expression)4 EscapeSyntaxModifier (org.teiid.translator.jdbc.EscapeSyntaxModifier)4 LocateFunctionModifier (org.teiid.translator.jdbc.LocateFunctionModifier)4 TemplateFunctionModifier (org.teiid.translator.jdbc.TemplateFunctionModifier)4 LinkedList (java.util.LinkedList)3 Literal (org.teiid.language.Literal)3 ConcatFunctionModifier (org.teiid.translator.jdbc.oracle.ConcatFunctionModifier)3 QueryExpression (org.teiid.language.QueryExpression)2 FunctionMethod (org.teiid.metadata.FunctionMethod)2 ExtractFunctionModifier (org.teiid.translator.jdbc.ExtractFunctionModifier)2 ParseFormatFunctionModifier (org.teiid.translator.jdbc.ParseFormatFunctionModifier)2 BasicDBList (com.mongodb.BasicDBList)1 AggregateFunction (org.teiid.language.AggregateFunction)1