Created
February 27, 2026 14:16
-
-
Save koron/0526d5feec5d7a7160c099bc91284fa4 to your computer and use it in GitHub Desktop.
C (MSYS2 + UCRT64) で duckdb を使って Content-Length を返さないサーバーの parquet にアクセスしてみた
This file contains hidden or 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
| #include <stdio.h> | |
| #include <duckdb.h> | |
| int main(int argc, char **argv) | |
| { | |
| duckdb_database db; | |
| duckdb_connection con; | |
| if (duckdb_open(NULL, &db) == DuckDBError) { | |
| printf("duckdb_open failed\n"); | |
| return 1; | |
| } | |
| if (duckdb_connect(db, &con) == DuckDBError) { | |
| printf("duckdb_connect failed\n"); | |
| return 1; | |
| } | |
| // run queries... | |
| duckdb_state state; | |
| duckdb_result result; | |
| state = duckdb_query(con, "INSTALL httpfs", NULL); | |
| if (state == DuckDBError) { | |
| printf("failed: INSTALL httpfs\n"); | |
| return 1; | |
| } | |
| state = duckdb_query(con, "LOAD httpfs", NULL); | |
| if (state == DuckDBError) { | |
| printf("failed: LOAD httpfs\n"); | |
| return 1; | |
| } | |
| #if 1 | |
| state = duckdb_query(con, "SELECT avg(c_acctbal) FROM 'https://shell.duckdb.org/data/tpch/0_01/parquet/customer.parquet'", &result); | |
| #else | |
| //state = duckdb_query(con, "SELECT avg(c_acctbal) FROM 'customer.parquet'", &result); | |
| #endif | |
| if (state == DuckDBError) { | |
| printf("duckdb_query failed: %s\n", duckdb_result_error(&result)); | |
| } | |
| while (true) { | |
| duckdb_data_chunk chunk = duckdb_fetch_chunk(result); | |
| if (!chunk) { | |
| break; | |
| } | |
| printf("column#0: name=%s type=%d\n", | |
| duckdb_column_name(&result, 0), | |
| duckdb_column_type(&result, 0)); | |
| idx_t row_count = duckdb_data_chunk_get_size(chunk); | |
| duckdb_vector col0 = duckdb_data_chunk_get_vector(chunk, 0); | |
| double *col0_data = (double *)duckdb_vector_get_data(col0); | |
| uint64_t *col0_validity = duckdb_vector_get_validity(col0); | |
| printf("row_count=%d\n", row_count); | |
| for (idx_t row = 0; row < row_count; row++) { | |
| if (duckdb_validity_row_is_valid(col0_validity, row)) { | |
| printf("%e", col0_data[row]); | |
| } else { | |
| printf("NULL"); | |
| } | |
| printf("\n"); | |
| } | |
| duckdb_destroy_data_chunk(&chunk); | |
| } | |
| // cleanup | |
| duckdb_destroy_result(&result); | |
| duckdb_disconnect(&con); | |
| duckdb_close(&db); | |
| return 0; | |
| } |
This file contains hidden or 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
| LDLIBS=-lduckdb | |
| main: main.c | |
| clean: | |
| rm -f *.o | |
| rm -f main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment