Search in sources :

Example 26 with ExprNode

use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.

the class SqlLexerOptimiser method parseRenameStatement.

private ParsedModel parseRenameStatement() throws ParserException {
    expectTok("table");
    RenameTableModel model = renameTableModelPool.next();
    ExprNode e = expectExpr();
    if (e.type != ExprNode.LITERAL && e.type != ExprNode.CONSTANT) {
        throw ParserException.$(e.position, "literal or constant expected");
    }
    model.setFrom(e);
    expectTok("to");
    e = expectExpr();
    if (e.type != ExprNode.LITERAL && e.type != ExprNode.CONSTANT) {
        throw ParserException.$(e.position, "literal or constant expected");
    }
    model.setTo(e);
    return model;
}
Also used : ExprNode(com.questdb.griffin.common.ExprNode)

Example 27 with ExprNode

use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.

the class SqlLexerOptimiser method emitAggregates.

private void emitAggregates(@Transient ExprNode node, QueryModel model) {
    this.exprNodeStack.clear();
    while (!this.exprNodeStack.isEmpty() || node != null) {
        if (node != null) {
            if (node.rhs != null) {
                ExprNode n = replaceIfAggregate(node.rhs, model);
                if (node.rhs == n) {
                    this.exprNodeStack.push(node.rhs);
                } else {
                    node.rhs = n;
                }
            }
            ExprNode n = replaceIfAggregate(node.lhs, model);
            if (n == node.lhs) {
                node = node.lhs;
            } else {
                node.lhs = n;
                node = null;
            }
        } else {
            node = this.exprNodeStack.poll();
        }
    }
}
Also used : ExprNode(com.questdb.griffin.common.ExprNode)

Example 28 with ExprNode

use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.

the class SqlLexerOptimiser method mergeContexts.

private JoinContext mergeContexts(QueryModel parent, JoinContext a, JoinContext b) {
    assert a.slaveIndex == b.slaveIndex;
    deletedContexts.clear();
    JoinContext r = contextPool.next();
    // or a.x = b.x to a.x = b.y, e.g. one of columns in the same
    for (int i = 0, n = b.aNames.size(); i < n; i++) {
        CharSequence ban = b.aNames.getQuick(i);
        int bai = b.aIndexes.getQuick(i);
        ExprNode bao = b.aNodes.getQuick(i);
        CharSequence bbn = b.bNames.getQuick(i);
        int bbi = b.bIndexes.getQuick(i);
        ExprNode bbo = b.bNodes.getQuick(i);
        for (int k = 0, z = a.aNames.size(); k < z; k++) {
            // don't seem to be adding indexes outside of main loop
            // if (deletedContexts.contains(k)) {
            // continue;
            // }
            final CharSequence aan = a.aNames.getQuick(k);
            final int aai = a.aIndexes.getQuick(k);
            final ExprNode aao = a.aNodes.getQuick(k);
            final CharSequence abn = a.bNames.getQuick(k);
            final int abi = a.bIndexes.getQuick(k);
            final ExprNode abo = a.bNodes.getQuick(k);
            if (aai == bai && Chars.equals(aan, ban)) {
                // a.x = ?.x
                // |     ?
                // a.x = ?.y
                addFilterOrEmitJoin(parent, k, abi, abn, abo, bbi, bbn, bbo);
                break;
            } else if (abi == bai && Chars.equals(abn, ban)) {
                // a.y = b.x
                // /
                // b.x = a.x
                addFilterOrEmitJoin(parent, k, aai, aan, aao, bbi, bbn, bbo);
                break;
            } else if (aai == bbi && Chars.equals(aan, bbn)) {
                // a.x = b.x
                // \
                // b.y = a.x
                addFilterOrEmitJoin(parent, k, abi, abn, abo, bai, ban, bao);
                break;
            } else if (abi == bbi && Chars.equals(abn, bbn)) {
                // a.x = b.x
                // |
                // a.y = b.x
                addFilterOrEmitJoin(parent, k, aai, aan, aao, bai, ban, bao);
                break;
            }
        }
        r.aIndexes.add(bai);
        r.aNames.add(ban);
        r.aNodes.add(bao);
        r.bIndexes.add(bbi);
        r.bNames.add(bbn);
        r.bNodes.add(bbo);
        int max = bai > bbi ? bai : bbi;
        int min = bai < bbi ? bai : bbi;
        r.slaveIndex = max;
        r.parents.add(min);
        linkDependencies(parent, min, max);
    }
    // add remaining a nodes
    for (int i = 0, n = a.aNames.size(); i < n; i++) {
        int aai, abi, min, max;
        aai = a.aIndexes.getQuick(i);
        abi = a.bIndexes.getQuick(i);
        if (aai < abi) {
            min = aai;
            max = abi;
        } else {
            min = abi;
            max = aai;
        }
        if (deletedContexts.contains(i)) {
            if (r.parents.excludes(min)) {
                unlinkDependencies(parent, min, max);
            }
        } else {
            r.aNames.add(a.aNames.getQuick(i));
            r.bNames.add(a.bNames.getQuick(i));
            r.aIndexes.add(aai);
            r.bIndexes.add(abi);
            r.aNodes.add(a.aNodes.getQuick(i));
            r.bNodes.add(a.bNodes.getQuick(i));
            r.parents.add(min);
            linkDependencies(parent, min, max);
        }
    }
    return r;
}
Also used : ExprNode(com.questdb.griffin.common.ExprNode) FlyweightCharSequence(com.questdb.std.str.FlyweightCharSequence)

