Skip to content
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

Bump DuckDB, properly propagate wasm_* platform and add test #1328

Merged
merged 10 commits into from
Jul 18, 2023
12 changes: 12 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ jobs:
submodules: 'recursive'
fetch-depth: 0

- name: Prepare repository
run: |
[ -f duckdb.patch ] && cd submodules/duckdb && git apply ../../duckdb.patch || echo "No patching needed"

- uses: mymindstorm/setup-emsdk@v12
with:
version: 'latest'
Expand Down Expand Up @@ -416,6 +420,10 @@ jobs:
submodules: 'recursive'
fetch-depth: 0

- name: Prepare repository
run: |
[ -f duckdb.patch ] && cd submodules/duckdb && git apply ../../duckdb.patch || echo "No patching needed"

- uses: mymindstorm/setup-emsdk@v12
with:
version: 'latest'
Expand Down Expand Up @@ -454,6 +462,10 @@ jobs:
submodules: 'recursive'
fetch-depth: 0

- name: Prepare repository
run: |
[ -f duckdb.patch ] && cd submodules/duckdb && git apply ../../duckdb.patch || echo "No patching needed"

- uses: mymindstorm/setup-emsdk@v12
with:
version: 'latest'
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ wasm_debug: wasm_setup
${EXEC_ENVIRONMENT} ${ROOT_DIR}/scripts/wasm_build_lib.sh debug eh
${EXEC_ENVIRONMENT} ${ROOT_DIR}/scripts/wasm_build_lib.sh debug coi

wasm: wasm_dev
wasm: wasm_relperf

.PHONY: wasm_star
wasm_star: wasm_relsize wasm_relperf wasm_dev wasm_debug
Expand All @@ -285,11 +285,13 @@ wasm_star: wasm_relsize wasm_relperf wasm_dev wasm_debug
.PHONY: js_debug
js_debug: build/bootstrap wasm yarn_install
yarn workspace @duckdb/duckdb-wasm build:debug
yarn workspace @duckdb/duckdb-wasm test

# Build the duckdb library in release mode
.PHONY: js_release
js_release: yarn_install
yarn workspace @duckdb/duckdb-wasm build:release
yarn workspace @duckdb/duckdb-wasm test

# Build the duckdb docs
.PHONY: docs
Expand Down
20 changes: 20 additions & 0 deletions duckdb.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/src/function/table/system/test_all_types.cpp b/src/function/table/system/test_all_types.cpp
index 1652c3eccd..c9f3db2459 100644
--- a/src/function/table/system/test_all_types.cpp
+++ b/src/function/table/system/test_all_types.cpp
@@ -204,13 +204,14 @@ vector<TestType> TestAllTypesFun::GetTestTypes(bool use_large_enum) {
auto max_map_value = Value::MAP(ListType::GetChildType(map_type), map_values);
result.emplace_back(map_type, "map", std::move(min_map_value), std::move(max_map_value));

+#ifndef DUCKDB_FROM_DUCKDB_WASM
// union
child_list_t<LogicalType> members = {{"name", LogicalType::VARCHAR}, {"age", LogicalType::SMALLINT}};
auto union_type = LogicalType::UNION(members);
const Value &min = Value::UNION(members, 0, Value("Frank"));
const Value &max = Value::UNION(members, 1, Value::SMALLINT(5));
result.emplace_back(union_type, "union", min, max);
-
+#endif
return result;
}

5 changes: 5 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ endif ()
# -Os shrinks the module by 600KB but slows down TPC-H by a factor of 2!
# Dedicated module?

set(DUCKDB_PLATFORM "wasm_mvp")

if(EMSCRIPTEN)
# Release build
if(CMAKE_BUILD_TYPE STREQUAL "Release")
Expand Down Expand Up @@ -107,6 +109,7 @@ if(EMSCRIPTEN)
endif()

