Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ae71212d
提交
ae71212d
authored
2月 06, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix derived column list in complex queries
上级
96c8f626
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
59 行增加
和
11 行删除
+59
-11
ExpressionColumn.java
h2/src/main/org/h2/expression/ExpressionColumn.java
+13
-1
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+15
-2
select.sql
h2/src/test/org/h2/test/scripts/dml/select.sql
+23
-0
histogram.sql
...est/org/h2/test/scripts/functions/aggregate/histogram.sql
+8
-8
没有找到文件。
h2/src/main/org/h2/expression/ExpressionColumn.java
浏览文件 @
ae71212d
...
...
@@ -39,6 +39,7 @@ public class ExpressionColumn extends Expression {
private
ColumnResolver
columnResolver
;
private
int
queryLevel
;
private
Column
column
;
private
String
derivedName
;
public
ExpressionColumn
(
Database
database
,
Column
column
)
{
this
.
database
=
database
;
...
...
@@ -76,7 +77,11 @@ public class ExpressionColumn extends Expression {
builder
.
append
(
'.'
);
}
if
(
column
!=
null
)
{
if
(
derivedName
!=
null
)
{
Parser
.
quoteIdentifier
(
builder
,
derivedName
);
}
else
{
builder
.
append
(
column
.
getSQL
());
}
}
else
if
(
quote
)
{
Parser
.
quoteIdentifier
(
builder
,
columnName
);
}
else
{
...
...
@@ -101,11 +106,18 @@ public class ExpressionColumn extends Expression {
}
for
(
Column
col
:
resolver
.
getColumns
())
{
String
n
=
resolver
.
getDerivedColumnName
(
col
);
boolean
derived
;
if
(
n
==
null
)
{
n
=
col
.
getName
();
derived
=
false
;
}
else
{
derived
=
true
;
}
if
(
database
.
equalsIdentifiers
(
columnName
,
n
))
{
mapColumn
(
resolver
,
col
,
level
);
if
(
derived
)
{
derivedName
=
n
;
}
return
;
}
}
...
...
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
ae71212d
...
...
@@ -7,6 +7,7 @@ package org.h2.table;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.Parser
;
...
...
@@ -122,7 +123,7 @@ public class TableFilter implements ColumnResolver {
private
final
int
hashCode
;
private
final
int
orderInFrom
;
private
HashMap
<
Column
,
String
>
derivedColumnMap
;
private
Linked
HashMap
<
Column
,
String
>
derivedColumnMap
;
/**
* Create a new table filter object.
...
...
@@ -801,6 +802,18 @@ public class TableFilter implements ColumnResolver {
if
(
alias
!=
null
)
{
builder
.
append
(
' '
);
Parser
.
quoteIdentifier
(
builder
,
alias
);
if
(
derivedColumnMap
!=
null
)
{
builder
.
append
(
'('
);
boolean
f
=
false
;
for
(
String
name
:
derivedColumnMap
.
values
())
{
if
(
f
)
{
builder
.
append
(
", "
);
}
f
=
true
;
Parser
.
quoteIdentifier
(
builder
,
name
);
}
builder
.
append
(
')'
);
}
}
if
(
indexHints
!=
null
)
{
builder
.
append
(
" USE INDEX ("
);
...
...
@@ -1091,7 +1104,7 @@ public class TableFilter implements ColumnResolver {
if
(
count
!=
derivedColumnNames
.
size
())
{
throw
DbException
.
get
(
ErrorCode
.
COLUMN_COUNT_DOES_NOT_MATCH
);
}
HashMap
<
Column
,
String
>
map
=
new
HashMap
<>();
LinkedHashMap
<
Column
,
String
>
map
=
new
Linked
HashMap
<>();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
String
alias
=
derivedColumnNames
.
get
(
i
);
for
(
int
j
=
0
;
j
<
i
;
j
++)
{
...
...
h2/src/test/org/h2/test/scripts/dml/select.sql
浏览文件 @
ae71212d
...
...
@@ -602,3 +602,26 @@ FROM (SELECT 1 X), (VALUES (1, 2), (2, 1), (3, 3)) T(A, B);
>
1
2
1
>
1
3
3
>
rows
:
3
SELECT
A
,
B
,
C
FROM
(
SELECT
A
,
B
,
C
FROM
(
VALUES
(
1
,
2
,
3
))
V
(
A
,
B
,
C
));
>
A
B
C
>
-
-
-
>
1
2
3
>
rows
:
1
SELECT
*
FROM
(
SELECT
*
FROM
(
VALUES
(
1
,
2
,
3
))
V
(
A
,
B
,
C
));
>
A
B
C
>
-
-
-
>
1
2
3
>
rows
:
1
SELECT
*
FROM
(
SELECT
X
*
X
,
Y
FROM
(
SELECT
A
+
5
,
B
FROM
(
VALUES
(
1
,
2
))
V
(
A
,
B
)
)
T
(
X
,
Y
)
);
>
X
*
X
Y
>
----- -
>
36
2
>
rows
:
1
h2/src/test/org/h2/test/scripts/functions/aggregate/histogram.sql
浏览文件 @
ae71212d
...
...
@@ -4,20 +4,20 @@
--
SELECT
HISTOGRAM
(
X
),
HISTOGRAM
(
DISTINCT
X
)
FROM
VALUES
(
1
),
(
2
),
(
3
),
(
1
),
(
2
),
(
NULL
),
(
5
)
T
(
X
);
>
HISTOGRAM
(
C1
)
HISTOGRAM
(
DISTINCT
C1
)
>
HISTOGRAM
(
X
)
HISTOGRAM
(
DISTINCT
X
)
>
------------------------------------------- -------------------------------------------
>
[[
null
,
1
],
[
1
,
2
],
[
2
,
2
],
[
3
,
1
],
[
5
,
1
]]
[[
null
,
1
],
[
1
,
1
],
[
2
,
1
],
[
3
,
1
],
[
5
,
1
]]
>
rows
:
1
SELECT
HISTOGRAM
(
X
)
FILTER
(
WHERE
X
>
1
),
HISTOGRAM
(
DISTINCT
X
)
FILTER
(
WHERE
X
>
1
)
FROM
VALUES
(
1
),
(
2
),
(
3
),
(
1
),
(
2
),
(
NULL
),
(
5
)
T
(
X
);
>
HISTOGRAM
(
C1
)
FILTER
(
WHERE
(
C1
>
1
))
HISTOGRAM
(
DISTINCT
C1
)
FILTER
(
WHERE
(
C1
>
1
))
>
-----------------------------------
-- --
--------------------------------------------
>
HISTOGRAM
(
X
)
FILTER
(
WHERE
(
X
>
1
))
HISTOGRAM
(
DISTINCT
X
)
FILTER
(
WHERE
(
X
>
1
))
>
-----------------------------------
--------------------------------------------
>
[[
2
,
2
],
[
3
,
1
],
[
5
,
1
]]
[[
2
,
1
],
[
3
,
1
],
[
5
,
1
]]
>
rows
:
1
SELECT
HISTOGRAM
(
X
)
FILTER
(
WHERE
X
>
0
),
HISTOGRAM
(
DISTINCT
X
)
FILTER
(
WHERE
X
>
0
)
FROM
VALUES
(
0
)
T
(
X
);
>
HISTOGRAM
(
C1
)
FILTER
(
WHERE
(
C1
>
0
))
HISTOGRAM
(
DISTINCT
C1
)
FILTER
(
WHERE
(
C1
>
0
))
>
-----------------------------------
-- --
--------------------------------------------
>
HISTOGRAM
(
X
)
FILTER
(
WHERE
(
X
>
0
))
HISTOGRAM
(
DISTINCT
X
)
FILTER
(
WHERE
(
X
>
0
))
>
-----------------------------------
--------------------------------------------
>
[]
[]
>
rows
:
1
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论