Skip to content

Commit

Permalink
Merge pull request #1 from kou/import
Browse files Browse the repository at this point in the history
Implement minimal API
  • Loading branch information
jimexist committed Jun 3, 2022
2 parents d9c815f + eb8b54c commit d7b78e6
Show file tree
Hide file tree
Showing 12 changed files with 730 additions and 2 deletions.
141 changes: 141 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# 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: CI

on:
- push
- pull_request

concurrency:
group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
rat:
name: Release Audit Tool (RAT)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
path: datafusion-c
- name: Checkout Arrow
uses: actions/checkout@v3
with:
path: arrow
repository: apache/arrow
- uses: actions/setup-python@v3
with:
python-version: "3.x"
- name: Setup Archery
run: |
pip install -e arrow/dev/archery[lint]
- name: Run RAT
run: |
cd datafusion-c && archery lint --rat
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
id: rust-toolchain
with:
toolchain: stable
override: true
components: rustfmt, clippy
- name: Cache Cargo
uses: actions/cache@v3
with:
path: ~/.cargo
key: cargo-lint-${{ steps.rust-toolchain.outputs.rustc_hash }}-${{ hashFiles('Cargo.lock') }}
- name: Check format
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Run Clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --all-features -- -D clippy::all -D warnings
- uses: actions/setup-node@v3
with:
node-version: "lts/*"
- name: Prettier
run: |
npx prettier --check "**.md"
test:
name: Test
strategy:
fail-fast: false
matrix:
runs-on:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
id: rust-toolchain
with:
toolchain: stable
override: true
- name: Cache Cargo
uses: actions/cache@v2
with:
path: ~/.cargo
key: cargo-test-${{ matrix.runs-on }}-${{ steps.rust-toolchain.outputs.rustc_hash }}-${{ hashFiles('Cargo.lock') }}
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
- name: Run C example
if: |
matrix.runs-on == 'ubuntu-latest'
run: |
cc \
-o target/debug/sql \
examples/sql.c \
-Iinclude \
-Ltarget/debug \
-Wl,--rpath=target/debug \
-ldatafusion
target/debug/sql
- uses: actions/setup-python@v3
if: |
matrix.runs-on == 'ubuntu-latest'
with:
python-version: "3.x"
- name: Run Python example
if: |
matrix.runs-on == 'ubuntu-latest'
run: |
LD_LIBRARY_PATH=$PWD/target/debug examples/sql.py
- uses: ruby/setup-ruby@v1
if: |
matrix.runs-on == 'ubuntu-latest'
with:
ruby-version: "3.1"
- name: Run Ruby example
if: |
matrix.runs-on == 'ubuntu-latest'
run: |
LD_LIBRARY_PATH=$PWD/target/debug examples/sql.rb
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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
/target
45 changes: 45 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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 = "datafusion-c"
description = "DataFusion C API"
version = "1.0.0"
homepage = "https://github.com/datafusion-contrib/datafusion-c"
repository = "https://github.com/datafusion-contrib/datafusion-c"
readme = "README.md"
authors = ["Apache Arrow <dev@arrow.apache.org>"]
license = "Apache-2.0"
keywords = ["arrow", "c"]
edition = "2021"
rust-version = "1.59"
exclude = [
"/cpp/",
]

[lib]
crate-type = ["cdylib"]
name = "datafusion"

[features]
default = []

[dependencies]
datafusion = "8"
libc = "0.2"
tokio = "1"
# { version = "1.0" , features = ["macros", "rt", "rt-multi-thread", "sync", "fs", "parking_lot"] }
89 changes: 87 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,87 @@
# datafusion-c
C language bindings for DataFusion
<!--
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.
-->

# DataFusion C API

C language bindings for DataFusion.

## Examples

### How to run

Build `libdatafusion.so`:

```bash
cargo build
```

C example:

```
cc \
-o target/debug/sql \
-I datafusion/c/include \
datafusion/c/examples/sql.c \
-L target/debug \
-Wl,--rpath=target/debug \
-ldatafusion
target/debug/sql
```

Output:

```text
+----------+
| Int64(1) |
+----------+
| 1 |
+----------+
```

Python example:

```bash
LD_LIBRARY_PATH=$PWD/target/debug datafusion/c/examples/sql.py
```

Output:

```text
+----------+
| Int64(1) |
+----------+
| 1 |
+----------+
```

Ruby example:

```bash
LD_LIBRARY_PATH=$PWD/target/debug datafusion/c/examples/sql.rb
```

Output:

```text
+----------+
| Int64(1) |
+----------+
| 1 |
+----------+
```
18 changes: 18 additions & 0 deletions cpp/CMakeLists.txt
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.

# This is just for mimicking apache/arrow repository to use "archery lint --rat".
1 change: 1 addition & 0 deletions dev/release/rat_exclude_files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev/release/rat_exclude_files.txt
45 changes: 45 additions & 0 deletions examples/sql.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.
*/

#include <datafusion.h>

#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
DFSessionContext *context = df_session_context_new();
DFError *error = NULL;
DFDataFrame *data_frame = df_session_context_sql(context, "SELECT 1;", &error);
if (error) {
printf("failed to run SQL: %s\n", df_error_get_message(error));
df_error_free(error);
df_session_context_free(context);
return EXIT_FAILURE;
}
df_data_frame_show(data_frame, &error);
if (error) {
printf("failed to show data frame: %s\n", df_error_get_message(error));
df_error_free(error);
}
df_data_frame_free(data_frame);
df_session_context_free(context);
return EXIT_SUCCESS;
}
Loading

0 comments on commit d7b78e6

Please sign in to comment.