Search in sources :

Example 21 with Expression

use of com.wplatform.ddal.command.expression.Expression in project jdbc-shards by wplatform.

the class Select method addGlobalCondition.

@Override
public void addGlobalCondition(Parameter param, int columnId, int comparisonType) {
    addParameter(param);
    Expression comp;
    Expression col = expressions.get(columnId);
    col = col.getNonAliasExpression();
    if (col.isEverything(ExpressionVisitor.QUERY_COMPARABLE_VISITOR)) {
        comp = new Comparison(session, comparisonType, col, param);
    } else {
        // this condition will always evaluate to true, but need to
        // add the parameter, so it can be set later
        comp = new Comparison(session, Comparison.EQUAL_NULL_SAFE, param, param);
    }
    comp = comp.optimize(session);
    boolean addToCondition = true;
    if (isGroupQuery) {
        addToCondition = false;
        for (int i = 0; groupIndex != null && i < groupIndex.length; i++) {
            if (groupIndex[i] == columnId) {
                addToCondition = true;
                break;
            }
        }
        if (!addToCondition) {
            if (havingIndex >= 0) {
                having = expressions.get(havingIndex);
            }
            if (having == null) {
                having = comp;
            } else {
                having = new ConditionAndOr(ConditionAndOr.AND, having, comp);
            }
        }
    }
    if (addToCondition) {
        if (condition == null) {
            condition = comp;
        } else {
            condition = new ConditionAndOr(ConditionAndOr.AND, condition, comp);
        }
    }
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression) Comparison(com.wplatform.ddal.command.expression.Comparison) ConditionAndOr(com.wplatform.ddal.command.expression.ConditionAndOr)

Example 22 with Expression

use of com.wplatform.ddal.command.expression.Expression in project jdbc-shards by wplatform.

the class Select method setEvaluatableRecursive.

private void setEvaluatableRecursive(TableFilter f) {
    for (; f != null; f = f.getJoin()) {
        f.setEvaluatable(f, true);
        if (condition != null) {
            condition.setEvaluatable(f, true);
        }
        TableFilter n = f.getNestedJoin();
        if (n != null) {
            setEvaluatableRecursive(n);
        }
        Expression on = f.getJoinCondition();
        if (on != null) {
            if (!on.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR)) {
                if (session.getDatabase().getSettings().nestedJoins) {
                    // need to check that all added are bound to a table
                    on = on.optimize(session);
                    if (!f.isJoinOuter() && !f.isJoinOuterIndirect()) {
                        f.removeJoinCondition();
                        addCondition(on);
                    }
                } else {
                    if (f.isJoinOuter()) {
                        // this will check if all columns exist - it may or
                        // may not throw an exception
                        on = on.optimize(session);
                        // it is not supported even if the columns exist
                        throw DbException.get(ErrorCode.UNSUPPORTED_OUTER_JOIN_CONDITION_1, on.getSQL());
                    }
                    f.removeJoinCondition();
                    // need to check that all added are bound to a table
                    on = on.optimize(session);
                    addCondition(on);
                }
            }
        }
        on = f.getFilterCondition();
        if (on != null) {
            if (!on.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR)) {
                f.removeFilterCondition();
                addCondition(on);
            }
        }
        // the result columns are evaluatable
        for (Expression e : expressions) {
            e.setEvaluatable(f, true);
        }
    }
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression)

Example 23 with Expression

use of com.wplatform.ddal.command.expression.Expression in project jdbc-shards by wplatform.

the class Update method prepare.

@Override
public void prepare() {
    if (condition != null) {
        condition.mapColumns(tableFilter, 0);
        condition = condition.optimize(session);
        condition.createIndexConditions(session, tableFilter);
    }
    for (int i = 0, size = columns.size(); i < size; i++) {
        Column c = columns.get(i);
        Expression e = expressionMap.get(c);
        e.mapColumns(tableFilter, 0);
        expressionMap.put(c, e.optimize(session));
    }
    PlanItem item = tableFilter.getBestPlanItem(session, 1);
    tableFilter.setPlanItem(item);
    tableFilter.prepare();
}
Also used : Column(com.wplatform.ddal.dbobject.table.Column) ValueExpression(com.wplatform.ddal.command.expression.ValueExpression) Expression(com.wplatform.ddal.command.expression.Expression) PlanItem(com.wplatform.ddal.dbobject.table.PlanItem)

Example 24 with Expression

use of com.wplatform.ddal.command.expression.Expression in project jdbc-shards by wplatform.

the class Call method queryMeta.

@Override
public ResultInterface queryMeta() {
    LocalResult result;
    if (isResultSet) {
        Expression[] expr = expression.getExpressionColumns(session);
        result = new LocalResult(session, expr, expr.length);
    } else {
        result = new LocalResult(session, expressions, 1);
    }
    result.done();
    return result;
}
Also used : LocalResult(com.wplatform.ddal.result.LocalResult) Expression(com.wplatform.ddal.command.expression.Expression)

Example 25 with Expression

use of com.wplatform.ddal.command.expression.Expression in project jdbc-shards by wplatform.

the class Explain method query.

@Override
public ResultInterface query(int maxrows) {
    Column column = new Column("PLAN", Value.STRING);
    Database db = session.getDatabase();
    ExpressionColumn expr = new ExpressionColumn(db, column);
    Expression[] expressions = { expr };
    result = new LocalResult(session, expressions, 1);
    if (maxrows >= 0) {
        String plan;
        if (executeCommand) {
            if (command.isQuery()) {
                command.query(maxrows);
            } else {
                command.update();
            }
            plan = command.getPlanSQL();
        } else {
            plan = command.getPlanSQL();
        }
        add(plan);
    }
    result.done();
    return result;
}
Also used : LocalResult(com.wplatform.ddal.result.LocalResult) Column(com.wplatform.ddal.dbobject.table.Column) ExpressionColumn(com.wplatform.ddal.command.expression.ExpressionColumn) Expression(com.wplatform.ddal.command.expression.Expression) Database(com.wplatform.ddal.engine.Database) ValueString(com.wplatform.ddal.value.ValueString) ExpressionColumn(com.wplatform.ddal.command.expression.ExpressionColumn)

Aggregations

Expression (com.wplatform.ddal.command.expression.Expression)40 Column (com.wplatform.ddal.dbobject.table.Column)15 Value (com.wplatform.ddal.value.Value)14 StatementBuilder (com.wplatform.ddal.util.StatementBuilder)9 Row (com.wplatform.ddal.result.Row)5 TableFilter (com.wplatform.ddal.dbobject.table.TableFilter)4 TableMate (com.wplatform.ddal.dbobject.table.TableMate)4 DbException (com.wplatform.ddal.message.DbException)4 SearchRow (com.wplatform.ddal.result.SearchRow)4 Query (com.wplatform.ddal.command.dml.Query)3 ExpressionColumn (com.wplatform.ddal.command.expression.ExpressionColumn)3 ValueExpression (com.wplatform.ddal.command.expression.ValueExpression)3 Database (com.wplatform.ddal.engine.Database)3 ResultInterface (com.wplatform.ddal.result.ResultInterface)3 Parameter (com.wplatform.ddal.command.expression.Parameter)2 Index (com.wplatform.ddal.dbobject.index.Index)2 LocalResult (com.wplatform.ddal.result.LocalResult)2 Prepared (com.wplatform.ddal.command.Prepared)1 AlterTableAddConstraint (com.wplatform.ddal.command.ddl.AlterTableAddConstraint)1 SelectOrderBy (com.wplatform.ddal.command.dml.SelectOrderBy)1