Search in sources :

Example 16 with RecordColumnMetadata

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;
}
Also used : RecordColumnMetadata(com.questdb.common.RecordColumnMetadata) FlyweightCharSequence(com.questdb.std.str.FlyweightCharSequence)

Example 17 with RecordColumnMetadata

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;
}
Also used : RecordColumnMetadata(com.questdb.common.RecordColumnMetadata) FlyweightCharSequence(com.questdb.std.str.FlyweightCharSequence)

Aggregations

RecordColumnMetadata (com.questdb.common.RecordColumnMetadata)17 FlyweightCharSequence (com.questdb.std.str.FlyweightCharSequence)4 Path (com.questdb.std.str.Path)3 StringSink (com.questdb.std.str.StringSink)3 ColumnMetadata (com.questdb.store.factory.configuration.ColumnMetadata)3 ResponseContentBufferTooSmallException (com.questdb.ex.ResponseContentBufferTooSmallException)2 ChunkedResponse (com.questdb.net.http.ChunkedResponse)2 ExprNode (com.questdb.griffin.common.ExprNode)1 ImportedColumnMetadata (com.questdb.parser.ImportedColumnMetadata)1 ExprNode (com.questdb.parser.sql.model.ExprNode)1 JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)1