发现模式

发现模式提供了一种描述tap 支持数据流的方式,使用了json schema 做为描述数据的结构以及每个数据流的
类型,发现模式的实现依赖tap 的数据源,有些taps 将硬编码每个流的模式,而其他的将连接到提供可用流的
描述的api,当运行发现模式时,tap 应该写如stdout 流列表,称为目录,每个条目包含关于流的一些基本信息和
描述流的json schema
发现模式下运行tap, 使用--discover

 
tap --config CONFIG --discover

我们可以在运行的时候将输出重定向到一个文件

tap --config CONFIG --discover > catalog.json
 

对于一些遗留的taps ,会使用properties.json 做为目录

schema

JSON用于表示数据,因为它无处不在,可读,并且特别适用于将数据公开为JSON(如Web API)的大量源。但是,
JSON远非完美:

  • 它有一个有限类型的系统,不支持日期等常见类型,也没有整数和浮点数之间的区别
  • 虽然它的灵活性使其易于使用,但它也可能导致兼容性问题
    模式用于解决这些问题。一般而言,模式是描述数据结构的任何方式。模式由TEMA在SCHEMA消息中编写,格式遵循
    JSON模式规范。
    模式通过提供有关如何解释JSON基本类型的更多信息来解决有限的数据类型问题。例如,JSON Schema规范区分integer和number
    类型,后者被适当地解释为浮点。此外,它定义了一个名为的字符串格式date-time,可用于指示数据点何时应为格式正确的时间戳字符串。
    Schema提供了一种验证一组数据点结构的简便方法,从而减轻了JSON的兼容性问题。Taps通过鼓励每个流仅使用单个模式,并在持
    久性之前根据其schema验证每个数据点来部署此概念。这迫使Tap作者思考如何解决模式演变和兼容性问题,将该责任尽可能接近原始数据源,
    并使下游系统无需做出明智的假设来解决这些问题。
    schema 是必需的,但它们可以用最广泛的术语定义 - “{}”的JSON schema 验证所有数据点。但是,Tap作者最好以尽可能窄的方式定义schema。

Stitch中的schema

Stitch Target和Stitch API使用schema如下:

  • 当Stitch Target遇到未根据其流的最新schema验证的数据点时,它会失败
  • schema必须是顶级的“对象”
  • Stitch支持具有嵌套到任何深度的对象的schema,以及嵌套到任何深度的对象数组 - Stitch docs中的更多信息
  • 在构造消息之前,必须完全解析并替换使用JSON模式$ref功能的引用SCHEMA。规范不支持传递额外schema以作为参考分辨率的方法。
  • 类型string和格式的属性date-time将转换为目标数据库中的相应时间戳或日期时间类型
  • 类型的属性integer在目标数据库中转换为整数
  • 类型的属性number在目标数据库中转换为十进制或数字
    (很快)maxLengthtype属性的参数string用于定义目标数据库中相应varchar列的宽度
  • 当Stitch遇到与要在目标数据库中加载流的表不兼容的流的schema时,它会将数据添加到拒绝堆中
    参考:
 
{
  "type": [
    "null", 
    "object"
  ],
  "additionalProperties": false,
  "properties": {
    "id": {
      "type": [
        "null",
        "string"
      ],
    },
    "name": {
      "type": [
        "null",
        "string"
      ],
    },
    "date_modified": {
      "type": [
        "null",
        "string"
      ],
      "format": "date-time",
    }
  }
}

目录(catalog)

发现模式的输出应该是Tap支持的数据流列表。此JSON格式的列表称为目录。顶层是一个对象,其中一个被调用的键"streams"指向一个对象数组,
每个对象都有以下字段:
tap_stream_id 字符串 需要 流的唯一标识符。允许这与流的名称不同,以允许具有重复流名称的源。
schema 对象 需要 流的JSON模式。
table_name 字符串 可选的 对于数据库源,表的名称。
metadata 元数据数组 可选的 请参阅下面的元数据以获取解释
参考:

 
{
  "streams": [
    {
      "tap_stream_id": "users",
      "stream": "users",
      "schema": {
        "type": ["null", "object"],
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": [
              "null",
              "string"
            ],
          },
          "name": {
            "type": [
              "null",
              "string"
            ],
          },
          "date_modified": {
            "type": [
              "null",
              "string"
            ],
            "format": "date-time",
          }
        }
      }
    }
  ]
}
 

