Arquero

Query processing and transformation of array-backed data tables.

README

# Arquero

Arquero is a JavaScript library for query processing and transformation of array-backed data tables. Following the relational algebra and inspired by the design of dplyr, Arquero provides a fluent API for manipulating column-oriented data frames. Arquero supports a range of data transformation tasks, including filter, sample, aggregation, window, join, and reshaping operations.

Fast: process data tables with million+ rows.
Flexible: query over arrays, typed arrays, array-like objects, or Apache Arrow columns.
Full-Featured: perform a variety of wrangling and analysis tasks.
Extensible: add new column types or functions, including aggregate & window operations.
Lightweight: small size, minimal dependencies.

To get up and running, start with the Introducing Arquero tutorial, part of the Arquero notebook collection.

Have a question or need help? Post to the Arquero GitHub Discussions board.

Arquero is Spanish for "archer": if datasets are arrows, Arquero helps their aim stay true. 🏹 Arquero also refers to a goalkeeper: safeguard your data from analytic "own goals"! 🥅 ✋ ⚽

API Documentation


Top-Level API - All methods in the top-level Arquero namespace.
Table - Table access and output methods.
Verbs - Table transformation verbs.
Op Functions - All functions, including aggregate and window functions.
Expressions - Parsing and generation of table expressions.
Extensibility - Extend Arquero with new expression functions or table verbs.

Example


The core abstractions in Arquero are data tables, which model each column as an array of values, and verbs that transform data and return new tables. Verbs are table methods, allowing method chaining for multi-step transformations. Though each table is unique, many verbs reuse the underlying columns to limit duplication.

  1. ``` js
  2. import { all, desc, op, table } from 'arquero';

  3. // Average hours of sunshine per month, from https://usclimatedata.com/.
  4. const dt = table({
  5.   'Seattle': [69,108,178,207,253,268,312,281,221,142,72,52],
  6.   'Chicago': [135,136,187,215,281,311,318,283,226,193,113,106],
  7.   'San Francisco': [165,182,251,281,314,330,300,272,267,243,189,156]
  8. });

  9. // Sorted differences between Seattle and Chicago.
  10. // Table expressions use arrow function syntax.
  11. dt.derive({
  12.     month: d => op.row_number(),
  13.     diff:  d => d.Seattle - d.Chicago
  14.   })
  15.   .select('month', 'diff')
  16.   .orderby(desc('diff'))
  17.   .print();

  18. // Is Seattle more correlated with San Francisco or Chicago?
  19. // Operations accept column name strings outside a function context.
  20. dt.rollup({
  21.     corr_sf:  op.corr('Seattle', 'San Francisco'),
  22.     corr_chi: op.corr('Seattle', 'Chicago')
  23.   })
  24.   .print();

  25. // Aggregate statistics per city, as output objects.
  26. // Reshape (fold) the data to a two column layout: city, sun.
  27. dt.fold(all(), { as: ['city', 'sun'] })
  28.   .groupby('city')
  29.   .rollup({
  30.     min:  d => op.min(d.sun), // functional form of op.min('sun')
  31.     max:  d => op.max(d.sun),
  32.     avg:  d => op.average(d.sun),
  33.     med:  d => op.median(d.sun),
  34.     // functional forms permit flexible table expressions
  35.     skew: ({sun: s}) => (op.mean(s) - op.median(s)) / op.stdev(s) || 0
  36.   })
  37.   .objects()
  38. ```

Usage


In Browser


To use in the browser, you can load Arquero from a content delivery network:

  1. ``` html
  2. <script src="https://cdn.jsdelivr.net/npm/arquero@latest"></script>
  3. ```

Arquero will be imported into the aq global object. The default browser bundle does not include the Apache Arrow library. To perform Arrow encoding using toArrow() or binary file loading using loadArrow(), import Apache Arrow first:

  1. ``` html
  2. <script src="https://cdn.jsdelivr.net/npm/apache-arrow@latest"></script>
  3. <script src="https://cdn.jsdelivr.net/npm/arquero@latest"></script>
  4. ```

Alternatively, you can build and import arquero.min.js from the dist directory, or build your own application bundle. When building custom application bundles for the browser, the module bundler should draw from the browser property of Arquero's package.json file. For example, if using rollup, pass thebrowser: true option to the node-resolve plugin.

Arquero uses modern JavaScript features, and so will not work with some outdated browsers. To use Arquero with older browsers including Internet Explorer, set up your project with a transpiler such as Babel.

In Node.js or Application Bundles


First install arquero as a dependency, via npm install arquero --save or yarn add arquero. Arquero assumes Node version 12 or higher.

Import using CommonJS module syntax:

  1. ``` js
  2. const aq = require('arquero');
  3. ```

Import using ES module syntax, import all exports into a single object:

  1. ``` js
  2. import * as aq from 'arquero';
  3. ```

Import using ES module syntax, with targeted imports:

  1. ``` js
  2. import { op, table } from 'arquero';
  3. ```

Build Instructions


To build and develop Arquero locally:

- Run yarn to install dependencies for all packages. If you don't have yarn installed, see https://yarnpkg.com/en/docs/install.
- Run yarn test to run test cases, yarn perf to run performance benchmarks, and yarn build to build output files.