• Stars
    star
    126
  • Rank 282,735 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Distributed query engine Presto client library for node.js

presto-client-node

Distributed query engine "Presto" 's client library for node.js.

var presto = require('presto-client');
var client = new presto.Client({user: 'myname'});

client.execute({
  query:   'SELECT count(*) as cnt FROM tblname WHERE ...',
  catalog: 'hive',
  schema:  'default',
  source:  'nodejs-client',
  state:   function(error, query_id, stats){ console.log({message:"status changed", id:query_id, stats:stats}); },
  columns: function(error, data){ console.log({resultColumns: data}); },
  data:    function(error, data, columns, stats){ console.log(data); },
  success: function(error, stats){},
  error:   function(error){}
});

Installation

npm install -g presto-client

Or add presto-client to your own package.json, and do npm install.

API

new Client(opts)

Instanciate client object and set default configurations.

  • opts [object]
    • host [string]
      • Presto coordinator hostname or address (default: localhost)
    • ssl [object]
      • Setting a Hash object enables SSL and verify server certificate with options (default: null):
        • ca: An authority certificate or array of authority certificates to check the remote host against
        • cert: Public x509 certificate to use (default : null)
        • ciphers : Default cipher suite to use. (default: https://nodejs.org/api/tls.html#tls_modifying_the_default_tls_cipher_suite)
        • key: Private key to use for SSL (default: null)
        • passphrase: A string of passphrase for the private key or pfx (default: null)
        • pfx: Certificate, Private key and CA certificates to use for SSL. (default: null).
        • rejectUnauthorized: If not false the server will reject any connection which is not authorized with the list of supplied CAs. This option only has an effect if requestCert is true (default: true)
        • secureProtocol: Optional SSL method to use. The possible values are listed as SSL_METHODS, use the function names as strings. For example, "SSLv3_method" to force SSL version 3 (default: SSLv23_method)
        • servername: Server name for the SNI (Server Name Indication) TLS extension
    • port [integer]
      • Presto coordinator port (default: 8080)
    • user [string]
      • Username of query (default: process user name)
    • source [string]
      • Source of query (default: nodejs-client)
    • basic_auth [object]
      • Pass in a user and password to enable Authorization Basic headers on all requests.
      • basic_auth: {user: "user", password: "password"} (default:null)
    • custom_auth [string]
      • Sets HTTP Authorization header with the provided string.
      • Throws exception if basic_auth is also given at the same time
    • catalog [string]
      • Default catalog name
    • schema [string]
      • Default schema name
    • checkInterval [integer]
      • Interval milliseconds of each RPC to check query status (default: 800ms)
    • enableVerboseStateCallback [boolean]
      • Enable more verbose callback for Presto query states (default: false)
      • When set to true, this flag modifies the condition of the state change callback to return data every checkInterval(default: 800ms). Modify checkInterval if you wish to change the frequency.
      • Otherwise (false), the state change callback will only be called upon a change in state.
      • The purpose of this variable is to enable verbose update capability in state callbacks. This is such that "percentage complete" and "processed rows" may be extracted despite the state still remaining in a particular state eg. "RUNNING".
    • jsonParser [object]
      • Custom json parser if required (default: JSON)
    • engine [string]
      • Change headers set. Added for compatibility with Trino.
      • Available options: presto, trino (default: presto)

return value: client instance object

execute(opts)

This is an API to execute queries. (Using "/v1/statement" HTTP RPC.)

Execute query on Presto cluster, and fetch results.

Attributes of opts [object] are:

  • query [string]
  • catalog [string]
  • schema [string]
  • timezone [string :optional]
  • user [string :optional]
  • prepares [array(string) :optional]
    • The array of prepared statements, without PREPARE query0 FROM prefix.
    • Prepared queries can be referred as queryN(N: index) like query0, query1 in the query specified as query. Example:
      client.execute({ query: 'EXECUTE query0 USING 2', prepares: ['SELECT 2 + ?'], /* ... */ });
  • info [boolean :optional]
    • fetch query info (execution statistics) for success callback, or not (default false)
  • headers [object :optional]
    • additional headers to be included in the request, check the full list for Trino and Presto engines
  • cancel [function() :optional]
    • client stops fetch of query results if this callback returns true
  • state [function(error, query_id, stats) :optional]
    • called when query stats changed
      • stats.state: QUEUED, PLANNING, STARTING, RUNNING, FINISHED, or CANCELED, FAILED
    • query_id
      • id string like 20140214_083451_00012_9w6p5
    • stats
      • object which contains running query status
  • columns [function(error, data) :optional]
    • called once when columns and its types are found in results
    • data
      • array of field info
      • [ { name: "username", type: "varchar" }, { name: "cnt", type: "bigint" } ]
  • data [function(error, data, columns, stats) :optional]
    • called per fetch of query results (may be called 2 or more)
    • data
      • array of array of each column
      • [ [ "tagomoris", 1013 ], [ "dain", 2056 ], ... ]
    • columns (optional)
      • same as data of columns callback
    • stats (optional)
      • runtime statistics object of query
  • success [function(error, stats, info) :optional]
    • called once when all results are fetched (default: value of callback)
  • error [function(error) :optional]
    • callback for errors of query execution (default: value of callback)
  • callback [function(error, stats) :optional]
    • callback for query completion (both of success and fail)
    • one of callback or success must be specified

Callbacks order (success query) is: columns -> data (-> data xN) -> success (or callback)

query(query_id, callback)

Get query current status. (Same with 'Raw' of Presto Web in browser.)

  • query_id [string]
  • callback [function(error, data)]

kill(query_id, callback)

Stop query immediately.

  • query_id [string]
  • callback [function(error) :optional]

nodes(opts, callback)

Get node list of presto cluster and return it.

  • opts [object :optional]
    • specify null, undefined or {} (currently)
  • callback [function(error,data)]
    • error
    • data
      • array of node objects

BIGINT value handling

Javascript standard JSON module cannot handle BIGINT values correctly by precision problems.

JSON.parse('{"bigint":1139779449103133602}').bigint //=> 1139779449103133600

If your query puts numeric values in its results and precision is important for that query, you can swap JSON parser with any modules which has parse method.

var JSONbig = require('json-bigint');
JSONbig.parse('{"bigint":1139779449103133602}').bigint.toString() //=> "1139779449103133602"
// set client option
var client = new presto.Client({
  // ...
  jsonParser: JSONbig,
  // ...
});

Versions

  • 0.13.0:
    • add "headers" option on execute() to specify any request headers
  • 0.12.2:
    • fix the bug of the "prepares" option
  • 0.12.1:
    • add "user" option on execute() to override the user specified per client
  • 0.12.0:
    • add X-Trino-Prepared-Statement to support SQL placeholder
    • catch Invalid URL errors
  • 0.11.2:
    • fix pregression for basic_auth feature
  • 0.11.1:
    • fix a critical bug around the code for authorization
  • 0.11.0:
  • 0.10.0:
    • add "engine" option to execute queries on Trino
  • 0.9.0:
    • make "catalog" and "schema" options optional (need to specify those in queries if omitted)
  • 0.8.1:
    • fix to specify default ports of http/https if nextUri doesn't have ports
  • 0.8.0:
    • fix the bug about SSL/TLS handling if redirections are required
  • 0.7.0:
    • support the change of prestodb 0.226 (compatible with others)
  • 0.6.0:
    • add X-Presto-Source if "source" specified
  • 0.5.0:
    • remove support for execute(arg, callback) using /v1/execute
  • 0.4.0:
    • add a parameter to call status callback in verbose
  • 0.3.0:
    • add Basic Authentication support
  • 0.2.0:
    • add HTTPS support
  • 0.1.3:
    • add X-Presto-Time-Zone if "timezone" specified
  • 0.1.2:
    • add X-Presto-Session if "session" specified
  • 0.1.1:
    • fix bug not to handle HTTP level errors correctly
  • 0.1.0:
    • add option to pass customized json parser to handle BIGINT values
    • add check for required callbacks of query execution
  • 0.0.6:
    • add API to get/delete queries
    • add callback state on query execution
  • 0.0.5:
    • fix to do error check on query execution
  • 0.0.4:
    • send cancel request of canceled query actually
  • 0.0.3:
    • simple and immediate query execution support
  • 0.0.2: maintenance release
    • add User-Agent header with version
  • 0.0.1: initial release

Todo

  • node: "failed" node list support
  • patches welcome!

Author & License

  • tagomoris
  • License:
    • MIT (see LICENSE)

More Repositories

1

shib

WebUI for query engines: Hive and Presto
JavaScript
200
star
2

xbuild

Language runtimes installer for production environment
Shell
197
star
3

deferral

Golang-style defer in Ruby
Ruby
175
star
4

fluent-plugin-forest

Ruby
149
star
5

fluent-plugin-secure-forward

Ruby
140
star
6

fluent-plugin-mysql

Ruby
91
star
7

fluent-agent-lite

Lightweight log delivery agent works w/ fluentd
Perl
79
star
8

fluent-plugin-parser

Ruby
75
star
9

fluent-plugin-flowcounter

TODO: one-line summary of your gem
Ruby
54
star
10

fluent-plugin-datacounter

Ruby
47
star
11

mysql2-cs-bind

'mysql2' extension to add pseudo prepared statement
Ruby
38
star
12

fluent-plugin-growthforecast

TODO: one-line summary of your gem
Ruby
37
star
13

maccro

Macro in Ruby
Ruby
30
star
14

fluent-plugin-file-alternative

Ruby
25
star
15

fluent-plugin-ping-message

Ruby
24
star
16

yabitz

Yet Another Business Information Tracker Z: host management application
Ruby
22
star
17

fluent-plugin-sampling-filter

TODO: one-line summary of your gem
Ruby
22
star
18

msgpack-inspect

A tool to inspect and dump the MessagePack binary data: msgpack.org[msgpack-inspect]
Ruby
20
star
19

fluent-plugin-route

This is copy of frsyuki's out_route
Ruby
20
star
20

fluent-plugin-numeric-monitor

Ruby
19
star
21

fluent-plugin-notifier

Ruby
18
star
22

rb-growthforecast

Ruby
17
star
23

astarisk

AST visualizer, named from "AST a risk"
Ruby
16
star
24

right_speed

Ruby
15
star
25

fluent-plugin-config-expander

Ruby
14
star
26

fluent-plugin-numeric-counter

Ruby
12
star
27

with_resources

Add "with" method in Ruby to allocate/release resources in safe way
Ruby
11
star
28

Apache-Log-Parser

Log Parser for Apache common, combined and other custom styles
Perl
11
star
29

fluent-mixin-config-placeholders

Ruby
10
star
30

fluent-plugin-pull_forward

Ruby
10
star
31

LFA

Web application framework to perform as Lambda Function Adapter
Ruby
8
star
32

scribe_line

Python script collection for log transfer with scribe
Python
7
star
33

binding-slicer

Let you write binding[:a, :b, :c] => Hash {a: a, b: b, c: c}
Ruby
7
star
34

fluent-plugin-hoop

TODO: one-line summary of your gem
Ruby
6
star
35

mysqldef_lambda_package

Docker container and scripts to run k0kubun/mysqldef
JavaScript
6
star
36

shibui

Perl
6
star
37

p5-Net-GrowthForecast

Client library for GrowthForecast
Perl
6
star
38

fluent-plugin-buffer-lightening

Ruby
6
star
39

stratum

O/R mapper library for ruby and MySQL on additional architecture
Ruby
6
star
40

fluent-mixin-plaintextformatter

Ruby
5
star
41

fluent-agent

Perl
4
star
42

fluent-plugin-ikachan

Ruby
4
star
43

fluentd-leak-test

Ruby
4
star
44

logstash-output-fluentd

Logstash plugin to forward data to Fluentd
Ruby
4
star
45

fluent-helper-plugin-spec

RSpec helper for Fluentd plugin development
Ruby
4
star
46

Net-Hadoop-DFSAdmin-ReportParser

Perl
4
star
47

fluent-plugin-dummydata-producer

Ruby
3
star
48

itunesconnect-reviews-bookmarklet

bookmarklet to load all reviews from all of countries in iTunes Connect
3
star
49

passenger-monitor

HTTP interface same as mod_status for passenger-status
Ruby
3
star
50

remote_driver

Python
3
star
51

fluentd-tester

Ruby
3
star
52

fluent-plugin-encrypt

Ruby
3
star
53

fluent-plugin-ruby-memory-usage-profiler

Fluentd plugin to output memory profiler information for debugging of ruby/fluentd itself
Ruby
3
star
54

fluentd-book-samples

Ruby
3
star
55

fluentd-v1-checker

Ruby
2
star
56

Net-Hadoop-WebHDFS

Perl
2
star
57

Net-Hadoop-Hive-QueryBuilder

Perl
2
star
58

ruby-memory-usage-profiler

Ruby
2
star
59

fluent-plugin-amplifier-filter

Ruby
2
star
60

scribed_launcher

start-stop script for facebook scribed
Python
2
star
61

isucon3-final-code

Perl
2
star
62

simpleoauth-gae

OAuth 1.0 library for Python on Google App Engine
Python
2
star
63

Net-Hadoop-Hoop

Hoop client library perl module
Perl
2
star
64

MessagePack-RPC-HTTP-Client

Perl
2
star
65

whada

Web Authentication Data Aggregator
Perl
2
star
66

fluent-plugin-reducer

TODO: one-line summary of your gem
Ruby
1
star
67

fluent-plugin-buffered-stdout

Ruby
1
star
68

fluent-plugin-http_file_upload

Ruby
1
star
69

ruby-cli

Ruby
1
star
70

node-scribed

facebook scribe server implementation on node.js (highly experimental)
JavaScript
1
star
71

fluent-plugin-deparser

Ruby
1
star
72

fluent-plugin-delay-inspector

Ruby
1
star
73

isucon7-elimination

Ruby
1
star
74

demo-webapps

Very simple Ruby webapps to verify app servers
Ruby
1
star
75

dyna_mo

Dynamic scope implementation for method overriding
Ruby
1
star
76

fluent-plugin-flatten-filter

Ruby
1
star
77

woothee-sqale

Ruby
1
star
78

logstash-output-treasure_data

Logstash output plugin to store data on Treasure Data service https://www.treasuredata.com/
Ruby
1
star
79

Net-Hadoop-HuahinManager

client library for Huahin Manager
Perl
1
star
80

fluent-plugin-test-counter

TODO: one-line summary of your gem
Ruby
1
star