presto-gateway nodejs client

Posted rongfengliang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了presto-gateway nodejs client相关的知识,希望对你有一定的参考价值。

目前已经有了好几个presto nodejs 的client,为了方便presto-gateway 的连接,修改了一个现有的nodejs client
可以方便的连接presto-gateway

原理

因为通过通过的rest api 调用的,所以直接在原有上添加http header X-Presto-Routing-Group

  • 参考修改的presto client
 
https://github.com/tagomoris/presto-client-node
  • 修改的地方
    headers.js
// Add X-Presto-Routing-Group for support presto gateway
Headers.ROUTING_GROUP = ‘X-Presto-Routing-Group‘;

index.js
对于查询支持添加routingGroup

Client.prototype.statementResource = function(opts) 
  var client = this;
  var columns = null;
?
  if (!opts.catalog && !this.catalog)
    throw message: "catalog not specified";
  if (!opts.schema && !this.schema)
    throw message: "schema not specified";
  if (!opts.success && !opts.callback)
    throw message: "callback function ‘success‘ (or ‘callback‘) not specified";
?
  var header = ;
  header[Headers.CATALOG] = opts.catalog || this.catalog;
  header[Headers.SCHEMA] = opts.schema || this.schema;
?
  if (opts.session)
    header[Headers.SESSION] = opts.session;
  if (opts.timezone)
    header[Headers.TIME_ZONE] = opts.timezone;
  if (opts.routingGroup)
    header[Headers.ROUTING_GROUP] = opts.routingGroup;
?
 
 
  • 说明
    已经push npm 仓库了

使用方法

  • 安装依赖
npm install @dalongrong/presto-client
  • 参考docker-compose 运行环境
version: "3"
services:
  proxy:
     image: dalongrong/presto-gateway:1.6.1
     ports:
     - "8888:8888"
     - "8082:8082"
     - "8083:8083"
     build: ./
     volumes:
     - "./config.yml.template:/config.yml.template"
  presto1:
     image: starburstdata/presto
     ports:
     - "8080:8080"
  presto2:
     image: starburstdata/presto
     ports:
     - "8081:8080"
  • 配置文件
requestRouter:
  port: 8888
  name: prestoRouter
  cacheDir: /var/log/prestoproxy/cache
  historySize: 1000
?
backends:
  - localPort: 8082
    name: presto1
    proxyTo: http://presto1:8080
    routingGroup: adhoc
?
  - localPort: 8083
    name: presto2
    proxyTo: http://presto2:8080
    routingGroup: scheduled
?
server:
  applicationConnectors:
    - type: http
      port: 8090
  adminConnectors:
    - type: http
      port: 8091
?
notifier:
  smtpHost: localhost
  smtpPort: 587
  sender: presto-gw-monitor-noreply@lyft.com
  recipients:
    - prestodev@yourorg.com
?
modules:
  - com.lyft.data.gateway.module.ProxyBackendProviderModule
  - com.lyft.data.gateway.module.GatewayProviderModule
  - com.lyft.data.gateway.module.NotifierModule
?
managedApps:
  - com.lyft.data.gateway.GatewayManagedApp
  - com.lyft.data.gateway.ActiveClusterMonitor
?
# Logging settings.
logging:
  # The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
  level: INFO
?
  # Logger-specific levels.
  loggers:
    com.lyft: DEBUG
?
  appenders:
    - type: console
    - type: file
      currentLogFilename: /var/log/prestoproxy/prestoproxy-java.log
      archivedLogFilenamePattern: /var/log/prestoproxy/prestoproxy-java-%dyyyy-MM-dd-%i.log.gz
      archivedFileCount: 7
      timeZone: UTC
      maxFileSize: 100MB
 
 
  • 参考代码
var presto = require(‘@dalongrong/presto-client‘);
var client = new presto.Client(
  user: ‘appdemo‘,
  host: "localhost",
  port: 8888
);
?
client.execute(
  query: ‘select * from nation2‘,
  catalog: ‘memory‘,
  schema: ‘default‘,
  source: ‘nodejs-client‘,
  routingGroup: ‘scheduled‘,
  state: function (error, query_id, stats) 
    console.log(error)
    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) 
    console.log(stats)
  ,
  error: function (error) 
    console.log(error)
  
);

参考资料

https://github.com/tagomoris/presto-client-node
https://github.com/rongfengliang/presto-client-node

以上是关于presto-gateway nodejs client的主要内容,如果未能解决你的问题,请参考以下文章

安装nodejs后无法安装@angular/cli@9.1.8

使用nodeJs安装Vue-cli

使用nodeJs安装Vue-cli

vue-cli最全的解析了 先全局安装nodejs 安装

如何从 NodeJS 运行 CLI 命令? [复制]

vue-cli