Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: examples

on:
pull_request:
branches:
- main
paths:
- 'Cargo.toml'
- 'Cargo.lock'
- '.github/workflows/rust.yml'
- 'rust/**'
- 'c/**'
- 'examples/**'
push:
branches:
- main

concurrency:
group: ${{ github.repository }}-${{ github.ref }}-${{ github.workflow }}-rust
cancel-in-progress: true

permissions:
contents: read

defaults:
run:
shell: bash -l -eo pipefail {0}

env:
# At GEOS updated to 3.14.0
VCPKG_REF: 5a01de756c28279ddfdd2b061d1c75710a6255fa

jobs:
rust:
strategy:
fail-fast: false

runs-on: ubuntu-latest
env:
CARGO_INCREMENTAL: 0

steps:
- uses: actions/checkout@v4
- name: Use stable Rust
id: rust
run: |
rustup toolchain install stable --no-self-update
rustup default stable

- uses: Swatinem/rust-cache@v2
with:
# Update this key to force a new cache
prefix-key: "rust-${{ matrix.name }}-v4"

- name: Install dependencies
shell: bash
run: |
sudo apt-get update && sudo apt-get install -y libgeos-dev

- name: Build and run examples/sedonadb-rust
shell: bash
run: |
rm -rf Cargo.toml
cd examples/sedonadb-rust
cargo run
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ rust-version = "1.86"
[workspace.dependencies]
approx = "0.5"
abi_stable = "0.11.3"
adbc_core = ">=0.20.0"
adbc_ffi = ">=0.20.0"
adbc_core = ">=0.21.0"
adbc_ffi = ">=0.21.0"
lru = "0.12"
arrow = { version = "56.0.0", features = ["prettyprint", "ffi", "chrono-tz"] }
arrow-array = { version = "56.0.0" }
Expand Down
18 changes: 18 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

Cargo.lock
36 changes: 36 additions & 0 deletions examples/sedonadb-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

[package]
name = "sedonadb-rust-example"
version = "0.0.1"
authors = ["Apache Sedona <dev@sedona.apache.org>"]
license = "Apache-2.0"
homepage = "https://github.com/apache/sedona-db"
repository = "https://github.com/apache/sedona-db"
description = "Apache SedonaDB Rust API Example"
readme = "README.md"
edition = "2021"
rust-version = "1.86"

[workspace]

[dependencies]
datafusion = { version = "50.2.0"}
# When sedona is released on crates.io, this can be a version and not a git repo
sedona = { git = "https://github.com/apache/sedona-db.git", package = "sedona"}
tokio = { version = "1.44", features = ["rt-multi-thread"]}
41 changes: 41 additions & 0 deletions examples/sedonadb-rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!---
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

# Using SedonaDB from Rust

This example shows how to use the `sedona` crate alongside `datafusion` in a Rust
Project to run a basic query.

```shell
git clone https://github.com/apache/sedona-db.git
cd sedona-db/examples/sedona-rust
cargo run
```

```
+-------------+----------------------------------------------+
| name | geometry |
+-------------+----------------------------------------------+
| Abidjan | POINT(-4.020206835187587 5.3231260722445715) |
| Abu Dhabi | POINT(54.3665934 24.4666836) |
| Abuja | POINT(7.489505042885861 9.054620406360845) |
| Accra | POINT(-0.2186616 5.5519805) |
| Addis Ababa | POINT(38.6980586 9.0352562) |
+-------------+----------------------------------------------+
```
35 changes: 35 additions & 0 deletions examples/sedonadb-rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// Because a number of methods only return Err() for not implemented,
// the compiler doesn't know how to guess which impl RecordBatchReader
// will be returned. When we implement the methods, we can remove this.

use datafusion::{common::Result, prelude::*};
use sedona::context::{SedonaContext, SedonaDataFrame};

#[tokio::main]
async fn main() -> Result<()> {
let ctx = SedonaContext::new_local_interactive().await?;
let url = "https://raw.githubusercontent.com/geoarrow/geoarrow-data/v0.2.0/natural-earth/files/natural-earth_cities_geo.parquet";
let df = ctx.read_parquet(url, Default::default()).await?;
let output = df
.sort_by(vec![col("name")])?
.show_sedona(&ctx, Some(5), Default::default())
.await?;
println!("{output}");
Ok(())
}
Loading