use of io.questdb.griffin.model.ExpressionNode in project questdb by bluestreak01.
the class SampleByTest method testSampleByFirstLastRecordCursorFactoryInvalidNotFirstLast.
@Test
public void testSampleByFirstLastRecordCursorFactoryInvalidNotFirstLast() {
try {
GenericRecordMetadata groupByMeta = new GenericRecordMetadata();
TableColumnMetadata column = new TableColumnMetadata("col1", 1, ColumnType.LONG, false, 0, false, null);
groupByMeta.add(column);
GenericRecordMetadata meta = new GenericRecordMetadata();
meta.add(column);
ObjList<QueryColumn> columns = new ObjList<>();
ExpressionNode first = ExpressionNode.FACTORY.newInstance().of(ColumnType.LONG, "min", 0, 0);
first.rhs = ExpressionNode.FACTORY.newInstance().of(ColumnType.LONG, "col1", 0, 0);
QueryColumn col = QueryColumn.FACTORY.newInstance().of("col1", first);
columns.add(col);
new SampleByFirstLastRecordCursorFactory(null, new MicroTimestampSampler(100L), groupByMeta, columns, meta, null, 0, null, 0, 0, getSymbolFilter(), -1);
Assert.fail();
} catch (SqlException e) {
TestUtils.assertContains(e.getFlyweightMessage(), "expected first() or last() functions but got min");
}
}
use of io.questdb.griffin.model.ExpressionNode in project questdb by bluestreak01.
the class SampleByTest method testSampleByFirstLastRecordCursorFactoryInvalidColumns.
@Test
public void testSampleByFirstLastRecordCursorFactoryInvalidColumns() {
try {
GenericRecordMetadata groupByMeta = new GenericRecordMetadata();
groupByMeta.add(new TableColumnMetadata("col1", 1, ColumnType.STRING, false, 0, false, null));
GenericRecordMetadata meta = new GenericRecordMetadata();
meta.add(new TableColumnMetadata("col1", 2, ColumnType.LONG, false, 0, false, null));
ObjList<QueryColumn> columns = new ObjList<>();
ExpressionNode first = ExpressionNode.FACTORY.newInstance().of(ColumnType.LONG, "first", 0, 0);
first.rhs = ExpressionNode.FACTORY.newInstance().of(ColumnType.LONG, "col1", 0, 0);
QueryColumn col = QueryColumn.FACTORY.newInstance().of("col1", first);
columns.add(col);
new SampleByFirstLastRecordCursorFactory(null, new MicroTimestampSampler(100L), groupByMeta, columns, meta, null, 0, null, 0, 0, getSymbolFilter(), -1);
Assert.fail();
} catch (SqlException e) {
TestUtils.assertContains(e.getFlyweightMessage(), "first(), last() is not supported on data type");
}
}
use of io.questdb.griffin.model.ExpressionNode in project questdb by bluestreak01.
the class WhereClauseParser method analyzeBetween.
private boolean analyzeBetween(AliasTranslator translator, IntrinsicModel model, ExpressionNode node, RecordMetadata m, FunctionParser functionParser, RecordMetadata metadata, SqlExecutionContext executionContext) throws SqlException {
ExpressionNode col = node.args.getLast();
if (col.type != ExpressionNode.LITERAL) {
return false;
}
CharSequence column = translator.translateAlias(col.token);
if (m.getColumnIndexQuiet(column) == -1) {
throw SqlException.invalidColumn(col.position, col.token);
}
return analyzeBetween0(model, col, node, false, functionParser, metadata, executionContext);
}
use of io.questdb.griffin.model.ExpressionNode in project questdb by bluestreak01.
the class WhereClauseParser method analyzeNotBetween.
private boolean analyzeNotBetween(AliasTranslator translator, IntrinsicModel model, ExpressionNode notNode, RecordMetadata m, FunctionParser functionParser, RecordMetadata metadata, SqlExecutionContext executionContext) throws SqlException {
ExpressionNode node = notNode.rhs;
ExpressionNode col = node.args.getLast();
if (col.type != ExpressionNode.LITERAL) {
return false;
}
CharSequence column = translator.translateAlias(col.token);
if (m.getColumnIndexQuiet(column) == -1) {
throw SqlException.invalidColumn(col.position, col.token);
}
boolean ok = analyzeBetween0(model, col, node, true, functionParser, metadata, executionContext);
if (ok) {
notNode.intrinsicValue = IntrinsicModel.TRUE;
} else {
analyzeNotListOfValues(model, column, m, node, notNode);
}
return ok;
}
use of io.questdb.griffin.model.ExpressionNode in project questdb by bluestreak01.
the class WhereClauseParser method analyzeListOfValues.
private boolean analyzeListOfValues(IntrinsicModel model, CharSequence columnName, RecordMetadata meta, ExpressionNode node) {
final int columnIndex = meta.getColumnIndex(columnName);
boolean newColumn = true;
boolean preferred = Chars.equalsIgnoreCaseNc(preferredKeyColumn, columnName);
if (preferred || (preferredKeyColumn == null && meta.isColumnIndexed(columnIndex))) {
//
if (model.keyColumn != null && (newColumn = !Chars.equals(model.keyColumn, columnName)) && meta.getIndexValueBlockCapacity(columnIndex) <= meta.getIndexValueBlockCapacity(model.keyColumn)) {
return false;
}
int i = node.paramCount - 1;
tempKeys.clear();
tempPos.clear();
// if any of values is not an indexed constant - bail out
if (i == 1) {
if (node.rhs == null || (node.rhs.type != ExpressionNode.CONSTANT && node.rhs.type != ExpressionNode.BIND_VARIABLE)) {
return false;
}
if (tempKeys.add(unquote(node.rhs.token))) {
tempPos.add(node.position);
}
} else {
for (i--; i > -1; i--) {
ExpressionNode c = node.args.getQuick(i);
if (c.type != ExpressionNode.CONSTANT && c.type != ExpressionNode.BIND_VARIABLE) {
return false;
}
if (isNullKeyword(c.token)) {
if (tempKeys.add(null)) {
tempPos.add(c.position);
}
} else {
if (tempKeys.add(unquote(c.token))) {
tempPos.add(c.position);
}
}
}
}
// and reset intrinsic values on nodes associated with old column
if (newColumn) {
model.keyValues.clear();
model.keyValuePositions.clear();
model.keyValues.addAll(tempKeys);
model.keyValuePositions.addAll(tempPos);
return revertProcessedNodes(keyNodes, model, columnName, node);
} else {
if (model.keyValues.size() == 0) {
model.keyValues.addAll(tempKeys);
model.keyValuePositions.addAll(tempPos);
}
}
if (model.keySubQuery == null) {
// calculate overlap of values
replaceAllWithOverlap(model, true);
keyNodes.add(node);
node.intrinsicValue = IntrinsicModel.TRUE;
return true;
}
}
return false;
}
Aggregations