Skip to content

Commit

Permalink
Consolidated JS data handling refactor
Browse files Browse the repository at this point in the history
Change-Id: I423b49d58842a88b8a26c7fa646ed4771f9e31a0
  • Loading branch information
trxcllnt authored and wesm committed Jan 5, 2019
1 parent 46b1bc7 commit aaf42c8
Show file tree
Hide file tree
Showing 160 changed files with 17,169 additions and 12,420 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ matrix:
- if [ $ARROW_CI_INTEGRATION_AFFECTED != "1" ]; then exit; fi
- $TRAVIS_BUILD_DIR/ci/travis_install_linux.sh
- $TRAVIS_BUILD_DIR/ci/travis_install_clang_tools.sh
- nvm install 10.1
- nvm install 11.6
- $TRAVIS_BUILD_DIR/ci/travis_before_script_js.sh
- $TRAVIS_BUILD_DIR/ci/travis_before_script_cpp.sh
script:
Expand All @@ -239,7 +239,7 @@ matrix:
language: node_js
os: linux
node_js:
- '10.1'
- '11.6'
before_script:
- if [ $ARROW_CI_JS_AFFECTED != "1" ]; then exit; fi
- $TRAVIS_BUILD_DIR/ci/travis_install_linux.sh
Expand Down
2 changes: 1 addition & 1 deletion ci/travis_script_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pushd $ARROW_JS_DIR

# lint and compile JS source
npm run lint
npm run build
npm run build -- -t apache-arrow

popd

Expand Down
5 changes: 3 additions & 2 deletions ci/travis_script_js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ source $TRAVIS_BUILD_DIR/ci/travis_env_common.sh

pushd $ARROW_JS_DIR

npm run lint
npm run lint:ci
npm run build
# run the non-snapshot unit tests
npm test
npm run test:coverage
bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"

popd
2 changes: 1 addition & 1 deletion integration/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ def _run(self, exe_cmd, arrow_path=None, json_path=None,
if json_path is not None:
cmd.extend(['-j', json_path])

cmd.extend(['--mode', command, '-t', 'es5', '-m', 'umd'])
cmd.extend(['--mode', command])

if self.debug:
print(' '.join(cmd))
Expand Down
9 changes: 7 additions & 2 deletions js/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

.vscode
.vscode/**
!.vscode/launch.json

# Runtime data
pids
Expand Down Expand Up @@ -78,10 +79,14 @@ yarn.lock
.env

# compilation targets
doc
dist
targets

# test data files
test/data/
test/data/cpp
test/data/java
test/data/json

# jest snapshots (too big)
test/__snapshots__/
169 changes: 169 additions & 0 deletions js/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Gulp Build",
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
"args": [
"build",
// Specify we want to debug the "src" target, which won't clean or build -- essentially a "dry-run" of the gulp build
"--target", "src"
]
},
{
"type": "node",
"request": "launch",
"name": "Debug Unit Tests",
"cwd": "${workspaceRoot}",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"skipFiles": [
"<node_internals>/**/*.js",
"${workspaceFolder}/node_modules/**/*.js"
],
"env": {
"NODE_NO_WARNINGS": "1",
"READABLE_STREAM": "disable",
"TEST_DOM_STREAMS": "true",
"TEST_NODE_STREAMS": "true",
// Modify these environment variables to run tests on a specific compilation target + module format combo
"TEST_TS_SOURCE": "true",
// "TEST_TS_SOURCE": "false",
// "TEST_TARGET": "es5",
// "TEST_MODULE": "umd"
},
"args": [
// "-i",
"test/unit/",

// Uncomment any of these to run individual test suites
// "test/unit/int-tests.ts",
// "test/unit/table-tests.ts",
// "test/unit/generated-data-tests.ts",

// "test/unit/vector/vector-tests.ts",
// "test/unit/vector/bool-vector-tests.ts",
// "test/unit/vector/date-vector-tests.ts",
// "test/unit/vector/float16-vector-tests.ts",
// "test/unit/vector/numeric-vector-tests.ts",

// "test/unit/visitor-tests.ts",

// "test/unit/ipc/message-reader-tests.ts",
// "test/unit/ipc/reader/file-reader-tests.ts",
// "test/unit/ipc/reader/json-reader-tests.ts",
// "test/unit/ipc/reader/from-inference-tests.ts",
// "test/unit/ipc/reader/stream-reader-tests.ts",
// "test/unit/ipc/reader/streams-dom-tests.ts",
// "test/unit/ipc/reader/streams-node-tests.ts",
// "test/unit/ipc/writer/file-writer-tests.ts",
// "test/unit/ipc/writer/json-writer-tests.ts",
// "test/unit/ipc/writer/stream-writer-tests.ts",
// "test/unit/ipc/writer/streams-dom-tests.ts",
// "test/unit/ipc/writer/streams-node-tests.ts",
]
},
{
"type": "node",
"request": "launch",
"name": "Debug Integration Tests",
"cwd": "${workspaceRoot}",
"program": "${workspaceFolder}/bin/integration.js",
"skipFiles": [
"<node_internals>/**/*.js",
"${workspaceFolder}/node_modules/**/*.js"
],
"env": {
"NODE_NO_WARNINGS": "1",
"READABLE_STREAM": "disable"
},
"args": [
"--mode", "VALIDATE"
]
},
{
"type": "node",
"request": "launch",
"name": "Debug bin/arrow2csv",
"env": { "ARROW_JS_DEBUG": "src", "TS_NODE_CACHE": "false" },
"runtimeArgs": ["-r", "ts-node/register"],
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**/*.js",
"${workspaceFolder}/node_modules/**/*.js"
],
"args": [
"${workspaceFolder}/src/bin/arrow2csv.ts",
"-f", "./test/data/cpp/stream/simple.arrow"
]
},
{
"type": "node",
"request": "launch",
"name": "Debug bin/file-to-stream",
"env": { "ARROW_JS_DEBUG": "src", "TS_NODE_CACHE": "false" },
"runtimeArgs": ["-r", "ts-node/register"],
"skipFiles": [
"<node_internals>/**/*.js",
"${workspaceFolder}/node_modules/**/*.js"
],
"args": [
"${workspaceFolder}/bin/file-to-stream.js",
"./test/data/cpp/file/struct_example.arrow",
"./struct_example-stream-out.arrow",
]
},
{
"type": "node",
"request": "launch",
"name": "Debug bin/stream-to-file",
"env": { "ARROW_JS_DEBUG": "src", "TS_NODE_CACHE": "false" },
"runtimeArgs": ["-r", "ts-node/register"],
"skipFiles": [
"<node_internals>/**/*.js",
"${workspaceFolder}/node_modules/**/*.js"
],
"args": [
"${workspaceFolder}/bin/stream-to-file.js",
"./test/data/cpp/stream/struct_example.arrow",
"./struct_example-file-out.arrow",
]
},
{
"type": "node",
"request": "launch",
"name": "Debug bin/json-to-arrow",
"env": { "ARROW_JS_DEBUG": "src", "TS_NODE_CACHE": "false" },
"runtimeArgs": ["-r", "ts-node/register"],
"skipFiles": [
"<node_internals>/**/*.js",
"${workspaceFolder}/node_modules/**/*.js"
],
"args": [
"${workspaceFolder}/bin/json-to-arrow.js",
"-j", "./test/data/json/struct_example.json",
"-a", "./struct_example-stream-out.arrow",
"-f", "stream"
]
},
{
"type": "node",
"request": "launch",
"name": "Debug bin/print-buffer-alignment",
"env": { "ARROW_JS_DEBUG": "src", "TS_NODE_CACHE": "false" },
"runtimeArgs": ["-r", "ts-node/register"],
"skipFiles": [
"<node_internals>/**/*.js",
"${workspaceFolder}/node_modules/**/*.js"
],
"args": [
"${workspaceFolder}/bin/print-buffer-alignment.js",
"./test/data/cpp/stream/struct_example.arrow"
]
}
]
}
43 changes: 26 additions & 17 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Check out our [API documentation][7] to learn more about how to use Apache Arrow

