Skip to content

Bump to last night duckdb #2018

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

Open
wants to merge 29 commits into
base: v1.3-ossivalis
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f0a042b
Publish on NPM only from main
carlopi May 7, 2025
423b528
Add patch to implement VirtualFileSystem constructor
carlopi May 7, 2025
fac5041
Actually rely on VirtualFileSystem at the duckdb-wasm level
carlopi May 7, 2025
420a0fd
fix patch
carlopi May 7, 2025
f3d7db7
Wrap results of fetchQueryResults via DuckDBWasmResultsWrapper
carlopi May 7, 2025
8ee9eac
Make sure we `Fetch` query result when ready
Y-- May 1, 2025
d9e0a4f
Use `DuckDBWasmResultsWrapper`
Y-- May 9, 2025
292d252
Add patch to rapidjson, to comply to CMake 4.0 requirements
carlopi May 12, 2025
be508b2
Add format target
Y-- May 12, 2025
449ea10
Format sources
Y-- May 12, 2025
6e6bb13
Pass EXPORTED_FUNCTIONS as external file
carlopi May 12, 2025
31464a3
Add Makefile step to generate hacky exported list
carlopi May 12, 2025
c8ce6a5
Conditionally on USE_GENERATED_EXPORTED_LIST, use just generated list
carlopi May 12, 2025
5621562
Use generated export list by default
carlopi May 12, 2025
356e15a
Fixup parameter passing
carlopi May 12, 2025
79e279e
try this
carlopi May 12, 2025
1f9d700
fix
carlopi May 12, 2025
af580b8
invert
carlopi May 12, 2025
c05e267
skip not loadable
carlopi May 12, 2025
89e0783
Fix parking lot
carlopi May 12, 2025
da153d8
Temporarily add chrono
carlopi May 13, 2025
ee7632c
Fixup for getTempRet0:
carlopi May 13, 2025
a543940
Fixup sed
carlopi May 13, 2025
a793af6
Move inner
carlopi May 13, 2025
b1c34ae
Remove unneeded wabt install
carlopi May 13, 2025
82c134e
Add base_exported_list also for no-extensions case
carlopi May 13, 2025
1920ffe
Merge remote-tracking branch 'duckdb/main' into v1.3-ossivalis
carlopi May 14, 2025
8a9fff0
Bump to duckdb 93fda3591f4298414fa362c59219c09e03f718ab
carlopi May 14, 2025
4e560db
Remove virtualized_file_system patch, already handled
carlopi May 14, 2025
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
18 changes: 15 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ jobs:
submodules: 'recursive'
fetch-depth: 0

- name: Install dependencies
run: |
sudo apt install wabt
- name: Prepare repository
run: |
make apply_patches
Expand All @@ -514,7 +518,7 @@ jobs:
- name: Build Wasm module
run: |
DUCKDB_PLATFORM="wasm_mvp" DUCKDB_WASM_LOADABLE_EXTENSIONS=1 GEN=ninja ./scripts/wasm_build_lib.sh relsize mvp
USE_GENERATED_EXPORTED_LIST="yes" DUCKDB_PLATFORM="wasm_mvp" DUCKDB_WASM_LOADABLE_EXTENSIONS=1 GEN=ninja ./scripts/wasm_build_lib.sh relsize mvp
- name: Upload artifact
uses: actions/upload-artifact@v4
Expand All @@ -537,6 +541,10 @@ jobs:
submodules: 'recursive'
fetch-depth: 0

- name: Install dependencies
run: |
sudo apt install wabt
- name: Prepare repository
run: |
make apply_patches
Expand All @@ -557,7 +565,7 @@ jobs:
- name: Build Wasm module
run: |
DUCKDB_PLATFORM="wasm_eh" DUCKDB_WASM_LOADABLE_EXTENSIONS=1 GEN=ninja ./scripts/wasm_build_lib.sh relsize eh
USE_GENERATED_EXPORTED_LIST="yes" DUCKDB_PLATFORM="wasm_eh" DUCKDB_WASM_LOADABLE_EXTENSIONS=1 GEN=ninja ./scripts/wasm_build_lib.sh relsize eh
- name: Upload artifact
uses: actions/upload-artifact@v4
Expand All @@ -580,6 +588,10 @@ jobs:
submodules: 'recursive'
fetch-depth: 0

- name: Install dependencies
run: |
sudo apt install wabt
- name: Prepare repository
run: |
make apply_patches
Expand All @@ -600,7 +612,7 @@ jobs:
- name: Build Wasm module
run: |
DUCKDB_PLATFORM="wasm_threads" DUCKDB_WASM_LOADABLE_EXTENSIONS="signed" GEN=ninja ./scripts/wasm_build_lib.sh relsize coi
USE_GENERATED_EXPORTED_LIST="yes" DUCKDB_PLATFORM="wasm_threads" DUCKDB_WASM_LOADABLE_EXTENSIONS="signed" GEN=ninja ./scripts/wasm_build_lib.sh relsize coi
- name: Upload artifact
uses: actions/upload-artifact@v4
Expand Down
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ app: wasm wasmpack shell docs js_tests_release
yarn workspace @duckdb/duckdb-wasm-app build:release

build_loadable:
DUCKDB_PLATFORM=wasm_${TARGET} DUCKDB_WASM_LOADABLE_EXTENSIONS=1 GEN=ninja ./scripts/wasm_build_lib.sh relsize ${TARGET}
USE_GENERATED_EXPORTED_LIST=yes DUCKDB_PLATFORM=wasm_${TARGET} DUCKDB_WASM_LOADABLE_EXTENSIONS=1 GEN=ninja ./scripts/wasm_build_lib.sh relsize ${TARGET}

