Skip to content

Commit 1c586f1

Browse files
authored
Merge pull request duckdb#268 from mick/gdal_vsi_fix
2 parents 132d8c5 + 5e58ff7 commit 1c586f1

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

spatial/src/spatial/gdal/file_handler.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,23 @@ class DuckDBFileSystemHandler : public VSIFilesystemHandler {
164164
auto file = fs.OpenFile(file_name, flags);
165165
return new DuckDBFileHandle(std::move(file));
166166
} catch (std::exception &ex) {
167-
if (bSetError) {
168-
VSIError(VSIE_FileError, "Failed to open file %s: %s", file_name, ex.what());
167+
// Failed to open file via DuckDB File System. If this doesnt have a VSI prefix we can return an error here.
168+
if (strncmp(file_name, "/vsi", 4) != 0) {
169+
if (bSetError) {
170+
VSIError(VSIE_FileError, "Failed to open file %s: %s", file_name, ex.what());
171+
}
172+
return nullptr;
169173
}
170-
return nullptr;
171174
}
175+
176+
VSIFilesystemHandler *poFSHandler =
177+
VSIFileManager::GetHandler(file_name);
178+
179+
VSIVirtualHandle *poVirtualHandle =
180+
poFSHandler->Open(file_name, access);
181+
182+
return poVirtualHandle;
183+
172184
}
173185

174186
int Stat(const char *prefixed_file_name, VSIStatBufL *pstatbuf, int n_flags) override {
6.37 KB
Binary file not shown.

test/sql/gdal/gdal_vsi.test

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require spatial
2+
3+
# Test read via VSI
4+
query I
5+
SELECT COUNT(*) FROM st_read('/vsigzip/__WORKING_DIRECTORY__/test/data/amsterdam_roads_50.geojson.gz');
6+
----
7+
50

0 commit comments

Comments
 (0)