use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class DB2Transformer method transformDateTrunc.
@Override
protected void transformDateTrunc(AstFunNode node) {
Function opConcat = DefaultParserContext.FUNC_MINUS;
SimpleNode date = node.child(1);
String field = ((AstStringConstant) node.child(0)).getValue();
AstFirstDayOf month = new AstFirstDayOf(new AstParenthesis(opConcat.node(DAY.node(date), AstNumericConstant.of(1))), "DAYS");
if (field.equalsIgnoreCase("'MONTH'"))
node.replaceWith(opConcat.node(date, month));
else {
AstFirstDayOf year = new AstFirstDayOf(new AstParenthesis(opConcat.node(MONTH.node(date), AstNumericConstant.of(1))), "MONTHS");
node.replaceWith(opConcat.node(date, opConcat.node(year, month)));
}
}
use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class FilterApplier method addFilter.
public void addFilter(AstQuery query, Map<ColumnRef, Object> conditions) {
if (conditions.size() == 0)
return;
AstWhere where = new AstWhere();
if (query.jjtGetNumChildren() == 1) {
AstSelect select = (AstSelect) query.child(0);
if (select.getWhere() != null)
where = select.getWhere();
else
select.where(where);
} else {
AstTableRef tableRef = new AstTableRef(new AstParenthesis(query.clone()), new AstIdentifierConstant("tmp"));
AstSelect select = new AstSelect(new AstSelectList(), new AstFrom(tableRef));
select.where(where);
query.replaceWith(new AstQuery(select));
}
addWhere(where, conditions);
}
use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class FilterApplier method setFilter.
public void setFilter(AstStart ast, Map<ColumnRef, Object> conditions) {
AstQuery query = ast.getQuery();
dropOldConditions(query);
if (conditions.size() == 0)
return;
AstWhere where = new AstWhere();
addWhere(where, conditions);
if (query.jjtGetNumChildren() == 1)
((AstSelect) query.child(0)).where(where);
else {
AstTableRef tableRef = new AstTableRef(new AstParenthesis(query.clone()), new AstIdentifierConstant("tmp"));
AstSelect select = new AstSelect(new AstSelectList(), new AstFrom(tableRef));
select.where(where);
query.replaceWith(new AstQuery(select));
}
}
use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class GenericDbmsTransformer method transformInterval.
private void transformInterval(AstInterval interval) {
SimpleNode mul = interval.jjtGetParent();
if (AstFunNode.isFunction("*").test(mul)) {
String type = interval.getLiteral();
String fn;
switch(type) {
case "1 MONTH":
fn = "ADD_MONTHS";
break;
case "1 DAYS":
case "1 DAY":
fn = "ADD_DAYS";
break;
case "1 MILLISECOND":
fn = "ADD_MILLIS";
break;
default:
throw new IllegalStateException("Unsupported interval format: " + interval.format());
}
SimpleNode content = mul.other(interval);
if (content instanceof AstParenthesis)
content = ((AstParenthesis) content).child(0);
SimpleNode add = mul.jjtGetParent();
if (!AstFunNode.isFunction("+").test(add))
throw new IllegalStateException("Interval grandparent is " + add + ", expected addition");
SimpleNode date = add.other(mul);
AstFunNode addFunction = parserContext.getFunction(fn).node(date, content);
date.pullUpPrefix();
SimpleNode toReplace = add;
if (toReplace.jjtGetParent() instanceof AstParenthesis)
toReplace = toReplace.jjtGetParent();
toReplace.replaceWith(addFunction);
transformDateAdd(addFunction);
}
}
use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class SqlServerTransformer method transformLeastGreatest.
@Override
protected void transformLeastGreatest(AstFunNode node) {
String name = node.getFunction().getName();
AstIdentifierConstant v = new AstIdentifierConstant("V");
Function func;
if ("LEAST".equals(name))
func = parserContext.getFunction("min");
else
func = parserContext.getFunction("max");
AstValues values = new AstValues(0);
for (SimpleNode child : node.children()) values.addChild(new AstParenthesis(child));
AstTableRef tableRef = new AstTableRef(new AstParenthesis(values), new AstIdentifierConstant(name), new AstColumnList(v));
node.replaceWith(new AstParenthesis(new AstSelect(new AstSelectList(func.node(v)), new AstFrom(tableRef))));
}
Aggregations