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

Implement derived column lists for plain selects too

上级 0099a2de
...@@ -1374,12 +1374,8 @@ public class Parser { ...@@ -1374,12 +1374,8 @@ public class Parser {
alias = readFromAlias(null); alias = readFromAlias(null);
if (alias != null) { if (alias != null) {
top.setAlias(alias); top.setAlias(alias);
if (readIf("(")) { ArrayList<String> derivedColumnNames = readDerivedColumnNames();
ArrayList<String> derivedColumnNames = New.arrayList(); if (derivedColumnNames != null) {
do {
derivedColumnNames.add(readAliasIdentifier());
} while (readIf(","));
read(")");
top.setDerivedColumns(derivedColumnNames); top.setDerivedColumns(derivedColumnNames);
} }
} }
...@@ -1434,6 +1430,7 @@ public class Parser { ...@@ -1434,6 +1430,7 @@ public class Parser {
table = readTableOrView(tableName); table = readTableOrView(tableName);
} }
} }
ArrayList<String> derivedColumnNames = null;
IndexHints indexHints = null; IndexHints indexHints = null;
// for backward compatibility, handle case where USE is a table alias // for backward compatibility, handle case where USE is a table alias
if (readIf("USE")) { if (readIf("USE")) {
...@@ -1441,10 +1438,12 @@ public class Parser { ...@@ -1441,10 +1438,12 @@ public class Parser {
indexHints = parseIndexHints(table); indexHints = parseIndexHints(table);
} else { } else {
alias = "USE"; alias = "USE";
derivedColumnNames = readDerivedColumnNames();
} }
} else { } else {
alias = readFromAlias(alias); alias = readFromAlias(alias);
if (alias != null) { if (alias != null) {
derivedColumnNames = readDerivedColumnNames();
// if alias present, a second chance to parse index hints // if alias present, a second chance to parse index hints
if (readIf("USE")) { if (readIf("USE")) {
read("INDEX"); read("INDEX");
...@@ -1456,8 +1455,12 @@ public class Parser { ...@@ -1456,8 +1455,12 @@ public class Parser {
if (table.isView() && table.isTableExpression() && alias == null) { if (table.isView() && table.isTableExpression() && alias == null) {
alias = table.getName(); alias = table.getName();
} }
return new TableFilter(session, table, alias, rightsChecked, TableFilter filter = new TableFilter(session, table, alias, rightsChecked,
currentSelect, orderInFrom++, indexHints); currentSelect, orderInFrom++, indexHints);
if (derivedColumnNames != null) {
filter.setDerivedColumns(derivedColumnNames);
}
return filter;
} }
private IndexHints parseIndexHints(Table table) { private IndexHints parseIndexHints(Table table) {
...@@ -1493,6 +1496,18 @@ public class Parser { ...@@ -1493,6 +1496,18 @@ public class Parser {
return readFromAlias(alias, excludeIdentifiers); 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() { private Prepared parseTruncate() {
read("TABLE"); read("TABLE");
Table table = readTableOrView(); 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 ...@@ -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 > 1 1 2
> rows: 1 > 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论