Skip to content

Commit c59f064

Browse files
authored
Merge pull request duckdb#271 from Maxxen/dev
Misc Fixes
2 parents 09e8781 + 64d0e18 commit c59f064

File tree

13 files changed

+298
-195
lines changed

13 files changed

+298
-195
lines changed

.github/workflows/MainDistributionPipeline.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ concurrency:
2424
jobs:
2525
duckdb-stable-build:
2626
name: Build extension binaries
27-
uses: duckdb/duckdb/.github/workflows/_extension_distribution.yml@3fbbd15390059b8028ad6dfd56a3172e5ebc0ab8
27+
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main
2828
with:
29-
vcpkg_commit: a42af01b72c28a8e1d7b48107b33e4f286a55ef6
3029
duckdb_version: main
3130
extension_name: spatial
3231

3332
duckdb-stable-deploy:
3433
name: Deploy extension binaries
3534
needs: duckdb-stable-build
36-
uses: duckdb/duckdb/.github/workflows/_extension_deploy.yml@3fbbd15390059b8028ad6dfd56a3172e5ebc0ab8
35+
uses: duckdb/extension-ci-tools/.github/workflows/_extension_deploy.yml@main
3736
secrets: inherit
3837
with:
3938
duckdb_version: main

.github/workflows/StableDistributionPipeline.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ concurrency:
2424
jobs:
2525
duckdb-stable-build:
2626
name: Build extension binaries
27-
uses: duckdb/duckdb/.github/workflows/_extension_distribution.yml@3fbbd15390059b8028ad6dfd56a3172e5ebc0ab8
27+
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@v0.10.0
2828
with:
29-
vcpkg_commit: a42af01b72c28a8e1d7b48107b33e4f286a55ef6
3029
duckdb_version: v0.10.0
3130
extension_name: spatial
3231

3332
duckdb-stable-deploy:
3433
name: Deploy extension binaries
3534
needs: duckdb-stable-build
36-
uses: duckdb/duckdb/.github/workflows/_extension_deploy.yml@3fbbd15390059b8028ad6dfd56a3172e5ebc0ab8
35+
uses: duckdb/extension-ci-tools/.github/workflows/_extension_deploy.yml@v0.10.0
3736
secrets: inherit
3837
with:
3938
duckdb_version: v0.10.0

CMakeLists.txt

+32-30
Original file line numberDiff line numberDiff line change
@@ -39,39 +39,41 @@ add_library(${EXTENSION_NAME} STATIC ${EXTENSION_SOURCES})
3939
# link to their own dependencies if they are building locally. If they have a
4040
# local (compatible) GDAL installation, we should use that instead of building
4141
# our own. (unless a static build is requested)
42-
execute_process(
43-
# Generate project
44-
COMMAND
45-
${CMAKE_COMMAND} -G ${CMAKE_GENERATOR}
46-
-DDUCKDB_ENABLE_DEPRECATED_API=1
47-
-DWASM_LOADABLE_EXTENSIONS=1
48-
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
49-
-DOSX_BUILD_ARCH=${OSX_BUILD_ARCH}
50-
-DSPATIAL_USE_NETWORK=${SPATIAL_USE_NETWORK}
51-
-DOPENSSL_ROOT_DIR=$ENV{OPENSSL_ROOT_DIR}
52-
-DVCPKG_MANIFEST_DIR='${VCPKG_MANIFEST_DIR}'
53-
-DVCPKG_INSTALLED_DIR='${CMAKE_BINARY_DIR}/vcpkg_installed'
54-
-DCMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'
55-
-DVCPKG_TARGET_TRIPLET='${VCPKG_TARGET_TRIPLET}'
56-
-S ${CMAKE_CURRENT_SOURCE_DIR}/deps -B ${CMAKE_BINARY_DIR}/deps
57-
RESULT_VARIABLE DEPENDENCIES_GENERATE_RESULT)
58-
if(NOT DEPENDENCIES_GENERATE_RESULT EQUAL 0)
59-
message(FATAL_ERROR "Could not generate dependencies project")
60-
endif()
61-
execute_process(
62-
# Build project
63-
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/deps --config
64-
${CMAKE_BUILD_TYPE} RESULT_VARIABLE DEPENDENCIES_BUILD_RESULT)
65-
if(NOT DEPENDENCIES_BUILD_RESULT EQUAL 0)
66-
message(FATAL_ERROR "Could not build dependencies project")
42+
43+
if(NOT EXISTS ${CMAKE_BINARY_DIR}/deps)
44+
execute_process(
45+
# Generate project
46+
COMMAND
47+
${CMAKE_COMMAND} -G ${CMAKE_GENERATOR}
48+
-DDUCKDB_ENABLE_DEPRECATED_API=1
49+
-DWASM_LOADABLE_EXTENSIONS=1
50+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
51+
-DOSX_BUILD_ARCH=${OSX_BUILD_ARCH}
52+
-DSPATIAL_USE_NETWORK=${SPATIAL_USE_NETWORK}
53+
-DOPENSSL_ROOT_DIR=$ENV{OPENSSL_ROOT_DIR}
54+
-DVCPKG_MANIFEST_DIR='${VCPKG_MANIFEST_DIR}'
55+
-DVCPKG_INSTALLED_DIR='${CMAKE_BINARY_DIR}/vcpkg_installed'
56+
-DCMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'
57+
-DVCPKG_TARGET_TRIPLET='${VCPKG_TARGET_TRIPLET}'
58+
-S ${CMAKE_CURRENT_SOURCE_DIR}/deps -B ${CMAKE_BINARY_DIR}/deps
59+
RESULT_VARIABLE DEPENDENCIES_GENERATE_RESULT)
60+
if(NOT DEPENDENCIES_GENERATE_RESULT EQUAL 0)
61+
message(FATAL_ERROR "Could not generate dependencies project")
62+
endif()
63+
64+
execute_process(
65+
# Build project
66+
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/deps --config
67+
${CMAKE_BUILD_TYPE} RESULT_VARIABLE DEPENDENCIES_BUILD_RESULT)
68+
if(NOT DEPENDENCIES_BUILD_RESULT EQUAL 0)
69+
message(FATAL_ERROR "Could not build dependencies project")
70+
endif()
6771
endif()
6872

69-
# Add dependencies
70-
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}
71-
${CMAKE_BINARY_DIR}/deps/local)
72-
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} MD.lib
73-
)# annoyingly for expat on windows
73+
# annoyingly for expat on windows
74+
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} MD.lib)
7475

76+
# Add dependencies
7577
list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_BINARY_DIR}/deps/local/")
7678
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/deps/local/")
7779

docs/src/functions/scalar/st_buffer.md

+42-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,35 @@
3333
"type": "INTEGER"
3434
}
3535
]
36+
},
37+
{
38+
"returns": "GEOMETRY",
39+
"parameters": [
40+
{
41+
"name": "geom",
42+
"type": "GEOMETRY"
43+
},
44+
{
45+
"name": "distance",
46+
"type": "DOUBLE"
47+
},
48+
{
49+
"name": "num_triangles",
50+
"type": "INTEGER"
51+
},
52+
{
53+
"name": "cap_style",
54+
"type": "STRING"
55+
}
56+
{
57+
"name": "join_style",
58+
"type": "STRING"
59+
}
60+
{
61+
"name": "mitre_limit",
62+
"type": "DOUBLE"
63+
}
64+
]
3665
}
3766
],
3867
"summary": "Returns a buffer around the input geometry at the target distance"
@@ -41,7 +70,19 @@
4170

4271
### Description
4372

44-
TODO
73+
`geom` is the input geometry.
74+
75+
`distance` is the target distance for the buffer, using the same units as the input geometry.
76+
77+
`num_triangles` represents how many triangles that will be produced to approximate a quarter circle. The larger the number, the smoother the resulting geometry. The default value is 8.
78+
79+
`join_style` must be one of "JOIN_ROUND", "JOIN_MITRE", "JOIN_BEVEL". This parameter is case-insensitive.
80+
81+
`cap_style` must be one of "CAP_ROUND", "CAP_FLAT", "CAP_SQUARE". This parameter is case-insensitive.
82+
83+
`mite_limit` only applies when `join_style` is "JOIN_MITRE". It is the ratio of the distance from the corner to the miter point to the corner radius. The default value is 1.0.
84+
85+
This is a planar operation and will not take into account the curvature of the earth.
4586

4687
### Examples
4788

spatial/include/spatial/core/types.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ struct GeoTypes {
1616
static LogicalType WKB_BLOB();
1717

1818
static void Register(DatabaseInstance &db);
19+
20+
static LogicalType CreateEnumType(const string &name, const vector<string> &members);
1921
};
2022

2123
enum class Side { LEFT, RIGHT, ON };

spatial/src/spatial/core/functions/scalar/st_geometrytype.cpp

+2-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "spatial/common.hpp"
33
#include "spatial/core/functions/scalar.hpp"
44
#include "spatial/core/geometry/geometry.hpp"
5-
#include "spatial/core/geometry/geometry_factory.hpp"
65
#include "spatial/core/functions/common.hpp"
76
#include "spatial/core/types.hpp"
87

@@ -14,20 +13,12 @@ static unique_ptr<FunctionData> GeometryTypeFunctionBind(ClientContext &context,
1413
vector<unique_ptr<Expression>> &arguments) {
1514
// Create an enum type for all geometry types
1615
// Ensure that these are in the same order as the GeometryType enum
17-
vector<string_t> enum_values = {"POINT", "LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING", "MULTIPOLYGON",
16+
vector<string> enum_values = {"POINT", "LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING", "MULTIPOLYGON",
1817
"GEOMETRYCOLLECTION",
1918
// or...
2019
"UNKNOWN"};
2120

22-
auto varchar_vector = Vector(LogicalType::VARCHAR, enum_values.size());
23-
auto varchar_data = FlatVector::GetData<string_t>(varchar_vector);
24-
for (idx_t i = 0; i < enum_values.size(); i++) {
25-
auto str = enum_values[i];
26-
varchar_data[i] = str.IsInlined() ? str : StringVector::AddString(varchar_vector, str);
27-
}
28-
auto enum_type = LogicalType::ENUM("GEOMETRY_TYPE", varchar_vector, enum_values.size());
29-
enum_type.SetAlias("GEOMETRY_TYPE");
30-
bound_function.return_type = enum_type;
21+
bound_function.return_type = GeoTypes::CreateEnumType("GEOMETRY_TYPE", enum_values);
3122

3223
return nullptr;
3324
}

spatial/src/spatial/core/types.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ LogicalType GeoTypes::WKB_BLOB() {
6464
return blob_type;
6565
}
6666

67+
LogicalType GeoTypes::CreateEnumType(const string &name, const vector<string> &members) {
68+
auto varchar_vector = Vector(LogicalType::VARCHAR, members.size());
69+
auto varchar_data = FlatVector::GetData<string_t>(varchar_vector);
70+
for (idx_t i = 0; i < members.size(); i++) {
71+
auto str = string_t(members[i]);
72+
varchar_data[i] = str.IsInlined() ? str : StringVector::AddString(varchar_vector, str);
73+
}
74+
auto enum_type = LogicalType::ENUM(name, varchar_vector, members.size());
75+
enum_type.SetAlias(name);
76+
return enum_type;
77+
}
78+
6779
void GeoTypes::Register(DatabaseInstance &db) {
6880

6981
// POINT_2D

spatial/src/spatial/gdal/file_handler.cpp

+24-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class DuckDBFileHandle : public VSIVirtualHandle {
2929
return static_cast<vsi_l_offset>(file_handle->SeekPosition());
3030
}
3131
int Seek(vsi_l_offset nOffset, int nWhence) override {
32+
if(nWhence == SEEK_SET && nOffset == 0) {
33+
// Use the reset function instead to allow compressed file handles to rewind
34+
// even if they don't support seeking
35+
file_handle->Reset();
36+
return 0;
37+
}
3238
switch (nWhence) {
3339
case SEEK_SET:
3440
file_handle->Seek(nOffset);
@@ -161,13 +167,26 @@ class DuckDBFileSystemHandler : public VSIFilesystemHandler {
161167
return new DuckDBFileHandle(std::move(file));
162168
}
163169
#endif
164-
auto file = fs.OpenFile(file_name, flags);
170+
auto file = fs.OpenFile(file_name, flags, FileSystem::DEFAULT_LOCK, FileCompressionType::AUTO_DETECT);
165171
return new DuckDBFileHandle(std::move(file));
166172
} catch (std::exception &ex) {
167-
if (bSetError) {
168-
VSIError(VSIE_FileError, "Failed to open file %s: %s", file_name, ex.what());
173+
// Failed to open file via DuckDB File System. If this doesnt have a VSI prefix we can return an error here.
174+
if (strncmp(file_name, "/vsi", 4) != 0) {
175+
if (bSetError) {
176+
VSIError(VSIE_FileError, "Failed to open file %s: %s", file_name, ex.what());
177+
}
178+
return nullptr;
169179
}
170-
return nullptr;
180+
// Fall back to GDAL instead
181+
auto handler = VSIFileManager::GetHandler(file_name);
182+
if(handler) {
183+
return handler->Open(file_name, access);
184+
} else {
185+
if (bSetError) {
186+
VSIError(VSIE_FileError, "Failed to open file %s: %s", file_name, ex.what());
187+
}
188+
return nullptr;
189+
}
171190
}
172191
}
173192

@@ -190,7 +209,7 @@ class DuckDBFileSystemHandler : public VSIFilesystemHandler {
190209

191210
unique_ptr<FileHandle> file;
192211
try {
193-
file = fs.OpenFile(file_name, FileFlags::FILE_FLAGS_READ);
212+
file = fs.OpenFile(file_name, FileFlags::FILE_FLAGS_READ, FileSystem::DEFAULT_LOCK, FileCompressionType::AUTO_DETECT);
194213
} catch (std::exception &ex) {
195214
return -1;
196215
}

0 commit comments

Comments
 (0)