forked from unikraft/catalog
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(examples): Introduce DuckDB C example #22
Open
razvand
wants to merge
1
commit into
unikraft:main
Choose a base branch
from
unikraft-upb:razvand/examples/duckdb-c
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/rootfs/ | ||
/rootfs.cpio | ||
/run-qemu* | ||
/run-fc* | ||
/kraft-run-* | ||
/fc*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
FROM --platform=linux/x86_64 debian:bookworm AS build | ||
|
||
RUN set -xe; \ | ||
apt -yqq update; \ | ||
apt -yqq install \ | ||
wget \ | ||
ca-certificates \ | ||
build-essential \ | ||
unzip \ | ||
; | ||
|
||
ARG DUCKDB_VERSION=0.9.1 | ||
|
||
WORKDIR /src | ||
|
||
RUN set -xe; \ | ||
wget https://github.com/duckdb/duckdb/releases/download/v${DUCKDB_VERSION}/libduckdb-linux-amd64.zip; \ | ||
unzip -q libduckdb-linux-amd64.zip; \ | ||
mv libduckdb.so /usr/local/lib/; \ | ||
ldconfig /usr/local/lib/libduckdb.so \ | ||
; | ||
|
||
COPY ./main.c /src/main.c | ||
|
||
RUN set -xe; \ | ||
gcc -Wall -I. -o /main /src/main.c -lduckdb | ||
|
||
FROM scratch | ||
|
||
COPY --from=build /main /main | ||
COPY --from=build /usr/local/lib/libduckdb.so /usr/local/lib/libduckdb.so | ||
COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6 | ||
COPY --from=build /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib/x86_64-linux-gnu/libgcc_s.so.1 | ||
COPY --from=build /lib/x86_64-linux-gnu/libpthread.so.0 /lib/x86_64-linux-gnu/libpthread.so.0 | ||
COPY --from=build /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so.2 | ||
COPY --from=build /lib/x86_64-linux-gnu/libstdc++.so.6 /lib/x86_64-linux-gnu/libstdc++.so.6 | ||
COPY --from=build /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6 | ||
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 | ||
COPY --from=build /etc/ld.so.cache /etc/ld.so.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
spec: v0.6 | ||
|
||
name: duckdb-c | ||
|
||
runtime: index.unikraft.io/unikraft.org/base:latest | ||
|
||
rootfs: ./Dockerfile | ||
|
||
cmd: ["/main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
IMAGE_NAME = unikraft-duckdb-c | ||
|
||
include ../../utils/bincompat/docker.Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# DuckDB C Example | ||
|
||
This directory contains a simple C example using the [DuckDB](https://duckdb.org) library running with Unikraft in binary compatibility mode. | ||
The C program is extracted from [DuckDB examples](https://github.com/duckdb/duckdb/blob/main/examples/embedded-c/main.c) and it creates and uses a test database. | ||
|
||
Follow the instructions in the common `../README.md` file to set up and configure the application. | ||
|
||
## Quick Run | ||
|
||
Use `kraft` to run the image: | ||
|
||
```console | ||
kraft run -M 128M | ||
``` | ||
|
||
Once executed, it will print out information from the created database: | ||
|
||
```console | ||
``` | ||
|
||
## Scripted Run | ||
|
||
Use the scripted runs, detailed in the common `../README.md`. | ||
Running the scripts will print out information ame as above. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
networking: False | ||
accel: True | ||
memory: 256 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* https://github.com/duckdb/duckdb/blob/main/examples/embedded-c/main.c */ | ||
|
||
#include "duckdb.h" | ||
#include <stdio.h> | ||
|
||
int main() { | ||
duckdb_database db = NULL; | ||
duckdb_connection con = NULL; | ||
duckdb_result result; | ||
|
||
if (duckdb_open(NULL, &db) == DuckDBError) { | ||
fprintf(stderr, "Failed to open database\n"); | ||
goto cleanup; | ||
} | ||
if (duckdb_connect(db, &con) == DuckDBError) { | ||
fprintf(stderr, "Failed to open connection\n"); | ||
goto cleanup; | ||
} | ||
if (duckdb_query(con, "CREATE TABLE integers(i INTEGER, j INTEGER);", NULL) == DuckDBError) { | ||
fprintf(stderr, "Failed to query database\n"); | ||
goto cleanup; | ||
} | ||
if (duckdb_query(con, "INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);", NULL) == DuckDBError) { | ||
fprintf(stderr, "Failed to query database\n"); | ||
goto cleanup; | ||
} | ||
if (duckdb_query(con, "SELECT * FROM integers", &result) == DuckDBError) { | ||
fprintf(stderr, "Failed to query database\n"); | ||
goto cleanup; | ||
} | ||
// print the names of the result | ||
idx_t row_count = duckdb_row_count(&result); | ||
idx_t column_count = duckdb_column_count(&result); | ||
for (size_t i = 0; i < column_count; i++) { | ||
printf("%s ", duckdb_column_name(&result, i)); | ||
} | ||
printf("\n"); | ||
// print the data of the result | ||
for (size_t row_idx = 0; row_idx < row_count; row_idx++) { | ||
for (size_t col_idx = 0; col_idx < column_count; col_idx++) { | ||
char *val = duckdb_value_varchar(&result, col_idx, row_idx); | ||
printf("%s ", val); | ||
duckdb_free(val); | ||
} | ||
printf("\n"); | ||
} | ||
// duckdb_print_result(result); | ||
cleanup: | ||
duckdb_destroy_result(&result); | ||
duckdb_disconnect(&con); | ||
duckdb_close(&db); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the output here.