繁体   English   中英

Clikhouse + 亚马逊 SNS 通知

[英]Clikhouse + Amazon SNS notification

我尝试插入一个 Amazon SNS 通知eventype = Open to 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 转换为更简单的形式而无需嵌套并使用 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 │
└──────┴────┴─────┘

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM