Giter Club home page Giter Club logo

rxjs-mapd's Introduction

reactive node bindings to mapd-core via rxjs and apache arrow

A thin Observable wrapper for connecting to mapd-core. Interact with query results in host or device memory as Arrow columns.

install:

npm install rxjs-mapd

collaborate:

git clone [email protected]:graphistry/rxjs-mapd.git

notes:

todos:

  1. add IPC handlers to node-cuda so we can use GPU Arrows
  2. need to investigate runnning mapd-core in CI so I can write tests
  3. break out custom Thrift setup into separate rxjs-thrift module
  4. contribute typings, bugfixes, and cuda integration to Apache Arrow's JS lib then switch
  5. submit PRs to Apache's Thrift compiler for smaller files, better typings, and option to omit Q
  6. finish writing LINQ in JS and fold this into that, so we can JIT to LLIR and run LINQ on GPUs

usage:

code from examples/index.js:

/**
 * Assumes default mapd-core setup and flights_2008_10k test dataset
 */

import open from 'rxjs-mapd';
const host = `localhost`, port = 9091, encrypted = false;
const username = `mapd`, password = `HyperInteractive`, dbName = `mapd`, timeout = 5000;
/**
 * establish the thrift connection to the mapd-core server and emit an rxjs-mapd Client Observable
 * open also accepts named parameters:
 * ```
 * open({
 *     host, port, secure,
 *     protocol: `sock`, transport: `binary`
 * })
 * ```
 */
open(host, port, encrypted)
    /**
     * connect the emitted Client to a mapd-core db. This is a convenience method for
     * calling `connect` on the emitted client via flatMap, so it's identical to this:
     * ```
     * open(...).flatMap((client) => client.connect(username, password, dbName, timeout))
     * ```
     * `connect` also accepts named parameters:
     * ```
     * connect({ dbName, timeout, username, password })
     * ```
     */
    .connect(username, password, dbName, timeout)
    .flatMap((client) => client
        // .query(`SELECT count(*) FROM flights_2008_10k`) // <- 1 col/1 row
        // .query(`SELECT origin_city FROM flights_2008_10k WHERE dest_city ILIKE 'dallas'`) // <- will work when mapd-core serializes categorical results to arrows
        .query(`SELECT origin_lat, origin_lon FROM flights_2008_10k WHERE dest_city ILIKE 'dallas'`) // 2 cols/many rows
        .toArrow()
        .repeat(2) // <- execute the query again -- everything's an Observable!
        .disconnect() // <- disconnect this client session when finished
    )
    .subscribe(printArrowTable, (err) => console.error(err));

function printArrowTable(arrow, schema = arrow.getSchema()) {
    let rows, table = [
        schema.map(({ name }) => name).join(', ')
    ];
    while ((rows = arrow.loadNextBatch()) > 0) {
        for (let row = -1; ++row < rows;) {
            const tRow = [];
            for (const { name } of schema) {
                tRow.push(arrow.getVector(name).get(row));
            }
            table.push(tRow.join(', '));
        }
    }
    console.log(table.join('\n'));
}

rxjs-mapd's People

Contributors

trxcllnt avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.