use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.
the class SqlLexerOptimiser method parseCreateTableCastDef.
private void parseCreateTableCastDef(CreateTableModel model) throws ParserException {
if (model.getQueryModel() == null) {
throw ParserException.$(lexer.position(), "cast is only supported in 'create table as ...' context");
}
expectTok('(');
ColumnCastModel columnCastModel = columnCastModelPool.next();
columnCastModel.setName(expectLiteral());
expectTok("as");
final ExprNode node = expectLiteral();
final int type = toColumnType(node.token);
columnCastModel.setType(type, node.position);
if (type == ColumnType.SYMBOL) {
if (Chars.equals(optTok(), "capacity")) {
columnCastModel.setSymbolCapacity(expectInt());
} else {
lexer.unparse();
columnCastModel.setSymbolCapacity(configuration.getCutlassSymbolCapacity());
}
}
expectTok(')');
if (!model.addColumnCastModel(columnCastModel)) {
throw ParserException.$(columnCastModel.getName().position, "duplicate cast");
}
}
use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.
the class SqlLexerOptimiser method optimiseJoins.
private void optimiseJoins(QueryModel model) throws ParserException {
ObjList<QueryModel> joinModels = model.getJoinModels();
int n = joinModels.size();
if (n > 1) {
emittedJoinClauses = joinClausesSwap1;
emittedJoinClauses.clear();
// for sake of clarity, "model" model is the first in the list of
// joinModels, e.g. joinModels.get(0) == model
// only model model is allowed to have "where" clause
// so we can assume that "where" clauses of joinModel elements are all null (except for element 0).
// in case one of joinModels is subquery, its entire query model will be set as
// nestedModel, e.g. "where" clause is still null there as well
ExprNode where = model.getWhereClause();
// clear where clause of model so that
// optimiser can assign there correct nodes
model.setWhereClause(null);
processJoinConditions(model, where);
for (int i = 1; i < n; i++) {
processJoinConditions(model, joinModels.getQuick(i).getJoinCriteria());
}
processEmittedJoinClauses(model);
createImpliedDependencies(model);
homogenizeCrossJoins(model);
reorderTables(model);
assignFilters(model);
alignJoinClauses(model);
addTransitiveFilters(model);
}
for (int i = 0; i < n; i++) {
QueryModel m = model.getJoinModels().getQuick(i).getNestedModel();
if (m != null) {
optimiseJoins(m);
}
}
}
use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.
the class SqlLexerOptimiser method optimiseBooleanNot.
private ExprNode optimiseBooleanNot(final ExprNode node, boolean reverse) throws ParserException {
switch(notOps.get(node.token)) {
case NOT_OP_NOT:
if (reverse) {
return optimiseBooleanNot(node.rhs, false);
} else {
switch(node.rhs.type) {
case ExprNode.LITERAL:
case ExprNode.CONSTANT:
return node;
default:
assertNotNull(node.rhs, node.position, "Missing right argument");
return optimiseBooleanNot(node.rhs, true);
}
}
case NOT_OP_AND:
if (reverse) {
node.token = "or";
}
assertNotNull(node.lhs, node.position, "Missing right argument");
assertNotNull(node.rhs, node.position, "Missing left argument");
node.lhs = optimiseBooleanNot(node.lhs, reverse);
node.rhs = optimiseBooleanNot(node.rhs, reverse);
return node;
case NOT_OP_OR:
if (reverse) {
node.token = "and";
}
assertNotNull(node.lhs, node.position, "Missing right argument");
assertNotNull(node.rhs, node.position, "Missing left argument");
node.lhs = optimiseBooleanNot(node.lhs, reverse);
node.rhs = optimiseBooleanNot(node.rhs, reverse);
return node;
case NOT_OP_GREATER:
if (reverse) {
node.token = "<=";
}
return node;
case NOT_OP_GREATER_EQ:
if (reverse) {
node.token = "<";
}
return node;
case NOT_OP_LESS:
if (reverse) {
node.token = ">=";
}
return node;
case NOT_OP_LESS_EQ:
if (reverse) {
node.token = ">";
}
return node;
case NOT_OP_EQUAL:
if (reverse) {
node.token = "!=";
}
return node;
case NOT_OP_NOT_EQ:
if (reverse) {
node.token = "=";
}
return node;
default:
if (reverse) {
ExprNode n = exprNodePool.next();
n.token = "not";
n.paramCount = 1;
n.rhs = node;
n.type = ExprNode.OPERATION;
return n;
}
return node;
}
}
use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.
the class SqlLexerOptimiser method alignJoinClauses.
/**
* Move fields that belong to slave table to left and parent fields
* to right of equals operator.
*/
private void alignJoinClauses(QueryModel parent) {
ObjList<QueryModel> joinModels = parent.getJoinModels();
for (int i = 0, n = joinModels.size(); i < n; i++) {
JoinContext jc = joinModels.getQuick(i).getContext();
if (jc != null) {
int index = jc.slaveIndex;
for (int k = 0, kc = jc.aIndexes.size(); k < kc; k++) {
if (jc.aIndexes.getQuick(k) != index) {
int idx = jc.aIndexes.getQuick(k);
CharSequence name = jc.aNames.getQuick(k);
ExprNode node = jc.aNodes.getQuick(k);
jc.aIndexes.setQuick(k, jc.bIndexes.getQuick(k));
jc.aNames.setQuick(k, jc.bNames.getQuick(k));
jc.aNodes.setQuick(k, jc.bNodes.getQuick(k));
jc.bIndexes.setQuick(k, idx);
jc.bNames.setQuick(k, name);
jc.bNodes.setQuick(k, node);
}
}
}
}
}
use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.
the class SqlLexerOptimiser method emitLiterals.
private void emitLiterals(@Transient ExprNode node, QueryModel translatingModel, QueryModel innerModel, QueryModel validatingModel) throws ParserException {
this.exprNodeStack.clear();
while (!this.exprNodeStack.isEmpty() || node != null) {
if (node != null) {
if (node.rhs != null) {
ExprNode n = replaceLiteral(node.rhs, translatingModel, innerModel, validatingModel);
if (node.rhs == n) {
this.exprNodeStack.push(node.rhs);
} else {
node.rhs = n;
}
}
ExprNode n = replaceLiteral(node.lhs, translatingModel, innerModel, validatingModel);
if (n == node.lhs) {
node = node.lhs;
} else {
node.lhs = n;
node = null;
}
} else {
node = this.exprNodeStack.poll();
}
}
}
Aggregations