build_loadable_unsigned: build_loadable
# need to propagate the unsigned flag
Expand Down Expand Up @@ -436,6 +436,7 @@ build/docker_ci_image:
patch_duckdb:
(find patches/duckdb/* -type f -name '*.patch' -print0 | xargs -0 cat | patch -p1 --forward -d submodules/duckdb) || true
(find patches/arrow/* -type f -name '*.patch' -print0 | xargs -0 cat | patch -p1 --forward -d submodules/arrow) || true
(find patches/rapidjson/* -type f -name '*.patch' -print0 | xargs -0 cat | patch -p1 --forward -d submodules/rapidjson) || true

apply_patches: patch_duckdb

Expand All @@ -447,3 +448,15 @@ submodules:
build/bootstrap: submodules yarn_install
mkdir -p build
touch build/bootstrap

update_exported_list:
cd build/relsize/${TARGET} && wasm2wat duckdb_wasm.wasm --enable-all -o duckdb-wasm.wat
cd build/relsize/${TARGET} && grep export duckdb-wasm.wat | cut -d \" -f2 | sed '$d' | grep -v "^orig" | grep -v "^dynCall_" > export_list.txt
## filter list of c++ symbols
cd build/relsize/${TARGET} && cat export_list.txt | grep "^_" | grep -v "_Unwind_" | grep -v "__syscall_shutdown" | grep -v "0\\00\\0" | grep -v "^_ZZN5arrow" | grep -v "^_ZGVZN5arrow" | grep -v "^_ZN5arrow" | sort > cpp_list
cd build/relsize/${TARGET} && sed 's/^/_/g' cpp_list > exported_list.txt
## filter list of c symbols
cd build/relsize/${TARGET} && cat export_list.txt | grep -v "^_" | grep -v "getTempRet" | grep -v "^sched_yield" | grep -v "emscripten_wget" | grep -v "0\\00\\0" | sort > c_exported_list
# prepend '_'
cd build/relsize/${TARGET} && sed 's/^/_/g' c_exported_list >> exported_list.txt
cd build/relsize/${TARGET} && echo '__ZNSt3__26chrono12system_clock9to_time_tERKNS0_10time_pointIS1_NS0_8durationIxNS_5ratioILx1ELx1000000EEEEEEE' >> exported_list.txt
61 changes: 9 additions & 52 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,15 @@ else()
endif()

if (DUCKDB_WASM_LOADABLE_EXTENSIONS)
set(WASM_LINK_FLAGS "${WASM_LINK_FLAGS} -s MAIN_MODULE=1 -s FILESYSTEM=1 -s ENVIRONMENT='web,node,worker' -s ALLOW_TABLE_GROWTH -lembind")
set(WASM_LINK_FLAGS "${WASM_LINK_FLAGS} -s FILESYSTEM=1 -s ENVIRONMENT='web,node,worker' -s ALLOW_TABLE_GROWTH -lembind")

if (USE_GENERATED_EXPORTED_LIST)
set(WASM_LINK_FLAGS "${WASM_LINK_FLAGS} -s MAIN_MODULE=2 -s EXPORTED_FUNCTIONS='@exported_list.txt'")
else()
set(WASM_LINK_FLAGS "${WASM_LINK_FLAGS} -s MAIN_MODULE=1")
endif()
else()
set(WASM_LINK_FLAGS "${WASM_LINK_FLAGS} -s FILESYSTEM=0 -s ENVIRONMENT='web,node,worker'")
set(WASM_LINK_FLAGS "${WASM_LINK_FLAGS} -s FILESYSTEM=0 -s ENVIRONMENT='web,node,worker' -s EXPORTED_FUNCTIONS='@../../../lib/base_exported_list.txt'")
endif()

# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -287,56 +293,7 @@ if(EMSCRIPTEN)
-s MAXIMUM_MEMORY=4GB \
-s MODULARIZE=1 \
-s EXPORT_NAME='DuckDB' \
-s EXPORTED_FUNCTIONS='[ \
_main, \
_malloc, \
_calloc, \
_free, \
_duckdb_web_clear_response, \
_duckdb_web_collect_file_stats, \
_duckdb_web_connect, \
_duckdb_web_copy_file_to_buffer, \
_duckdb_web_copy_file_to_path, \
_duckdb_web_disconnect, \
_duckdb_web_export_file_stats, \
_duckdb_web_fail_with, \
_duckdb_web_flush_file, \
_duckdb_web_flush_files, \
_duckdb_web_fs_drop_file, \
_duckdb_web_fs_drop_files, \
_duckdb_web_fs_get_file_info_by_id, \
_duckdb_web_fs_get_file_info_by_name, \
_duckdb_web_fs_glob_add_path, \
_duckdb_web_fs_glob_file_infos, \
_duckdb_web_fs_register_file_buffer, \
_duckdb_web_fs_register_file_url, \
_duckdb_web_get_feature_flags, \
_duckdb_web_get_global_file_info, \
_duckdb_web_get_tablenames, \
_duckdb_web_get_tablenames_buffer, \
_duckdb_web_get_version, \
_duckdb_web_insert_arrow_from_ipc_stream, \
_duckdb_web_insert_csv_from_path, \
_duckdb_web_insert_json_from_path, \
_duckdb_web_open, \
_duckdb_web_pending_query_cancel, \
_duckdb_web_pending_query_poll, \
_duckdb_web_pending_query_start, \
_duckdb_web_pending_query_start_buffer, \
_duckdb_web_prepared_close, \
_duckdb_web_prepared_create, \
_duckdb_web_prepared_create_buffer, \
_duckdb_web_prepared_run, \
_duckdb_web_prepared_send, \
_duckdb_web_query_fetch_results, \
_duckdb_web_query_run, \
_duckdb_web_query_run_buffer, \
_duckdb_web_reset, \
_duckdb_web_tokenize, \
_duckdb_web_tokenize_buffer, \
_duckdb_web_udf_scalar_create \
]' \
-s EXPORTED_RUNTIME_METHODS='[\"ccall\", \"stackSave\", \"stackAlloc\", \"stackRestore\"]' \
-s EXPORTED_RUNTIME_METHODS='[\"ccall\", \"stackSave\", \"stackAlloc\", \"stackRestore\", \"createDyncallWrapper\", \"getTempRet0\", \"setTempRet0\"]' \
--js-library=${CMAKE_SOURCE_DIR}/js-stubs.js")

endif()
Expand Down
47 changes: 47 additions & 0 deletions lib/base_exported_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
_main
_malloc
_calloc
_free
_duckdb_web_clear_response
_duckdb_web_collect_file_stats
_duckdb_web_connect
_duckdb_web_copy_file_to_buffer
_duckdb_web_copy_file_to_path
_duckdb_web_disconnect
_duckdb_web_export_file_stats
_duckdb_web_fail_with
_duckdb_web_flush_file
_duckdb_web_flush_files
_duckdb_web_fs_drop_file
_duckdb_web_fs_drop_files
_duckdb_web_fs_get_file_info_by_id
_duckdb_web_fs_get_file_info_by_name
_duckdb_web_fs_glob_add_path
_duckdb_web_fs_glob_file_infos
_duckdb_web_fs_register_file_buffer
_duckdb_web_fs_register_file_url
_duckdb_web_get_feature_flags
_duckdb_web_get_global_file_info
_duckdb_web_get_tablenames
_duckdb_web_get_tablenames_buffer
_duckdb_web_get_version
_duckdb_web_insert_arrow_from_ipc_stream
_duckdb_web_insert_csv_from_path
_duckdb_web_insert_json_from_path
_duckdb_web_open
_duckdb_web_pending_query_cancel
_duckdb_web_pending_query_poll
_duckdb_web_pending_query_start
_duckdb_web_pending_query_start_buffer
_duckdb_web_prepared_close
_duckdb_web_prepared_create
_duckdb_web_prepared_create_buffer
_duckdb_web_prepared_run
_duckdb_web_prepared_send
_duckdb_web_query_fetch_results
_duckdb_web_query_run
_duckdb_web_query_run_buffer
_duckdb_web_reset
_duckdb_web_tokenize
_duckdb_web_tokenize_buffer
_duckdb_web_udf_scalar_create
4 changes: 4 additions & 0 deletions lib/include/duckdb/web/utils/wasm_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace duckdb {
namespace web {

struct DuckDBWasmResultsWrapper;

struct WASMResponse {
/// The status code
double statusCode = 1;
Expand Down Expand Up @@ -35,6 +37,8 @@ class WASMResponseBuffer {
/// Store the arrow status.
/// Returns wheather the result was OK
bool Store(WASMResponse& response, arrow::Status status);
/// Store a DuckDBWasmResultsWrapper
void Store(WASMResponse& response, DuckDBWasmResultsWrapper& value);
/// Store a string
void Store(WASMResponse& response, std::string value);
/// Store a string view
Expand Down
18 changes: 17 additions & 1 deletion lib/include/duckdb/web/webdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ namespace web {

struct BufferingArrowIPCStreamDecoder;

struct DuckDBWasmResultsWrapper {
// Additional ResponseStatuses to be >= 256, and mirrored to packages/duckdb-wasm/src/status.ts
// Missing mapping result in a throw, but they should eventually align (it's fine if typescript side only has a
// subset)
enum ResponseStatus : uint32_t { ARROW_BUFFER = 0, MAX_ARROW_ERROR = 255, DUCKDB_WASM_RETRY = 256 };
DuckDBWasmResultsWrapper(arrow::Result<std::shared_ptr<arrow::Buffer>> res,
ResponseStatus status = ResponseStatus::ARROW_BUFFER)
: arrow_buffer(res), status(status) {}
DuckDBWasmResultsWrapper(arrow::Status res, ResponseStatus status = ResponseStatus::ARROW_BUFFER)
: arrow_buffer(res), status(status) {}
DuckDBWasmResultsWrapper(ResponseStatus status = ResponseStatus::ARROW_BUFFER)
: DuckDBWasmResultsWrapper(nullptr, status) {}
arrow::Result<std::shared_ptr<arrow::Buffer>> arrow_buffer;
ResponseStatus status;
};

class WebDB {
public:
/// A connection
Expand Down Expand Up @@ -93,7 +109,7 @@ class WebDB {
/// Cancel a pending query
bool CancelPendingQuery();
/// Fetch a data chunk from a pending query
arrow::Result<std::shared_ptr<arrow::Buffer>> FetchQueryResults();
DuckDBWasmResultsWrapper FetchQueryResults();
/// Get table names
arrow::Result<std::string> GetTableNames(std::string_view text);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/parking_lot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void ParkingLot::Park(const void* addr, std::function<bool()> check, std::chrono
bucket.cv.wait(lock);
}
} else {
auto stop = std::chrono::system_clock::now() + timeout;
auto stop = std::chrono::high_resolution_clock::now() + timeout;
while (!check()) {
if (bucket.cv.wait_until(lock, stop) == std::cv_status::timeout) break;
}
Expand Down
10 changes: 10 additions & 0 deletions lib/src/utils/wasm_response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstdint>

#include "arrow/buffer.h"
#include "duckdb/web/webdb.h"

namespace duckdb {
namespace web {
Expand All @@ -26,6 +27,15 @@ bool WASMResponseBuffer::Store(WASMResponse& response, arrow::Status status) {
return true;
}

void WASMResponseBuffer::Store(WASMResponse& response, DuckDBWasmResultsWrapper& value) {
if (value.status == DuckDBWasmResultsWrapper::ResponseStatus::ARROW_BUFFER) {
Store(response, std::move(value.arrow_buffer));
} else {
Clear();
response.statusCode = value.status;
}
}

void WASMResponseBuffer::Store(WASMResponse& response, std::string value) {
result_str_ = std::move(value);
response.statusCode = 0;
Expand Down
46 changes: 43 additions & 3 deletions lib/src/webdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,53 @@ bool WebDB::Connection::CancelPendingQuery() {
}
}

arrow::Result<std::shared_ptr<arrow::Buffer>> WebDB::Connection::FetchQueryResults() {
DuckDBWasmResultsWrapper WebDB::Connection::FetchQueryResults() {
try {
// Fetch data if a query is active
duckdb::unique_ptr<duckdb::DataChunk> chunk;
if (current_query_result_ == nullptr) {
return nullptr;
return DuckDBWasmResultsWrapper{nullptr};
}

if (current_query_result_->type == QueryResultType::STREAM_RESULT) {
auto& stream_result = current_query_result_->Cast<duckdb::StreamQueryResult>();

auto before = std::chrono::steady_clock::now();
uint64_t elapsed;
auto polling_interval =
webdb_.config_->query.query_polling_interval.value_or(DEFAULT_QUERY_POLLING_INTERVAL);
bool ready = false;
do {
switch (stream_result.ExecuteTask()) {
case StreamExecutionResult::EXECUTION_ERROR:
return arrow::Status{arrow::StatusCode::ExecutionError,
std::move(current_query_result_->GetError())};
case StreamExecutionResult::EXECUTION_CANCELLED:
return arrow::Status{arrow::StatusCode::ExecutionError,
"The execution of the query was cancelled before it could finish, likely "
"caused by executing a different query"};
case StreamExecutionResult::CHUNK_READY:
case StreamExecutionResult::EXECUTION_FINISHED:
ready = true;
break;
case StreamExecutionResult::BLOCKED:
stream_result.WaitForTask();
return DuckDBWasmResultsWrapper::ResponseStatus::DUCKDB_WASM_RETRY;
case StreamExecutionResult::NO_TASKS_AVAILABLE:
return DuckDBWasmResultsWrapper::ResponseStatus::DUCKDB_WASM_RETRY;
case StreamExecutionResult::CHUNK_NOT_READY:
break;
}

auto after = std::chrono::steady_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(after - before).count();
} while (!ready && elapsed < polling_interval);

if (!ready) {
return DuckDBWasmResultsWrapper::ResponseStatus::DUCKDB_WASM_RETRY;
}
}

// Fetch next result chunk
chunk = current_query_result_->Fetch();
if (current_query_result_->HasError()) {
Expand All @@ -249,7 +289,7 @@ arrow::Result<std::shared_ptr<arrow::Buffer>> WebDB::Connection::FetchQueryResul
current_query_result_.reset();
current_schema_.reset();
current_schema_patched_.reset();
return nullptr;
return DuckDBWasmResultsWrapper{nullptr};
}

// Serialize the record batch
Expand Down
2 changes: 1 addition & 1 deletion lib/src/webdb_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ bool duckdb_web_pending_query_cancel(ConnectionHdl connHdl, const char* script)
void duckdb_web_query_fetch_results(WASMResponse* packed, ConnectionHdl connHdl) {
auto c = reinterpret_cast<WebDB::Connection*>(connHdl);
auto r = c->FetchQueryResults();
WASMResponseBuffer::Get().Store(*packed, std::move(r));
WASMResponseBuffer::Get().Store(*packed, r);
}
/// Get table names
void duckdb_web_get_tablenames(WASMResponse* packed, ConnectionHdl connHdl, const char* query) {
Expand Down
Loading