Skip to content

How to transform canal message? Which is flag map Array data and add field #10820

Answered by spencergilbert
yaohuacheng asked this question in Q&A
Discussion options

You must be logged in to vote

I pulled together the following transform:

transforms:
  unnest:
    type: remap
    inputs:
      - file
    source: |
      message = del(.message)
      . = object!(parse_json!(message))
      . = unnest!(.data)
  remap:
    type: remap
    inputs:
      - unnest
    source: |
      data = del(.data)
      . |= object!(data)

      ._meta_data.database = del(.database)
      ._meta_data.table = del(.table)
      ._meta_data.ts = del(.ts)
      ._meta_data.type = del(.type)

      del(.es)
      del(.isDdl)
      del(.old)
      del(.pkNames)
      del(.sql)

Which from your original event:

{"data":[{"create_time":"2022-01-09 00:00:19","id":"9204245","reason":"4","user_id":"134048732"},{"…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jszwedko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
type: task Generic non-code related tasks
2 participants
Converted from issue

This discussion was converted from issue #10763 on January 12, 2022 17:08.