提交 04cf8dd4 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Implement derived column lists for plain selects too

上级 0099a2de
......@@ -1374,12 +1374,8 @@ public class Parser {
alias = readFromAlias(null);
if (alias != null) {
top.setAlias(alias);
if (readIf("(")) {
ArrayList<String> derivedColumnNames = New.arrayList();
do {
derivedColumnNames.add(readAliasIdentifier());
} while (readIf(","));
read(")");
ArrayList<String> derivedColumnNames = readDerivedColumnNames();
if (derivedColumnNames != null) {
top.setDerivedColumns(derivedColumnNames);
}
}
......@@ -1434,6 +1430,7 @@ public class Parser {
table = readTableOrView(tableName);
}
}
ArrayList<String> derivedColumnNames = null;
IndexHints indexHints = null;
// for backward compatibility, handle case where USE is a table alias
if (readIf("USE")) {
......@@ -1441,10 +1438,12 @@ public class Parser {
indexHints = parseIndexHints(table);
} else {
alias = "USE";
derivedColumnNames = readDerivedColumnNames();
}
} else {
alias = readFromAlias(alias);
if (alias != null) {
derivedColumnNames = readDerivedColumnNames();
// if alias present, a second chance to parse index hints
if (readIf("USE")) {
read("INDEX");
......@@ -1456,8 +1455,12 @@ public class Parser {
if (table.isView() && table.isTableExpression() && alias == null) {
alias = table.getName();
}
return new TableFilter(session, table, alias, rightsChecked,
TableFilter filter = new TableFilter(session, table, alias, rightsChecked,
currentSelect, orderInFrom++, indexHints);
if (derivedColumnNames != null) {
filter.setDerivedColumns(derivedColumnNames);
}
return filter;
}
private IndexHints parseIndexHints(Table table) {
......@@ -1493,6 +1496,18 @@ public class Parser {
return readFromAlias(alias, excludeIdentifiers);
}
private ArrayList<String> readDerivedColumnNames() {
if (readIf("(")) {
ArrayList<String> derivedColumnNames = New.arrayList();
do {
derivedColumnNames.add(readAliasIdentifier());
} while (readIf(","));
read(")");
return derivedColumnNames;
}
return null;
}
private Prepared parseTruncate() {
read("TABLE");
Table table = readTableOrView();
......
......@@ -50,3 +50,33 @@ SELECT V AS V1, A AS A1, B AS B1 FROM (VALUES (1)) T1(V) INNER JOIN (VALUES(1, 2
> -- -- --
> 1 1 2
> rows: 1
CREATE TABLE TEST(I INT, J INT);
> ok
CREATE INDEX TEST_I_IDX ON TEST(I);
> ok
INSERT INTO TEST VALUES (1, 2);
> update count: 1
SELECT * FROM (TEST) AS T(A, B);
> A B
> - -
> 1 2
> rows: 1
SELECT * FROM TEST AS T(A, B);
> A B
> - -
> 1 2
> rows: 1
SELECT * FROM TEST AS T(A, B) USE INDEX (TEST_I_IDX);
> A B
> - -
> 1 2
> rows: 1
DROP TABLE TEST;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论