Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
6c53c6e9
提交
6c53c6e9
authored
9月 06, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add ESTIMATED_ENVELOPE system function
上级
a7e7aea5
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
89 行增加
和
7 行删除
+89
-7
help.csv
h2/src/docsrc/help/help.csv
+17
-0
Function.java
h2/src/main/org/h2/expression/Function.java
+28
-6
MVSpatialIndex.java
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
+36
-0
envelope.sql
...test/org/h2/test/scripts/functions/aggregate/envelope.sql
+7
-0
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-1
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
6c53c6e9
...
...
@@ -4736,6 +4736,23 @@ Throw an SQLException with the passed SQLState and reason.
CALL SIGNAL('23505', 'Duplicate user ID: ' || user_id);
"
"Functions (System)","ESTIMATED_ENVELOPE","
ESTIMATED_ENVELOPE(tableNameString, columnNameString)
","
Returns the estimated minimum bounding box that encloses all specified GEOMETRY values.
Only 2D coordinate plane is supported.
NULL values are ignored.
This function is only supported by MVStore engine.
Column must have a spatial index.
This function is fast, but estimation may include uncommitted data (including data from other transactions),
may return approximate bounds, or be different with actual value due to other reasons.
Use with caution.
If estimation is not available this function returns NULL.
For accurate and reliable result use ESTIMATE aggregate function instead.
","
CALL ESTIMATED_ENVELOPE('MY_TABLE', 'GEOMETRY_COLUMN');
"
"Functions (System)","FILE_READ","
FILE_READ(fileNameString [,encodingString])
","
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
6c53c6e9
...
...
@@ -27,9 +27,11 @@ import org.h2.engine.Constants;
import
org.h2.engine.Database
;
import
org.h2.engine.Mode
;
import
org.h2.engine.Session
;
import
org.h2.index.Index
;
import
org.h2.message.DbException
;
import
org.h2.mode.FunctionsMSSQLServer
;
import
org.h2.mode.FunctionsMySQL
;
import
org.h2.mvstore.db.MVSpatialIndex
;
import
org.h2.schema.Schema
;
import
org.h2.schema.Sequence
;
import
org.h2.security.BlockCipher
;
...
...
@@ -116,7 +118,7 @@ public class Function extends Expression implements FunctionCall {
public
static
final
int
DATABASE
=
150
,
USER
=
151
,
CURRENT_USER
=
152
,
IDENTITY
=
153
,
SCOPE_IDENTITY
=
154
,
AUTOCOMMIT
=
155
,
READONLY
=
156
,
DATABASE_PATH
=
157
,
LOCK_TIMEOUT
=
158
,
DISK_SPACE_USED
=
159
,
SIGNAL
=
160
;
DISK_SPACE_USED
=
159
,
SIGNAL
=
160
,
ESTIMATED_ENVELOPE
=
161
;
private
static
final
Pattern
SIGNAL_PATTERN
=
Pattern
.
compile
(
"[0-9A-Z]{5}"
);
...
...
@@ -456,6 +458,7 @@ public class Function extends Expression implements FunctionCall {
addFunctionNotDeterministic
(
"DISK_SPACE_USED"
,
DISK_SPACE_USED
,
1
,
Value
.
LONG
);
addFunctionWithNull
(
"SIGNAL"
,
SIGNAL
,
2
,
Value
.
NULL
);
addFunctionNotDeterministic
(
"ESTIMATED_ENVELOPE"
,
ESTIMATED_ENVELOPE
,
2
,
Value
.
LONG
);
addFunction
(
"H2VERSION"
,
H2VERSION
,
0
,
Value
.
STRING
);
// TableFunction
...
...
@@ -883,6 +886,9 @@ public class Function extends Expression implements FunctionCall {
case
DISK_SPACE_USED:
result
=
ValueLong
.
get
(
getDiskSpaceUsed
(
session
,
v0
));
break
;
case
ESTIMATED_ENVELOPE:
result
=
getEstimatedEnvelope
(
session
,
v0
,
values
[
1
]);
break
;
case
CAST:
case
CONVERT:
{
Mode
mode
=
database
.
getMode
();
...
...
@@ -1096,11 +1102,27 @@ public class Function extends Expression implements FunctionCall {
return
false
;
}
private
static
long
getDiskSpaceUsed
(
Session
session
,
Value
v0
)
{
Parser
p
=
new
Parser
(
session
);
String
sql
=
v0
.
getString
();
Table
table
=
p
.
parseTableName
(
sql
);
return
table
.
getDiskSpaceUsed
();
private
static
long
getDiskSpaceUsed
(
Session
session
,
Value
tableName
)
{
return
getTable
(
session
,
tableName
).
getDiskSpaceUsed
();
}
private
static
Value
getEstimatedEnvelope
(
Session
session
,
Value
tableName
,
Value
columnName
)
{
Table
table
=
getTable
(
session
,
tableName
);
Column
column
=
table
.
getColumn
(
columnName
.
getString
());
ArrayList
<
Index
>
indexes
=
table
.
getIndexes
();
if
(
indexes
!=
null
)
{
for
(
int
i
=
1
,
size
=
indexes
.
size
();
i
<
size
;
i
++)
{
Index
index
=
indexes
.
get
(
i
);
if
(
index
instanceof
MVSpatialIndex
&&
index
.
isFirstColumn
(
column
))
{
return
((
MVSpatialIndex
)
index
).
getEstimatedBounds
(
session
);
}
}
}
return
ValueNull
.
INSTANCE
;
}
private
static
Table
getTable
(
Session
session
,
Value
tableName
)
{
return
new
Parser
(
session
).
parseTableName
(
tableName
.
getString
());
}
protected
static
Value
getNullOrValue
(
Session
session
,
Expression
[]
args
,
...
...
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
浏览文件 @
6c53c6e9
...
...
@@ -234,6 +234,42 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
return
cursor
.
getBounds
();
}
/**
* Returns the estimated minimum bounding box that encloses all keys.
*
* The returned value may be incorrect.
*
* @param session the session
* @return the estimated minimum bounding box that encloses all keys, or null
*/
public
Value
getEstimatedBounds
(
Session
session
)
{
Page
p
=
spatialMap
.
getRootPage
();
int
count
=
p
.
getKeyCount
();
if
(
count
>
0
)
{
SpatialKey
key
=
(
SpatialKey
)
p
.
getKey
(
0
);
float
bminxf
=
key
.
min
(
0
),
bmaxxf
=
key
.
max
(
0
),
bminyf
=
key
.
min
(
1
),
bmaxyf
=
key
.
max
(
1
);
for
(
int
i
=
1
;
i
<
count
;
i
++)
{
key
=
(
SpatialKey
)
p
.
getKey
(
i
);
float
minxf
=
key
.
min
(
0
),
maxxf
=
key
.
max
(
0
),
minyf
=
key
.
min
(
1
),
maxyf
=
key
.
max
(
1
);
if
(
minxf
<
bminxf
)
{
bminxf
=
minxf
;
}
if
(
maxxf
>
bmaxxf
)
{
bmaxxf
=
maxxf
;
}
if
(
minyf
<
bminyf
)
{
bminyf
=
minyf
;
}
if
(
maxyf
>
bmaxyf
)
{
bmaxyf
=
maxyf
;
}
}
return
ValueGeometry
.
getFromGeometry
(
new
GeometryFactory
().
toGeometry
(
new
Envelope
(
bminxf
,
bmaxxf
,
bminyf
,
bmaxyf
)));
}
return
ValueNull
.
INSTANCE
;
}
private
SpatialKey
getKey
(
SearchRow
row
)
{
Value
v
=
row
.
getValue
(
columnIds
[
0
]);
if
(
v
==
ValueNull
.
INSTANCE
)
{
...
...
h2/src/test/org/h2/test/scripts/functions/aggregate/envelope.sql
浏览文件 @
6c53c6e9
...
...
@@ -66,6 +66,9 @@ SELECT ENVELOPE(N) FROM (SELECT V AS N FROM TEST);
SELECT
ENVELOPE
(
V
)
FROM
TEST
;
>>
null
SELECT
ESTIMATED_ENVELOPE
(
'TEST'
,
'V'
);
>>
null
SELECT
RAND
(
1000
)
*
0
;
>>
0
.
0
...
...
@@ -80,6 +83,10 @@ SELECT ENVELOPE(N) FROM (SELECT V AS N FROM TEST);
SELECT
ENVELOPE
(
V
)
FROM
TEST
;
>>
POLYGON
((
68
78
,
68
99951
,
99903
99951
,
99903
78
,
68
78
))
SELECT
ESTIMATED_ENVELOPE
(
'TEST'
,
'V'
);
#+
mvStore
#>>
POLYGON
((
68
78
,
68
99951
,
99903
99951
,
99903
78
,
68
78
))
#-
mvStore
#>>
null
TRUNCATE
TABLE
TEST
;
>
ok
...
...
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
6c53c6e9
...
...
@@ -789,6 +789,6 @@ inconsistencies discover eliminated violates tweaks postpone leftovers
tied ties
launched unavailable smallmoney erroneously multiplier newid pan streamline unmap preview unexpectedly presumably
converging smth rng curs casts unmapping unmapper
immediate hhmmss scheduled hhmm prematurely postponed arranges subexpression subexpressions encloses plane
immediate hhmmss scheduled hhmm prematurely postponed arranges subexpression subexpressions encloses plane
caution
minxf maxxf minyf maxyf bminxf bmaxxf bminyf bmaxyf
minxd maxxd minyd maxyd bminxd bmaxxd bminyd bmaxyd
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论