Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
8f89554c
提交
8f89554c
authored
3月 26, 2015
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Issue 609: the spatial index did not support NULL (ClassCastException).
上级
0d26b2ae
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
54 行增加
和
22 行删除
+54
-22
SpatialTreeIndex.java
h2/src/main/org/h2/index/SpatialTreeIndex.java
+11
-4
MVSpatialIndex.java
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
+9
-15
SpatialDataType.java
h2/src/main/org/h2/mvstore/rtree/SpatialDataType.java
+12
-0
TestSpatial.java
h2/src/test/org/h2/test/db/TestSpatial.java
+22
-3
没有找到文件。
h2/src/main/org/h2/index/SpatialTreeIndex.java
浏览文件 @
8f89554c
...
...
@@ -23,6 +23,7 @@ import org.h2.table.Table;
import
org.h2.table.TableFilter
;
import
org.h2.value.Value
;
import
org.h2.value.ValueGeometry
;
import
org.h2.value.ValueNull
;
import
com.vividsolutions.jts.geom.Envelope
;
import
com.vividsolutions.jts.geom.Geometry
;
...
...
@@ -125,11 +126,17 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
if
(
closed
)
{
throw
DbException
.
throwInternalError
();
}
treeMap
.
add
(
get
Envelope
(
row
),
row
.
getKey
());
treeMap
.
add
(
get
Key
(
row
),
row
.
getKey
());
}
private
SpatialKey
getEnvelope
(
SearchRow
row
)
{
private
SpatialKey
getKey
(
SearchRow
row
)
{
if
(
row
==
null
)
{
return
null
;
}
Value
v
=
row
.
getValue
(
columnIds
[
0
]);
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
null
;
}
Geometry
g
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getGeometryNoCopy
();
Envelope
env
=
g
.
getEnvelopeInternal
();
return
new
SpatialKey
(
row
.
getKey
(),
...
...
@@ -142,7 +149,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
if
(
closed
)
{
throw
DbException
.
throwInternalError
();
}
if
(!
treeMap
.
remove
(
get
Envelope
(
row
),
row
.
getKey
()))
{
if
(!
treeMap
.
remove
(
get
Key
(
row
),
row
.
getKey
()))
{
throw
DbException
.
throwInternalError
(
"row not found"
);
}
}
...
...
@@ -167,7 +174,7 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
return
find
(
filter
.
getSession
());
}
return
new
SpatialCursor
(
treeMap
.
findIntersectingKeys
(
get
Envelope
(
intersection
)),
table
,
treeMap
.
findIntersectingKeys
(
get
Key
(
intersection
)),
table
,
filter
.
getSession
());
}
...
...
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
浏览文件 @
8f89554c
...
...
@@ -32,6 +32,7 @@ import org.h2.table.TableFilter;
import
org.h2.value.Value
;
import
org.h2.value.ValueGeometry
;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueNull
;
import
com.vividsolutions.jts.geom.Envelope
;
import
com.vividsolutions.jts.geom.Geometry
;
...
...
@@ -161,18 +162,6 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
}
}
private
SpatialKey
getKey
(
SearchRow
r
)
{
if
(
r
==
null
)
{
return
null
;
}
Value
v
=
r
.
getValue
(
columnIds
[
0
]);
Geometry
g
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getGeometryNoCopy
();
Envelope
env
=
g
.
getEnvelopeInternal
();
return
new
SpatialKey
(
r
.
getKey
(),
(
float
)
env
.
getMinX
(),
(
float
)
env
.
getMaxX
(),
(
float
)
env
.
getMinY
(),
(
float
)
env
.
getMaxY
());
}
@Override
public
void
remove
(
Session
session
,
Row
row
)
{
SpatialKey
key
=
getKey
(
row
);
...
...
@@ -213,14 +202,20 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
return
find
(
session
);
}
Iterator
<
SpatialKey
>
cursor
=
spatialMap
.
findIntersectingKeys
(
get
Envelope
(
intersection
));
spatialMap
.
findIntersectingKeys
(
get
Key
(
intersection
));
TransactionMap
<
SpatialKey
,
Value
>
map
=
getMap
(
session
);
Iterator
<
SpatialKey
>
it
=
map
.
wrapIterator
(
cursor
,
false
);
return
new
MVStoreCursor
(
session
,
it
);
}
private
SpatialKey
getEnvelope
(
SearchRow
row
)
{
private
SpatialKey
getKey
(
SearchRow
row
)
{
if
(
row
==
null
)
{
return
null
;
}
Value
v
=
row
.
getValue
(
columnIds
[
0
]);
if
(
v
==
ValueNull
.
INSTANCE
)
{
return
null
;
}
Geometry
g
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getGeometryNoCopy
();
Envelope
env
=
g
.
getEnvelopeInternal
();
return
new
SpatialKey
(
row
.
getKey
(),
...
...
@@ -228,7 +223,6 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
(
float
)
env
.
getMinY
(),
(
float
)
env
.
getMaxY
());
}
/**
* Get the row with the given index key.
*
...
...
h2/src/main/org/h2/mvstore/rtree/SpatialDataType.java
浏览文件 @
8f89554c
...
...
@@ -32,6 +32,13 @@ public class SpatialDataType implements DataType {
@Override
public
int
compare
(
Object
a
,
Object
b
)
{
if
(
a
==
b
)
{
return
0
;
}
else
if
(
a
==
null
)
{
return
-
1
;
}
else
if
(
b
==
null
)
{
return
1
;
}
long
la
=
((
SpatialKey
)
a
).
getId
();
long
lb
=
((
SpatialKey
)
b
).
getId
();
return
la
<
lb
?
-
1
:
la
>
lb
?
1
:
0
;
...
...
@@ -45,6 +52,11 @@ public class SpatialDataType implements DataType {
* @return true if they are equal
*/
public
boolean
equals
(
Object
a
,
Object
b
)
{
if
(
a
==
b
)
{
return
true
;
}
else
if
(
a
==
null
||
b
==
null
)
{
return
false
;
}
long
la
=
((
SpatialKey
)
a
).
getId
();
long
lb
=
((
SpatialKey
)
b
).
getId
();
return
la
==
lb
;
...
...
h2/src/test/org/h2/test/db/TestSpatial.java
浏览文件 @
8f89554c
...
...
@@ -89,6 +89,7 @@ public class TestSpatial extends TestBase {
testScanIndexOnNonSpatialQuery
();
testStoreCorruption
();
testExplainSpatialIndexWithPk
();
testNullableGeometry
();
}
private
void
testHashCode
()
{
...
...
@@ -889,9 +890,9 @@ public class TestSpatial extends TestBase {
try
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"drop table if exists pt_cloud;"
);
stat
.
execute
(
"CREATE TABLE PT_CLOUD(id serial, the_geom geometry) AS"
+
" SELECT null, CONCAT('POINT(',A.X,' ',B.X,')')::geometry the_geom "
+
"from system_range(0,120) A,system_range(0,10) B;"
);
stat
.
execute
(
"CREATE TABLE PT_CLOUD(id serial, the_geom geometry) AS"
+
" SELECT null, CONCAT('POINT(',A.X,' ',B.X,')')::geometry the_geom "
+
"from system_range(0,120) A,system_range(0,10) B;"
);
stat
.
execute
(
"create spatial index on pt_cloud(the_geom);"
);
ResultSet
rs
=
stat
.
executeQuery
(
"explain select * from PT_CLOUD "
+
...
...
@@ -909,5 +910,23 @@ public class TestSpatial extends TestBase {
}
deleteDb
(
"spatial"
);
}
private
void
testNullableGeometry
()
throws
SQLException
{
deleteDb
(
"spatial"
);
Connection
conn
=
getConnection
(
url
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create memory table test"
+
"(id int primary key, the_geom geometry)"
);
stat
.
execute
(
"create spatial index on test(the_geom)"
);
stat
.
execute
(
"insert into test values(1, null)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertNull
(
rs
.
getObject
(
2
));
stat
.
execute
(
"drop table test"
);
conn
.
close
();
deleteDb
(
"spatial"
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论