use of org.teiid.translator.jdbc.oracle.ConcatFunctionModifier in project teiid by teiid.
the class H2ExecutionFactory method start.
@Override
public void start() throws TranslatorException {
super.start();
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.PARSETIMESTAMP, new AliasModifier("parsedatetime"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.FORMATTIMESTAMP, new AliasModifier("formatdatetime"));
// $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.WEEK, new AliasModifier("iso_week"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new AliasModifier("day_of_year"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.UNESCAPE, new AliasModifier("stringdecode"));
registerFunctionModifier(SourceSystemFunctions.MOD, new ModFunctionModifier(SourceSystemFunctions.MOD, getLanguageFactory()));
// TODO: this behavior is configurable in h2 starting with 1.1.119
registerFunctionModifier(SourceSystemFunctions.CONCAT, new ConcatFunctionModifier(getLanguageFactory()));
registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new AddDiffModifier(true, getLanguageFactory()));
registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new AddDiffModifier(false, getLanguageFactory()));
ConvertModifier convert = new ConvertModifier();
// $NON-NLS-1$
convert.addTypeMapping("boolean", FunctionModifier.BOOLEAN);
// $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.LONG);
// $NON-NLS-1$
convert.addTypeMapping("real", FunctionModifier.FLOAT);
// $NON-NLS-1$
convert.addTypeMapping("double", FunctionModifier.DOUBLE);
// $NON-NLS-1$
convert.addTypeMapping("decimal", FunctionModifier.BIGDECIMAL);
// $NON-NLS-1$
convert.addTypeMapping("decimal(38,0)", FunctionModifier.BIGINTEGER);
// $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("char(1)", FunctionModifier.CHAR);
// $NON-NLS-1$
convert.addTypeMapping("varchar", FunctionModifier.STRING);
registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);
// $NON-NLS-1$ //$NON-NLS-2$
addPushDownFunction("h2", "timestampdiff", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.TIMESTAMP, TypeFacility.RUNTIME_NAMES.TIMESTAMP);
}
use of org.teiid.translator.jdbc.oracle.ConcatFunctionModifier in project teiid by teiid.
the class SybaseExecutionFactory method start.
public void start() throws TranslatorException {
super.start();
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.MOD, new ModFunctionModifier("%", getLanguageFactory()));
if (nullPlusNonNullIsNull()) {
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CONCAT, new AliasModifier("+"));
} else {
registerFunctionModifier(SourceSystemFunctions.CONCAT, new ConcatFunctionModifier(getLanguageFactory()) {
@Override
public List<?> translate(Function function) {
// $NON-NLS-1$
function.setName("+");
return super.translate(function);
}
});
}
registerFunctionModifier(SourceSystemFunctions.LPAD, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
List<Expression> params = function.getParameters();
return // $NON-NLS-1$
Arrays.asList(// $NON-NLS-1$
"RIGHT(REPLICATE(", // $NON-NLS-1$ //$NON-NLS-2$
params.size() > 2 ? params.get(2) : new Literal(" ", TypeFacility.RUNTIME_TYPES.STRING), // $NON-NLS-1$ //$NON-NLS-2$
", ", params.get(1), ") + ", params.get(0), ", ", params.get(1), // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
")");
}
});
registerFunctionModifier(SourceSystemFunctions.RPAD, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
List<Expression> params = function.getParameters();
return // $NON-NLS-1$ //$NON-NLS-2$
Arrays.asList(// $NON-NLS-1$ //$NON-NLS-2$
"LEFT(", // $NON-NLS-1$ //$NON-NLS-2$
params.get(0), // $NON-NLS-1$ //$NON-NLS-2$
" + REPLICATE(", // $NON-NLS-1$ //$NON-NLS-2$
params.size() > 2 ? params.get(2) : new Literal(" ", TypeFacility.RUNTIME_TYPES.STRING), // $NON-NLS-1$ //$NON-NLS-2$
", ", params.get(1), "), ", params.get(1), // $NON-NLS-1$ //$NON-NLS-2$
")");
}
});
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("lower"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier("isnull"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("upper"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.REPEAT, new AliasModifier("replicate"));
registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new SubstringFunctionModifier(getLanguageFactory()));
registerFunctionModifier(SourceSystemFunctions.DAYNAME, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.MONTHNAME, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.HOUR, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.MINUTE, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.QUARTER, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.SECOND, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.WEEK, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.LENGTH, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.ATAN2, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new EscapeSyntaxModifier() {
@Override
public List<?> translate(Function function) {
if (!isFracSeconds(function)) {
return super.translate(function);
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return Arrays.asList("dateadd(millisecond, ", function.getParameters().get(1), "/1000000, ", function.getParameters().get(2), ")");
}
});
registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new EscapeSyntaxModifier() {
@Override
public List<?> translate(Function function) {
if (!isFracSeconds(function)) {
return super.translate(function);
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return Arrays.asList("datediff(millisecond, ", function.getParameters().get(1), ",", function.getParameters().get(2), ")*1000000");
}
});
// add in type conversion
convertModifier.setBooleanNullable(booleanNullable());
// boolean isn't treated as bit, since it doesn't support null
// byte is treated as smallint, since tinyint is unsigned
// $NON-NLS-1$
convertModifier.addTypeMapping("smallint", FunctionModifier.BYTE, FunctionModifier.SHORT);
// $NON-NLS-1$
convertModifier.addTypeMapping("int", FunctionModifier.INTEGER);
// $NON-NLS-1$
convertModifier.addTypeMapping("numeric(19,0)", FunctionModifier.LONG);
// $NON-NLS-1$
convertModifier.addTypeMapping("real", FunctionModifier.FLOAT);
// $NON-NLS-1$
convertModifier.addTypeMapping("double precision", FunctionModifier.DOUBLE);
// $NON-NLS-1$
convertModifier.addTypeMapping("numeric(38, 0)", FunctionModifier.BIGINTEGER);
// $NON-NLS-1$
convertModifier.addTypeMapping("numeric(38, 19)", FunctionModifier.BIGDECIMAL);
// $NON-NLS-1$
convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR);
// $NON-NLS-1$
convertModifier.addTypeMapping("varchar(4000)", FunctionModifier.STRING);
convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.DATE, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
List<Object> result = new ArrayList<Object>();
// $NON-NLS-1$
result.add("cast(");
result.addAll(convertDateToString(function));
// $NON-NLS-1$
result.add(" AS datetime)");
return result;
}
});
convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
return convertTimeToString(function);
}
});
convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.STRING, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
return convertDateToString(function);
}
});
convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
return convertTimestampToString(function);
}
});
convertModifier.addNumericBooleanConversions();
registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.PARSETIMESTAMP, new SybaseFormatFunctionModifier("CONVERT(DATETIME, ", formatMap));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.FORMATTIMESTAMP, new SybaseFormatFunctionModifier("CONVERT(VARCHAR, ", formatMap));
}
use of org.teiid.translator.jdbc.oracle.ConcatFunctionModifier in project teiid by teiid.
the class SAPIQExecutionFactory method start.
public void start() throws TranslatorException {
super.start();
registerFunctionModifier(SourceSystemFunctions.CONCAT, new ConcatFunctionModifier(getLanguageFactory()) {
@Override
public List<?> translate(Function function) {
// $NON-NLS-1$
function.setName("||");
return super.translate(function);
}
});
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CONCAT2, new AliasModifier("STRING"));
registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new EscapeSyntaxModifier());
// $NON-NLS-1$ //$NON-NLS-2$
registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new TemplateFunctionModifier("DATEPART(dy,", 0, ")"));
registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.WEEK, new EscapeSyntaxModifier());
registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new AddDiffModifier(true, this.getLanguageFactory()).supportsQuarter(true));
registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new AddDiffModifier(false, this.getLanguageFactory()).supportsQuarter(true));
registerFunctionModifier(SourceSystemFunctions.IFNULL, new AliasModifier(SourceSystemFunctions.COALESCE));
registerFunctionModifier(SourceSystemFunctions.LOCATE, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
List<Expression> params = function.getParameters();
Expression param1 = params.get(0);
Expression param2 = params.set(1, param1);
params.set(0, param2);
return null;
}
});
// add in type conversion
ConvertModifier convertModifier = new ConvertModifier();
convertModifier.setBooleanNullable(booleanNullable());
convertModifier.addNumericBooleanConversions();
// boolean isn't treated as bit, since it doesn't support null
// byte is treated as smallint, since tinyint is unsigned
// $NON-NLS-1$
convertModifier.addTypeMapping("smallint", FunctionModifier.BYTE, FunctionModifier.SHORT);
// $NON-NLS-1$
convertModifier.addTypeMapping("bigint", FunctionModifier.LONG);
// $NON-NLS-1$
convertModifier.addTypeMapping("int", FunctionModifier.INTEGER);
// $NON-NLS-1$
convertModifier.addTypeMapping("double", FunctionModifier.DOUBLE);
// $NON-NLS-1$
convertModifier.addTypeMapping("real", FunctionModifier.FLOAT);
// $NON-NLS-1$
convertModifier.addTypeMapping("numeric(38, 0)", FunctionModifier.BIGINTEGER);
// $NON-NLS-1$
convertModifier.addTypeMapping("numeric(38, 19)", FunctionModifier.BIGDECIMAL);
// $NON-NLS-1$
convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR);
// $NON-NLS-1$
convertModifier.addTypeMapping("varchar(4000)", FunctionModifier.STRING);
// $NON-NLS-1$
convertModifier.addTypeMapping("varbinary", FunctionModifier.VARBINARY);
// $NON-NLS-1$
convertModifier.addTypeMapping("date", FunctionModifier.DATE);
// $NON-NLS-1$
convertModifier.addTypeMapping("time", FunctionModifier.TIME);
// $NON-NLS-1$
convertModifier.addTypeMapping("timestamp", FunctionModifier.TIMESTAMP);
convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
return convertTimeToString(function);
}
});
convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.STRING, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
return convertDateToString(function);
}
});
convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
return convertTimestampToString(function);
}
});
registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
}
Aggregations