### Get a table from an Arrow file on disk (in IPC format)

```es6
```js
import { readFileSync } from 'fs';
import { Table } from 'apache-arrow';

Expand All @@ -70,7 +70,7 @@ null, null, null

### Create a Table when the Arrow file is split across buffers

```es6
```js
import { readFileSync } from 'fs';
import { Table } from 'apache-arrow';

Expand All @@ -93,33 +93,42 @@ console.log(table.toString());

### Create a Table from JavaScript arrays

```es6
```js
import {
Table,
FloatVector,
DateVector
} from 'apache-arrow';

const LENGTH = 2000;
const rainAmounts = Float32Array.from({length: LENGTH}, () => Number((Math.random() * 20).toFixed(1)));
const rainDates = Array.from({length: LENGTH}, (_, i) => new Date(Date.now() - 1000 * 60 * 60 * 24 * i));

const rainfall = arrow.Table.fromVectors(
const rainAmounts = Float32Array.from(
{ length: LENGTH },
() => Number((Math.random() * 20).toFixed(1)));

const rainDates = Array.from(
{ length: LENGTH },
(_, i) => new Date(Date.now() - 1000 * 60 * 60 * 24 * i));

const rainfall = Table.fromVectors(
[FloatVector.from(rainAmounts), DateVector.from(rainDates)],
['precipitation', 'date']
);
```

### Load data with `fetch`

```es6
```js
import { Table } from "apache-arrow";

fetch(require("simple.arrow")).then(response => {
response.arrayBuffer().then(buffer => {
const table = Table.from(new Uint8Array(buffer));
console.log(table.toString());
});
});
const table = await Table.from(fetch(("/simple.arrow")));
console.log(table.toString());

```

### Columns look like JS Arrays

```es6
```js
import { readFileSync } from 'fs';
import { Table } from 'apache-arrow';

Expand All @@ -131,7 +140,7 @@ const table = Table.from([
const column = table.getColumn('origin_lat');

// Copy the data into a TypedArray
const typed = column.slice();
const typed = column.toArray();
assert(typed instanceof Float32Array);

for (let i = -1, n = column.length; ++i < n;) {
Expand All @@ -141,7 +150,7 @@ for (let i = -1, n = column.length; ++i < n;) {

### Usage with MapD Core

```es6
```js
import MapD from 'rxjs-mapd';
import { Table } from 'apache-arrow';

Expand All @@ -164,7 +173,7 @@ MapD.open(host, port)
)
.map(([schema, records]) =>
// Create Arrow Table from results
Table.from(schema, records))
Table.from([schema, records]))
.map((table) =>
// Stringify the table to CSV with row numbers
table.toString({ index: true }))
Expand Down
27 changes: 27 additions & 0 deletions js/bin/arrow2csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#! /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.

const Path = require(`path`);
const here = Path.resolve(__dirname, '../');
const tsnode = require.resolve(`ts-node/register`);
const arrow2csv = Path.join(here, `src/bin/arrow2csv.ts`);

require('child_process').spawn(`node`, [
`-r`, tsnode, arrow2csv, ...process.argv.slice(2)
], { cwd: here, env: process.env, stdio: `inherit` });
Loading

0 comments on commit aaf42c8

Please sign in to comment.