madlib 可以让我们直接在sql 中进行机器学习,集成了强大的sql 能力,以及分析能力,后边会尝试
集成graphql engine ,让功能更强大

docker 镜像准备

使用了一个别人的写好的,也可以参考官方提供的,就是镜像包有点大

  • docker-compose 文件
 
version: '2'
services:
  db:
    container_name: madlib-postgres
    build:
      context: .
      dockerfile: postgres/Dockerfile
    environment:
      - PG_MODE=primary
      - PG_PRIMARY_USER=postgres
      - PG_PRIMARY_PASSWORD=postgres
      - PG_DATABASE=sample
      - PG_USER=user
      - PG_PASSWORD=user
      - PG_ROOT_PASSWORD=root
      - PG_PRIMARY_PORT=5432
    restart: always
    ports:
      - 5432:5432
  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
    depends_on:
      - db
  graphql-engine:
    image: hasura/graphql-engine:v1.0.0-alpha30
    ports:
    - "9090:8080"
    depends_on:
    - db
    environment:
    - "POSTGRES_PASSWORD:postgres"
    command: >
      /bin/sh -c "
      graphql-engine --database-url postgres://postgres:root@db:5432/sample serve --enable-console;
      "
networks:
  default:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 180.16.0.0/16
        gateway: 180.16.0.1 
 
 
  • madlib pg dockerfile
FROM crunchydata/crunchy-postgres:centos7-10.5-2.1.0
USER root
RUN yum -y update; yum clean all
RUN yum -y install postgresql10-plpython supervisor; yum clean all
### Get postgres specific add-ons
RUN yum update -y && yum install -y \
                    git \
                    gcc \
                    wget \
                    postgresql10-devel \
                    openssl \
                    m4 \
                    vim \
                    flex \
                    bison \
                    graphviz \
                    java \
                    epel-release \
                    python-devel
RUN yum install -y python-pip
ENV PATH="$PATH:/usr/pgsql-10/bin"
RUN pip install awscli pygresql paramiko --upgrade
RUN mkdir -p /src/madlib
COPY ./data/apache-madlib-1.15.1-bin-Linux.rpm /src/madlib
RUN yum install -y /src/madlib/apache-madlib-1.15.1-bin-Linux.rpm --nogpgcheck
USER 26
EXPOSE 5432
CMD ["/opt/cpm/bin/start.sh"]
 
 

启动&&初始化环境

  • 启动
docker-compose build &&  docker-compose up -d
  • 初始化
docker-compose exec db bash
/usr/local/madlib/bin/madpack -p postgres -c postgres/root@localhost:5432/sample install
/usr/local/madlib/bin/madpack -p postgres -c postgres/root@localhost:5432/sample install-check
 
  • 访问
    默认账户信息为 postgres root sample
  • 添加一个简单的数据函数测试
    创建表
 
CREATE TABLE array_tbl (
    id integer,
    array1 integer[],
    array2 integer[]
);
 
 

添加数据

INSERT INTO "public"."array_tbl"("id","array1","array2")
VALUES
(1,E'{1,2,3,4,5,6}',E'{6,5,4,3,2,1}'),
(2,E'{1,1,0,0,99,8}',E'{0,0,0,-5,2,1}');
 
 

使用数组函数:
说明:主要使用了madlib 的数组最大以及最小函数

 
select id,madlib.array_min(array1) min, madlib.array_max(array1) max from array_tbl
 

结果

graphql 引擎使用

  • 打开地址
http://localhost:9090
 
 

效果

  • 集成
    为了方便使用计算的结果,我们使用了试图进行扩展
  • 查询madlib 的结果数据

说明

这个只是简单的试用,试用上madlib 的功能还是很强大的,同时对于graphql engine 的扩展,我们有好多种
方法,这个只是一种简单的方式,但同时也无法使用强大的weebhook 等功能了(view 的原因)

参考资料

https://github.com/rongfengliang/docker-madlib

