use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class Be5QueryExecutor method countFromQuery.
private void countFromQuery(AstQuery query) {
AstSelect select = Ast.selectCount().from(AstTableRef.as(new AstParenthesis(query.clone()), new AstIdentifierConstant("data", true)));
query.replaceWith(new AstQuery(select));
}
use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class LimitsApplier method transformQuery.
public boolean transformQuery(AstQuery query) {
if (query.jjtGetNumChildren() == 1) {
AstSelect select = (AstSelect) query.child(0);
if (select.getLimit() != null)
return false;
AstLimit limit = new AstLimit();
limit.setLimit(offset, count);
select.addChild(limit);
} else {
AstTableRef tableRef = new AstTableRef(new AstParenthesis(query.clone()), new AstIdentifierConstant("tmp"));
AstSelect select = new AstSelect(new AstSelectList(), new AstFrom(tableRef));
AstLimit limit = new AstLimit();
limit.setLimit(offset, count);
select.addChild(limit);
query.replaceWith(new AstQuery(select));
}
// TODO: support offset, union, etc.
return true;
}
use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class MySqlTransformer method transformConcat.
@Override
protected void transformConcat(AstFunNode node) {
if (isConcat(node))
return;
node.setFunction(parserContext.getFunction("concat"));
List<SimpleNode> flatChildren = node.children().flatMap(child -> isConcat(child) ? child.children() : Stream.of(child)).toList();
node.removeChildren();
flatChildren.forEach(node::addChild);
SimpleNode parent = node.jjtGetParent();
if (parent instanceof AstParenthesis)
parent.replaceWith(node);
}
use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class MySqlTransformer method transformDateAdd.
@Override
protected void transformDateAdd(AstFunNode node) {
Function opTimes = DefaultParserContext.FUNC_TIMES;
SimpleNode date = node.child(0);
SimpleNode number = node.child(1);
String name = node.getFunction().getName();
String type = name.equalsIgnoreCase("add_months") ? "MONTH" : name.equalsIgnoreCase("add_days") ? "DAY" : "MICROSECOND";
if (type.equals("MICROSECOND"))
number = new AstParenthesis(opTimes.node(number, AstNumericConstant.of(1000)));
node.replaceWith(new AstDateAdd(date, new AstInterval(number), type));
}
use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class OracleTransformer method getDateTimeDiff.
@Override
protected SimpleNode getDateTimeDiff(SimpleNode startDate, SimpleNode endDate, String format) {
Function trunc = parserContext.getFunction("trunc");
AstParenthesis dateDifference = new AstParenthesis(DefaultParserContext.FUNC_MINUS.node(new AstCast(endDate, "DATE"), new AstCast(startDate, "DATE")));
PredefinedFunction opTimes = DefaultParserContext.FUNC_TIMES;
switch(format) {
case "SECOND":
return trunc.node(opTimes.node(dateDifference, AstNumericConstant.of(24 * 60 * 60)));
case "MINUTE":
return trunc.node(opTimes.node(dateDifference, AstNumericConstant.of(24 * 60)));
case "HOUR":
return trunc.node(opTimes.node(dateDifference, AstNumericConstant.of(24)));
case "DAY":
return trunc.node(dateDifference);
case "MONTH":
return MONTHS_BETWEEN.node(trunc.node(endDate, new AstStringConstant(format)), trunc.node(startDate, new AstStringConstant(format)));
case "YEAR":
PredefinedFunction opDivide = DefaultParserContext.FUNC_DIVIDE;
return parserContext.getFunction("floor").node(opDivide.node(MONTHS_BETWEEN.node(endDate, startDate), AstNumericConstant.of(12)));
default:
throw new IllegalStateException("Unsupported value for datepart in TIMESTAMPDIFF: " + format);
}
}
Aggregations