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. Cracking The Coding Interview 2.0 单链表

    #include <iostream> #include <string> using namespace std; class linklist { private: cla ...

  2. jdk8-stream的api

    1.stream流的概念 1.流的创建 //1. 创建 Stream @Test public void test1(){ //1. Collection 提供了两个方法 stream() 与 par ...

  3. requery.js使用姿势

    最近在看requerjs,现在来总结下自己的收获,有不对的地方,望大家指正! 1.首先介绍下requirejs,引用中文官网http://www.requirejs.cn的一句话,requirejs是 ...

  4. Python 嵌套

    1 要yuanhao的首字母大写 li = [1,2,5,'taibai','yuanhao',[1,'alex',3,],True]li[4] = 'Yuanhao'print(li) li[4] ...

  5. 在 子 iframe中 点击一个按钮, 变换 这个 iframe的地址url.

    //跳到测试结果: function jump() { console.log(self.parent.document.getElementById("iframe").src) ...

  6. python 时间戳转换格式

    1.简介 在编写代码时,往往涉及时间.日期.时间戳的相互转换. 2.示例 # 引入模块 import time, datetime 2.1 str类型的日期转换为时间戳 1 # 字符类型的时间 2 t ...

  7. ipython output logging:使用日志记录输出

    通常使用ipython的%logstart日志功能时,仅开启输入的记录. 例如在ipython中开启%logstart后,记录的日志文件内容如下: #!/usr/bin/env python # 20 ...

  8. springboot区分开发、测试、生产多环境的应用配置

    转:https://blog.csdn.net/daguairen/article/details/79236885 springboot区分开发.测试.生产多环境的应用配置(一) Spring可使用 ...

  9. 引入网站标题小logo

    <link rel="icon" type="image/png" href="路径/favicon.png"> 关注微信小程序

  10. Server SSL certificate verification failed: certificate has expired, issuer is not trusted

    Unable to connect to a repository at URL 'https://xxxxx/svn/include' Server SSL certificate verifica ...