-
Notifications
You must be signed in to change notification settings - Fork 83
DuckDBClient #313
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
Merged
Merged
DuckDBClient #313
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,11 @@ const mains = ["unpkg", "jsdelivr", "browser", "main"]; | |
} | ||
{ | ||
const package = await resolve("apache-arrow@4"); | ||
console.log(`export const arrow = dependency("${package.name}", "${package.version}", "${package.export}");`); | ||
console.log(`export const arrow4 = dependency("${package.name}", "${package.version}", "${package.export}");`); | ||
} | ||
{ | ||
const package = await resolve("apache-arrow@9"); | ||
console.log(`export const arrow9 = dependency("${package.name}", "${package.version}", "+esm");`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arrow 10 is out so you can update to that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Going to stick with Arrow 9 until duckdb-wasm upgrades… |
||
} | ||
{ | ||
const package = await resolve("arquero"); | ||
|
@@ -87,8 +91,8 @@ const mains = ["unpkg", "jsdelivr", "browser", "main"]; | |
console.log(`export const leaflet = dependency("${package.name}", "${package.version}", "${package.export.replace(/-src\.js$/, ".js")}");`); | ||
} | ||
{ | ||
const package = await resolve("@duckdb/duckdb-wasm@1.17.0"); | ||
console.log(`export const duckdb = dependency("${package.name}", "${package.version}", "${package.export}");`); | ||
const package = await resolve("@duckdb/duckdb-wasm"); | ||
console.log(`export const duckdb = dependency("${package.name}", "${package.version}", "+esm");`); | ||
} | ||
})(); | ||
|
||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Returns true if the vaue is an Apache Arrow table. This uses a “duck” test | ||
// (instead of strict instanceof) because we want it to work with a range of | ||
// Apache Arrow versions at least 7.0.0 or above. | ||
// https://arrow.apache.org/docs/7.0/js/classes/Arrow_dom.Table.html | ||
export function isArrowTable(value) { | ||
return ( | ||
value && | ||
typeof value.getChild === "function" && | ||
typeof value.toArray === "function" && | ||
value.schema && | ||
Array.isArray(value.schema.fields) | ||
); | ||
} | ||
|
||
export function getArrowTableSchema(table) { | ||
return table.schema.fields.map(getArrowFieldSchema); | ||
} | ||
|
||
function getArrowFieldSchema(field) { | ||
return { | ||
name: field.name, | ||
type: getArrowType(field.type), | ||
nullable: field.nullable, | ||
databaseType: String(field.type) | ||
}; | ||
} | ||
|
||
// https://github.com/apache/arrow/blob/89f9a0948961f6e94f1ef5e4f310b707d22a3c11/js/src/enum.ts#L140-L141 | ||
function getArrowType(type) { | ||
switch (type.typeId) { | ||
case 2: // Int | ||
return "integer"; | ||
case 3: // Float | ||
case 7: // Decimal | ||
return "number"; | ||
case 4: // Binary | ||
case 15: // FixedSizeBinary | ||
return "buffer"; | ||
case 5: // Utf8 | ||
return "string"; | ||
case 6: // Bool | ||
return "boolean"; | ||
case 8: // Date | ||
case 9: // Time | ||
case 10: // Timestamp | ||
return "date"; | ||
case 12: // List | ||
case 16: // FixedSizeList | ||
return "array"; | ||
case 13: // Struct | ||
case 14: // Union | ||
return "object"; | ||
case 11: // Interval | ||
case 17: // Map | ||
default: | ||
return "other"; | ||
} | ||
} |
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
Oops, something went wrong.
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.
This is needed for dynamic import. However, this probably means that this should be released as a major version bump since it means older JavaScript environments may not be able to support the new syntax. We could avoid this by reverting to the AMD (require) bundle for duckdb-wasm and apache-arrow, but it might be time to move forward. I still need to think about this a bit.