handle multi-valued XML paths

Follow

Comments

2 comments

  • Avatar
    Pavel Prozorov

    Hi Julian,
    I try to use your solution 2 with string[] array. I get data from an API and try to put it in XMLTABLE, but get an error:

    Cannot convert insert query expression projected symbol 'x."value"' of 
    type [Ljava.lang.String; to insert column
    '#__LOCAL__things__Attributes."value"' of type java.lang.String

     

    Insert Into #__LOCAL__THINGS__Attributes
            Select 
                 i
             ,    "id"
             ,    "createdBy" 
             ,    From_UnixTime(Cast(("createdOn" / 1000) as INTEGER))
             ,    "lastModifiedBy"
             ,    From_UnixTime(Cast(("lastModifiedOn" / 1000) as INTEGER))
             ,    "system"
             ,    "resourceType"
             ,    "type_id"
             ,    "type_resourceType"
             ,    Replace("type_name", '>', '>')
             ,    "asset_id"
             ,    "asset_resourceType"
             ,    Replace("asset_name", '>', '>')
             ,    "value"
            From (
              call src_THINGS.internal_doQuery (
                    endpoint => QueryString(
                        'attributes', 
                        typeIds as typeIds,
                        pageSize as "limit", 
                        "offset" as "offset"
                    ),
                    requestContentType => 'application/json',
                    requestHeaders => 'Accept: application/json',
                    label => label
                )
            ) w,
            XmlTable(
                '/root/results'
                Passing w.response
                COLUMNS
                     "id" STRING
                 ,    "createdBy" STRING
                 ,    "createdOn" LONG
                 ,    "lastModifiedBy" STRING
                 ,    "lastModifiedOn" LONG
                 ,    "system" BOOLEAN
                 ,    "resourceType" STRING
                 ,    "type_id" STRING PATH 'type/id'
                 ,    "type_resourceType" STRING PATH 'type/resourceType'
                 ,    "type_name" STRING PATH 'type/name'
                 ,    "asset_id" STRING PATH 'asset/id'
                 ,    "asset_resourceType" STRING PATH 'asset/resourceType'
                 ,    "asset_name" STRING PATH 'asset/name'
               ,    "value" STRING[] PATH '.'
            ) x;

    Any idea what is the matter?
    Thank you in advance.

    0
    Comment actions Permalink
  • Avatar
    Matthias Korn

    Hi Pavel,

    looking at the code you provided, the XMLTABLE function is only called once. You will need two different calls to it, the first one doing the xml-table transformation for the json itself and then another call to unnest the array.

    Please let me know if you have any questions. If it cant be solved, please provide a sample json file and we can have a look.

    Best,
    Matthias

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk