Search in sources :

Example 16 with FunctionModifier

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

the class MongoDBExecutionFactory method start.

@SuppressWarnings("nls")
@Override
public void start() throws TranslatorException {
    super.start();
    // $NON-NLS-1$ //$NON-NLS-2$
    registerFunctionModifier("+", new AliasModifier("$add"));
    // $NON-NLS-1$ //$NON-NLS-2$
    registerFunctionModifier("-", new AliasModifier("$subtract"));
    // $NON-NLS-1$ //$NON-NLS-2$
    registerFunctionModifier("*", new AliasModifier("$multiply"));
    // $NON-NLS-1$ //$NON-NLS-2$
    registerFunctionModifier("/", new AliasModifier("$divide"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CONCAT, new AliasModifier("$concat"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new AliasModifier("$substr"));
    registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            // $NON-NLS-1$
            function.setName("$substr");
            ArrayList<Expression> params = new ArrayList<Expression>();
            params.add(function.getParameters().get(0));
            // MongoDB is zero base index; Teiid is 1 based;
            params.add(LanguageFactory.INSTANCE.createFunction("-", new Expression[] { function.getParameters().get(1), LanguageFactory.INSTANCE.createLiteral(1, TypeFacility.RUNTIME_TYPES.INTEGER) }, TypeFacility.RUNTIME_TYPES.INTEGER));
            if (function.getParameters().size() == 2) {
                function.getParameters().add(LanguageFactory.INSTANCE.createLiteral(DataTypeManager.MAX_STRING_LENGTH, TypeFacility.RUNTIME_TYPES.INTEGER));
            }
            params.add(function.getParameters().get(2));
            function.getParameters().clear();
            function.getParameters().addAll(params);
            return null;
        }
    });
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("$toLower"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("$toUpper"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new AliasModifier("$dayOfYear"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new AliasModifier("$dayOfMonth"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new AliasModifier("$dayOfWeek"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.YEAR, new AliasModifier("$year"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.MONTH, new AliasModifier("$month"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.WEEK, new AliasModifier("$week"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.HOUR, new AliasModifier("$hour"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.MINUTE, new AliasModifier("$minute"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.SECOND, new AliasModifier("$second"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("$ifNull"));
    FunctionMethod method = null;
    method = addPushDownFunction(MONGO, FUNC_GEO_INTERSECTS, TypeFacility.RUNTIME_NAMES.BOOLEAN, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, // $NON-NLS-1$
    TypeFacility.RUNTIME_NAMES.DOUBLE + "[][]");
    method.setProperty(AVOID_PROJECTION, "true");
    method = addPushDownFunction(MONGO, FUNC_GEO_INTERSECTS, TypeFacility.RUNTIME_NAMES.BOOLEAN, // $NON-NLS-1$
    TypeFacility.RUNTIME_NAMES.GEOMETRY);
    method.setProperty(AVOID_PROJECTION, "true");
    method = addPushDownFunction(MONGO, FUNC_GEO_WITHIN, TypeFacility.RUNTIME_NAMES.BOOLEAN, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, // $NON-NLS-1$
    TypeFacility.RUNTIME_NAMES.DOUBLE + "[][]");
    method.setProperty(AVOID_PROJECTION, "true");
    method = addPushDownFunction(MONGO, FUNC_GEO_WITHIN, TypeFacility.RUNTIME_NAMES.BOOLEAN, // $NON-NLS-1$
    TypeFacility.RUNTIME_NAMES.GEOMETRY);
    method.setProperty(AVOID_PROJECTION, "true");
    if (getVersion().compareTo(MongoDBExecutionFactory.TWO_6) >= 0) {
        method = addPushDownFunction(MONGO, FUNC_GEO_NEAR, TypeFacility.RUNTIME_NAMES.BOOLEAN, // $NON-NLS-1$
        TypeFacility.RUNTIME_NAMES.STRING, // $NON-NLS-1$
        TypeFacility.RUNTIME_NAMES.DOUBLE + "[]", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.INTEGER);
        method.setProperty(AVOID_PROJECTION, "true");
        method = addPushDownFunction(MONGO, FUNC_GEO_NEAR, TypeFacility.RUNTIME_NAMES.BOOLEAN, TypeFacility.RUNTIME_NAMES.GEOMETRY, TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.INTEGER);
        method.setProperty(AVOID_PROJECTION, "true");
        method = addPushDownFunction(MONGO, FUNC_GEO_NEAR_SPHERE, TypeFacility.RUNTIME_NAMES.BOOLEAN, // $NON-NLS-1$
        TypeFacility.RUNTIME_NAMES.STRING, // $NON-NLS-1$
        TypeFacility.RUNTIME_NAMES.DOUBLE + "[]", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.INTEGER);
        method.setProperty(AVOID_PROJECTION, "true");
        method = addPushDownFunction(MONGO, FUNC_GEO_NEAR_SPHERE, TypeFacility.RUNTIME_NAMES.BOOLEAN, TypeFacility.RUNTIME_NAMES.GEOMETRY, TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.INTEGER);
        method.setProperty(AVOID_PROJECTION, "true");
    } else {
        method = addPushDownFunction(MONGO, FUNC_GEO_NEAR, TypeFacility.RUNTIME_NAMES.BOOLEAN, // $NON-NLS-1$
        TypeFacility.RUNTIME_NAMES.STRING, // $NON-NLS-1$
        TypeFacility.RUNTIME_NAMES.DOUBLE + "[]", TypeFacility.RUNTIME_NAMES.INTEGER);
        method.setProperty(AVOID_PROJECTION, "true");
        method = addPushDownFunction(MONGO, FUNC_GEO_NEAR_SPHERE, TypeFacility.RUNTIME_NAMES.BOOLEAN, // $NON-NLS-1$
        TypeFacility.RUNTIME_NAMES.STRING, // $NON-NLS-1$
        TypeFacility.RUNTIME_NAMES.DOUBLE + "[]", TypeFacility.RUNTIME_NAMES.INTEGER);
        method.setProperty(AVOID_PROJECTION, "true");
    }
    method = addPushDownFunction(MONGO, FUNC_GEO_POLYGON_INTERSECTS, TypeFacility.RUNTIME_NAMES.BOOLEAN, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.DOUBLE, TypeFacility.RUNTIME_NAMES.DOUBLE, TypeFacility.RUNTIME_NAMES.DOUBLE, TypeFacility.RUNTIME_NAMES.DOUBLE);
    method.setProperty(AVOID_PROJECTION, "true");
    method = addPushDownFunction(MONGO, FUNC_GEO_POLYGON_INTERSECTS, TypeFacility.RUNTIME_NAMES.BOOLEAN, TypeFacility.RUNTIME_NAMES.GEOMETRY);
    method.setProperty(AVOID_PROJECTION, "true");
    method = addPushDownFunction(MONGO, FUNC_GEO_POLYGON_WITHIN, TypeFacility.RUNTIME_NAMES.BOOLEAN, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.DOUBLE, TypeFacility.RUNTIME_NAMES.DOUBLE, TypeFacility.RUNTIME_NAMES.DOUBLE, TypeFacility.RUNTIME_NAMES.DOUBLE);
    method.setProperty(AVOID_PROJECTION, "true");
    method = addPushDownFunction(MONGO, FUNC_GEO_POLYGON_WITHIN, TypeFacility.RUNTIME_NAMES.BOOLEAN, TypeFacility.RUNTIME_NAMES.GEOMETRY);
    method.setProperty(AVOID_PROJECTION, "true");
    // $NON-NLS-1$
    registerFunctionModifier(FUNC_GEO_NEAR, new AliasModifier("$near"));
    // $NON-NLS-1$
    registerFunctionModifier(FUNC_GEO_NEAR_SPHERE, new AliasModifier("$nearSphere"));
    // $NON-NLS-1$
    registerFunctionModifier(FUNC_GEO_WITHIN, new AliasModifier("$geoWithin"));
    // $NON-NLS-1$
    registerFunctionModifier(FUNC_GEO_INTERSECTS, new AliasModifier("$geoIntersects"));
    // $NON-NLS-1$
    registerFunctionModifier(FUNC_GEO_POLYGON_INTERSECTS, new GeoPolygonFunctionModifier("$geoIntersects"));
    // $NON-NLS-1$
    registerFunctionModifier(FUNC_GEO_POLYGON_WITHIN, new GeoPolygonFunctionModifier("$geoWithin"));
}
Also used : Function(org.teiid.language.Function) Expression(org.teiid.language.Expression) QueryExpression(org.teiid.language.QueryExpression) FunctionModifier(org.teiid.translator.jdbc.FunctionModifier) AliasModifier(org.teiid.translator.jdbc.AliasModifier) ArrayList(java.util.ArrayList) FunctionMethod(org.teiid.metadata.FunctionMethod) BasicDBList(com.mongodb.BasicDBList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 17 with FunctionModifier

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

the class CouchbaseExecutionFactory method start.

@Override
public void start() throws TranslatorException {
    super.start();
    registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new SubstringFunctionModifier());
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CEILING, new AliasModifier("CEIL"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.LOG, new AliasModifier("LN"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.LOG10, new AliasModifier("LOG"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.RAND, new AliasModifier("RANDOM"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("LOWER"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("UPPER"));
    registerFunctionModifier(SourceSystemFunctions.CONVERT, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            Expression param = function.getParameters().get(0);
            int targetCode = getCode(function.getType());
            if (targetCode == BYTE || targetCode == SHORT || targetCode == INTEGER || targetCode == LONG || targetCode == FLOAT || targetCode == DOUBLE || targetCode == BIGINTEGER || targetCode == BIGDECIMAL) {
                if ((Number.class.isAssignableFrom(param.getType()))) {
                    return Arrays.asList(param);
                }
                // $NON-NLS-1$
                return Arrays.asList("TONUMBER" + Tokens.LPAREN, param, Tokens.RPAREN);
            } else if (targetCode == STRING || targetCode == CHAR) {
                // $NON-NLS-1$
                return Arrays.asList("TOSTRING" + Tokens.LPAREN, param, Tokens.RPAREN);
            } else if (targetCode == BOOLEAN) {
                // $NON-NLS-1$
                return Arrays.asList("TOBOOLEAN" + Tokens.LPAREN, param, Tokens.RPAREN);
            } else {
                return Arrays.asList(param);
            }
        }
    });
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "CONTAINS", TypeFacility.RUNTIME_NAMES.BOOLEAN, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "TITLE", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "LTRIM", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "TRIM", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "RTRIM", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "POSITION", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "CLOCK_MILLIS", TypeFacility.RUNTIME_NAMES.DOUBLE);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "CLOCK_STR", TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "CLOCK_STR", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "DATE_ADD_MILLIS", TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "DATE_ADD_STR", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "DATE_DIFF_MILLIS", TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "DATE_DIFF_STR", TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "DATE_PART_MILLIS", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "DATE_PART_STR", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "NOW_MILLIS", TypeFacility.RUNTIME_NAMES.DOUBLE);
    // $NON-NLS-1$
    addPushDownFunction(COUCHBASE, "NOW_STR", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
}
Also used : Function(org.teiid.language.Function) Expression(org.teiid.language.Expression) QueryExpression(org.teiid.language.QueryExpression) FunctionModifier(org.teiid.translator.jdbc.FunctionModifier) AliasModifier(org.teiid.translator.jdbc.AliasModifier) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with FunctionModifier

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

the class AccessExecutionFactory method start.

@Override
public void start() throws TranslatorException {
    super.start();
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.ASCII, new AliasModifier("Asc"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CHAR, new AliasModifier("Chr"));
    registerFunctionModifier(SourceSystemFunctions.CONCAT, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            List<Object> result = new ArrayList<Object>(function.getParameters().size() * 2 - 1);
            for (int i = 0; i < function.getParameters().size(); i++) {
                if (i > 0) {
                    // $NON-NLS-1$
                    result.add(" & ");
                }
                result.add(function.getParameters().get(i));
            }
            return result;
        }
    });
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.LENGTH, new AliasModifier("Len"));
}
Also used : Function(org.teiid.language.Function) AggregateFunction(org.teiid.language.AggregateFunction) FunctionModifier(org.teiid.translator.jdbc.FunctionModifier) AliasModifier(org.teiid.translator.jdbc.AliasModifier) ArrayList(java.util.ArrayList) List(java.util.List) LanguageObject(org.teiid.language.LanguageObject)

Example 19 with FunctionModifier

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

Example 20 with FunctionModifier

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

the class HiveExecutionFactory 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("int", FunctionModifier.INTEGER);
    // $NON-NLS-1$
    convert.addTypeMapping("bigint", FunctionModifier.BIGINTEGER, FunctionModifier.LONG);
    // $NON-NLS-1$
    convert.addTypeMapping("boolean", FunctionModifier.BOOLEAN);
    // $NON-NLS-1$
    convert.addTypeMapping("double", FunctionModifier.DOUBLE);
    // $NON-NLS-1$
    convert.addTypeMapping("float", FunctionModifier.FLOAT);
    // $NON-NLS-1$
    convert.addTypeMapping("string", FunctionModifier.STRING);
    // $NON-NLS-1$
    convert.addTypeMapping("timestamp", FunctionModifier.TIMESTAMP);
    // $NON-NLS-1$
    convert.addTypeMapping("binary", FunctionModifier.BLOB, FunctionModifier.VARBINARY);
    // $NON-NLS-1$
    convert.addTypeMapping("decimal", FunctionModifier.BIGDECIMAL);
    // $NON-NLS-1$
    convert.addTypeMapping("date", FunctionModifier.DATE);
    // unsupported types
    // FunctionModifier.TIME,
    // FunctionModifier.CHAR,
    // FunctionModifier.CLOB,
    // FunctionModifier.XML
    registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.BITAND, new AliasModifier("&"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.BITNOT, new AliasModifier("~"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.BITOR, new AliasModifier("|"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.BITXOR, new AliasModifier("^"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.CURDATE, new AliasModifier("unix_timestamp"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce"));
    // $NON-NLS-1$
    registerFunctionModifier(SourceSystemFunctions.MOD, new ModFunctionModifier("%", getLanguageFactory(), Arrays.asList(TypeFacility.RUNTIME_TYPES.BIG_INTEGER, TypeFacility.RUNTIME_TYPES.BIG_DECIMAL)));
    registerFunctionModifier(SourceSystemFunctions.ARRAY_GET, new FunctionModifier() {

        @Override
        public List<?> translate(Function function) {
            return Arrays.asList(function.getParameters().get(0), '[', function.getParameters().get(1), ']');
        }
    });
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "lower", STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "upper", STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "positive", INTEGER, DOUBLE);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "positive", DOUBLE, DOUBLE);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "negitive", INTEGER, DOUBLE);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "negitive", DOUBLE, DOUBLE);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "ln", DOUBLE, DOUBLE);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "reverse", STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "space", INTEGER, STRING);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "split", OBJECT, STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "hex", STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "unhex", STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "bin", STRING, LONG);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "day", INTEGER, DATE);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "datediff", INTEGER, STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "date_add", INTEGER, STRING, INTEGER);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "date_sub", INTEGER, STRING, INTEGER);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "from_unixtime", STRING, LONG);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "from_unixtime", STRING, LONG, STRING);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "unix_timestamp", LONG, STRING);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "unix_timestamp", LONG, STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "to_date", STRING, STRING);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "from_utc_timestamp", TIMESTAMP, TIMESTAMP, STRING);
    // $NON-NLS-1$
    addPushDownFunction(HIVE, "to_utc_timestamp", TIMESTAMP, TIMESTAMP, STRING);
    // $NON-NLS-1$
    addAggregatePushDownFunction(HIVE, "LEAD", OBJECT, OBJECT);
    // $NON-NLS-1$
    addAggregatePushDownFunction(HIVE, "LEAD", OBJECT, OBJECT, INTEGER);
    // $NON-NLS-1$
    addAggregatePushDownFunction(HIVE, "LEAD", OBJECT, OBJECT, INTEGER, OBJECT);
    // $NON-NLS-1$
    addAggregatePushDownFunction(HIVE, "LAG", OBJECT, OBJECT);
    // $NON-NLS-1$
    addAggregatePushDownFunction(HIVE, "LAG", OBJECT, OBJECT, INTEGER);
    // $NON-NLS-1$
    addAggregatePushDownFunction(HIVE, "LAG", OBJECT, OBJECT, INTEGER, OBJECT);
    // $NON-NLS-1$
    addAggregatePushDownFunction(HIVE, "FIRST_VALUE", OBJECT, OBJECT);
    // $NON-NLS-1$
    addAggregatePushDownFunction(HIVE, "LAST_VALUE", OBJECT, OBJECT);
    // $NON-NLS-1$
    addAggregatePushDownFunction(HIVE, "PERCENT_RANK", FLOAT);
    // $NON-NLS-1$
    addAggregatePushDownFunction(HIVE, "CUME_DIST", FLOAT);
    // $NON-NLS-1$
    addAggregatePushDownFunction(HIVE, "NTILE", LONG, INTEGER);
}
Also used : Function(org.teiid.language.Function) ModFunctionModifier(org.teiid.translator.jdbc.ModFunctionModifier) 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)

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