Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c7668d41
Unverified
提交
c7668d41
authored
2月 26, 2018
作者:
Noel Grandin
提交者:
GitHub
2月 26, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #909 from katzyn/derived_column_list
Derived column list
上级
d4891863
0816f2fb
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
181 行增加
和
13 行删除
+181
-13
help.csv
h2/src/docsrc/help/help.csv
+2
-1
Parser.java
h2/src/main/org/h2/command/Parser.java
+24
-1
Select.java
h2/src/main/org/h2/command/dml/Select.java
+2
-1
SelectListColumnResolver.java
h2/src/main/org/h2/command/dml/SelectListColumnResolver.java
+5
-0
ExpressionColumn.java
h2/src/main/org/h2/expression/ExpressionColumn.java
+11
-2
ColumnResolver.java
h2/src/main/org/h2/table/ColumnResolver.java
+8
-0
SingleColumnResolver.java
h2/src/main/org/h2/table/SingleColumnResolver.java
+5
-0
TableBase.java
h2/src/main/org/h2/table/TableBase.java
+1
-1
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+33
-0
TestIndex.java
h2/src/test/org/h2/test/db/TestIndex.java
+1
-1
TestScript.java
h2/src/test/org/h2/test/scripts/TestScript.java
+1
-0
derived-column-names.sql
h2/src/test/org/h2/test/scripts/derived-column-names.sql
+82
-0
joins.sql
h2/src/test/org/h2/test/scripts/joins.sql
+5
-5
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-1
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
c7668d41
...
...
@@ -2256,7 +2256,8 @@ ID + 20
"
"Other Grammar","Table Expression","
{ [ schemaName. ] tableName | ( select ) | valuesExpression } [ [ AS ] newTableAlias ]
{ [ schemaName. ] tableName | ( select ) | valuesExpression }
[ [ AS ] newTableAlias [ ( columnName [,...] ) ] ]
[ USE INDEX ([ indexName [,...] ]) ]
[ { { LEFT | RIGHT } [ OUTER ] | [ INNER ] | CROSS | NATURAL }
JOIN tableExpression [ ON expression ] ]
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
c7668d41
...
...
@@ -1374,6 +1374,10 @@ public class Parser {
alias
=
readFromAlias
(
null
);
if
(
alias
!=
null
)
{
top
.
setAlias
(
alias
);
ArrayList
<
String
>
derivedColumnNames
=
readDerivedColumnNames
();
if
(
derivedColumnNames
!=
null
)
{
top
.
setDerivedColumns
(
derivedColumnNames
);
}
}
return
top
;
}
...
...
@@ -1426,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"
))
{
...
...
@@ -1433,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"
);
...
...
@@ -1448,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
)
{
...
...
@@ -1485,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
();
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
c7668d41
...
...
@@ -737,8 +737,9 @@ public class Select extends Query {
if
(
filter
.
isNaturalJoinColumn
(
c
))
{
continue
;
}
String
name
=
filter
.
getDerivedColumnName
(
c
);
ExpressionColumn
ec
=
new
ExpressionColumn
(
session
.
getDatabase
(),
null
,
alias
,
c
.
getName
());
session
.
getDatabase
(),
null
,
alias
,
name
!=
null
?
name
:
c
.
getName
());
expressions
.
add
(
index
++,
ec
);
}
return
index
;
...
...
h2/src/main/org/h2/command/dml/SelectListColumnResolver.java
浏览文件 @
c7668d41
...
...
@@ -52,6 +52,11 @@ public class SelectListColumnResolver implements ColumnResolver {
return
columns
;
}
@Override
public
String
getDerivedColumnName
(
Column
column
)
{
return
null
;
}
@Override
public
String
getSchemaName
()
{
return
null
;
...
...
h2/src/main/org/h2/expression/ExpressionColumn.java
浏览文件 @
c7668d41
...
...
@@ -33,7 +33,7 @@ public class ExpressionColumn extends Expression {
private
final
Database
database
;
private
final
String
schemaName
;
private
final
String
tableAlias
;
private
final
String
columnName
;
private
String
columnName
;
private
ColumnResolver
columnResolver
;
private
int
queryLevel
;
private
Column
column
;
...
...
@@ -89,7 +89,10 @@ public class ExpressionColumn extends Expression {
return
;
}
for
(
Column
col
:
resolver
.
getColumns
())
{
String
n
=
col
.
getName
();
String
n
=
resolver
.
getDerivedColumnName
(
col
);
if
(
n
==
null
)
{
n
=
col
.
getName
();
}
if
(
database
.
equalsIdentifiers
(
columnName
,
n
))
{
mapColumn
(
resolver
,
col
,
level
);
return
;
...
...
@@ -253,6 +256,12 @@ public class ExpressionColumn extends Expression {
@Override
public
String
getAlias
()
{
if
(
column
!=
null
)
{
if
(
columnResolver
!=
null
)
{
String
name
=
columnResolver
.
getDerivedColumnName
(
column
);
if
(
name
!=
null
)
{
return
name
;
}
}
return
column
.
getName
();
}
if
(
tableAlias
!=
null
)
{
...
...
h2/src/main/org/h2/table/ColumnResolver.java
浏览文件 @
c7668d41
...
...
@@ -30,6 +30,14 @@ public interface ColumnResolver {
*/
Column
[]
getColumns
();
/**
* Get derived column name, or {@code null}.
*
* @param column column
* @return derived column name, or {@code null}
*/
String
getDerivedColumnName
(
Column
column
);
/**
* Get the list of system columns, if any.
*
...
...
h2/src/main/org/h2/table/SingleColumnResolver.java
浏览文件 @
c7668d41
...
...
@@ -42,6 +42,11 @@ public class SingleColumnResolver implements ColumnResolver {
return
new
Column
[]
{
column
};
}
@Override
public
String
getDerivedColumnName
(
Column
column
)
{
return
null
;
}
@Override
public
String
getSchemaName
()
{
return
null
;
...
...
h2/src/main/org/h2/table/TableBase.java
浏览文件 @
c7668d41
...
...
@@ -39,7 +39,7 @@ public abstract class TableBase extends Table {
if
(
data
.
tableEngineParams
!=
null
)
{
this
.
tableEngineParams
=
data
.
tableEngineParams
;
}
else
{
this
.
tableEngineParams
=
Collections
.
EMPTY_LIST
;
this
.
tableEngineParams
=
Collections
.
emptyList
()
;
}
setTemporary
(
data
.
temporary
);
Column
[]
cols
=
data
.
columns
.
toArray
(
new
Column
[
0
]);
...
...
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
c7668d41
...
...
@@ -6,6 +6,7 @@
package
org
.
h2
.
table
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.Parser
;
...
...
@@ -117,6 +118,8 @@ public class TableFilter implements ColumnResolver {
private
final
int
hashCode
;
private
final
int
orderInFrom
;
private
HashMap
<
Column
,
String
>
derivedColumnMap
;
/**
* Create a new table filter object.
*
...
...
@@ -992,6 +995,12 @@ public class TableFilter implements ColumnResolver {
return
table
.
getColumns
();
}
@Override
public
String
getDerivedColumnName
(
Column
column
)
{
HashMap
<
Column
,
String
>
map
=
derivedColumnMap
;
return
map
!=
null
?
map
.
get
(
column
)
:
null
;
}
/**
* Get the system columns that this table understands. This is used for
* compatibility with other databases. The columns are only returned if the
...
...
@@ -1056,6 +1065,30 @@ public class TableFilter implements ColumnResolver {
this
.
alias
=
alias
;
}
/**
* Set derived column list.
*
* @param derivedColumnNames names of derived columns
*/
public
void
setDerivedColumns
(
ArrayList
<
String
>
derivedColumnNames
)
{
Column
[]
columns
=
getColumns
();
int
count
=
columns
.
length
;
if
(
count
!=
derivedColumnNames
.
size
())
{
throw
DbException
.
get
(
ErrorCode
.
COLUMN_COUNT_DOES_NOT_MATCH
);
}
HashMap
<
Column
,
String
>
map
=
new
HashMap
<>(
count
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
String
alias
=
derivedColumnNames
.
get
(
i
);
for
(
int
j
=
0
;
j
<
i
;
j
++)
{
if
(
alias
.
equals
(
derivedColumnNames
.
get
(
j
)))
{
throw
DbException
.
get
(
ErrorCode
.
DUPLICATE_COLUMN_NAME_1
,
alias
);
}
}
map
.
put
(
columns
[
i
],
alias
);
}
this
.
derivedColumnMap
=
map
;
}
@Override
public
Expression
optimize
(
ExpressionColumn
expressionColumn
,
Column
column
)
{
return
expressionColumn
;
...
...
h2/src/test/org/h2/test/db/TestIndex.java
浏览文件 @
c7668d41
...
...
@@ -712,7 +712,7 @@ public class TestIndex extends TestBase {
public
static
ResultSet
testFunctionIndexFunction
()
{
// There are additional callers like JdbcConnection.prepareCommand() and
// CommandContainer.recompileIfReqired()
// CommandContainer.recompileIfReq
u
ired()
for
(
StackTraceElement
element
:
Thread
.
currentThread
().
getStackTrace
())
{
if
(
element
.
getClassName
().
startsWith
(
Select
.
class
.
getName
()))
{
testFunctionIndexCounter
++;
...
...
h2/src/test/org/h2/test/scripts/TestScript.java
浏览文件 @
c7668d41
...
...
@@ -82,6 +82,7 @@ public class TestScript extends TestBase {
reconnectOften
=
!
config
.
memory
&&
config
.
big
;
testScript
(
"testScript.sql"
);
testScript
(
"derived-column-names.sql"
);
testScript
(
"joins.sql"
);
testScript
(
"altertable-index-reuse.sql"
);
testScript
(
"query-optimisations.sql"
);
...
...
h2/src/test/org/h2/test/scripts/derived-column-names.sql
0 → 100644
浏览文件 @
c7668d41
-- Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
SELECT
*
FROM
(
VALUES
(
1
,
2
));
>
C1
C2
>
-- --
>
1
2
>
rows
:
1
SELECT
*
FROM
(
VALUES
(
1
,
2
))
AS
T
;
>
C1
C2
>
-- --
>
1
2
>
rows
:
1
SELECT
*
FROM
(
VALUES
(
1
,
2
))
AS
T
(
A
,
B
);
>
A
B
>
-
-
>
1
2
>
rows
:
1
SELECT
A
AS
A1
,
B
AS
B1
FROM
(
VALUES
(
1
,
2
))
AS
T
(
A
,
B
);
>
A1
B1
>
-- --
>
1
2
>
rows
:
1
SELECT
A
AS
A1
,
B
AS
B1
FROM
(
VALUES
(
1
,
2
))
AS
T
(
A
,
B
)
WHERE
A
<>
B
;
>
A1
B1
>
-- --
>
1
2
>
rows
:
1
SELECT
A
AS
A1
,
B
AS
B1
FROM
(
VALUES
(
1
,
2
))
AS
T
(
A
,
B
)
WHERE
A1
<>
B1
;
>
exception
SELECT
*
FROM
(
VALUES
(
1
,
2
))
AS
T
(
A
);
>
exception
SELECT
*
FROM
(
VALUES
(
1
,
2
))
AS
T
(
A
,
a
);
>
exception
SELECT
*
FROM
(
VALUES
(
1
,
2
))
AS
T
(
A
,
B
,
C
);
>
exception
SELECT
V
AS
V1
,
A
AS
A1
,
B
AS
B1
FROM
(
VALUES
(
1
))
T1
(
V
)
INNER
JOIN
(
VALUES
(
1
,
2
))
T2
(
A
,
B
)
ON
V
=
A
;
>
V1
A1
B1
>
-- -- --
>
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
h2/src/test/org/h2/test/scripts/joins.sql
浏览文件 @
c7668d41
...
...
@@ -781,11 +781,11 @@ INSERT INTO T5 VALUES (1);
INSERT
INTO
T5
VALUES
(
NULL
);
SELECT
T1
.
X1
,
T2
.
X2
,
T3
.
X3
,
T4
.
X4
,
T5
.
X5
FROM
(
T1
INNER
JOIN
(
T2
LEFT
OUTER
JOIN
(
T3
INNER
JOIN
T4
ON
T3
.
X3
=
T4
.
X4
)
ON
T2
.
X2
=
T4
.
X4
)
ON
T1
.
X1
=
T2
.
X2
T1
INNER
JOIN
(
T2
LEFT
OUTER
JOIN
(
T3
INNER
JOIN
T4
ON
T3
.
X3
=
T4
.
X4
)
ON
T2
.
X2
=
T4
.
X4
)
ON
T1
.
X1
=
T2
.
X2
)
INNER
JOIN
T5
ON
T2
.
X2
=
T5
.
X5
;
>
X1
X2
X3
X4
X5
>
-- -- -- -- --
...
...
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
c7668d41
...
...
@@ -765,4 +765,4 @@ jacoco xdata invokes sourcefiles classfiles duplication crypto stacktraces prt d
interpolated thead
die weekdiff osx subprocess dow proleptic microsecond microseconds divisible cmp denormalized suppressed saturated mcs
london dfs weekdays intermittent looked msec tstz africa monrovia asia tokyo weekday
london dfs weekdays intermittent looked msec tstz africa monrovia asia tokyo weekday
joi callers
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论