-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-613: WIP TypeScript Implementation #358
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
00bb974
Initial typescript implementation
TheNeuralBit 71e72df
Added support for the browser via webpack
TheNeuralBit c221f74
Create README.md
TheNeuralBit 0f43270
Replaced table style with an original, basic one
TheNeuralBit 8092810
Moved index.html to examples/ directory
TheNeuralBit 3a92bdd
Added ASF Licence headers
TheNeuralBit 1f6dcf3
Renamed _arrayToInt
TheNeuralBit 3839485
Removed tabs
a5800d9
Added docstrings for Vector functions
3f0d9f0
Added missing runtime dependency
ce81034
Cleaned up TextDecoder/Utf8Vector
74e8520
added a few more license headers
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| lib/*_generated.js | ||
| dist | ||
| node_modules | ||
| typings |
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,50 @@ | ||
| <!--- | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. See accompanying LICENSE file. | ||
| --> | ||
|
|
||
| ### Installation | ||
|
|
||
| From this directory, run: | ||
|
|
||
| ``` bash | ||
| $ npm install # pull dependencies | ||
| $ tsc # build typescript | ||
| $ webpack # bundle for the browser | ||
| ``` | ||
|
|
||
| ### Usage | ||
| The library is designed to be used with node.js or in the browser, this repository contains examples of both. | ||
|
|
||
| #### Node | ||
| Import the arrow module: | ||
|
|
||
| ``` js | ||
| var arrow = require("arrow.js"); | ||
| ``` | ||
|
|
||
| See [bin/arrow_schema.js](bin/arrow_schema.js) and [bin/arrow2csv.js](bin/arrow2csv.js) for usage examples. | ||
|
|
||
| #### Browser | ||
| Include `dist/arrow-bundle.js` in a `<script />` tag: | ||
| ``` html | ||
| <script src="arrow-bundle.js"/> | ||
| ``` | ||
| See [examples/read_file.html](examples/read_file.html) for a usage example - or try it out now at [theneuralbit.github.io/arrow](http://theneuralbit.github.io/arrow) | ||
|
|
||
| ### API | ||
| ##### `arrow.loadSchema(buffer)` | ||
| Returns a JSON representation of the file's Arrow schema. | ||
|
|
||
| ##### `arrow.loadVectors(buffer)` | ||
| Returns a dictionary of `Vector` objects, one for each column, indexed by the column's name. | ||
| Vector objects have, at minimum, a `get(i)` method and a `length` attribute. |
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,47 @@ | ||
| #! /usr/bin/env node | ||
|
|
||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| var fs = require('fs') | ||
| var process = require('process'); | ||
| var loadVectors = require('../dist/arrow.js').loadVectors; | ||
| var program = require('commander'); | ||
|
|
||
| function list (val) { | ||
| return val.split(','); | ||
| } | ||
|
|
||
| program | ||
| .version('0.1.0') | ||
| .usage('[options] <file>') | ||
| .option('-s --schema <list>', 'A comma-separated list of column names', list) | ||
| .parse(process.argv); | ||
|
|
||
| if (!program.schema) { | ||
| program.outputHelp(); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| var buf = fs.readFileSync(process.argv[process.argv.length - 1]); | ||
| var vectors = loadVectors(buf); | ||
|
|
||
| for (var i = 0; i < vectors[program.schema[0]].length; i += 1|0) { | ||
| console.log(program.schema.map(function (field) { | ||
| return '' + vectors[field].get(i); | ||
| }).join(',')); | ||
| } |
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,25 @@ | ||
| #! /usr/bin/env node | ||
|
|
||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| var fs = require('fs'); | ||
| var process = require('process'); | ||
| var loadSchema = require('../dist/arrow.js').loadSchema; | ||
|
|
||
| var buf = fs.readFileSync(process.argv[process.argv.length - 1]); | ||
| console.log(JSON.stringify(loadSchema(buf), null, '\t')); |
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,79 @@ | ||
| <!DOCTYPE html> | ||
|
|
||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
| --> | ||
|
|
||
| <html> | ||
| <head> | ||
| <title>arrow.js browser test</title> | ||
| <meta charset="utf-8"> | ||
| <style> | ||
| table { | ||
| border-collapse: collapse; | ||
| } | ||
| table, th, td { | ||
| border: 1px solid black; | ||
| } | ||
| </style> | ||
| <script type="text/javascript"> | ||
| var reader = new FileReader(); | ||
| function addCell (tr, type, name) { | ||
| var td = document.createElement(type) | ||
| td.textContent = name; | ||
| tr.appendChild(td); | ||
| } | ||
| reader.onload = function (evt) { | ||
| var buf = new Uint8Array(evt.target.result); | ||
| var schema = arrow.loadSchema(buf); | ||
| var vectors = arrow.loadVectors(buf); | ||
| var length = vectors[schema[0].name].length; | ||
|
|
||
| var thead = document.getElementById("thead"); | ||
| var tbody = document.getElementById("tbody"); | ||
| var header_row = document.createElement("tr"); | ||
|
|
||
| schema.forEach(function (d) { | ||
| addCell(header_row, "th", d.name); | ||
| }); | ||
|
|
||
| thead.appendChild(header_row); | ||
|
|
||
| for (var i = 0; i < length; i += 1|0) { | ||
| var tr = document.createElement("tr"); | ||
| schema.forEach(function (d) { addCell(tr, "td", vectors[d.name].get(i)); }); | ||
| tbody.appendChild(tr); | ||
| } | ||
| } | ||
|
|
||
| function handleFiles(files) { | ||
| reader.readAsArrayBuffer(files[0]); | ||
| } | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <input id="arrow-in" type="file" onchange="handleFiles(this.files)" /> | ||
| <table> | ||
| <thead id="thead"> | ||
| </thead> | ||
| <tbody id="tbody"> | ||
| </tbody> | ||
| </table> | ||
| <script type="text/javascript" src="../dist/arrow-bundle.js"></script> | ||
| </body> | ||
| </html> |
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,5 @@ | ||
| export var org: { | ||
| apache: { | ||
| arrow: any | ||
| } | ||
| } | ||
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.
There's a WIP PR for adding TypeScript support to flatbuffers (#4065), which should make this definition unnecessary.