Skip to content

Commit 4d90608

Browse files
authored
Merge pull request #1 from MobilityDB/import-duck
Import MobilityDuck
2 parents a825e16 + 3906347 commit 4d90608

194 files changed

Lines changed: 138068 additions & 0 deletions

File tree

Some content is hidden

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

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
duckdb/.clang-format

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
duckdb/.clang-tidy

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
duckdb/.editorconfig
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#
2+
# This workflow calls the main distribution pipeline from DuckDB to build, test and (optionally) release the extension
3+
#
4+
name: Main Extension Distribution Pipeline
5+
on:
6+
pull_request:
7+
branches:
8+
- main
9+
paths-ignore:
10+
- '**/README.md'
11+
- 'doc/**'
12+
push:
13+
branches:
14+
- main
15+
paths-ignore:
16+
- '**/README.md'
17+
- 'doc/**'
18+
workflow_dispatch:
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || '' }}-${{ github.base_ref || '' }}-${{ github.ref != 'refs/heads/main' || github.sha }}
22+
cancel-in-progress: true
23+
24+
25+
jobs:
26+
duckdb-latest-build:
27+
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@v1.3.2
28+
with:
29+
duckdb_version: v1.3.2
30+
extension_name: mobilityduck
31+
ci_tools_version: v1.3.2
32+
vcpkg_commit: 6603e6392c5a1474ce2d7d0574eb774ab43a3236
33+
34+
duckdb-latest-deploy:
35+
needs: duckdb-latest-build
36+
uses: duckdb/extension-ci-tools/.github/workflows/_extension_deploy.yml@v1.3.2
37+
secrets: inherit
38+
with:
39+
duckdb_version: v1.3.2
40+
ci_tools_version: v1.3.2
41+
extension_name: mobilityduck
42+
deploy_latest: ${{ startsWith(github.ref, 'refs/heads/v') || github.ref == 'refs/heads/main' }}

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
build
2+
.idea
3+
cmake-build-debug
4+
duckdb_unittest_tempdir/
5+
.DS_Store
6+
testext
7+
test/python/__pycache__/
8+
.Rhistory
9+
vcpkg/
10+
*.log

.gitmodules

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[submodule "duckdb"]
2+
path = duckdb
3+
url = https://github.com/duckdb/duckdb
4+
branch = main
5+
[submodule "extension-ci-tools"]
6+
path = extension-ci-tools
7+
url = https://github.com/duckdb/extension-ci-tools
8+
branch = main

