Skip to content

Commit 592bda4

Browse files
authored
Merge pull request duckdb#280 from Maxxen/dev
Support geometries with Z and M values
2 parents c59f064 + a248a47 commit 592bda4

File tree

125 files changed

+5488
-3367
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+5488
-3367
lines changed

spatial/include/spatial/common.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "duckdb.hpp"
4+
#include "duckdb/common/typedefs.hpp"
45
#include "duckdb/common/helper.hpp"
56
#include "duckdb/main/extension_util.hpp"
67

spatial/include/spatial/core/functions/cast.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct CoreVectorOperations {
1313
static void LineString2DToVarchar(Vector &source, Vector &result, idx_t count);
1414
static void Polygon2DToVarchar(Vector &source, Vector &result, idx_t count);
1515
static void Box2DToVarchar(Vector &source, Vector &result, idx_t count);
16-
static void GeometryToVarchar(Vector &source, Vector &result, idx_t count, GeometryFactory &factory);
16+
static void GeometryToVarchar(Vector &source, Vector &result, idx_t count);
1717
};
1818

1919
struct CoreCastFunctions {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
#include "spatial/common.hpp"
3+
#include "spatial/core/geometry/geometry.hpp"
4+
5+
namespace spatial {
6+
7+
namespace core {
8+
9+
struct CoreScalarMacros {
10+
public:
11+
static void Register(DatabaseInstance &db);
12+
};
13+
14+
} // namespace core
15+
16+
} // namespace spatial

spatial/include/spatial/core/functions/scalar.hpp

+32
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ struct CoreScalarFunctions {
2424
RegisterStExtent(db);
2525
RegisterStExteriorRing(db);
2626
RegisterStFlipCoordinates(db);
27+
RegisterStForce(db);
2728
RegisterStGeometryType(db);
2829
RegisterStGeomFromHEXWKB(db);
30+
RegisterStGeomFromText(db);
2931
RegisterStGeomFromWKB(db);
3032
RegisterStIntersects(db);
3133
RegisterStIntersectsExtent(db);
@@ -49,6 +51,12 @@ struct CoreScalarFunctions {
4951
RegisterStY(db);
5052
RegisterStYMax(db);
5153
RegisterStYMin(db);
54+
RegisterStZ(db);
55+
RegisterStZMax(db);
56+
RegisterStZMin(db);
57+
RegisterStM(db);
58+
RegisterStMMax(db);
59+
RegisterStMMin(db);
5260
}
5361

5462
private:
@@ -100,12 +108,18 @@ struct CoreScalarFunctions {
100108
// ST_FlipCoordinates
101109
static void RegisterStFlipCoordinates(DatabaseInstance &db);
102110

111+
// ST_Force(2D/3D)
112+
static void RegisterStForce(DatabaseInstance &db);
113+
103114
// ST_GeometryType
104115
static void RegisterStGeometryType(DatabaseInstance &db);
105116

106117
// ST_GeomFromHEXWKB
107118
static void RegisterStGeomFromHEXWKB(DatabaseInstance &db);
108119

120+
// ST_GeomFromText
121+
static void RegisterStGeomFromText(DatabaseInstance &db);
122+
109123
// ST_GeomFromWKB
110124
static void RegisterStGeomFromWKB(DatabaseInstance &db);
111125

@@ -174,6 +188,24 @@ struct CoreScalarFunctions {
174188

175189
// ST_YMin
176190
static void RegisterStYMin(DatabaseInstance &db);
191+
192+
// ST_Z
193+
static void RegisterStZ(DatabaseInstance &db);
194+
195+
// ST_ZMax
196+
static void RegisterStZMax(DatabaseInstance &db);
197+
198+
// ST_ZMin
199+
static void RegisterStZMin(DatabaseInstance &db);
200+
201+
// ST_M
202+
static void RegisterStM(DatabaseInstance &db);
203+
204+
// ST_MMax
205+
static void RegisterStMMax(DatabaseInstance &db);
206+
207+
// ST_MMin
208+
static void RegisterStMMin(DatabaseInstance &db);
177209
};
178210

179211
} // namespace core

spatial/include/spatial/core/functions/table.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ struct CoreTableFunctions {
1313
// TODO: Move these
1414
RegisterShapefileTableFunction(db);
1515
RegisterShapefileMetaTableFunction(db);
16+
RegisterTestTableFunctions(db);
1617
}
1718

1819
private:
1920
static void RegisterOsmTableFunction(DatabaseInstance &db);
2021
static void RegisterShapefileTableFunction(DatabaseInstance &db);
2122
static void RegisterShapefileMetaTableFunction(DatabaseInstance &db);
23+
static void RegisterTestTableFunctions(DatabaseInstance &db);
2224
};
2325

2426
} // namespace core

spatial/include/spatial/core/geometry/cursor.hpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace spatial {
55

66
namespace core {
77

8+
// TODO: Split this into a read and write cursor. Get rid of bounds checks in release mode
89
class Cursor {
910
private:
1011
data_ptr_t start;
@@ -17,13 +18,21 @@ class Cursor {
1718
explicit Cursor(data_ptr_t start, data_ptr_t end) : start(start), ptr(start), end(end) {
1819
}
1920

20-
explicit Cursor(string_t blob) : start((data_ptr_t)blob.GetDataUnsafe()), ptr(start), end(start + blob.GetSize()) {
21+
// Be really careful with passing string_ts here, if we accidentally copy we may end up writing to the inlined data
22+
// of a temporary
23+
explicit Cursor(const string_t &blob)
24+
: start((data_ptr_t)blob.GetDataWriteable()), ptr(start), end(start + blob.GetSize()) {
2125
}
2226

2327
data_ptr_t GetPtr() {
2428
return ptr;
2529
}
2630

31+
uint32_t Remaining() {
32+
D_ASSERT(ptr <= end);
33+
return end - ptr;
34+
}
35+
2736
void SetPtr(data_ptr_t ptr_p) {
2837
if (ptr_p < start || ptr_p > end) {
2938
throw SerializationException("Trying to set ptr outside of buffer");
@@ -61,6 +70,12 @@ class Cursor {
6170
return Load<T>(ptr);
6271
}
6372

73+
template <class T>
74+
void Skip() {
75+
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable");
76+
Skip(sizeof(T));
77+
}
78+
6479
void Skip(uint32_t bytes) {
6580
if (ptr + bytes > end) {
6681
throw SerializationException("Trying to read past end of buffer");

0 commit comments

Comments
 (0)