Search in sources :

Example 1 with TableFilter

use of com.wplatform.ddal.dbobject.table.TableFilter in project jdbc-shards by wplatform.

the class Optimizer method shuffleAll.

private void shuffleAll(TableFilter[] f) {
    for (int i = 0; i < f.length - 1; i++) {
        int j = i + random.nextInt(f.length - i);
        if (j != i) {
            TableFilter temp = f[i];
            f[i] = f[j];
            f[j] = temp;
        }
    }
}
Also used : TableFilter(com.wplatform.ddal.dbobject.table.TableFilter)

Example 2 with TableFilter

use of com.wplatform.ddal.dbobject.table.TableFilter in project jdbc-shards by wplatform.

the class Aggregate method getColumnIndex.

private Index getColumnIndex() {
    if (on instanceof ExpressionColumn) {
        ExpressionColumn col = (ExpressionColumn) on;
        Column column = col.getColumn();
        TableFilter filter = col.getTableFilter();
        if (filter != null) {
            Table table = filter.getTable();
            Index index = table.getIndexForColumn(column);
            return index;
        }
    }
    return null;
}
Also used : Table(com.wplatform.ddal.dbobject.table.Table) Column(com.wplatform.ddal.dbobject.table.Column) TableFilter(com.wplatform.ddal.dbobject.table.TableFilter) Index(com.wplatform.ddal.dbobject.index.Index)

Example 3 with TableFilter

use of com.wplatform.ddal.dbobject.table.TableFilter in project jdbc-shards by wplatform.

the class SelectExecutor method getPlanSQL.

public String getPlanSQL() {
    // can not use the field sqlStatement because the parameter
    // indexes may be incorrect: ? may be in fact ?2 for a subquery
    // but indexes may be set manually as well
    Expression[] exprList = expressions.toArray(new Expression[expressions.size()]);
    StatementBuilder buff = new StatementBuilder("SELECT");
    if (distinct) {
        buff.append(" DISTINCT");
    }
    for (int i = 0; i < visibleColumnCount; i++) {
        buff.appendExceptFirst(",");
        buff.append('\n');
        buff.append(StringUtils.indent(exprList[i].getSQL(), 4, false));
    }
    buff.append("\nFROM ");
    TableFilter filter = topTableFilter;
    if (filter != null) {
        buff.resetCount();
        int i = 0;
        do {
            buff.appendExceptFirst("\n");
            buff.append(filter.getPlanSQL(i++ > 0));
            filter = filter.getJoin();
        } while (filter != null);
    } else {
        buff.resetCount();
        int i = 0;
        for (TableFilter f : topFilters) {
            do {
                buff.appendExceptFirst("\n");
                buff.append(f.getPlanSQL(i++ > 0));
                f = f.getJoin();
            } while (f != null);
        }
    }
    if (condition != null) {
        buff.append("\nWHERE ").append(StringUtils.unEnclose(condition.getSQL()));
    }
    if (groupIndex != null) {
        buff.append("\nGROUP BY ");
        buff.resetCount();
        for (int gi : groupIndex) {
            Expression g = exprList[gi];
            g = g.getNonAliasExpression();
            buff.appendExceptFirst(", ");
            buff.append(StringUtils.unEnclose(g.getSQL()));
        }
    }
    if (group != null) {
        buff.append("\nGROUP BY ");
        buff.resetCount();
        for (Expression g : group) {
            buff.appendExceptFirst(", ");
            buff.append(StringUtils.unEnclose(g.getSQL()));
        }
    }
    if (having != null) {
        // could be set in addGlobalCondition
        // in this case the query is not run directly, just getPlanSQL is
        // called
        Expression h = having;
        buff.append("\nHAVING ").append(StringUtils.unEnclose(h.getSQL()));
    } else if (havingIndex >= 0) {
        Expression h = exprList[havingIndex];
        buff.append("\nHAVING ").append(StringUtils.unEnclose(h.getSQL()));
    }
    if (sort != null) {
        buff.append("\nORDER BY ").append(sort.getSQL(exprList, visibleColumnCount));
    }
    if (limitExpr != null) {
        buff.append("\nLIMIT ").append(StringUtils.unEnclose(limitExpr.getSQL()));
        if (offsetExpr != null) {
            buff.append(" OFFSET ").append(StringUtils.unEnclose(offsetExpr.getSQL()));
        }
    }
    if (sampleSizeExpr != null) {
        buff.append("\nSAMPLE_SIZE ").append(StringUtils.unEnclose(sampleSizeExpr.getSQL()));
    }
    if (isForUpdate) {
        buff.append("\nFOR UPDATE");
    }
    return buff.toString();
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression) TableFilter(com.wplatform.ddal.dbobject.table.TableFilter) StatementBuilder(com.wplatform.ddal.util.StatementBuilder)

