Skip to content

Commit a743acf

Browse files
committed
Consolidate the Rust and Sqllogictest tests
1 parent 2405243 commit a743acf

File tree

9 files changed

+107
-65
lines changed

9 files changed

+107
-65
lines changed

.github/workflows/dist_pipeline.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
name: Build Extensions
1+
name: Build Extension Binaries
22
on:
3-
pull_request:
43
workflow_dispatch:
4+
push:
5+
tags:
6+
- 'v*'
57

68
permissions:
79
contents: read

.github/workflows/lints.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run Linters
1+
name: Run Rust Linters
22

33
on:
44
workflow_dispatch:
@@ -10,7 +10,7 @@ permissions:
1010
contents: read
1111

1212
jobs:
13-
lint:
13+
lints:
1414
runs-on: ubuntu-latest
1515

1616
steps:

.github/workflows/tests.yml

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ on:
55
pull_request:
66
branches:
77
- main
8+
push:
9+
branches:
10+
- main
811

912
permissions:
1013
contents: read
1114

1215
jobs:
13-
test:
16+
rust-tests:
17+
name: Rust Unit & Coverage
1418
runs-on: ubuntu-latest
15-
19+
env:
20+
CARGO_TERM_COLOR: always
1621
steps:
1722
- name: Checkout Code
1823
uses: actions/checkout@v4
@@ -22,17 +27,55 @@ jobs:
2227
- name: Set up Rust
2328
uses: actions-rust-lang/setup-rust-toolchain@v1
2429

25-
- name: Install Dependencies
30+
- name: Cache Cargo
31+
uses: actions/cache@v4
32+
with:
33+
path: |
34+
~/.cargo/registry
35+
~/.cargo/git
36+
infera/target
37+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
38+
restore-keys: |
39+
${{ runner.os }}-cargo-
40+
41+
- name: Install System Dependencies
2642
run: |
27-
sudo apt-get update && sudo apt-get upgrade -y
43+
sudo apt-get update
2844
sudo apt-get install -y gcc curl pkg-config libssl-dev make
29-
cargo install cargo-tarpaulin
45+
cargo install cargo-tarpaulin --locked || true
46+
47+
- name: Run Rust Tests
48+
run: |
49+
make rust-test
3050
31-
- name: Run Tests and Generate Coverage Report
32-
run: make rust-coverage # Generates a coverage report for Infera crate
51+
- name: Generate Coverage (Tarpaulin)
52+
run: |
53+
make rust-coverage
3354
3455
- name: Upload Coverage Reports to Codecov
3556
uses: codecov/codecov-action@v5
3657
with:
3758
token: ${{ secrets.CODECOV_TOKEN }}
3859
continue-on-error: false
60+
61+
sqllogictest:
62+
name: SQLLogic (DuckDB Extension)
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: Checkout Code
66+
uses: actions/checkout@v4
67+
with:
68+
submodules: recursive
69+
70+
- name: Set up Rust
71+
uses: actions-rust-lang/setup-rust-toolchain@v1
72+
73+
- name: Install System Dependencies
74+
run: |
75+
sudo apt-get update
76+
sudo apt-get install -y gcc curl pkg-config libssl-dev make
77+
78+
- name: Build Extension & Run SQL Tests
79+
run: |
80+
make release
81+
make test

README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<h2>Infera</h2>
88

99
[![Tests](https://img.shields.io/github/actions/workflow/status/CogitatorTech/infera/tests.yml?label=tests&style=flat&labelColor=282c34&logo=github)](https://github.com/CogitatorTech/infera/actions/workflows/tests.yml)
10-
[![Code Coverage](https://img.shields.io/codecov/c/github/CogitatorTech/infera?label=coverage&style=flat&labelColor=282c34&logo=codecov)](https://codecov.io/gh/CogitatorTech/infera)
1110
[![Code Quality](https://img.shields.io/codefactor/grade/github/CogitatorTech/infera?label=quality&style=flat&labelColor=282c34&logo=codefactor)](https://www.codefactor.io/repository/github/CogitatorTech/infera)
1211
[![Examples](https://img.shields.io/badge/examples-view-green?style=flat&labelColor=282c34&logo=github)](https://github.com/CogitatorTech/infera/tree/main/docs/examples)
1312
[![Docs](https://img.shields.io/badge/docs-view-blue?style=flat&labelColor=282c34&logo=read-the-docs)](https://github.com/CogitatorTech/infera/tree/main/docs)
@@ -23,7 +22,7 @@ Infera is DuckDB extension that allows you use machine learning (ML) models dire
2322
on data stored in DuckDB tables.
2423
It is developed in Rust and uses [Tract](https://github.com/snipsco/tract) as the backend inference engine.
2524
Infera supports loading and running models in [ONNX](https://onnx.ai/) format.
26-
Check out the [ONNX Model Zoo](https://huggingface.co/onnxmodelzoo) repositors on Hugging Face for a very large
25+
Check out the [ONNX Model Zoo](https://huggingface.co/onnxmodelzoo) repositors on Hugging Face for a large
2726
collection of ready-to-use models that can be used with Infera.
2827

2928
### Motivation
@@ -41,7 +40,7 @@ It simplifies the workflow and speeds up the process for users, and eliminates t
4140
- Adds ML inference as first-class citizens in SQL queries.
4241
- Supports loading and using local as well as remote models.
4342
- Supports using ML models in ONNX format with a simple and flexible API.
44-
- Supports performing inference on table columns or raw `BLOB` (tensor) data.
43+
- Supports performing inference on table columns or raw BLOB (tensor) data.
4544
- Supports both single-value and multi-value model outputs.
4645
- Supports autoloading all models from a specified directory.
4746
- Thread-safe, fast, and memory-efficient.
@@ -56,22 +55,34 @@ See the [ROADMAP.md](ROADMAP.md) for the list of implemented and planned feature
5655

5756
### Quickstart
5857

58+
```bash
59+
git clone --recursive https://github.com/CogitatorTech/infera.git
60+
cd infera
61+
62+
make release
63+
64+
./build/release/duckdb
65+
```
66+
5967
```sql
60-
-- 1. Load the extension
61-
LOAD
62-
infera;
68+
-- 1. Load the extension (optional when building from source)
69+
load 'build/release/extension/infera/infera.duckdb_extension'
70+
load infera;
6371

6472
-- 2. Load a simple linear model from a remote URL
65-
SELECT infera_load_model('linear_model',
73+
select infera_load_model('linear_model',
6674
'https://github.com/CogitatorTech/infera/raw/refs/heads/main/test/models/linear.onnx');
6775

6876
-- 3. Run a prediction using a very simple linear model
6977
-- Model: y = 2*x1 - 1*x2 + 0.5*x3 + 0.25
70-
SELECT infera_predict('linear_model', 1.0, 2.0, 3.0);
78+
select infera_predict('linear_model', 1.0, 2.0, 3.0);
7179
-- Expected output: 1.75
7280

7381
-- 4. Unload the model when we're done with it
74-
SELECT infera_unload_model('linear_model');
82+
select infera_unload_model('linear_model');
83+
84+
-- 5. Check the Infera version
85+
select infera_get_version();
7586
````
7687

7788
---

docs/README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
Table below includes the information about all SQL functions exposed by the Infera.
44

5-
| Function | Return Type | Description |
6-
|:--------------------------------------------------------|:-----------------|:--------------------------------------------------------------------------------------------------------------------------------------------|
7-
| `infera_load_model(name VARCHAR, path_or_url VARCHAR)` | `BOOLEAN` | Loads an ONNX model from a local file path or a remote URL and assigns it a unique name. Returns `true` on success. |
8-
| `infera_unload_model(name VARCHAR)` | `BOOLEAN` | Unloads a model, freeing its associated resources. Returns `true` on success. |
9-
| `infera_set_autoload_dir(path VARCHAR)` | `VARCHAR (JSON)` | Scans a directory for `.onnx` files, loads them automatically, and returns a JSON report of loaded models and any errors. |
10-
| `infera_get_loaded_models()` | `VARCHAR (JSON)` | Returns a JSON array containing the names of all currently loaded models. |
11-
| `infera_get_model_info(name VARCHAR)` | `VARCHAR (JSON)` | Returns a JSON object with metadata about a specific loaded model, including its name, input/output shapes, and status. |
12-
| `infera_predict(name VARCHAR, features... FLOAT)` | `FLOAT` | Performs inference on a batch of data, returning a single float value for each input row. |
13-
| `infera_predict_multi(name VARCHAR, features... FLOAT)` | `VARCHAR (JSON)` | Performs inference and returns all outputs as a JSON-encoded array. This is useful for models that produce multiple predictions per sample. |
14-
| `infera_predict_from_blob(name VARCHAR, data BLOB)` | `LIST[FLOAT]` | Performs inference on raw `BLOB` data (for example, used for an image tensor), returning the result as a list of floats. |
15-
| `infera_get_version()` | `VARCHAR (JSON)` | Returns a JSON object with version and build information for the Infera extension. |
5+
| # | Function | Return Type | Description |
6+
|---|:--------------------------------------------------------|:-----------------|:--------------------------------------------------------------------------------------------------------------------------------------------|
7+
| 1 | `infera_load_model(name VARCHAR, path_or_url VARCHAR)` | `BOOLEAN` | Loads an ONNX model from a local file path or a remote URL and assigns it a unique name. Returns `true` on success. |
8+
| 2 | `infera_unload_model(name VARCHAR)` | `BOOLEAN` | Unloads a model, freeing its associated resources. Returns `true` on success. |
9+
| 3 | `infera_set_autoload_dir(path VARCHAR)` | `VARCHAR (JSON)` | Scans a directory for `.onnx` files, loads them automatically, and returns a JSON report of loaded models and any errors. |
10+
| 4 | `infera_get_loaded_models()` | `VARCHAR (JSON)` | Returns a JSON array containing the names of all currently loaded models. |
11+
| 5 | `infera_get_model_info(name VARCHAR)` | `VARCHAR (JSON)` | Returns a JSON object with metadata about a specific loaded model, including its name, input/output shapes, and status. |
12+
| 6 | `infera_predict(name VARCHAR, features... FLOAT)` | `FLOAT` | Performs inference on a batch of data, returning a single float value for each input row. |
13+
| 7 | `infera_predict_multi(name VARCHAR, features... FLOAT)` | `VARCHAR (JSON)` | Performs inference and returns all outputs as a JSON-encoded array. This is useful for models that produce multiple predictions per sample. |
14+
| 8 | `infera_predict_from_blob(name VARCHAR, data BLOB)` | `LIST[FLOAT]` | Performs inference on raw `BLOB` data (for example, used for an image tensor), returning the result as a list of floats. |
15+
| 9 | `infera_get_version()` | `VARCHAR (JSON)` | Returns a JSON object with version and build information for the Infera extension. |
1616

1717
---
1818

@@ -24,42 +24,42 @@ This section includes some examples of how to use the Infera functions.
2424

2525
```sql
2626
-- Load a model from a local file
27-
SELECT infera_load_model('local_model', '/path/to/model.onnx');
27+
select infera_load_model('local_model', '/path/to/model.onnx');
2828

2929
-- Load a model from a remote URL
30-
SELECT infera_load_model('remote_model', 'https://.../model.onnx');
30+
select infera_load_model('remote_model', 'https://.../model.onnx');
3131

3232
-- List all loaded models
33-
SELECT infera_get_loaded_models();
33+
select infera_get_loaded_models();
3434
-- Output: ["local_model", "remote_model"]
3535

3636
-- Get information about a specific model
37-
SELECT infera_get_model_info('local_model');
37+
select infera_get_model_info('local_model');
3838
-- Output: {"name":"local_model","input_shape":[-1,3],"output_shape":[-1,1],"loaded":true}
3939

4040
-- Unload a loaded model
41-
SELECT infera_unload_model('remote_model');
41+
select infera_unload_model('remote_model');
4242
```
4343

4444
#### Inference
4545

4646
```sql
4747
-- Predict using literal feature values
48-
SELECT infera_predict('my_model', 1.0, 2.5, 3.0) as prediction;
48+
select infera_predict('my_model', 1.0, 2.5, 3.0) as prediction;
4949

5050
-- Predict using columns from a table
51-
SELECT id,
51+
select id,
5252
infera_predict('my_model', feature1, feature2, feature3) as prediction
53-
FROM features_table;
53+
from features_table;
5454

5555
-- Get multiple outputs as a JSON array.
5656
-- This is useful models that return multiple outputs per prediction (like a non-binary classifier)
57-
SELECT infera_predict_multi('multi_output_model', 1.0, 2.0);
57+
select infera_predict_multi('multi_output_model', 1.0, 2.0);
5858
-- Output: [0.85, 0.12, 0.03]
5959

6060
-- Predict using raw BLOB data (like tensor data)
61-
SELECT infera_predict_from_blob('my_model', my_blob_column)
62-
FROM my_table;
61+
select infera_predict_from_blob('my_model', my_blob_column)
62+
from my_table;
6363
-- Expected output: [0.1, 0.2, 0.3, ...] (as a LIST<FLOAT>)
6464
```
6565

@@ -71,11 +71,11 @@ FROM my_table;
7171

7272
```sql
7373
-- Get a JSON list of all loaded models
74-
SELECT infera_get_loaded_models();
74+
select infera_get_loaded_models();
7575
-- Output: ["linear_model", "squeezenet"]
7676

7777
-- Get detailed metadata for a specific model
78-
SELECT infera_get_model_info('squeezenet');
78+
select infera_get_model_info('squeezenet');
7979
/* Output:
8080
{
8181
"name": "squeezenet",
@@ -86,7 +86,7 @@ SELECT infera_get_model_info('squeezenet');
8686
*/
8787

8888
-- Load all models from the 'models/' directory
89-
SELECT infera_set_autoload_dir('path/to/your/models');
89+
select infera_set_autoload_dir('path/to/your/models');
9090
/* Output:
9191
{
9292
"loaded": ["model1", "model2"],

docs/examples/README.md

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,24 @@
1-
# Infera Examples
1+
## Examples
22

33
This directory contains DuckDB SQL scripts that show usage patterns of the Infera extension.
44
Each file is self‑contained and can be executed in the DuckDB shell (or via `duckdb < file.sql`).
55

6-
## Prerequisites
6+
### Prerequisites
77

8-
1. Build the extension:
8+
1. Build the extension
99
```bash
1010
make release
1111
```
12-
2. Start the DuckDB shell from the project root directory:
12+
2. Start the DuckDB shell from the project root directory
1313
```bash
1414
./build/release/duckdb
1515
```
16-
3. Inside the shell, load a script:
16+
3. Inside the shell, load a script
1717
```sql
1818
.read docs/examples/e1_core_functionality.sql
1919
```
2020

21-
## Example Index
22-
23-
| File | Topic | Functionalities |
24-
|---------------------------------|--------------------------------------|-----------------------------------------------------------------------------------------------------------|
25-
| `e1_core_functionality.sql` | Core lifecycle | Version, load, inspect model info, single prediction, unload, autoload directory reuse |
26-
| `e2_advanced_features.sql` | Remote and BLOB inference | Remote model load (GitHub), large vision model, constructing a zero‑filled BLOB for inference |
27-
| `e3_integration_and_errors.sql` | Integration patterns and errors | Deterministic batch table, aggregation, null feature detection, missing model handling |
28-
| `e4_multi_output.sql` | Multi‑output models | Uses `multi_output.onnx`, shows `infera_predict_multi` vs (commented) single‑output mismatch |
29-
| `e5_autoload_and_json.sql` | Autoload and lightweight JSON checks | Error JSON from missing dir, loading multiple models via directory scan, simple substring presence checks |
30-
| `e6_blob_diagnostics.sql` | BLOB diagnostics | Shows correct BLOB sizing for mobilenet; commented invalid case to illustrate error path |
31-
32-
## Running All Examples
21+
### Running All Examples
3322

3423
```bash
3524
make examples

docs/examples/e4_multi_output.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ select '## predict (single-output API) will raise mismatch error if executed';
1919
select '## cleanup';
2020
select infera_unload_model('multi_output') as unloaded_multi;
2121
.echo off
22-

docs/examples/e5_autoload_and_json.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ select '## cleanup';
1919
select infera_unload_model('linear') as unload_linear;
2020
select infera_unload_model('multi_output') as unload_multi_output;
2121
.echo off
22-

docs/examples/e6_blob_diagnostics.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ select len(infera_predict_from_blob('mobilenet', zero_blob)) as output_len from
2121
select '## cleanup';
2222
select infera_unload_model('mobilenet') as mobilenet_unloaded;
2323
.echo off
24-

0 commit comments

Comments
 (0)