Hive XML Serde : Parsing error when loading xml content











up vote
0
down vote

favorite












I am trying to load the following XML content using SerDe with Hive :



<?xml version="1.0"?>
<RootTag xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.website.com/service">
<Code>123</Code>
<ParentElement>
<Entity>
<EntityId>A</EntityId>
<EntityCode i:nil="true"/>
</Entity>
<Entity>
<EntityId>M</EntityId>
<EntityCode i:nil="true"/>
</Entity>
</ParentElement>
</RootTag>


The hive table was created as follows:



CREATE EXTERNAL TABLE database.mytable(
code String,
Entity array<struct<Entity:struct<EntityId:String,EntityCode:String>>>
)
ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
WITH SERDEPROPERTIES
(
"column.xpath.Code" = "/RootTag/Code/text()",
"column.xpath.ParentElement" = "/RootTag/ParentElement"
)
STORED AS
INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
LOCATION '/xml_content/'
TBLPROPERTIES ("xmlinput.start" = "<RootTag", "xmlinput.end" = "</RootTag>");


I have 2 issues:




  1. when I specify the "xmlinput.start" as specified above, it doesn't work. I had to remove manually the content "xmlns:i = ... /service" next to the "RootTage" in order to start parsing the xml.

  2. Even though, there is another issue with "EntityCode" attribute. I am getting the error:


Caused by: org.apache.hive.service.cli.HiveSQLException:
java.io.IOException:
org.apache.hadoop.hive.serde2.SerDeException:
java.lang.RuntimeException:
org.xml.sax.SAXParseException;
lineNumber: 41;
columnNumber: 33;
The prefix "i" for attribute "i:nil" associated with an element type "ParentCode" is not bound.


What am I doing wrong? I would appreciate your suggestions and comments regarding this.










share|improve this question









New contributor




