use of com.questdb.parser.sql.model.ExprNode in project questdb by bluestreak01.
the class PostOrderTreeTraversalAlgo method traverse.
void traverse(ExprNode node, Visitor visitor) throws ParserException {
// post-order iterative tree traversal
// see http://en.wikipedia.org/wiki/Tree_traversal
stack.clear();
indexStack.clear();
ExprNode lastVisited = null;
while (!stack.isEmpty() || node != null) {
if (node != null) {
stack.push(node);
indexStack.push(0);
node = node.rhs;
} else {
ExprNode peek = stack.peek();
if (peek.paramCount < 3) {
if (peek.lhs != null && lastVisited != peek.lhs) {
node = peek.lhs;
} else {
visitor.visit(peek);
lastVisited = stack.poll();
indexStack.pop();
}
} else {
int index = indexStack.peek();
if (index < peek.paramCount) {
node = peek.args.getQuick(index);
indexStack.update(index + 1);
} else {
visitor.visit(peek);
lastVisited = stack.poll();
indexStack.pop();
}
}
}
}
}
use of com.questdb.parser.sql.model.ExprNode in project questdb by bluestreak01.
the class QueryFilterAnalyser method analyzeNotInInterval.
private boolean analyzeNotInInterval(IntrinsicModel model, ExprNode col, ExprNode in) throws ParserException {
if (!isTimestamp(col)) {
return false;
}
if (in.paramCount > 3) {
throw QueryError.$(in.args.getQuick(0).position, "Too many args");
}
if (in.paramCount < 3) {
throw QueryError.$(in.position, "Too few args");
}
ExprNode lo = in.args.getQuick(1);
ExprNode hi = in.args.getQuick(0);
if (lo.type == ExprNode.CONSTANT && hi.type == ExprNode.CONSTANT) {
long loMillis;
long hiMillis;
try {
loMillis = DateFormatUtils.tryParse(quoteEraser.ofQuoted(lo.token));
} catch (NumericException ignore) {
throw QueryError.$(lo.position, "Unknown date format");
}
try {
hiMillis = DateFormatUtils.tryParse(quoteEraser.ofQuoted(hi.token));
} catch (NumericException ignore) {
throw QueryError.$(hi.position, "Unknown date format");
}
model.subtractIntervals(loMillis, hiMillis);
in.intrinsicValue = IntrinsicValue.TRUE;
return true;
}
return false;
}
use of com.questdb.parser.sql.model.ExprNode in project questdb by bluestreak01.
the class QueryFilterAnalyser method extract.
IntrinsicModel extract(AliasTranslator translator, ExprNode node, RecordMetadata m, String preferredKeyColumn, int timestampIndex) throws ParserException {
this.stack.clear();
this.keyNodes.clear();
this.timestamp = timestampIndex < 0 ? null : m.getColumnName(timestampIndex);
this.preferredKeyColumn = preferredKeyColumn;
IntrinsicModel model = models.next();
if (removeAndIntrinsics(translator, model, node, m)) {
return model;
}
ExprNode root = node;
while (!stack.isEmpty() || node != null) {
if (node != null) {
switch(node.token) {
case "and":
if (!removeAndIntrinsics(translator, model, node.rhs, m)) {
stack.push(node.rhs);
}
node = removeAndIntrinsics(translator, model, node.lhs, m) ? null : node.lhs;
break;
default:
node = stack.poll();
break;
}
} else {
node = stack.poll();
}
}
applyKeyExclusions(translator, model);
model.filter = collapseIntrinsicNodes(root);
return model;
}
use of com.questdb.parser.sql.model.ExprNode in project questdb by bluestreak01.
the class QueryFilterAnalyser method analyzeInInterval.
private boolean analyzeInInterval(IntrinsicModel model, ExprNode col, ExprNode in) throws ParserException {
if (!isTimestamp(col)) {
return false;
}
if (in.paramCount > 3) {
throw QueryError.$(in.args.getQuick(0).position, "Too many args");
}
if (in.paramCount < 3) {
throw QueryError.$(in.position, "Too few args");
}
ExprNode lo = in.args.getQuick(1);
ExprNode hi = in.args.getQuick(0);
if (lo.type == ExprNode.CONSTANT && hi.type == ExprNode.CONSTANT) {
long loMillis;
long hiMillis;
try {
loMillis = DateFormatUtils.tryParse(quoteEraser.ofQuoted(lo.token));
} catch (NumericException ignore) {
throw QueryError.$(lo.position, "Unknown date format");
}
try {
hiMillis = DateFormatUtils.tryParse(quoteEraser.ofQuoted(hi.token));
} catch (NumericException ignore) {
throw QueryError.$(hi.position, "Unknown date format");
}
model.intersectIntervals(loMillis, hiMillis);
in.intrinsicValue = IntrinsicValue.TRUE;
return true;
}
return false;
}
Aggregations