CMakeLists.txt

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
# -----------------------------
4+
# Project
5+
# -----------------------------
6+
set(TARGET_NAME mobilityduck)
7+
project(${TARGET_NAME} LANGUAGES C CXX)
8+
9+
set(CMAKE_CXX_STANDARD 17)
10+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
11+
12+
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/cmake" ${CMAKE_MODULE_PATH})
13+
14+
# -----------------------------
15+
# Endianness for WKB (MEOS flag)
16+
# -----------------------------
17+
include(TestBigEndian)
18+
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
19+
if(IS_BIG_ENDIAN)
20+
add_definitions(-DMEOS_IS_BIG_ENDIAN=1)
21+
else()
22+
add_definitions(-DMEOS_IS_BIG_ENDIAN=0)
23+
endif()
24+
25+
# -----------------------------
26+
# Dependencies (vcpkg)
27+
# -----------------------------
28+
find_package(GEOS CONFIG REQUIRED)
29+
find_package(PROJ CONFIG REQUIRED)
30+
find_package(GSL REQUIRED)
31+
find_package(OpenSSL REQUIRED)
32+
find_package(json-c CONFIG QUIET)
33+
if(NOT json-c_FOUND)
34+
find_package(JSON-C REQUIRED)
35+
endif()
36+
37+
# MEOS from overlay port
38+
find_package(MEOS CONFIG REQUIRED)
39+
40+
if(TARGET GEOS::geos_c)
41+
set(GEOS_TGT GEOS::geos_c)
42+
elseif(TARGET GEOS::geos)
43+
set(GEOS_TGT GEOS::geos)
44+
else()
45+
message(FATAL_ERROR "Neither GEOS::geos_c nor GEOS::geos was found.")
46+
endif()
47+
48+
# -----------------------------
49+
# DuckDB extension targets
50+
# -----------------------------
51+
set(EXTENSION_NAME ${TARGET_NAME}_extension)
52+
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
53+
54+
include_directories(src/include)
55+
56+
set(EXTENSION_SOURCES
57+
src/mobilityduck_extension.cpp
58+
src/temporal/temporal.cpp
59+
src/temporal/temporal_functions.cpp
60+
src/temporal/tbox.cpp
61+
src/temporal/tbox_functions.cpp
62+
src/geo/stbox.cpp
63+
src/geo/stbox_functions.cpp
64+
src/geo/tgeompoint.cpp
65+
src/geo/tgeompoint_functions.cpp
66+
src/temporal/set.cpp
67+
src/temporal/span.cpp
68+
src/geo/geoset.cpp
69+
src/temporal/spanset.cpp
70+
src/geo/tgeometry.cpp
71+
src/geo/tgeometry_in_out.cpp
72+
src/index/rtree_module.cpp
73+
src/index/rtree_index_create_physical.cpp
74+
src/index/rtree_index_scan.cpp
75+
src/index/rtree_optimize_scan.cpp
76+
)
77+
78+
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
79+
build_loadable_extension(${TARGET_NAME} "" ${EXTENSION_SOURCES})
80+
81+
# ----- SRID CSV defaults (works with/without vcpkg) -----
82+
if(DEFINED VCPKG_INSTALLED_DIR AND DEFINED VCPKG_TARGET_TRIPLET)
83+
target_compile_definitions(${EXTENSION_NAME} PRIVATE
84+
MDUCK_DEFAULT_SRID_CSV="${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/spatial_ref_sys.csv"
85+
MDUCK_SRID_ENV_NAME="SPATIAL_REF_SYS"
86+
)
87+
target_compile_definitions(${LOADABLE_EXTENSION_NAME} PRIVATE
88+
MDUCK_DEFAULT_SRID_CSV="${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/spatial_ref_sys.csv"
89+
MDUCK_SRID_ENV_NAME="SPATIAL_REF_SYS"
90+
)
91+
else()
92+
target_compile_definitions(${EXTENSION_NAME} PRIVATE
93+
MDUCK_DEFAULT_SRID_CSV="${CMAKE_SOURCE_DIR}/data/spatial_ref_sys.csv"
94+
MDUCK_SRID_ENV_NAME="SPATIAL_REF_SYS"
95+
)
96+
target_compile_definitions(${LOADABLE_EXTENSION_NAME} PRIVATE
97+
MDUCK_DEFAULT_SRID_CSV="${CMAKE_SOURCE_DIR}/data/spatial_ref_sys.csv"
98+
MDUCK_SRID_ENV_NAME="SPATIAL_REF_SYS"
99+
)
100+
endif()
101+
102+
103+
# -----------------------------
104+
# json-c target / include handling
105+
# -----------------------------
106+
if (TARGET json-c::json-c)
107+
set(JSONC_TGT json-c::json-c)
108+
else()
109+
target_include_directories(${EXTENSION_NAME} PRIVATE ${JSON-C_INCLUDE_DIRS})
110+
target_include_directories(${LOADABLE_EXTENSION_NAME} PRIVATE ${JSON-C_INCLUDE_DIRS})
111+
set(JSONC_TGT ${JSON-C_LIBRARIES})
112+
endif()
113+
114+
# -----------------------------
115+
# Link libraries
116+
# -----------------------------
117+
target_link_libraries(${EXTENSION_NAME}
118+
MEOS::meos
119+
${GEOS_TGT}
120+
PROJ::proj
121+
GSL::gsl
122+
GSL::gslcblas
123+
${JSONC_TGT}
124+
OpenSSL::SSL
125+
OpenSSL::Crypto
126+
)
127+
128+
target_link_libraries(${LOADABLE_EXTENSION_NAME}
129+
MEOS::meos
130+
${GEOS_TGT}
131+
PROJ::proj
132+
GSL::gsl
133+
GSL::gslcblas
134+
${JSONC_TGT}
135+
OpenSSL::SSL
136+
OpenSSL::Crypto
137+
)
138+
139+
if (WIN32)
140+
# target_link_libraries(${EXTENSION_NAME} ws2_32 crypt32)
141+
# target_link_libraries(${LOADABLE_EXTENSION_NAME} ws2_32 crypt32)
142+
endif()
143+
144+
# -----------------------------
145+
# Install (static extension)
146+
# -----------------------------
147+
install(
148+
TARGETS ${EXTENSION_NAME}
149+
EXPORT "${DUCKDB_EXPORT_SET}"
150+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
151+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
152+
)
153+
154+
install(
155+
TARGETS ${LOADABLE_EXTENSION_NAME}
156+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
157+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
158+
RUNTIME DESTINATION "${INSTALL_LIB_DIR}"
159+
)

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2018-2025 Stichting DuckDB Foundation
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PROJ_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
2+
3+
# Configuration of extension
4+
EXT_NAME=mobilityduck
5+
EXT_CONFIG=${PROJ_DIR}extension_config.cmake
6+
7+
# Include the Makefile from extension-ci-tools
8+
include extension-ci-tools/makefiles/duckdb_extension.Makefile