madlib 集成 hasura graphql-engine 试用的更多相关文章

  1. hasura graphql server event trigger 试用

    hasura graphql server 是一个很不错的graphql 引擎,当前版本已经支持event triiger 了 使用此功能我们可以方便的集成webhook功能,实现灵活,稳定,快捷的消 ...

  2. hasura graphql server 集成gatsby

    hasura graphql server 社区基于gatsby-source-graphql 开发了gatsby-postgres-graphql 插件, 可以快速的开发丰富的网站 基本使用 安装h ...

  3. 通过torodb && hasura graphql 让mongodb 快速支持graphql api

    torodb 可以方便的将mongo 数据实时同步到pg,hasura graphql 可以方便的将pg 数据暴露为graphql api,集成在一起真的很方便 环境准备 docker-compose ...

  4. hasura graphql subscriptions 使用

      subscriptions graphql 的一项实时数据推送的功能,还是很方便的,自己在直接使用subscriptions-transport-ws npm 包 的时候运行一直有错误(主要是依赖 ...

  5. Hasura GraphQL schema 生成是如何工作的

    不像大部分的graphql 引擎,使用标准的graphql 规范的处理模型,Hasura graphql 不存在resolver 的概念(实际上是有的,只是转换为了sql语法) 以下是Hasura g ...

  6. hasura graphql auth-webhook api 说明

    hasura graphql 生产的使用是推荐使用webhook 进行角色访问控制的,官方同时提供了一个nodejs 的简单demo 代码 git clone https://github.com/h ...

  7. hasura graphql pg 自定义函数的使用

      hasura graphql 的安装可以参考相关项目 创建函数 数据表创建 CREATE TABLE sql_function_table ( id SERIAL PRIMARY KEY, inp ...

  8. hasura graphql server 集成gitlab

    默认官方是提供了gitlab 集成的demo的,但是因为gitlab 一些版本的问题, 跑起来总有问题,所以查找相关资料测试了一个可以运行的版本 项目使用docker-compose 运行 参考 ht ...

  9. hasura graphql 集成pipelinedb测试

    实际上因为pipelinedb 是原生支持pg的,所以应该不存在太大的问题,以下为测试 使用doker-compose 运行 配置 docker-compose 文件 version: '3.6' s ...

随机推荐

  1. STA/LTA方法

    STA是用于捕捉地震信号的时间窗,因此STA越短,就对短周期的地震信号捕捉越有效:LTA是用于衡量时间窗内的平均噪声,STA/LTA就可以根据周围环境噪声程度自适应地调整其对于某一类型地震信号的敏感度 ...

  2. HTTPS加密原理(转)

    Header HTTP.HTTPS在我们日常开发中是经常会接触到的. 我们也都知道,一般 Android 应用开发,在请求 API 网络接口的时候,很多使用的都是 HTTP 协议:使用浏览器打开网页, ...

  3. poj3279(dfs+二进制枚举思路)

    题意转载自https://www.cnblogs.com/blumia/p/poj3279.html 题目属性:DFS 相关题目:poj3276 题目原文:[desc]Farmer John know ...

  4. Oracle学习(四)_SQL函数

    --第一部分:SQL基础 --ch1 简单查询 --ch2 查询基本概念 --ch3 数据过滤 --第二部分:多表操作 --ch4 集合理论 --ch5 内连接 --ch6 外连接 --ch7 子查询 ...

  5. Unity最新版打包AssetBundle和加载的方法

    一.设置assetBundleName二.构建AssetBundle包三.上传AssetBundle到服务器四.把AssetBundle放到本地五.操作AssetBundle六.完整例子七.Asset ...

  6. pytest的HTML

    安装html: 1.github上源码地址[https://github.com/pytest-dev/pytest-html] 2.pip安装  pip install pytest-html 3. ...

  7. elasticsearch学习笔记——相关插件和使用场景

    logstash-input-jdbc学习 ES(elasticsearch缩写)的一大优点就是开源,插件众多.所以扩展起来非常的方便,这也造成了它的生态系统越来越强大.这种开源分享的思想真是与天朝格 ...

  8. python day03--字符串

    一.字符串 1.索引 s1 = "python最牛B" S1[0]第0个,从零开始算 s1[8]“B” 2.切片 语法: str[start: end]规则: 顾头不顾腚, 从st ...

  9. windows下利用nodejs压缩.min文件

    利用nodejs中的npm工具,压缩文件,必须在node环境下 压缩js文件 1.在全局中安装uglify-js模块 npm install uglify-js -g 2.可以直接使用uglifyjs ...

  10. 部署php的正确姿势

    1. 更新源 apt-get update 2.安装apache apt-get install apache2 ubuntu下apache2虚拟主机配置 cd /etc/apache2/sites- ...