ilmar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    0
    down vote

    favorite












    I am trying to load the following XML content using SerDe with Hive :



    <?xml version="1.0"?>
    <RootTag xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.website.com/service">
    <Code>123</Code>
    <ParentElement>
    <Entity>
    <EntityId>A</EntityId>
    <EntityCode i:nil="true"/>
    </Entity>
    <Entity>
    <EntityId>M</EntityId>
    <EntityCode i:nil="true"/>
    </Entity>
    </ParentElement>
    </RootTag>


    The hive table was created as follows:



    CREATE EXTERNAL TABLE database.mytable(
    code String,
    Entity array<struct<Entity:struct<EntityId:String,EntityCode:String>>>
    )
    ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
    WITH SERDEPROPERTIES
    (
    "column.xpath.Code" = "/RootTag/Code/text()",
    "column.xpath.ParentElement" = "/RootTag/ParentElement"
    )
    STORED AS
    INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
    LOCATION '/xml_content/'
    TBLPROPERTIES ("xmlinput.start" = "<RootTag", "xmlinput.end" = "</RootTag>");


    I have 2 issues:




    1. when I specify the "xmlinput.start" as specified above, it doesn't work. I had to remove manually the content "xmlns:i = ... /service" next to the "RootTage" in order to start parsing the xml.

    2. Even though, there is another issue with "EntityCode" attribute. I am getting the error:


    Caused by: org.apache.hive.service.cli.HiveSQLException:
    java.io.IOException:
    org.apache.hadoop.hive.serde2.SerDeException:
    java.lang.RuntimeException:
    org.xml.sax.SAXParseException;
    lineNumber: 41;
    columnNumber: 33;
    The prefix "i" for attribute "i:nil" associated with an element type "ParentCode" is not bound.


    What am I doing wrong? I would appreciate your suggestions and comments regarding this.










    share|improve this question









    New contributor




    ilmar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to load the following XML content using SerDe with Hive :



      <?xml version="1.0"?>
      <RootTag xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.website.com/service">
      <Code>123</Code>
      <ParentElement>
      <Entity>
      <EntityId>A</EntityId>
      <EntityCode i:nil="true"/>
      </Entity>
      <Entity>
      <EntityId>M</EntityId>
      <EntityCode i:nil="true"/>
      </Entity>
      </ParentElement>
      </RootTag>


      The hive table was created as follows:



      CREATE EXTERNAL TABLE database.mytable(
      code String,
      Entity array<struct<Entity:struct<EntityId:String,EntityCode:String>>>
      )
      ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
      WITH SERDEPROPERTIES
      (
      "column.xpath.Code" = "/RootTag/Code/text()",
      "column.xpath.ParentElement" = "/RootTag/ParentElement"
      )
      STORED AS
      INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
      OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
      LOCATION '/xml_content/'
      TBLPROPERTIES ("xmlinput.start" = "<RootTag", "xmlinput.end" = "</RootTag>");


      I have 2 issues:




      1. when I specify the "xmlinput.start" as specified above, it doesn't work. I had to remove manually the content "xmlns:i = ... /service" next to the "RootTage" in order to start parsing the xml.

      2. Even though, there is another issue with "EntityCode" attribute. I am getting the error:


      Caused by: org.apache.hive.service.cli.HiveSQLException:
      java.io.IOException:
      org.apache.hadoop.hive.serde2.SerDeException:
      java.lang.RuntimeException:
      org.xml.sax.SAXParseException;
      lineNumber: 41;
      columnNumber: 33;
      The prefix "i" for attribute "i:nil" associated with an element type "ParentCode" is not bound.


      What am I doing wrong? I would appreciate your suggestions and comments regarding this.










      share|improve this question









      New contributor




      ilmar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am trying to load the following XML content using SerDe with Hive :



      <?xml version="1.0"?>
      <RootTag xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.website.com/service">
      <Code>123</Code>
      <ParentElement>
      <Entity>
      <EntityId>A</EntityId>
      <EntityCode i:nil="true"/>
      </Entity>
      <Entity>
      <EntityId>M</EntityId>
      <EntityCode i:nil="true"/>
      </Entity>
      </ParentElement>
      </RootTag>


      The hive table was created as follows:



      CREATE EXTERNAL TABLE database.mytable(
      code String,
      Entity array<struct<Entity:struct<EntityId:String,EntityCode:String>>>
      )
      ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
      WITH SERDEPROPERTIES
      (
      "column.xpath.Code" = "/RootTag/Code/text()",
      "column.xpath.ParentElement" = "/RootTag/ParentElement"
      )
      STORED AS
      INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
      OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
      LOCATION '/xml_content/'
      TBLPROPERTIES ("xmlinput.start" = "<RootTag", "xmlinput.end" = "</RootTag>");


      I have 2 issues:




      1. when I specify the "xmlinput.start" as specified above, it doesn't work. I had to remove manually the content "xmlns:i = ... /service" next to the "RootTage" in order to start parsing the xml.

      2. Even though, there is another issue with "EntityCode" attribute. I am getting the error:


      Caused by: org.apache.hive.service.cli.HiveSQLException:
      java.io.IOException:
      org.apache.hadoop.hive.serde2.SerDeException:
      java.lang.RuntimeException:
      org.xml.sax.SAXParseException;
      lineNumber: 41;
      columnNumber: 33;
      The prefix "i" for attribute "i:nil" associated with an element type "ParentCode" is not bound.


      What am I doing wrong? I would appreciate your suggestions and comments regarding this.







      xml parsing hadoop hive hive-serde






      share|improve this question









      New contributor




      ilmar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      ilmar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Nov 19 at 17:06









      E_net4 is kind and welcoming

      11.2k63468




      11.2k63468






      New contributor




      ilmar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 19 at 14:03









      ilmar

      11




      11




      New contributor




      ilmar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      ilmar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      ilmar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          There are few things.




          • I think the root tag with namespace is only supported on version 1.5.0.3 or greater. check the following link https://github.com/dvasilen/Hive-XML-SerDe/issues/15

          • I am don't think it supports the i:nil="true"

          • Mapping of column should match the column name and it's case sensitive. column.xpath.Code and code won't work. Also there is no corrosponding column for column.xpath.ParentElement


          So what you need to do?




          • Upgrade your serde.

          • replace <EntityCode i:nil="true"/> to <EntityCode/> in your xml

          • Fix the code as mentioned below


          Code



          CREATE EXTERNAL TABLE temp.test_xml(
          code String,
          Entity array<struct<Entity:struct<EntityId:String,EntityCode:String>>>
          )
          ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
          WITH SERDEPROPERTIES
          (
          "column.xpath.code" = "/RootTag/Code/text()",
          "column.xpath.Entity" = "/RootTag/ParentElement/Entity"

          )
          STORED AS
          INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
          OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
          LOCATION '/tmp/test_xml1/table/'
          TBLPROPERTIES (
          "xmlinput.start"="<RootTag",
          "xmlinput.end"="</RootTag>");





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            ilmar is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376332%2fhive-xml-serde-parsing-error-when-loading-xml-content%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            There are few things.




            • I think the root tag with namespace is only supported on version 1.5.0.3 or greater. check the following link https://github.com/dvasilen/Hive-XML-SerDe/issues/15

            • I am don't think it supports the i:nil="true"

            • Mapping of column should match the column name and it's case sensitive. column.xpath.Code and code won't work. Also there is no corrosponding column for column.xpath.ParentElement


            So what you need to do?




            • Upgrade your serde.

            • replace <EntityCode i:nil="true"/> to <EntityCode/> in your xml

            • Fix the code as mentioned below


            Code



            CREATE EXTERNAL TABLE temp.test_xml(
            code String,
            Entity array<struct<Entity:struct<EntityId:String,EntityCode:String>>>
            )
            ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
            WITH SERDEPROPERTIES
            (
            "column.xpath.code" = "/RootTag/Code/text()",
            "column.xpath.Entity" = "/RootTag/ParentElement/Entity"

            )
            STORED AS
            INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
            OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
            LOCATION '/tmp/test_xml1/table/'
            TBLPROPERTIES (
            "xmlinput.start"="<RootTag",
            "xmlinput.end"="</RootTag>");





            share|improve this answer

























              up vote
              0
              down vote













              There are few things.




              • I think the root tag with namespace is only supported on version 1.5.0.3 or greater. check the following link https://github.com/dvasilen/Hive-XML-SerDe/issues/15

              • I am don't think it supports the i:nil="true"

              • Mapping of column should match the column name and it's case sensitive. column.xpath.Code and code won't work. Also there is no corrosponding column for column.xpath.ParentElement


              So what you need to do?




              • Upgrade your serde.

              • replace <EntityCode i:nil="true"/> to <EntityCode/> in your xml

              • Fix the code as mentioned below


              Code



              CREATE EXTERNAL TABLE temp.test_xml(
              code String,
              Entity array<struct<Entity:struct<EntityId:String,EntityCode:String>>>
              )
              ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
              WITH SERDEPROPERTIES
              (
              "column.xpath.code" = "/RootTag/Code/text()",
              "column.xpath.Entity" = "/RootTag/ParentElement/Entity"

              )
              STORED AS
              INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
              OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
              LOCATION '/tmp/test_xml1/table/'
              TBLPROPERTIES (
              "xmlinput.start"="<RootTag",
              "xmlinput.end"="</RootTag>");





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                There are few things.




                • I think the root tag with namespace is only supported on version 1.5.0.3 or greater. check the following link https://github.com/dvasilen/Hive-XML-SerDe/issues/15

                • I am don't think it supports the i:nil="true"

                • Mapping of column should match the column name and it's case sensitive. column.xpath.Code and code won't work. Also there is no corrosponding column for column.xpath.ParentElement


                So what you need to do?




                • Upgrade your serde.

                • replace <EntityCode i:nil="true"/> to <EntityCode/> in your xml

                • Fix the code as mentioned below


                Code



                CREATE EXTERNAL TABLE temp.test_xml(
                code String,
                Entity array<struct<Entity:struct<EntityId:String,EntityCode:String>>>
                )
                ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
                WITH SERDEPROPERTIES
                (
                "column.xpath.code" = "/RootTag/Code/text()",
                "column.xpath.Entity" = "/RootTag/ParentElement/Entity"

                )
                STORED AS
                INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
                OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
                LOCATION '/tmp/test_xml1/table/'
                TBLPROPERTIES (
                "xmlinput.start"="<RootTag",
                "xmlinput.end"="</RootTag>");





                share|improve this answer












                There are few things.




                • I think the root tag with namespace is only supported on version 1.5.0.3 or greater. check the following link https://github.com/dvasilen/Hive-XML-SerDe/issues/15

                • I am don't think it supports the i:nil="true"

                • Mapping of column should match the column name and it's case sensitive. column.xpath.Code and code won't work. Also there is no corrosponding column for column.xpath.ParentElement


                So what you need to do?




                • Upgrade your serde.

                • replace <EntityCode i:nil="true"/> to <EntityCode/> in your xml

                • Fix the code as mentioned below


                Code



                CREATE EXTERNAL TABLE temp.test_xml(
                code String,
                Entity array<struct<Entity:struct<EntityId:String,EntityCode:String>>>
                )
                ROW FORMAT SERDE 'com.ibm.spss.hive.serde2.xml.XmlSerDe'
                WITH SERDEPROPERTIES
                (
                "column.xpath.code" = "/RootTag/Code/text()",
                "column.xpath.Entity" = "/RootTag/ParentElement/Entity"

                )
                STORED AS
                INPUTFORMAT 'com.ibm.spss.hive.serde2.xml.XmlInputFormat'
                OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat'
                LOCATION '/tmp/test_xml1/table/'
                TBLPROPERTIES (
                "xmlinput.start"="<RootTag",
                "xmlinput.end"="</RootTag>");






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 19 at 20:18









                Gaurang Shah

                2,67311030




                2,67311030






















                    ilmar is a new contributor. Be nice, and check out our Code of Conduct.










                     

                    draft saved


                    draft discarded


















                    ilmar is a new contributor. Be nice, and check out our Code of Conduct.













                    ilmar is a new contributor. Be nice, and check out our Code of Conduct.












                    ilmar is a new contributor. Be nice, and check out our Code of Conduct.















                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376332%2fhive-xml-serde-parsing-error-when-loading-xml-content%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    TypeError: fit_transform() missing 1 required positional argument: 'X'