use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.
the class SqlLexerOptimiser method enumerateTableColumns.
public void enumerateTableColumns(QueryModel model) throws ParserException {
final ObjList<QueryModel> jm = model.getJoinModels();
// deal with _this_ model first, it will always be the first element in join model list
if (model.getTableName() != null) {
RecordMetadata m = model.getTableMetadata(engine, tableLookupSequence);
// todo: test that this is the case
for (int i = 0, k = m.getColumnCount(); i < k; i++) {
model.addField(createColumnAlias(m.getColumnName(i), model));
}
// validate explicitly defined timestamp, if it exists
ExprNode timestamp = model.getTimestamp();
if (timestamp == null) {
if (m.getTimestampIndex() != -1) {
model.setTimestamp(exprNodePool.next().of(ExprNode.LITERAL, m.getColumnQuick(m.getTimestampIndex()).getName(), 0, 0));
}
} else {
int index = m.getColumnIndexQuiet(timestamp.token);
if (index == -1) {
throw ParserException.invalidColumn(timestamp.position, timestamp.token);
} else if (m.getColumnQuick(index).getType() != ColumnType.TIMESTAMP) {
throw ParserException.$(timestamp.position, "not a TIMESTAMP");
}
}
} else {
if (model.getNestedModel() != null) {
enumerateTableColumns(model.getNestedModel());
// copy columns of nested model onto parent one
// we must treat sub-query just like we do a table
model.copyColumnsFrom(model.getNestedModel());
}
}
for (int i = 1, n = jm.size(); i < n; i++) {
enumerateTableColumns(jm.getQuick(i));
}
}
use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.
the class SqlLexerOptimiser method parseCreateTable.
private ParsedModel parseCreateTable() throws ParserException {
final CreateTableModel model = createTableModelPool.next();
model.setName(nextLiteral(lexer.unquote(tok("table name")), lexer.position()));
CharSequence tok = tok("'(' or 'as'");
if (Chars.equals(tok, '(')) {
lexer.unparse();
parseCreateTableColumns(model);
} else if (Chars.equals(tok, "as")) {
parseCreateTableAsSelect(model);
} else {
throw errUnexpected(tok);
}
while ((tok = optTok()) != null && Chars.equals(tok, ',')) {
tok = tok("'index' or 'cast'");
if (Chars.equals(tok, "index")) {
parseCreateTableIndexDef(model);
} else if (Chars.equals(tok, "cast")) {
parseCreateTableCastDef(model);
} else {
throw errUnexpected(tok);
}
}
ExprNode timestamp = parseTimestamp(tok);
if (timestamp != null) {
// ignore index, validate column
getCreateTableColumnIndex(model, timestamp.token, timestamp.position);
model.setTimestamp(timestamp);
tok = optTok();
}
ExprNode partitionBy = parseCreateTablePartition(tok);
if (partitionBy != null) {
if (PartitionBy.fromString(partitionBy.token) == -1) {
throw ParserException.$(partitionBy.position, "'NONE', 'DAY', 'MONTH' or 'YEAR' expected");
}
model.setPartitionBy(partitionBy);
tok = optTok();
}
if (tok != null) {
throw errUnexpected(tok);
}
return model;
}
use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.
the class SqlLexerOptimiser method setAndGetModelAlias.
private CharSequence setAndGetModelAlias(QueryModel model) {
CharSequence name = model.getName();
if (name != null) {
return name;
}
ExprNode alias = makeJoinAlias(defaultAliasCount++);
model.setAlias(alias);
return alias.token;
}
use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.
the class QueryModel method parseWhereClause.
/*
* Splits "where" clauses into "and" chunks
*/
public ObjList<ExprNode> parseWhereClause() {
ExprNode n = getWhereClause();
// pre-order traversal
exprNodeStack.clear();
while (!exprNodeStack.isEmpty() || n != null) {
if (n != null) {
if (Chars.equals("and", n.token)) {
if (n.rhs != null) {
exprNodeStack.push(n.rhs);
}
n = n.lhs;
} else {
addParsedWhereNode(n);
n = null;
}
} else {
n = exprNodeStack.poll();
}
}
return getParsedWhere();
}
use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.
the class QueryModel method addColumn.
public void addColumn(QueryColumn column) {
columns.add(column);
final CharSequence alias = column.getAlias();
final ExprNode ast = column.getAst();
assert alias != null;
aliasToColumnMap.put(alias, ast.token);
columnToAliasMap.put(ast.token, alias);
columnNameTypeMap.put(alias, ast.type);
}
Aggregations