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

Converting Avro file to JSONs using JsonOutputer #134

Open
lalithakiran opened this issue May 29, 2018 · 3 comments
Open

Converting Avro file to JSONs using JsonOutputer #134

lalithakiran opened this issue May 29, 2018 · 3 comments

Comments

@lalithakiran
Copy link

lalithakiran commented May 29, 2018

I have a requirement where I need to extract JSON files from Avro by using U-SQL. Avro files contain a collection of JSON and need to extract individual JSON from Avro. Here I have written code. I used JsonOuptter() for writing jsons.

OUTPUT @source
TO "C://schemaType.json"
USING new JsonOutputter();

I am getting JSON as like below.

[
  {
    "type": "C",
    "cnn": "1",
    "source": "{\r\n  \"vendorCd\": \"G\",\r\n  \"brandCd\": \"4\",\r\n  \"channelCd\": \"C\",\r\n  \"accessTypeCd\": \"I\"\r\n}",
    
  },
  {
    "type": "C",
    "cnn": "9",
    "source": "{\r\n  \"vendorCd\": \"G\",\r\n  \"brandCd\": \"4\",\r\n  \"channelCd\": \"C\",\r\n  \"accessTypeCd\": \"I\"\r\n}",
   
  }
]

I am expecting jSON as like below.

[
{  
   "type":"C",
   "ccn":"1",
   "source":{  
      "vendorCd":"G",
      "brandCd":"4",
      "channelCd":"C",
      "accessTypeCd":"I"
   },
{  
   "type":"C",
   "ccn":"9",
   "source":{  
      "vendorCd":"G",
      "brandCd":"4",
      "channelCd":"C",
      "accessTypeCd":"I"
   }
]

Thanks for your help and support.

@lalithakiran lalithakiran changed the title Converting Avro file to JSONs using JSONOutputer Converting Avro file to JSONs using JsonOutputer May 29, 2018
@MikeRys
Copy link
Collaborator

MikeRys commented May 29, 2018

This is as expected.

Your column source is of type string so it outputs it as a string property. You have the following options (both involving most likely to extend the outputter:

  1. Add an option to indicate a column to be treated as JSON instead of a string.
  2. Keep the data in the column as a SqlMap<string,string> and then output it as a set of properties for the object.

Both most likely need changes to the outputter.

Best regards
Michael

@lalithakiran
Copy link
Author

Would you please help me more on this. Where can I get the option to indicate column as JSON?

@MikeRys
Copy link
Collaborator

MikeRys commented May 31, 2018

You would have to write your own version of the outputter to add this option. Please note that these are samples that are meant to help people get started and if something is missing to contribute to it :).

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