跳转至

Vertica 集成 Apache DataSketches

技术探索

关于本文档

本探索的目标是连接 Vertica 和 Apache DataSketches。DataSketches 提供称为 theta 函数的机器学习函数,可导入 Vertica 以增强 Vertica 的机器学习功能。

本探索提供了将 theta 分析函数紧密集成到 Vertica 中的说明。首先,您需要在 Vertica 中构建 DataSketches 库,然后创建一个表来对这些数据使用 theta 函数。

DataSketches 概述

DataSketches 是一个开源的软件算法库(称为 sketches),可以流式处理海量数据集,提供快速近似分析和实时分析,并具有经过验证的误差界限。

测试环境

  • Vertica DataSketches(GitHub 链接
  • CMake 3.14+
  • GCC+(C++ 编译器)
  • Linux RHEL 8.3
  • Vertica Analytical Database 12.0.1

为 Vertica 构建 DataSketches 库

DataSketches 仓库包含 UDx,其源代码用 C++ 开发。它由 Criteo 的分析基础设施团队创建。您需要编译源代码并构建 .so 文件。

按以下步骤构建 DataSketches 源代码:

  1. 打开 RHEL 8.3 机器,在其上设置 Vertica 12.0.1。按照 Vertica 文档中的 设置 说明操作。
  2. 在 Vertica 12.0.1 机器上安装 CMake 3.14+ 和 C++ 编译器。
  3. GitHub 下载 Vertica DataSketches 源代码。
  4. 转到包含 Vertica-DataSketches 源代码的目录。
  5. 执行以下命令为 Vertica 构建 Vertica DataSketches 库:
<Base_Loc>/vertica-datasketch-master> mkdir build
<Base_Loc>/vertica-datasketch-master> cd build
<Base_Loc>/vertica-datasketch-master/build> cmake ../SOURCE
<Base_Loc>/vertica-datasketch-master/build> make

Vertica 库现在已构建在 build 文件夹中。

截图

使用 Theta 函数的示例查询

创建一个将由 theta 函数使用的表。在以下示例中,我们创建一个名为 theta 的表,将在其上使用 theta 函数:

Create table test (id varchar, name varchar);
Insert into test values ('a', '1st value');
Insert into test values ('b', '2nd value');
Insert into test values ('c', '3rd value');
Insert into test values ('d', '4th value');
commit;
select theta_sketch_create(id) id, name into theta from test group by name;

以下是演示如何使用 theta 库中每个函数的示例查询:

  • theta_sketch_create
    select theta_sketch_create(id) id, name into theta from test group by name;
    
  • theta_sketch_a_not_b
    select theta_sketch_a_not_b(id, id), name from theta;
    
  • theta_sketch_get_estimate
    select theta_sketch_get_estimate(id), name from theta;
    
  • theta_sketch_intersection
    select theta_sketch_intersection(id, id), name from theta;
    
  • theta_sketch_intersection_agg
    select theta_sketch_intersection_agg(id), name from theta group by name;
    
  • theta_sketch_union
    select theta_sketch_union(id, id), name from theta;
    
  • theta_sketch_union_agg
    select theta_sketch_union_agg(id), name from theta group by name;
    

更多信息


原文来源:https://www.vertica.com/kb/Apache_DataSketches_TE/Content/Partner/Apache_DataSketches_TE.htm