【问题标题】:Clikhouse + Amazon SNS notificationClikhouse + Amazon SNS 通知
【发布时间】:2021-02-22 14:51:49
【问题描述】:

我尝试将 Amazon SNS 通知 eventype = Open 插入到 ClickHouse,Json 架构很复杂,所以我不知道如何创建我的表(嵌套在嵌套的...中)

{
  "eventType":"Open",
  "mail":{
    "commonHeaders":{
      "from":[
        "sender@example.com"
      ],
      "messageId":"EXAMPLE7c191be45-e9aedb9a-02f9-4d12-a87d-dd0099a07f8a-000000",
      "subject":"Message sent from Amazon SES",
      "to":[
        "recipient@example.com"
      ]
    },
    "destination":[
      "recipient@example.com"
    ],
    "headers ":[
      {
        "name":"X-SES-CONFIGURATION-SET",
        "value":"ConfigSet"
      },
      {
        "name":"X-SES-MESSAGE-TAGS",
        "value":"myCustomTag1=myCustomValue1, myCustomTag2=myCustomValue2"
      },
      {
        "name":"From",
        "value":"sender@example.com"
      },
      {
        "name":"To",
        "value":"recipient@example.com"
      },
      {
        "name":"Subject",
        "value":"Message sent from Amazon SES"
      },
      {
        "name":"MIME-Version",
        "value":"1.0"
      },
      {
        "name":"Content-Type",
        "value":"multipart/alternative; boundary=\"XBoundary\""
      }
    ],
    "headersTruncated":false,
    "messageId":"EXAMPLE7c191be45-e9aedb9a-02f9-4d12-a87d-dd0099a07f8a-000000",
    "sendingAccountId":"123456789012",
    "source":"sender@example.com",
    "tags":{
      "myCustomTag1":[
        "myCustomValue1"
      ],
      "myCustomTag2":[
        "myCustomValue2"
      ],
      "ses:caller-identity":[
        "ses-user"
      ],
      "ses:configuration-set":[
        "ConfigSet"
      ],
      "ses:from-domain":[
        "example.com"
      ],
      "ses:source-ip":[
        "192.0.2.0"
      ]
    },
    "timestamp":"2017-08-09T21:59:49.927Z"
  },
  "open":{
    "ipAddress":"192.0.2.1",
    "timestamp":"2017-08-09T22:00:19.652Z",
    "userAgent":"Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60"
  }
}

我尝试了INSERT INTO Open FORMAT JSONEachRowINSERT INTO Open FORMAT JSONCompact 但不起作用。

谢谢。

【问题讨论】:

    标签: json amazon-web-services amazon-sns clickhouse


    【解决方案1】:

    您应该将您的 JSON 转换为更简单的形式而不使用嵌套并使用 JSONEachRow。

    或将数据作为 JSONAsString 插入 CH 并使用 JSONExtract 进行转换

    create table i(J String) Engine=Null;
    create table f(a String, i Int64, f Float64) Engine=MergeTree order by a;
    
    create materialized view vv to f
    as select (JSONExtract(J, 'Tuple(String,Tuple(Int64,Float64))') as x),
            x.1 as a,
            x.2.1 as i,
            x.2.2 as f
    from i;
    
    echo '{"s": "val1", "b2": {"i": 42, "f": 0.1}}' |clickhouse-client -q "insert into i format JSONAsString"
    
    select * from f
    ┌─a────┬──i─┬───f─┐
    │ val1 │ 42 │ 0.1 │
    └──────┴────┴─────┘
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-25
      • 1970-01-01
      相关资源
      最近更新 更多