Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

presto-client

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

presto-client - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

53

lib/presto-client/index.js

@@ -90,14 +90,55 @@ var http = require('http');

Client.prototype.execute = function(opts) {
Client.prototype.execute = function(opts, callback) {
if (callback)
this.executeResource(opts, callback);
else
this.statementResource(opts);
};
Client.prototype.executeResource = function(opts, callback) {
var client = this;
var query = null;
if (opts instanceof Object) {
query = opts.query;
} else { // opts is query string itself
query = opts;
opts = {};
}
if (!opts.catalog && !this.catalog)
throw {message: "catalog not specified"};
if (!opts.schema && !this.schema)
throw {message: "schema not specified"};
var header = {};
header[Headers.CATALOG] = opts.catalog || this.catalog;
header[Headers.SCHEMA] = opts.schema || this.schema;
var req = { method: 'POST', path: '/v1/execute', headers: header, body: query };
client.request(req, function(err, code, content){
if (err || code !== 200) {
var message = "execution error" + (content && content.length > 0 ? ":" + content : "");
callback({message:message, error: err, code: code});
return;
}
// content: {"columns":[{"name":"Schema","type":"varchar"}],"data":[["default"],["information_schema"],["sys"]]}
callback(null, content.data, content.columns);
});
};
Client.prototype.statementResource = function(opts) {
var client = this;
var query_id = null;
var columns = null;
if (!opts.catalog && !this.catalog)
throw {message: "catalog not specified"};
if (!opts.schema && !this.schema)
throw {message: "schema not specified"};
var header = {};
header[Headers.CATALOG] = opts.catalog || this.catalog;
header[Headers.SCHEMA] = opts.schema || this.schema;
if (opts.catalog || this.catalog)
header[Headers.CATALOG] = opts.catalog || this.catalog;
if (opts.schema || this.schema)
header[Headers.SCHEMA] = opts.schema || this.schema;
var fetch_info = opts.info || false;

@@ -104,0 +145,0 @@

2

package.json
{
"name": "presto-client",
"version": "0.0.2",
"version": "0.0.3",
"description": "Distributed query engine Presto client library for node.js",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -7,4 +7,14 @@ # presto-client-node

var presto = require('presto-client');
var client = new presto.Client();
var client = new presto.Client({user: 'myname', catalog: 'hive', schema: 'default'});
client.execute('show schemas', function(error, data, columns){
console.log({databases: data});
});
```
For queries with long process time and heavy output:
```js
var presto = require('presto-client');
var client = new presto.Client({user: 'myname'});
client.execute({

@@ -51,4 +61,32 @@ query: 'SELECT count(*) as cnt FROM tblname WHERE ...',

### execute(arg, callback)
If 2nd argument `callback` specified, this api will be selected.
This is an API to execute queries that returns result immediately, like `show schemas`, `show tables` and others. (Using "/v1/execute" HTTP RPC.)
Execute query on Presto cluster, and fetch results.
* arg [Object or string]
* arg [String]: query string executed
* `catalog` and `schema` must be specified in `new Client()` for this argument type
* arg [Object]
* query [string]
* catalog [string]
* catalog string (default: instance default catalog)
* schema [string]
* schema string (default: intance default schema)
* callback [function(error, data, columns)]
* called once when query finished
* data
* array of arrays of each field values
* `[ [ 'field1Value', 'field2Value', 3 ], [ 'field1Value', 'field2Value', 6 ], ... ]`
* columns
* array of field names and types
* `[ { name: 'timestamp', type: 'varchar' }, { name: 'username', type: 'varchar' }, { name: 'cnt', type: 'bigint' } ] `
### execute(opts)
This is an API to execute queries that really read large amount of data. (Using "/v1/statement" HTTP RPC.)
Execute query on Presto cluster, and fetch results.

@@ -58,7 +96,4 @@

* query [string]
* presto query
* catalog [string]
* catalog string (default: instance default catalog)
* schema [string]
* schema string (default: intance default schema)
* info [boolean :optional]

@@ -105,2 +140,4 @@ * fetch query info (execution statistics) for success callback, or not (default false)

* 0.0.3:
* simple and immediate query execution support
* 0.0.2: maintenance release

@@ -107,0 +144,0 @@ * add User-Agent header with version

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc