Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing a sibling's value from a JSON Array in JSONserde #195

Open
saidatta opened this issue Aug 23, 2017 · 2 comments
Open

Accessing a sibling's value from a JSON Array in JSONserde #195

saidatta opened this issue Aug 23, 2017 · 2 comments

Comments

@saidatta
Copy link

saidatta commented Aug 23, 2017

Hey,

Given
This is my JSON

...
    "actions": [
      {
        "action_type": "link_click",
        "value": "1"
      },
      {
        "action_type": "page_engagement",
        "value": "1"
      },
      {
        "action_type": "post_engagement",
        "value": "1"
      },
      .....
    ]
  }
...

I would like to map each action_type's value into a specific column of my external Table

CREATE EXTERNAL TABLE IF NOT EXISTS  raw_marketing_other.facebook_ad_cost_dtl_hrly (
   ...
   linkClick : int
   pageEngagement : int
...
)

For example, linkClick column will have the value of 1 derived from that json object.

Question
Is this possible in the mapping of serdeProperties? something like this.

WITH serdeproperties(
    "mapping.linkClick" = "actions[action_type="link_click].value",
...

Note: where actions[action_type="link_click]" is meant to return the first occurence of json object with that condition?

If it is not possible through custom mappings, then is there any alternative solution for it?

Thanks

@saidatta saidatta changed the title Accessing a sibling's value from a JSON Array in serde Accessing a sibling's value from a JSON Array in JSONserde Aug 23, 2017
@rcongiu
Copy link
Owner

rcongiu commented Aug 23, 2017 via email

@saidatta
Copy link
Author

Bummer.

I can do mapping with nested map attributes, right?
For example

    "actions": {
        "link_click": "1",
        "page_like": "2"
      },
      .....

and do

WITH serdeproperties(
    "mapping.linkClick" = "actions.link_click",
    "mapping.page_like" = "actions.page_like",
...

for mapping linkClick and page_like columns to the nested attributes link_click and page_like respectively.

Do I need to provide any additional flags?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants