use of org.teiid.translator.jdbc.AliasModifier 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"));
}
use of org.teiid.translator.jdbc.AliasModifier in project teiid by teiid.
the class PrestoDBExecutionFactory method start.
@Override
public void start() throws TranslatorException {
super.start();
// $NON-NLS-1$
convert.addTypeMapping("boolean", FunctionModifier.BOOLEAN);
// $NON-NLS-1$
convert.addTypeMapping("bigint", FunctionModifier.BIGINTEGER, FunctionModifier.LONG);
// $NON-NLS-1$
convert.addTypeMapping("double", FunctionModifier.DOUBLE);
// $NON-NLS-1$
convert.addTypeMapping("varchar", 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);
// $NON-NLS-1$
convert.addTypeMapping("varbinary", FunctionModifier.BLOB);
// $NON-NLS-1$
convert.addTypeMapping("json", FunctionModifier.BLOB);
registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CURDATE, new AliasModifier("current_date"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CURTIME, new AliasModifier("current_time"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new AliasModifier("day_of_month"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new AliasModifier("day_of_week"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new AliasModifier("day_of_year"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("coalesce"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.FORMATTIMESTAMP, new AliasModifier("format_datetime"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.PARSETIMESTAMP, new AliasModifier("parse_datetime"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.POWER, new AliasModifier("pow"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("lower"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("upper"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CHAR, new AliasModifier("chr"));
registerFunctionModifier(SourceSystemFunctions.LOG, new // $NON-NLS-1$
AliasModifier(// $NON-NLS-1$
"ln") {
@Override
protected void modify(Function function) {
if (function.getParameters().size() == 1) {
super.modify(function);
}
}
});
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "cbrt", DOUBLE, DOUBLE);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "ceil", INTEGER, DOUBLE);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "current_timestamp", TIMESTAMP);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "current_timezone", STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "e", DOUBLE);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "ln", DOUBLE, DOUBLE);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "log2", DOUBLE, DOUBLE);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "log", DOUBLE, DOUBLE, INTEGER);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "random", DOUBLE);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "cosh", DOUBLE, DOUBLE);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "tanh", DOUBLE, DOUBLE);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "infinity", DOUBLE);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "is_finite", BOOLEAN, DOUBLE);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "is_infinite", BOOLEAN, DOUBLE);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "is_nan", BOOLEAN, DOUBLE);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "nan", DOUBLE);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "reverse", STRING, STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "split_part", STRING, STRING, CHAR, INTEGER);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "to_base64", STRING, VARBINARY);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "from_base64", VARBINARY, STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "to_base64url", STRING, VARBINARY);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "from_base64url", VARBINARY, STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "to_hex", STRING, VARBINARY);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "from_hex", VARBINARY, STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "timezone_hour", BIG_INTEGER, TIMESTAMP);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "timezone_minute", BIG_INTEGER, TIMESTAMP);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "regexp_extract", STRING, STRING, STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "regexp_extract", STRING, STRING, INTEGER);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "regexp_like", BOOLEAN, STRING, STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "regexp_replace", STRING, STRING, STRING, STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "url_extract_fragment", STRING, STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "url_extract_host", STRING, STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "url_extract_parameter", STRING, STRING, STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "url_extract_path", STRING, STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "url_extract_port", INTEGER, STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "url_extract_protocol", STRING, STRING);
// $NON-NLS-1$
addPushDownFunction(PRESTODB, "url_extract_query", STRING, STRING);
// TODO: JSON functions, not sure how to represent the JSON type?
// Array Functions, MAP functions?
// aggregate functions?
}
use of org.teiid.translator.jdbc.AliasModifier 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);
}
use of org.teiid.translator.jdbc.AliasModifier 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"));
}
use of org.teiid.translator.jdbc.AliasModifier 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);
}
Aggregations