Search in sources :

Example 21 with ExpressionNode

use of io.questdb.griffin.model.ExpressionNode in project questdb by bluestreak01.

the class WhereClauseParser method analyzeNotListOfValues.

private void analyzeNotListOfValues(IntrinsicModel model, CharSequence columnName, RecordMetadata meta, ExpressionNode node, ExpressionNode notNode) {
    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;
        }
        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) {
                return;
            }
            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) {
                    return;
                }
                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.keyExcludedValues.clear();
            model.keyExcludedValuePositions.clear();
            model.keyExcludedValues.addAll(tempKeys);
            model.keyExcludedValuePositions.addAll(tempPos);
            revertProcessedNodes(keyExclNodes, model, columnName, notNode);
            return;
        } else {
            if (model.keyExcludedValues.size() == 0) {
                model.keyExcludedValues.addAll(tempKeys);
                model.keyExcludedValuePositions.addAll(tempPos);
            }
        }
        if (model.keySubQuery == null) {
            // calculate overlap of values
            replaceAllWithOverlap(model, false);
            keyExclNodes.add(notNode);
            notNode.intrinsicValue = IntrinsicModel.TRUE;
        }
    }
}
Also used : ExpressionNode(io.questdb.griffin.model.ExpressionNode)

Example 22 with ExpressionNode

use of io.questdb.griffin.model.ExpressionNode in project questdb by bluestreak01.

the class WhereClauseParser method analyzeIn.

private boolean analyzeIn(AliasTranslator translator, IntrinsicModel model, ExpressionNode node, RecordMetadata metadata, FunctionParser functionParser, SqlExecutionContext executionContext) throws SqlException {
    if (node.paramCount < 2) {
        throw SqlException.$(node.position, "Too few arguments for 'in'");
    }
    ExpressionNode col = node.paramCount < 3 ? node.lhs : node.args.getLast();
    if (col.type != ExpressionNode.LITERAL) {
        return false;
    }
    CharSequence column = translator.translateAlias(col.token);
    if (metadata.getColumnIndexQuiet(column) == -1) {
        throw SqlException.invalidColumn(col.position, col.token);
    }
    return analyzeInInterval(model, col, node, false, functionParser, metadata, executionContext) || analyzeListOfValues(model, column, metadata, node) || analyzeInLambda(model, column, metadata, node);
}
Also used : ExpressionNode(io.questdb.griffin.model.ExpressionNode) FlyweightCharSequence(io.questdb.std.str.FlyweightCharSequence)

Aggregations

ExpressionNode (io.questdb.griffin.model.ExpressionNode)22 QueryColumn (io.questdb.griffin.model.QueryColumn)6 FlyweightCharSequence (io.questdb.std.str.FlyweightCharSequence)6 Function (io.questdb.cairo.sql.Function)4 GroupByFunction (io.questdb.griffin.engine.functions.GroupByFunction)3 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)2 SqlException (io.questdb.griffin.SqlException)2 SymbolFunction (io.questdb.griffin.engine.functions.SymbolFunction)2 ObjList (io.questdb.std.ObjList)2 Test (org.junit.Test)2 AbstractGeoHashFunction (io.questdb.griffin.engine.functions.AbstractGeoHashFunction)1 IntrinsicModel (io.questdb.griffin.model.IntrinsicModel)1 QueryModel (io.questdb.griffin.model.QueryModel)1 NotNull (org.jetbrains.annotations.NotNull)1