Skip to content

Commit f763b92

Browse files
committed
fix improper use of data vector without indirection
1 parent 1e701fd commit f763b92

File tree

4 files changed

+58
-20
lines changed

4 files changed

+58
-20
lines changed

src/h3_hierarchy.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,18 @@ static void CellToChildrenFunction(DataChunk &args, ExpressionState &state,
9292
static void CellToChildrenVarcharFunction(DataChunk &args,
9393
ExpressionState &state,
9494
Vector &result) {
95-
UnifiedVectorFormat vdata;
96-
args.data[0].ToUnifiedFormat(args.size(), vdata);
97-
auto ldata = UnifiedVectorFormat::GetData<string_t>(vdata);
98-
9995
auto result_data = FlatVector::GetData<list_entry_t>(result);
10096
for (idx_t i = 0; i < args.size(); i++) {
10197
result_data[i].offset = ListVector::GetListSize(result);
10298

103-
string_t parentStr = ldata[i];
99+
string parentStr = args.GetValue(0, i)
100+
.DefaultCastAs(LogicalType::VARCHAR)
101+
.GetValue<string>();
104102
int32_t res = args.GetValue(1, i)
105103
.DefaultCastAs(LogicalType::INTEGER)
106104
.GetValue<int32_t>();
107105
H3Index parent;
108-
H3Error err0 = stringToH3(parentStr.GetString().c_str(), &parent);
106+
H3Error err0 = stringToH3(parentStr.c_str(), &parent);
109107
if (err0) {
110108
result.SetValue(i, Value(LogicalType::SQLNULL));
111109
} else {

src/h3_indexing.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,16 @@ static void CellToLatLngFunction(DataChunk &args, ExpressionState &state,
156156

157157
static void CellToLatLngVarcharFunction(DataChunk &args, ExpressionState &state,
158158
Vector &result) {
159-
UnifiedVectorFormat vdata;
160-
args.data[0].ToUnifiedFormat(args.size(), vdata);
161-
162-
auto ldata = UnifiedVectorFormat::GetData<string_t>(vdata);
163-
164159
result.SetVectorType(VectorType::FLAT_VECTOR);
165160
auto result_data = FlatVector::GetData<list_entry_t>(result);
166161
for (idx_t i = 0; i < args.size(); i++) {
167162
result_data[i].offset = ListVector::GetListSize(result);
168163

169-
string_t cellAddress = ldata[i];
164+
string cellAddress = args.GetValue(0, i)
165+
.DefaultCastAs(LogicalType::VARCHAR)
166+
.GetValue<string>();
170167
H3Index cell;
171-
H3Error err0 = stringToH3(cellAddress.GetString().c_str(), &cell);
168+
H3Error err0 = stringToH3(cellAddress.c_str(), &cell);
172169
if (err0) {
173170
result.SetValue(i, Value(LogicalType::SQLNULL));
174171
} else {

src/h3_inspection.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,21 +272,18 @@ static void GetIcosahedronFacesFunction(DataChunk &args, ExpressionState &state,
272272
static void GetIcosahedronFacesVarcharFunction(DataChunk &args,
273273
ExpressionState &state,
274274
Vector &result) {
275-
UnifiedVectorFormat vdata;
276-
args.data[0].ToUnifiedFormat(args.size(), vdata);
277-
278-
auto ldata = UnifiedVectorFormat::GetData<string_t>(vdata);
279-
280275
result.SetVectorType(VectorType::FLAT_VECTOR);
281276
auto result_data = FlatVector::GetData<list_entry_t>(result);
282277
for (idx_t i = 0; i < args.size(); i++) {
283278
result_data[i].offset = ListVector::GetListSize(result);
284279

285280
int faceCount;
286281
int64_t actual = 0;
287-
string_t cellAddress = ldata[i];
282+
string cellAddress = args.GetValue(0, i)
283+
.DefaultCastAs(LogicalType::VARCHAR)
284+
.GetValue<string>();
288285
H3Index cell;
289-
H3Error err0 = stringToH3(cellAddress.GetString().c_str(), &cell);
286+
H3Error err0 = stringToH3(cellAddress.c_str(), &cell);
290287
if (err0) {
291288
result.SetValue(i, Value(LogicalType::SQLNULL));
292289
} else {

test/sql/h3/h3_json.test

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# name: test/sql/h3/h3_json.test
2+
# group: [h3]
3+
4+
statement ok
5+
install json
6+
7+
statement ok
8+
load json
9+
10+
require h3
11+
12+
statement ok
13+
create table cells as (
14+
select unnest(cells) as cell
15+
from 'test/data/cell_order.json'
16+
);
17+
18+
query I
19+
select h3_cell_to_children(cell, 6) from cells where cell = '85283083fffffff';
20+
----
21+
[862830807ffffff, 86283080fffffff, 862830817ffffff, 86283081fffffff, 862830827ffffff, 86283082fffffff, 862830837ffffff]
22+
23+
query I
24+
select h3_cell_to_children(cell, 6) from cells where cell = '85283097fffffff';
25+
----
26+
[862830947ffffff, 86283094fffffff, 862830957ffffff, 86283095fffffff, 862830967ffffff, 86283096fffffff, 862830977ffffff]
27+
28+
query I
29+
SELECT list_transform(h3_cell_to_latlng(cell), x-> round(x, 12)) from cells where cell = '85283083fffffff';
30+
----
31+
[37.790261155804, -122.345478597884]
32+
33+
query I
34+
SELECT list_transform(h3_cell_to_latlng(cell), x-> round(x, 12)) from cells where cell = '85283097fffffff';
35+
----
36+
[37.699065685397, -122.51211811448]
37+
38+
query I
39+
select h3_get_icosahedron_faces(cell) from cells where cell = '85283083fffffff';
40+
----
41+
[7]
42+
43+
query I
44+
select h3_get_icosahedron_faces(cell) from cells where cell = '85d02903fffffff';
45+
----
46+
[13]

0 commit comments

Comments
 (0)