metadata

元数据是关联模式中节点的额外信息的首选机制。
应该通过tap 来写入和读取某些元数据。此元数据称为discoverable元数据。其他元数据将由其他系统(如UI)编写
,因此只能通过tap读取。这种类型的元数据称为non-discoverable元数据
参考的字段信息:

Keyword Tap Type Discoverable? Description
selected any non-discoverable Either true or false. Indicates that this node in the schema has been selected by the user for replication.
replication-method any non-discoverable Either FULL_TABLE, INCREMENTAL, or LOG_BASED. The replication method to use for a stream.
replication-key any non-discoverable The name of a property in the source to use as a "bookmark". For example, this will often be an "updated-at" field or an auto-incrementing primary key (requires replication-method).
view-key-properties database non-discoverable List of key properties for a database view.
inclusion any discoverable Either available, automatic, or unsupported.

available means the field is available for selection, and the tap will only emit values for that field if it is marked with "selected": true.

automatic means that the tap will emit values for the field.

unsupported means that the field exists in the source data but the tap is unable to provide it.

selected-by-default any discoverable Either true or false. Indicates if a node in the schema should be replicated if a user has not expressed any opinion on whether or not to replicate it.
valid-replication-keys any discoverable List of the fields that could be used as replication keys.
schema-name any discoverable The name of the stream.
forced-replication-method any discoverable Used to force the replication method to either FULL_TABLE or INCREMENTAL.
table-key-properties database discoverable List of key properties for a database table.
is-view database discoverable Either true or false. Indicates whether a stream corresponds to a database view.
row-count database discoverable Number of rows in a database table/view.
database-name database discoverable Name of database.
sql-datatype database discoverable Represents the datatype of a database column.

参考的数据格式

 
{
  "metadata" : {
    "selected" : true,
    "some-other-metadata" : "whatever"
  },
  "breadcrumb" : ["properties", "some-field-name"]
}
 
 

上面的breadcrumb对象定义了到元数据所属节点的模式的路径。流的元数据将具有空的面包屑。
参考完整例子

 
{
  "streams": [
    {
      "tap_stream_id": "users",
      "stream": "users",
      "schema": {
        "type": ["null", "object"],
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": [
              "null",
              "string"
            ],
          },
          "name": {
            "type": [
              "null",
              "string"
            ],
          },
          "date_modified": {
            "type": [
              "null",
              "string"
            ],
            "format": "date-time",
          }
        }
      },
      "metadata": [
        {
          "metadata": {
            "inclusion": "available",
            "table-key-properties": ["id"],
            "selected-by-default": true,
            "valid-replication-keys": ["date_modified"],
            "schema-name": "users",
          },
          "breadcrumb": []
        },
        {
          "metadata": {
            "inclusion": "automatic",
          },
          "breadcrumb": ["properties", "id"]
        },
        {
          "metadata": {
            "inclusion": "available",
            "selected-by-default": true,
          },
          "breadcrumb": ["properties", "name"]
        },
        {
          "metadata": {
            "inclusion": "automatic",
          },
          "breadcrumb": ["properties", "date_modified"]
        }
      ]
    }
  ]
}
 

参考资料

https://github.com/singer-io/getting-started/blob/master/docs/DISCOVERY_MODE.md

Singer 学习十三 发现模式的更多相关文章

  1. Singer 学习十 同步模式

    sync 模式是属于tap 的操作,同步模式下,tap 需要提交 schema. record .state message, singer 指南对于每种 类型有详细的说明 streams 每个str ...

  2. 设计模式 ( 十三 ) 命令模式Command(对象行为型)

    设计模式 ( 十三 ) 命令模式Command(对象行为型) 1.概述         在软件设计中,我们经常需要向某些对象发送请求,但是并不知道请求的接收者是谁,也不知道被请求的操作是哪个,我们只需 ...

  3. 跟着ZHONGHuan学习设计模式--桥接模式

    转载请注明出处! ! !http://blog.csdn.net/zhonghuan1992 全部配套代码均在github上:https://github.com/ZHONGHuanGit/Desig ...

  4. (@WhiteTaken)设计模式学习——享元模式

    继续学习享元模式... 乍一看到享元的名字,一头雾水,学习了以后才觉得,这个名字确实比较适合这个模式. 享元,即共享对象的意思. 举个例子,如果制作一个五子棋的游戏,如果每次落子都实例化一个对象的话, ...

  5. C#设计模式之二十三解释器模式(Interpreter Pattern)【行为型】

    一.引言   今天我们开始讲"行为型"设计模式的第十一个模式,也是面向对象设计模式的最后一个模式,先要说明一下,其实这个模式不是最后一个模式(按Gof的排序来讲),为什么把它放在最 ...

  6. Java设计模式学习记录-状态模式

    前言 状态模式是一种行为模式,用于解决系统中复杂的对象状态转换以及各个状态下的封装等问题.状态模式是将一个对象的状态从该对象中分离出来,封装到专门的状态类中,使得对象的状态可以灵活多变.这样在客户端使 ...

  7. Singer 学习七 运行&&开发taps、targets (二 targets 运行说明)

    接上文: Singer 学习六 运行&&开发taps.targets (一 taps 运行说明) 说明target 需要tap 进行配合运行,所以需要了解tap 的使用 运行targe ...

  8. Spring学习13-中IOC(工厂模式)和AOP(代理模式)的详细解释

    我们是在使用Spring框架的过程中,其实就是为了使用IOC,依赖注入,和AOP,面向切面编程,这两个是Spring的灵魂. 主要用到的设计模式有工厂模式和代理模式. IOC是工厂模式参考:设计模式- ...

  9. 《Head first设计模式》学习笔记 – 迭代器模式

    <Head first设计模式>学习笔记 – 迭代器模式 代器模式提供一种方法顺序访问一个聚合对象中的各个元素,而又不暴露其内部的表示. 爆炸性新闻:对象村餐厅和对象村煎饼屋合并了!真是个 ...

随机推荐

  1. MicroOrm.Dapper.Repositories 的使用

    https://github.com/geffzhang/MicroOrm.Dapper.Repositories 1.特性标记都是要引用: System.ComponentModel.DataAnn ...

  2. UBUNTU 测试跑分

    time echo "scale=5000; 4*a(1)" | bc -l -q3.14159265358979323846264338327950288419716939937 ...

  3. 强化学习6-MC与TD的比较-实战

    # encoding:utf-8 import numpy as np import matplotlib.pylab as plt ''' 随机行走问题 0 - 1 - 2 - 3 - 4 - 5 ...

  4. innodb mvcc,事务隔离级别,读写锁

    mvcc其实和copyonwritelist的思路差不多:读不加锁,写加锁,事务提交之后释放锁,并且延伸的是,在UNdolog里面保存了几个版本,实现不同的隔离级别.如果读数据页里面最新的数据,那么就 ...

  5. Linux:配置samba服务

    配置samba服务  一.简略教程 1.挂载系统 mount /dev/cdrom /mnt/cdrom2.创建用户:useradd linlin3.创建用户密码:passwd linlin4.在用户 ...

  6. shell脚本实例-case 删除用户判断的小案例

    #!/usr/bin/bash read -p "Please input a username:" user id $user &>/dev/null if [ $ ...

  7. 基于centos的freeradius高可用lvs(UDP)

    最近在做freeradius的高可用配置,使用lvs的vip做轮询: freeradius的配置见前面的文章: 下面是lvs的keepalived的配置: global_defs { router_i ...

  8. http协议tcp协议ip协议三次握手四次挥手,为什么三次握手,为什么四次挥手,sockete套接字理解

    1.1 TCP是什么? TCP是Tranfer Control Protocol的简称,TCP协议是一种面向连接的.可靠的.基于字节流的运输层通信协议.通过TCP协议传输,得到的是一个顺序的无差错的数 ...

  9. MacBookPro-OSX

    修改用户名 sudo hostname macbookpro sudo scutil --set HostName macbookpro sudo scutil --set LocalHostName ...

  10. CVE-2018-7566

    概念解读 什么是竞争条件? 由于两个或者多个进程竞争使用不能被同时访问的资源,使得这些进程有可能因为时间上推进的先后原因而出现问题,这叫做竞争条件(Race Condition). 什么是互斥锁? 在 ...