Skip to content

Commit 9dfa61e

Browse files
committed
Replace add_row() by insert() in tests
As preparation for the removal of the add_row() function.
1 parent c7578ac commit 9dfa61e

File tree

7 files changed

+105
-84
lines changed

7 files changed

+105
-84
lines changed

tests/data/test_output_flex.lua

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local tables = {}
33

44
tables.point = osm2pgsql.define_node_table('osm2pgsql_test_point', {
55
{ column = 'tags', type = 'hstore' },
6-
{ column = 'geom', type = 'point' },
6+
{ column = 'geom', type = 'point', not_null = true },
77
})
88

99
tables.line = osm2pgsql.define_table{
@@ -12,7 +12,7 @@ tables.line = osm2pgsql.define_table{
1212
columns = {
1313
{ column = 'tags', type = 'hstore' },
1414
{ column = 'name', type = 'text' },
15-
{ column = 'geom', type = 'linestring' },
15+
{ column = 'geom', type = 'linestring', not_null = true },
1616
},
1717
cluster = 'auto'
1818
}
@@ -23,8 +23,8 @@ tables.polygon = osm2pgsql.define_table{
2323
columns = {
2424
{ column = 'tags', type = 'hstore' },
2525
{ column = 'name', type = 'text' },
26-
{ column = 'geom', type = 'geometry' },
27-
{ column = 'area', type = 'area' },
26+
{ column = 'geom', type = 'geometry', not_null = true },
27+
{ column = 'area', type = 'real' },
2828
}
2929
}
3030

@@ -33,7 +33,7 @@ tables.route = osm2pgsql.define_table{
3333
ids = { type = 'relation', id_column = 'osm_id' },
3434
columns = {
3535
{ column = 'tags', type = 'hstore' },
36-
{ column = 'geom', type = 'multilinestring' },
36+
{ column = 'geom', type = 'multilinestring', not_null = true },
3737
}
3838
}
3939

@@ -85,8 +85,9 @@ function osm2pgsql.process_node(object)
8585
return
8686
end
8787

88-
tables.point:add_row({
89-
tags = object.tags
88+
tables.point:insert({
89+
tags = object.tags,
90+
geom = object:as_point()
9091
})
9192
end
9293

@@ -96,15 +97,18 @@ function osm2pgsql.process_way(object)
9697
end
9798

9899
if is_polygon(object.tags) then
99-
tables.polygon:add_row({
100+
local geom = object:as_polygon()
101+
tables.polygon:insert({
100102
tags = object.tags,
101103
name = object.tags.name,
102-
geom = { create = 'area' }
104+
geom = geom,
105+
area = geom:area()
103106
})
104107
else
105-
tables.line:add_row({
108+
tables.line:insert({
106109
tags = object.tags,
107-
name = object.tags.name
110+
name = object.tags.name,
111+
geom = object:as_linestring()
108112
})
109113
end
110114
end
@@ -115,18 +119,22 @@ function osm2pgsql.process_relation(object)
115119
end
116120

117121
if object.tags.type == 'multipolygon' or object.tags.type == 'boundary' then
118-
tables.polygon:add_row({
119-
tags = object.tags,
120-
name = object.tags.name,
121-
geom = { create = 'area', split_at = 'multi' }
122-
})
122+
local mgeom = object:as_multipolygon()
123+
for sgeom in mgeom:geometries() do
124+
tables.polygon:insert({
125+
tags = object.tags,
126+
name = object.tags.name,
127+
geom = sgeom,
128+
area = sgeom:area()
129+
})
130+
end
123131
return
124132
end
125133

126134
if object.tags.type == 'route' then
127-
tables.route:add_row({
135+
tables.route:insert({
128136
tags = object.tags,
129-
geom = { create = 'line' }
137+
geom = object:as_multilinestring()
130138
})
131139
end
132140
end

tests/data/test_output_flex_copy.lua

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local tables = {}
33

44
tables.point = osm2pgsql.define_node_table('osm2pgsql_test_point', {
55
{ column = 'tags', type = 'hstore' },
6-
{ column = 'geom', type = 'point' },
6+
{ column = 'geom', type = 'point', not_null = true },
77
})
88

99
tables.line = osm2pgsql.define_table{
@@ -12,7 +12,7 @@ tables.line = osm2pgsql.define_table{
1212
columns = {
1313
{ column = 'tags', type = 'hstore' },
1414
{ column = 'name', type = 'text' },
15-
{ column = 'geom', type = 'linestring' },
15+
{ column = 'geom', type = 'linestring', not_null = true },
1616
},
1717
cluster = 'auto'
1818
}
@@ -23,8 +23,8 @@ tables.polygon = osm2pgsql.define_table{
2323
columns = {
2424
{ column = 'tags', type = 'hstore' },
2525
{ column = 'name', type = 'text' },
26-
{ column = 'geom', type = 'geometry' },
27-
{ column = 'area', type = 'area' },
26+
{ column = 'geom', type = 'geometry', not_null = true },
27+
{ column = 'area', type = 'real' },
2828
}
2929
}
3030

@@ -33,7 +33,7 @@ tables.route = osm2pgsql.define_table{
3333
ids = { type = 'relation', id_column = 'osm_id' },
3434
columns = {
3535
{ column = 'tags', type = 'hstore' },
36-
{ column = 'geom', type = 'multilinestring' },
36+
{ column = 'geom', type = 'multilinestring', not_null = true },
3737
}
3838
}
3939

@@ -85,8 +85,9 @@ function osm2pgsql.process_node(object)
8585
return
8686
end
8787

88-
tables.point:add_row({
89-
tags = object.tags
88+
tables.point:insert({
89+
tags = object.tags,
90+
geom = object:as_point()
9091
})
9192
end
9293

@@ -96,15 +97,18 @@ function osm2pgsql.process_way(object)
9697
end
9798

9899
if is_polygon(object.tags) then
99-
tables.polygon:add_row({
100+
local geom = object:as_polygon()
101+
tables.polygon:insert({
100102
tags = object.tags,
101103
name = object.tags.name,
102-
geom = { create = 'area' }
104+
geom = geom,
105+
area = geom:area()
103106
})
104107
else
105-
tables.line:add_row({
108+
tables.line:insert({
106109
tags = object.tags,
107-
name = object.tags.name
110+
name = object.tags.name,
111+
geom = object:as_linestring()
108112
})
109113
end
110114
end
@@ -115,18 +119,22 @@ function osm2pgsql.process_relation(object)
115119
end
116120

117121
if object.tags.type == 'multipolygon' or object.tags.type == 'boundary' then
118-
tables.polygon:add_row({
119-
tags = object.tags,
120-
name = object.tags.name,
121-
geom = { create = 'area', split_at = 'multi' }
122-
})
122+
local mgeom = object:as_multipolygon()
123+
for sgeom in mgeom:geometries() do
124+
tables.polygon:insert({
125+
tags = object.tags,
126+
name = object.tags.name,
127+
geom = sgeom,
128+
area = sgeom:area()
129+
})
130+
end
123131
return
124132
end
125133

126134
if object.tags.type == 'route' then
127-
tables.route:add_row({
135+
tables.route:insert({
128136
tags = object.tags,
129-
geom = { create = 'line' }
137+
geom = object:as_multilinestring()
130138
})
131139
end
132140
end

tests/data/test_output_flex_stage2.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tables.highways = osm2pgsql.define_table{
77
columns = {
88
{ column = 'tags', type = 'hstore' },
99
{ column = 'refs', type = 'text' },
10-
{ column = 'geom', type = 'linestring', projection = 4326 },
10+
{ column = 'geom', type = 'linestring', projection = 4326, not_null = true },
1111
}
1212
}
1313

@@ -17,7 +17,7 @@ tables.routes = osm2pgsql.define_table{
1717
columns = {
1818
{ column = 'tags', type = 'hstore' },
1919
{ column = 'members', type = 'text' },
20-
{ column = 'geom', type = 'multilinestring', projection = 4326 },
20+
{ column = 'geom', type = 'multilinestring', projection = 4326, not_null = true },
2121
}
2222
}
2323

@@ -26,7 +26,7 @@ local w2r = {}
2626
function osm2pgsql.process_way(object)
2727
local row = {
2828
tags = object.tags,
29-
geom = { create = 'line' }
29+
geom = object:as_linestring()
3030
}
3131

3232
local d = w2r[object.id]
@@ -40,7 +40,7 @@ function osm2pgsql.process_way(object)
4040
row.refs = table.concat(refs, ',')
4141
end
4242

43-
tables.highways:add_row(row)
43+
tables.highways:insert(row)
4444
end
4545

4646
function osm2pgsql.select_relation_members(relation)
@@ -65,10 +65,10 @@ function osm2pgsql.process_relation(object)
6565
end
6666
end
6767

68-
tables.routes:add_row({
68+
tables.routes:insert({
6969
tags = object.tags,
7070
members = table.concat(mlist, ','),
71-
geom = { create = 'line' }
71+
geom = object:as_multilinestring()
7272
})
7373
end
7474

tests/data/test_output_flex_stage2_alt.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function osm2pgsql.process_way(object)
3030

3131
local row = {
3232
tags = object.tags,
33-
geom = { create = 'line' }
33+
geom = object:as_linestring()
3434
}
3535

3636
local d = w2r[object.id]
@@ -44,7 +44,7 @@ function osm2pgsql.process_way(object)
4444
row.refs = table.concat(refs, ',')
4545
end
4646

47-
tables.highways:add_row(row)
47+
tables.highways:insert(row)
4848
end
4949

5050
function osm2pgsql.select_relation_members(relation)
@@ -69,10 +69,10 @@ function osm2pgsql.process_relation(object)
6969
end
7070
end
7171

72-
tables.routes:add_row({
72+
tables.routes:insert({
7373
tags = object.tags,
7474
members = table.concat(mlist, ','),
75-
geom = { create = 'line' }
75+
geom = object:as_multilinestring()
7676
})
7777
end
7878

tests/data/test_output_flex_uni.lua

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local table1idcol = osm2pgsql.define_table{
66
columns = {
77
{ column = 'orig_id', type = 'int8' },
88
{ column = 'tags', type = 'hstore' },
9-
{ column = 'geom', type = 'geometry' },
9+
{ column = 'geom', type = 'geometry', not_null = true },
1010
}
1111
}
1212

@@ -16,7 +16,7 @@ local table2idcol = osm2pgsql.define_table{
1616
ids = { type = 'any', type_column = 'x_type', id_column = 'x_id' },
1717
columns = {
1818
{ column = 'tags', type = 'hstore' },
19-
{ column = 'geom', type = 'geometry' },
19+
{ column = 'geom', type = 'geometry', not_null = true },
2020
}
2121
}
2222

@@ -29,14 +29,14 @@ function osm2pgsql.process_node(object)
2929
return
3030
end
3131

32-
table1idcol:add_row({
32+
table1idcol:insert({
3333
orig_id = object.id,
3434
tags = object.tags,
35-
geom = { create = 'point' }
35+
geom = object:as_point()
3636
})
37-
table2idcol:add_row({
37+
table2idcol:insert({
3838
tags = object.tags,
39-
geom = { create = 'point' }
39+
geom = object:as_point()
4040
})
4141
end
4242

@@ -46,40 +46,42 @@ function osm2pgsql.process_way(object)
4646
end
4747

4848
if object.tags.building then
49-
table1idcol:add_row({
49+
table1idcol:insert({
5050
orig_id = object.id,
5151
tags = object.tags,
52-
geom = { create = 'area' }
52+
geom = object:as_polygon()
5353
})
54-
table2idcol:add_row({
54+
table2idcol:insert({
5555
tags = object.tags,
56-
geom = { create = 'area' }
56+
geom = object:as_polygon()
5757
})
5858
else
59-
table1idcol:add_row({
59+
table1idcol:insert({
6060
orig_id = object.id,
6161
tags = object.tags,
62-
geom = { create = 'line' }
62+
geom = object:as_linestring()
6363
})
64-
table2idcol:add_row({
64+
table2idcol:insert({
6565
tags = object.tags,
66-
geom = { create = 'line' }
66+
geom = object:as_linestring()
6767
})
6868
end
6969
end
7070

7171
function osm2pgsql.process_relation(object)
7272
if object.tags.type == 'multipolygon' then
73-
table1idcol:add_row({
74-
orig_id = object.id,
75-
tags = object.tags,
76-
geom = { create = 'area', split_at = 'multi' }
77-
})
78-
table2idcol:add_row({
79-
tags = object.tags,
80-
geom = { create = 'area', split_at = 'multi' }
81-
})
82-
return
73+
local mgeom = object:as_multipolygon()
74+
for sgeom in mgeom:geometries() do
75+
table1idcol:insert({
76+
orig_id = object.id,
77+
tags = object.tags,
78+
geom = sgeom
79+
})
80+
table2idcol:insert({
81+
tags = object.tags,
82+
geom = sgeom
83+
})
84+
end
8385
end
8486
end
8587

0 commit comments

Comments
 (0)