Example 4 with TableFilter

use of com.wplatform.ddal.dbobject.table.TableFilter in project jdbc-shards by wplatform.

the class DeleteExecutor method executeUpdate.

@Override
public int executeUpdate() {
    TableFilter tableFilter = prepared.getTableFilter();
    TableMate table = castTableMate(tableFilter.getTable());
    table.check();
    session.getUser().checkRight(table, Right.DELETE);
    return updateRow(table, null, tableFilter.getIndexConditions());
}
Also used : TableFilter(com.wplatform.ddal.dbobject.table.TableFilter) TableMate(com.wplatform.ddal.dbobject.table.TableMate)

Example 5 with TableFilter

use of com.wplatform.ddal.dbobject.table.TableFilter in project jdbc-shards by wplatform.

the class UpdateExecutor method doTranslate.

@Override
protected List<Value> doTranslate(TableNode node, SearchRow row, StatementBuilder buff) {
    ArrayList<Value> params = New.arrayList();
    TableFilter tableFilter = prepared.getTableFilter();
    String forTable = node.getCompositeObjectName();
    List<Column> columns = prepared.getColumns();
    Expression condition = prepared.getCondition();
    Expression limitExpr = prepared.getLimitExpr();
    buff.append("UPDATE ");
    buff.append(identifier(forTable)).append(" SET ");
    for (int i = 0, size = columns.size(); i < size; i++) {
        Column c = columns.get(i);
        buff.appendExceptFirst(", ");
        buff.append(c.getSQL()).append(" = ");
        Value v = row.getValue(i);
        buff.appendExceptFirst(", ");
        if (v == null) {
            buff.append("DEFAULT");
        } else if (isNull(v)) {
            buff.append("NULL");
        } else {
            buff.append('?');
            params.add(v);
        }
    }
    if (condition != null) {
        condition.exportParameters(tableFilter, params);
        buff.append(" WHERE ").append(StringUtils.unEnclose(condition.getSQL()));
    }
    if (limitExpr != null) {
        limitExpr.exportParameters(tableFilter, params);
        buff.append(" LIMIT ").append(StringUtils.unEnclose(limitExpr.getSQL()));
    }
    return params;
}
Also used : TableFilter(com.wplatform.ddal.dbobject.table.TableFilter) Column(com.wplatform.ddal.dbobject.table.Column) Expression(com.wplatform.ddal.command.expression.Expression) Value(com.wplatform.ddal.value.Value)

Aggregations

TableFilter (com.wplatform.ddal.dbobject.table.TableFilter)13 Expression (com.wplatform.ddal.command.expression.Expression)4 Column (com.wplatform.ddal.dbobject.table.Column)3 Value (com.wplatform.ddal.value.Value)3 TableMate (com.wplatform.ddal.dbobject.table.TableMate)2 Index (com.wplatform.ddal.dbobject.index.Index)1 IndexCondition (com.wplatform.ddal.dbobject.index.IndexCondition)1 Plan (com.wplatform.ddal.dbobject.table.Plan)1 PlanItem (com.wplatform.ddal.dbobject.table.PlanItem)1 Table (com.wplatform.ddal.dbobject.table.Table)1 Database (com.wplatform.ddal.engine.Database)1 DbException (com.wplatform.ddal.message.DbException)1 Row (com.wplatform.ddal.result.Row)1 SearchRow (com.wplatform.ddal.result.SearchRow)1 BitField (com.wplatform.ddal.util.BitField)1 StatementBuilder (com.wplatform.ddal.util.StatementBuilder)1