use of com.questdb.common.RecordColumnMetadata in project questdb by bluestreak01.
the class QueryFilterAnalyser method analyzeEquals0.
private boolean analyzeEquals0(AliasTranslator translator, IntrinsicModel model, ExprNode node, ExprNode a, ExprNode b, RecordMetadata m) throws ParserException {
if (Chars.equals(a.token, b.token)) {
node.intrinsicValue = IntrinsicValue.TRUE;
return true;
}
if (a.type == ExprNode.LITERAL && b.type == ExprNode.CONSTANT) {
if (isTimestamp(a)) {
model.intersectIntervals(b.token, 1, b.token.length() - 1, b.position);
node.intrinsicValue = IntrinsicValue.TRUE;
return true;
} else {
CharSequence column = translator.translateAlias(a.token);
int index = m.getColumnIndexQuiet(column);
if (index == -1) {
throw ParserException.invalidColumn(a.position, a.token);
}
RecordColumnMetadata meta = m.getColumnQuick(index);
switch(meta.getType()) {
case ColumnType.SYMBOL:
case ColumnType.STRING:
case ColumnType.LONG:
case ColumnType.INT:
if (meta.isIndexed()) {
// check if we are limited by preferred column
if (preferredKeyColumn != null && !Chars.equals(preferredKeyColumn, column)) {
return false;
}
boolean newColumn = true;
// check if we already have indexed column and it is of worse selectivity
if (model.keyColumn != null && (newColumn = !Chars.equals(model.keyColumn, column)) && meta.getBucketCount() <= m.getColumn(model.keyColumn).getBucketCount()) {
return false;
}
CharSequence value = Chars.equals("null", b.token) ? null : unquote(b.token);
if (newColumn) {
model.keyColumn = column;
model.keyValues.clear();
model.keyValuePositions.clear();
model.keyValues.add(value);
model.keyValuePositions.add(b.position);
for (int n = 0, k = keyNodes.size(); n < k; n++) {
keyNodes.getQuick(n).intrinsicValue = IntrinsicValue.UNDEFINED;
}
keyNodes.clear();
} else {
// otherwise invalidate entire model
if (model.keyValues.contains(value)) {
model.keyValues.clear();
model.keyValuePositions.clear();
model.keyValues.add(value);
model.keyValuePositions.add(b.position);
} else {
model.intrinsicValue = IntrinsicValue.FALSE;
return false;
}
}
keyNodes.add(node);
node.intrinsicValue = IntrinsicValue.TRUE;
return true;
}
// fall through
default:
return false;
}
}
}
return false;
}
use of com.questdb.common.RecordColumnMetadata in project questdb by bluestreak01.
the class QueryFilterAnalyser method analyzeNotEquals0.
private boolean analyzeNotEquals0(AliasTranslator translator, IntrinsicModel model, ExprNode node, ExprNode a, ExprNode b, RecordMetadata m) throws ParserException {
if (Chars.equals(a.token, b.token)) {
model.intrinsicValue = IntrinsicValue.FALSE;
return true;
}
if (a.type == ExprNode.LITERAL && b.type == ExprNode.CONSTANT) {
if (isTimestamp(a)) {
model.subtractIntervals(b.token, 1, b.token.length() - 1, b.position);
node.intrinsicValue = IntrinsicValue.TRUE;
return true;
} else {
CharSequence column = translator.translateAlias(a.token);
int index = m.getColumnIndexQuiet(column);
if (index == -1) {
throw ParserException.invalidColumn(a.position, a.token);
}
RecordColumnMetadata meta = m.getColumnQuick(index);
switch(meta.getType()) {
case ColumnType.SYMBOL:
case ColumnType.STRING:
case ColumnType.LONG:
case ColumnType.INT:
if (meta.isIndexed()) {
// check if we are limited by preferred column
if (preferredKeyColumn != null && !Chars.equals(preferredKeyColumn, column)) {
return false;
}
keyExclNodes.add(node);
return false;
}
break;
default:
break;
}
}
}
return false;
}
Aggregations