包装一个cube.js dremio 的驱动

因为默认cube.js dremio 查询1s 延迟的问题,进行了调整(参考了bigquery driver 的模式)

项目代码说明

  • 代码结构
├── README.md
├── driver
├── DremioDriver.js
├── DremioQuery.js
└── index.js
├── package.json
└── yarn.lock
  • pacakge.json
{
  "name": "@dalongrong/mydremio-driver",
  "description": "Cube.js dremio database driver",
  "author": "rongfengliang",
  "version": "1.0.4",
  "public": true,
  "repository": {
    "type": "git",
    "url": "https://github.com/rongfengliang/cubejs-dremio-driver"
  },
  "engines": {
    "node": ">=10.8.0"
  },
  "main": "driver/index.js",
  "dependencies": {
    "@cubejs-backend/query-orchestrator": "^0.26.81",
    "@cubejs-backend/schema-compiler": "^0.26.81",
    "@cubejs-backend/shared": "^0.26.81",
    "axios": "^0.21.1",
    "moment-timezone": "^0.5.33",
    "sqlstring": "^2.3.2"
  },
  "license": "Apache-2.0",
  "devDependencies": {
    "@cubejs-backend/linter": "^0.26.74"
  },
  "publishConfig": {
    "registry": "https://registry.npmjs.org/"
  },
  "scripts": {
    "p": "yarn publish --access public"
  }
}
  • 代码说明
    具体可以参考github

使用说明

因为cube.js 目前处理数据driver 方言的问题,需要自己配置下,参考

 
// Cube.js configuration options: https://cube.dev/docs/config
const {DremioDriver,DremioQuery} = require("@dalongrong/mydremio-driver")
 
module.exports = {
    dialectFactory: (dataSource) => {
        // need config  datasource  for multitenant env
        return DremioQuery
    },
    queryTransformer: (query, { securityContext }) => {
        console.log(securityContext)
        return query;
      },
    dbType: ({ dataSource } = {}) => {
        return "mydremio"
    },
    driverFactory: ({ dataSource } = {}) => {
        return new DremioDriver({})
    }
};

说明

关于cube.js 集成dremio驱动的修改已经pr了,但是官方暂时还没有合并,如果需要提高查询速度的可以基于此进行扩展,npm包已经发布了
可以直接使用@dalongrong/mydremio-driver

参考资料

https://github.com/rongfengliang/cubejs-dremio-driver
https://github.com/cube-js/cube.js/pull/2475

posted on 2021-04-08 20:22  荣锋亮  阅读(3)  评论(0编辑  收藏

导航