Search in sources :

Example 1 with ExpressionColumn

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

the class Select method expandColumnList.

private void expandColumnList() {
    Database db = session.getDatabase();
    // the expressions may change within the loop
    for (int i = 0; i < expressions.size(); i++) {
        Expression expr = expressions.get(i);
        if (!expr.isWildcard()) {
            continue;
        }
        String schemaName = expr.getSchemaName();
        String tableAlias = expr.getTableAlias();
        if (tableAlias == null) {
            int temp = i;
            expressions.remove(i);
            for (TableFilter filter : filters) {
                Wildcard c2 = new Wildcard(filter.getTable().getSchema().getName(), filter.getTableAlias());
                expressions.add(i++, c2);
            }
            i = temp - 1;
        } else {
            TableFilter filter = null;
            for (TableFilter f : filters) {
                if (db.equalsIdentifiers(tableAlias, f.getTableAlias())) {
                    if (schemaName == null || db.equalsIdentifiers(schemaName, f.getSchemaName())) {
                        filter = f;
                        break;
                    }
                }
            }
            if (filter == null) {
                throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableAlias);
            }
            Table t = filter.getTable();
            String alias = filter.getTableAlias();
            expressions.remove(i);
            Column[] columns = t.getColumns();
            for (Column c : columns) {
                if (filter.isNaturalJoinColumn(c)) {
                    continue;
                }
                ExpressionColumn ec = new ExpressionColumn(session.getDatabase(), null, alias, c.getName());
                expressions.add(i++, ec);
            }
            i--;
        }
    }
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression) Wildcard(com.wplatform.ddal.command.expression.Wildcard) ExpressionColumn(com.wplatform.ddal.command.expression.ExpressionColumn) Database(com.wplatform.ddal.engine.Database) ExpressionColumn(com.wplatform.ddal.command.expression.ExpressionColumn)

Example 2 with ExpressionColumn

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

the class SortOrder method getColumn.

/**
 * Get the column for the given table filter, if the sort column is for this
 * filter.
 *
 * @param index  the column index (0, 1,..)
 * @param filter the table filter
 * @return the column, or null
 */
public Column getColumn(int index, TableFilter filter) {
    if (orderList == null) {
        return null;
    }
    SelectOrderBy order = orderList.get(index);
    Expression expr = order.expression;
    if (expr == null) {
        return null;
    }
    expr = expr.getNonAliasExpression();
    if (expr.isConstant()) {
        return null;
    }
    if (!(expr instanceof ExpressionColumn)) {
        return null;
    }
    ExpressionColumn exprCol = (ExpressionColumn) expr;
    if (exprCol.getTableFilter() != filter) {
        return null;
    }
    return exprCol.getColumn();
}
Also used : SelectOrderBy(com.wplatform.ddal.command.dml.SelectOrderBy) Expression(com.wplatform.ddal.command.expression.Expression) ExpressionColumn(com.wplatform.ddal.command.expression.ExpressionColumn)

Example 3 with ExpressionColumn

use of com.wplatform.ddal.command.expression.ExpressionColumn 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)3 ExpressionColumn (com.wplatform.ddal.command.expression.ExpressionColumn)3 Database (com.wplatform.ddal.engine.Database)2 SelectOrderBy (com.wplatform.ddal.command.dml.SelectOrderBy)1 Wildcard (com.wplatform.ddal.command.expression.Wildcard)1 Column (com.wplatform.ddal.dbobject.table.Column)1 LocalResult (com.wplatform.ddal.result.LocalResult)1 ValueString (com.wplatform.ddal.value.ValueString)1