use of com.questdb.common.RecordMetadata 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.common.RecordMetadata in project questdb by bluestreak01.
the class QueryModel method createColumnNameHistogram0.
private static void createColumnNameHistogram0(CharSequenceIntHashMap histogram, QueryModel model, Factory factory, boolean ignoreJoins) throws ParserException {
ObjList<QueryModel> jm = model.getJoinModels();
int jmSize = ignoreJoins ? 0 : jm.size();
int n = model.getColumns().size();
if (n > 0) {
for (int i = 0; i < n; i++) {
QueryColumn qc = model.getColumns().getQuick(i);
switch(qc.getAst().type) {
case ExprNode.LITERAL:
histogram.increment(qc.getName());
break;
default:
break;
}
}
} else if (jmSize > 0) {
for (int i = 0; i < jmSize; i++) {
createColumnNameHistogram0(histogram, jm.getQuick(i), factory, true);
}
} else if (model.getJournalName() != null) {
RecordMetadata m = model.collectJournalMetadata(factory);
for (int i = 0, k = m.getColumnCount(); i < k; i++) {
histogram.increment(m.getColumnName(i));
}
} else {
createColumnNameHistogram0(histogram, model.getNestedModel(), factory, false);
}
}
use of com.questdb.common.RecordMetadata in project questdb by bluestreak01.
the class HashJoinRecordSource method toSink.
@Override
public void toSink(CharSink sink) {
sink.put('{');
sink.putQuoted("op").put(':').putQuoted("HashJoinRecordSource").put(',');
sink.putQuoted("master").put(':').put(master).put(',');
sink.putQuoted("slave").put(':').put(slave).put(',');
sink.putQuoted("joinOn").put(':').put('[');
sink.put('[');
RecordMetadata mm = master.getMetadata();
for (int i = 0, n = masterColIndex.size(); i < n; i++) {
if (i > 0) {
sink.put(',');
}
sink.putQuoted(mm.getColumnQuick(masterColIndex.getQuick(i)).getName());
}
sink.put(']').put(',');
sink.put('[');
RecordMetadata sm = slave.getMetadata();
for (int i = 0, n = slaveColIndex.size(); i < n; i++) {
if (i > 0) {
sink.put(',');
}
sink.putQuoted(sm.getColumnQuick(slaveColIndex.getQuick(i)).getName());
}
sink.put("]]}");
}
Aggregations