Example 29 with ExprNode

use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.

the class SqlLexerOptimiser method parseSelectFrom.

private void parseSelectFrom(QueryModel model, CharSequence name, QueryModel masterModel) throws ParserException {
    final ExprNode literal = literal(name);
    final WithClauseModel withClause = masterModel.getWithClause(name);
    if (withClause != null) {
        model.setNestedModel(parseWith(withClause));
        model.setAlias(literal);
    } else {
        model.setTableName(literal);
    }
}
Also used : ExprNode(com.questdb.griffin.common.ExprNode)

Example 30 with ExprNode

use of com.questdb.griffin.common.ExprNode in project questdb by bluestreak01.

the class SqlLexerOptimiser method processJoinConditions.

/**
 * Splits "where" clauses into "and" concatenated list of boolean expressions.
 *
 * @param node expression n
 */
private void processJoinConditions(QueryModel parent, ExprNode node) throws ParserException {
    ExprNode n = node;
    // pre-order traversal
    exprNodeStack.clear();
    while (!exprNodeStack.isEmpty() || n != null) {
        if (n != null) {
            switch(joinOps.get(n.token)) {
                case JOIN_OP_EQUAL:
                    analyseEquals(parent, n);
                    n = null;
                    break;
                case JOIN_OP_AND:
                    if (n.rhs != null) {
                        exprNodeStack.push(n.rhs);
                    }
                    n = n.lhs;
                    break;
                case JOIN_OP_OR:
                    processOrConditions(parent, n);
                    n = null;
                    break;
                case JOIN_OP_REGEX:
                    analyseRegex(parent, n);
                // intentional fallthrough
                default:
                    parent.addParsedWhereNode(n);
                    n = null;
                    break;
            }
        } else {
            n = exprNodeStack.poll();
        }
    }
}
Also used : ExprNode(com.questdb.griffin.common.ExprNode)

Aggregations

ExprNode (com.questdb.griffin.common.ExprNode)40 FlyweightCharSequence (com.questdb.std.str.FlyweightCharSequence)14 NumericException (com.questdb.common.NumericException)2 CairoException (com.questdb.cairo.CairoException)1 TableReader (com.questdb.cairo.TableReader)1 EntryLockedException (com.questdb.cairo.pool.ex.EntryLockedException)1 RecordColumnMetadata (com.questdb.common.RecordColumnMetadata)1 RecordMetadata (com.questdb.common.RecordMetadata)1 IntrinsicModel (com.questdb.griffin.lexer.model.IntrinsicModel)1 NotNull (org.jetbrains.annotations.NotNull)1