Skip to content

Commit

Permalink
增加注释并删除Expression.getTableAlias()
Browse files Browse the repository at this point in the history
  • Loading branch information
codefollower committed Jul 13, 2015
1 parent c786bc7 commit 3d1ab05
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
22 changes: 13 additions & 9 deletions lealone-sql/src/main/java/org/lealone/command/dml/Select.java
Expand Up @@ -275,25 +275,29 @@ private void expandColumnList() {
continue; continue;
} }
String schemaName = expr.getSchemaName(); String schemaName = expr.getSchemaName();
String tableAlias = expr.getTableAlias(); // select mytable.* from mytable as t这种用法是错的,MySQL也报错
if (tableAlias == null) { // 必须这样select t.* from mytable as t或者select mytable.* from mytable
// 这里的tableName有可能是mytable也可能是t
String tableName = expr.getTableName();
if (tableName == null) { // select *,展开所有表中的字段
expressions.remove(i); expressions.remove(i);
for (TableFilter filter : filters) { for (TableFilter filter : filters) {
i = expandColumnList(filter, i); i = expandColumnList(filter, i);
} }
i--; i--;
} else { } else { // select s.t.*或select t.*,展开指定模式和指定表中的字段
TableFilter filter = null; TableFilter filter = null;
for (TableFilter f : filters) { for (TableFilter f : filters) {
if (db.equalsIdentifiers(tableAlias, f.getTableAlias())) { // 如果没有指定别名,f.getTableAlias()就返回最初的表名
if (db.equalsIdentifiers(tableName, f.getTableAlias())) {
if (schemaName == null || db.equalsIdentifiers(schemaName, f.getSchemaName())) { if (schemaName == null || db.equalsIdentifiers(schemaName, f.getSchemaName())) {
filter = f; filter = f;
break; break;
} }
} }
} }
if (filter == null) { if (filter == null) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableAlias); throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableName);
} }
expressions.remove(i); expressions.remove(i);
i = expandColumnList(filter, i); i = expandColumnList(filter, i);
Expand All @@ -303,10 +307,11 @@ private void expandColumnList() {
} }


private int expandColumnList(TableFilter filter, int index) { private int expandColumnList(TableFilter filter, int index) {
Table t = filter.getTable();
String alias = filter.getTableAlias(); String alias = filter.getTableAlias();
Column[] columns = t.getColumns(); Column[] columns = filter.getTable().getColumns();
for (Column c : columns) { for (Column c : columns) {
// 跳过Natural Join列,
// 右边的表对应的TableFilter有Natural Join列,而左边没有
if (filter.isNaturalJoinColumn(c)) { if (filter.isNaturalJoinColumn(c)) {
continue; continue;
} }
Expand Down Expand Up @@ -971,8 +976,7 @@ private void queryGroup(int columnCount, LocalResult result) {
} }
currentGroup = values; currentGroup = values;
currentGroupRowId++; currentGroupRowId++;
int len = columnCount; for (int i = 0; i < columnCount; i++) {
for (int i = 0; i < len; i++) {
if (groupByExpression == null || !groupByExpression[i]) { if (groupByExpression == null || !groupByExpression[i]) {
Expression expr = expressions.get(i); Expression expr = expressions.get(i);
expr.updateAggregate(session); expr.updateAggregate(session);
Expand Down
10 changes: 0 additions & 10 deletions lealone-sql/src/main/java/org/lealone/expression/Expression.java
Expand Up @@ -231,16 +231,6 @@ public int getNullable() {
return Column.NULLABLE_UNKNOWN; return Column.NULLABLE_UNKNOWN;
} }


/**
* Get the table alias name or null
* if this expression does not represent a column.
*
* @return the table alias name
*/
public String getTableAlias() {
return null;
}

/** /**
* Get the alias name of a column or SQL expression * Get the alias name of a column or SQL expression
* if it is not an aliased expression. * if it is not an aliased expression.
Expand Down
Expand Up @@ -74,13 +74,13 @@ public int getDisplaySize() {
} }


@Override @Override
public String getTableAlias() { public String getSchemaName() {
return table; return schema;
} }


@Override @Override
public String getSchemaName() { public String getTableName() {
return schema; return table;
} }


@Override @Override
Expand Down

0 comments on commit 3d1ab05

Please sign in to comment.