if(WITH_WASM_EXCEPTIONS)
set(DUCKDB_PLATFORM "wasm_eh")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -fwasm-exceptions -DWEBDB_FAST_EXCEPTIONS=1")
else()
Expand All @@ -126,6 +129,7 @@ if(EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -sUSE_PTHREADS=1 -DWEBDB_THREADS=1")
set(DUCKDB_CXX_FLAGS "${CMAKE_CXX_FLAGS} -sUSE_PTHREADS=1")
set(WASM_LINK_FLAGS "${WASM_LINK_FLAGS} -sUSE_PTHREADS=1 -sPTHREAD_POOL_SIZE=4")
set(DUCKDB_PLATFORM "wasm_threads")
else()
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -sUSE_PTHREADS=0 -DDUCKDB_NO_THREADS=1")
Expand All @@ -134,6 +138,7 @@ if(EMSCRIPTEN)
set(WASM_LINK_FLAGS "${WASM_LINK_FLAGS} -sUSE_PTHREADS=0")
set(THREAD_LIBS)
endif()
set(DUCKDB_CXX_FLAGS "${DUCKDB_CXX_FLAGS} -DDUCKDB_CUSTOM_PLATFORM=${DUCKDB_PLATFORM}")
else()
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -DWEBDB_FAST_EXCEPTIONS=1 -DWEBDB_THREADS=1")
Expand Down
2 changes: 1 addition & 1 deletion lib/cmake/duckdb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if(DUCKDB_LOCATION)
set(DUCKDB_CORE_DIR ${DUCKDB_LOCATION})
endif()

set(DUCKDB_CXX_FLAGS "${DUCKDB_CXX_FLAGS} -Wno-unqualified-std-cast-call -DDUCKDB_DEBUG_NO_SAFETY")
set(DUCKDB_CXX_FLAGS "${DUCKDB_CXX_FLAGS} -Wno-unqualified-std-cast-call -DDUCKDB_DEBUG_NO_SAFETY -DDUCKDB_FROM_DUCKDB_WASM")
message("DUCKDB_CXX_FLAGS=${DUCKDB_CXX_FLAGS}")

set(DUCKDB_EXTENSIONS "fts;excel;json")
Expand Down
2 changes: 1 addition & 1 deletion packages/duckdb-wasm-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"devDependencies": {
"@types/fontfaceobserver": "^2.1.0",
"@types/node": "^20.4.1",
"@types/node": "^20.4.2",
"@types/react-dom": "^18.0.11",
"@types/react-router-dom": "^5.3.3",
"@types/react-virtualized": "^9.21.21",
Expand Down
2 changes: 1 addition & 1 deletion packages/duckdb-wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"csv"
],
"dependencies": {
"apache-arrow": "^11.0.0"
"apache-arrow": "^12.0.0"
},
"devDependencies": {
"@types/emscripten": "^1.39.6",
Expand Down
1 change: 1 addition & 0 deletions packages/duckdb-wasm/src/bindings/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class DuckDBConnection {
try {
resolve(this._bindings.pollPendingQuery(this._conn));
} catch (e: any) {
console.log(e);
reject(e);
}
});
Expand Down
6 changes: 6 additions & 0 deletions packages/duckdb-wasm/src/bindings/runtime_browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
BROWSER_RUNTIME._fileInfoCache.set(fileId, file);
return file;
} catch (e: any) {
console.log(e);
return null;
}
},
Expand Down Expand Up @@ -80,6 +81,7 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {

return BROWSER_RUNTIME._globalFileInfo;
} catch (e: any) {
console.log(e);
return null;
}
},
Expand Down Expand Up @@ -315,6 +317,7 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
mod.ccall('duckdb_web_fs_glob_add_path', null, ['string'], [path]);
}
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
return 0;
}
Expand All @@ -338,6 +341,7 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
return xhr.status == 206 || xhr.status == 200;
}
} catch (e: any) {
console.log(e);
return false;
}
return false;
Expand Down Expand Up @@ -434,6 +438,7 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
);
}
} catch (e) {
console.log(e);
throw new Error(`Range request for ${file.dataUrl} failed with error: ${e}"`);
}
}
Expand All @@ -458,6 +463,7 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
}
return 0;
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
return 0;
}
Expand Down
13 changes: 13 additions & 0 deletions packages/duckdb-wasm/src/bindings/runtime_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const NODE_RUNTIME: DuckDBRuntime & {
NODE_RUNTIME._fileInfoCache.set(fileId, info);
return info as DuckDBFileInfo;
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
return null;
}
Expand Down Expand Up @@ -95,6 +96,7 @@ export const NODE_RUNTIME: DuckDBRuntime & {
failWith(mod, 'Unsupported data protocol');
}
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
}
return 0;
Expand All @@ -120,6 +122,7 @@ export const NODE_RUNTIME: DuckDBRuntime & {
break;
}
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
}
return 0;
Expand All @@ -139,6 +142,7 @@ export const NODE_RUNTIME: DuckDBRuntime & {
failWith(mod, 'Unsupported data protocol');
}
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
}
return 0;
Expand All @@ -162,6 +166,7 @@ export const NODE_RUNTIME: DuckDBRuntime & {
failWith(mod, 'Unsupported data protocol');
}
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
}
return 0;
Expand All @@ -186,6 +191,7 @@ export const NODE_RUNTIME: DuckDBRuntime & {
failWith(mod, 'Unsupported data protocol');
}
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
}
return 0;
Expand All @@ -209,6 +215,7 @@ export const NODE_RUNTIME: DuckDBRuntime & {
failWith(mod, 'Unsupported data protocol');
}
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
}
return 0;
Expand All @@ -219,6 +226,7 @@ export const NODE_RUNTIME: DuckDBRuntime & {
const path = decodeText(mod.HEAPU8.subarray(pathPtr, pathPtr + pathLen));
return fs.existsSync(path);
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
return false;
}
Expand All @@ -228,6 +236,7 @@ export const NODE_RUNTIME: DuckDBRuntime & {
const path = decodeText(mod.HEAPU8.subarray(pathPtr, pathPtr + pathLen));
return fs.mkdirSync(path);
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
return 0;
}
Expand All @@ -237,6 +246,7 @@ export const NODE_RUNTIME: DuckDBRuntime & {
const path = decodeText(mod.HEAPU8.subarray(pathPtr, pathPtr + pathLen));
return fs.rmdirSync(path);
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
return 0;
}
Expand All @@ -253,6 +263,7 @@ export const NODE_RUNTIME: DuckDBRuntime & {
mod.ccall('duckdb_web_fs_glob_add_path', null, ['string'], [entry]);
}
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
return 0;
}
Expand All @@ -278,6 +289,7 @@ export const NODE_RUNTIME: DuckDBRuntime & {
const path = decodeText(mod.HEAPU8.subarray(pathPtr, pathPtr + pathLen));
return fs.existsSync(path);
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
return false;
}
Expand All @@ -287,6 +299,7 @@ export const NODE_RUNTIME: DuckDBRuntime & {
const path = decodeText(mod.HEAPU8.subarray(pathPtr, pathPtr + pathLen));
return fs.rmSync(path);
} catch (e: any) {
console.log(e);
failWith(mod, e.toString());
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/duckdb-wasm/src/parallel/worker_dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export abstract class AsyncDuckDBDispatcher implements Logger {
});
this.sendOK(request);
} catch (e: any) {
console.log(e);
this._bindings = null;
this.failWith(request, e);
}
Expand Down Expand Up @@ -395,6 +396,7 @@ export abstract class AsyncDuckDBDispatcher implements Logger {
}
}
} catch (e: any) {
console.log(e);
return this.failWith(request, e);
}
}
Expand Down
14 changes: 14 additions & 0 deletions packages/duckdb-wasm/test/bindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ export function testBindings(db: () => duckdb.DuckDBBindings, baseURL: string):
});
});

describe('Check platform', () => {
it('Platform check', async () => {
await db().reset();
conn = db().connect();
const version = conn.query<{ name: arrow.Utf8 }>(
"PRAGMA platform;",
);
const rows = version.getChildAt(0)?.toArray();
expect(rows.length).toEqual(1);
expect(rows[0].toString().substr(0,5)).toEqual("wasm_");
await db().reset();
});
});

//describe('Open', () => {
// XXX apparently synchronous XHR on the main thread does not allow for arraybuffer response type?
// it('Remote TPCH 0_01', async () => {
Expand Down
2 changes: 1 addition & 1 deletion submodules/arrow
Submodule arrow updated 781 files
2 changes: 1 addition & 1 deletion submodules/duckdb
Submodule duckdb updated 103 files
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -954,10 +954,10 @@
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"
integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==

"@types/node@*", "@types/node@>=10.0.0", "@types/node@^20.4.1":
version "20.4.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.4.1.tgz#a6033a8718653c50ac4962977e14d0f984d9527d"
integrity sha512-JIzsAvJeA/5iY6Y/OxZbv1lUcc8dNSE77lb2gnBH+/PJ3lFR1Ccvgwl5JWnHAkNHcRsT0TbpVOsiMKZ1F/yyJg==
"@types/node@*", "@types/node@>=10.0.0", "@types/node@^20.4.2":
version "20.4.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.4.2.tgz#129cc9ae69f93824f92fac653eebfb4812ab4af9"
integrity sha512-Dd0BYtWgnWJKwO1jkmTrzofjK2QXXcai0dmtzvIBhcA+RsG5h8R3xlyta0kGOZRNfL9GuRtb1knmPEhQrePCEw==

"@types/node@18.7.23":
version "18.7.23"
Expand Down