README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,100 @@ MobilityDuck is a binding for [DuckDB](https://duckdb.org/) built on top of MEOS
1111
The MobilityDB project is developed by the Computer & Decision Engineering Department of the [Université libre de Bruxelles](https://www.ulb.be/) (ULB) under the direction of [Prof. Esteban Zimányi](http://cs.ulb.ac.be/members/esteban/). ULB is an OGC Associate Member and member of the OGC Moving Feature Standard Working Group ([MF-SWG](https://www.ogc.org/projects/groups/movfeatswg)).
1212

1313
<img src="doc/images/OGC_Associate_Member_3DR.png" width="100" alt="OGC Associate Member Logo" />
14+
15+
This repository is based on https://github.com/duckdb/extension-template.
16+
17+
With MobilityDuck, users can use these data types and functions directly in DuckDB queries.
18+
19+
---
20+
## 1. Requirements
21+
MobilityDuck needs some dependencies(including MEOS) which can be installed through VCPKG. Run the following to enable it:
22+
23+
```sh
24+
cd <your-working-dir-not-the-plugin-repo>
25+
git clone https://github.com/Microsoft/vcpkg.git
26+
sh ./vcpkg/scripts/bootstrap.sh -disableMetrics
27+
export VCPKG_TOOLCHAIN_PATH=`pwd`/vcpkg/scripts/buildsystems/vcpkg.cmake
28+
```
29+
30+
---
31+
## 2. Building MobilityDuck
32+
### Clone the repository
33+
```sh
34+
git clone --recurse-submodules https://github.com/nhungoc1508/mobilityduck.git
35+
```
36+
Note that `--recurse-submodules` will ensure DuckDB is pulled which is required to build the extension.
37+
38+
### Build steps
39+
To build the extension, from the root directory (`mobilityduck`), run (for first build):
40+
```sh
41+
make
42+
```
43+
44+
For subsequent builds, use `ninja` for faster build relying on cache:
45+
```sh
46+
GEN=ninja make
47+
```
48+
The main binaries that will be built are:
49+
```sh
50+
./build/release/duckdb
51+
./build/release/test/unittest
52+
./build/release/extension/mobilityduck/mobilityduck.duckdb_extension
53+
```
54+
- `duckdb` is the binary for the duckdb shell with the extension code automatically loaded.
55+
- `unittest` is the test runner of duckdb. Again, the extension is already linked into the binary.
56+
- `mobilityduck.duckdb_extension` is the loadable binary as it would be distributed.
57+
58+
## 3. Running the extension
59+
To run the extension code, start the shell with `./build/release/duckdb`.
60+
61+
Now we can use the features from the extension directly in DuckDB. Some examples:
62+
```
63+
D SELECT '100@2025-01-01 10:00:00+05'::TINT as tint;
64+
┌────────────────────────────┐
65+
│ tint │
66+
│ tint │
67+
├────────────────────────────┤
68+
│ 100@2025-01-01 05:00:00+00 │
69+
└────────────────────────────┘
70+
71+
D SELECT duration('{1@2000-01-01, 2@2000-01-02, 1@2000-01-03}'::TINT, true) as duration;
72+
┌──────────┐
73+
│ duration │
74+
│ interval │
75+
├──────────┤
76+
│ 2 days │
77+
└──────────┘
78+
79+
D SELECT tstzspan('[2000-01-01,2000-01-01]') as ts_span;
80+
┌──────────────────────────────────────────────────┐
81+
│ ts_span │
82+
│ span │
83+
├──────────────────────────────────────────────────┤
84+
│ [2000-01-01 00:00:00+00, 2000-01-02 00:00:00+00) │
85+
└──────────────────────────────────────────────────┘
86+
87+
D SELECT timeSpan(tgeompoint('{Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03}')) as span;
88+
┌──────────────────────────────────────────────────┐
89+
│ span │
90+
│ span │
91+
├──────────────────────────────────────────────────┤
92+
│ [2000-01-01 00:00:00+00, 2000-01-03 00:00:00+00] │
93+
└──────────────────────────────────────────────────┘
94+
95+
D SELECT * FROM setUnnest(textset('{"highway", "car", "bike"}'));
96+
┌─────────┐
97+
│ unnest │
98+
│ varchar │
99+
├─────────┤
100+
│ bike │
101+
│ car │
102+
│ highway │
103+
└─────────┘
104+
```
105+
106+
## 4. Running the tests
107+
Test files are located in `./test/sql`. These SQL tests can be run using:
108+
```sh
109+
make test
110+
```

0 commit comments

Comments
 (0)