目前已经有了好几个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-%d{yyyy-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的更多相关文章

  1. C# Socket TCP Server & Client & nodejs client

    要调试公司某项目里的一个功能,因为要准备测试环境,趁这个机会重温了一下Socket(全还给老师了 -_-#),做个备份. C# Server static void Main(string[] arg ...

  2. What's New In Zeebe: Scaling Zeebe, New Client APIs, Faster Requests, Timestamps, NodeJS Client, and Default Topic is Back!

    Written by Daniel Meyer on May 16 2018 in the What's New In Zeebe category. Welcome to the first-eve ...

  3. NodeJS client code websocket

    var WebSocketClient = require('websocket').client; var client = new WebSocketClient(); client.on('co ...

  4. Nodejs Client for FastDFS

    FastDFS 是分布式文件存储系统.这个项目是FastDFS的NodeJS客户端,用来与FastDFS Server进行交互,进行文件的相关操作.我测试过的server版本是4.0.6. githu ...

  5. Nodejs学习笔记(九)--- 与Redis的交互(mranney/node_redis)入门

    目录 简介和安装 redis简介 redis安装 redis运行 node_redis安装 连接到redis服务器redis.createClient() 认证 client.auth(passwor ...

  6. Gearman + Nodejs + MySQL UDF异步实现 MySQL 到 Redis 的数据同步

    [TOC] 1, 环境 CentOS, MySQL, Redis, Nodejs 2, Redis简介 Redis是一个开源的K-V内存数据库,它的key可以是string/set/hash/list ...

  7. gRPC中Any类型的使用(Java和NodeJs端)

    工作中要把原来Java服务端基于SpringMVC的服务改为使用gRPC直接调用.由于原Service的返回值为动态的Map类型,key值不确定,且value的类型不唯一,因此使用了protobuf ...

  8. 【原创】大叔问题定位分享(33)beeline连接presto报错

    hive2.3.4 presto0.215 使用hive2.3.4的beeline连接presto报错 $ beeline -d com.facebook.presto.jdbc.PrestoDriv ...

  9. 数仓1.4 |业务数仓搭建| 拉链表| Presto

    电商业务及数据结构 SKU库存量,剩余多少SPU商品聚集的最小单位,,,这类商品的抽象,提取公共的内容 订单表:周期性状态变化(order_info) id 订单编号 total_amount 订单金 ...

随机推荐

  1. -Git 使用技巧 总结 MD

    目录 目录 Bash下的快捷操作 常用命令 常用操作 移动光标 删除输入内容 Tab键的作用 Git默认Vim编辑器基本使用 Git 使用场景 合并多个commit:rebase -i[s] 删除多个 ...

  2. vim中常用折叠命令

    最常用3个折叠命令 .反复打开关闭折叠:za (意思就是,当光标处折叠处于打开状态,za关闭之,当光标处折叠关闭状态,打开之) .打开全部折叠:zR .关闭全部折叠:zM 小试折叠: :set fdm ...

  3. C# SQl通过对视图数据二次查询,统计数据

    问题描述: 原数据---------需要在原视图数据中,统计出每个Device_Num设备号下面的交易的总额和分别统计出微信支付宝的交易总额. 解决:从上图数据没办法使用直接查询出要求的数据. .1. ...

  4. 一张图看懂SharpCamera

    通过下面的图片,可以瞬间看懂整个类库的脉络.

  5. IDEA 环境下更改Maven的仓库镜像提高下载速度

    Maven把所有常用的jar包存放在一个集中的仓库(repository)中,项目需要什么jar包和他相关的依赖,只要在pom.xml文件中声明就可了,还是很方便的.repository分两种,一个是 ...

  6. jQuery中的DOM操作【续】

    一.复制节点$(选择器字符串).clone(false)    [返回克隆的节点对象]参数:false,浅复制,复制元素但不复制元素中所绑定的事件[默认为false]true,深复制,复制元素且复制元 ...

  7. 【译】Matplotlib:plotting

    前言 本教程源于Scipy Lecture Notes,URL:http://www.scipy-lectures.org/ 本教程若有翻译不当或概念不明之处,请大家留言,博主及时更正,以便后来的用户 ...

  8. Android Handler类 发送消息-post()和postDelay(), Looper讲解

    https://blog.csdn.net/weixin_41101173/article/details/79701832 首先,post和postDelay都是Handler的方法,用以在子线程中 ...

  9. python实现广度优先搜索

    from collections import deque #解决从你的人际关系网中找到芒果销售商的问题#使用字典表示映射关系graph = {} graph["you"] = [ ...

  10. Top命令数据分析

    一.top命令详解 当前时间 20:27:12 当前系统运行时间 3:18秒 1个用户 系统负载平均长度为 0.00,0.00,0.00(分别为1分钟.5分钟.15分钟前到现在的平均值) 第二行为进程 ...