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);
}
}
}
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);
}
}
}
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();
}
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;
}
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;
}
Aggregations