Same column names in Spark DataFrame supported, but how to select individually - non JOINed scenario











up vote
0
down vote

favorite












Given that we can see the same Col name in a dataframe below - as I noted elsewhere:



root
|-- week: string (nullable = true)
|-- dim1: integer (nullable = false)
|-- dim2: string (nullable = true)
|-- t1: integer (nullable = false)
|-- t2: integer (nullable = false)
|-- t3: integer (nullable = false)
|-- t1: integer (nullable = false)
|-- t2: integer (nullable = false)
|-- t3: integer (nullable = false)
|-- t1_diff: integer (nullable = false)
|-- t2_diff: integer (nullable = false)


and that:



df.select("t1").show(false) 


returns ambiguous reference, then how can I state which one I want to select?



This is not a result of a JOIN, but just based on a Seq definition with .toDF(...) as follows:



val df = Seq(
("2016-04-02",14, null, 9784, 880, 23, 9789, 820, 45, -5, 60),
("2016-04-30",14, "FR", 9785, 13, 34, 9785, 9, 67, 90, 4),
("2016-04-16",14, "FR", 9785, 13, 34, 9785, 9, 67, -100, -123)
).toDF("week", "dim1", "dim2", "t1", "t2", "t3", "t1", "t2", "t3", "t1_diff", "t2_diff")


Somewhat inconsistent to me, and not something I would do, but I did note this, so more so out of curiosity. Seems an oversight?










share|improve this question




























    up vote
    0
    down vote

    favorite












    Given that we can see the same Col name in a dataframe below - as I noted elsewhere:



    root
    |-- week: string (nullable = true)
    |-- dim1: integer (nullable = false)
    |-- dim2: string (nullable = true)
    |-- t1: integer (nullable = false)
    |-- t2: integer (nullable = false)
    |-- t3: integer (nullable = false)
    |-- t1: integer (nullable = false)
    |-- t2: integer (nullable = false)
    |-- t3: integer (nullable = false)
    |-- t1_diff: integer (nullable = false)
    |-- t2_diff: integer (nullable = false)


    and that:



    df.select("t1").show(false) 


    returns ambiguous reference, then how can I state which one I want to select?



    This is not a result of a JOIN, but just based on a Seq definition with .toDF(...) as follows:



    val df = Seq(
    ("2016-04-02",14, null, 9784, 880, 23, 9789, 820, 45, -5, 60),
    ("2016-04-30",14, "FR", 9785, 13, 34, 9785, 9, 67, 90, 4),
    ("2016-04-16",14, "FR", 9785, 13, 34, 9785, 9, 67, -100, -123)
    ).toDF("week", "dim1", "dim2", "t1", "t2", "t3", "t1", "t2", "t3", "t1_diff", "t2_diff")


    Somewhat inconsistent to me, and not something I would do, but I did note this, so more so out of curiosity. Seems an oversight?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Given that we can see the same Col name in a dataframe below - as I noted elsewhere:



      root
      |-- week: string (nullable = true)
      |-- dim1: integer (nullable = false)
      |-- dim2: string (nullable = true)
      |-- t1: integer (nullable = false)
      |-- t2: integer (nullable = false)
      |-- t3: integer (nullable = false)
      |-- t1: integer (nullable = false)
      |-- t2: integer (nullable = false)
      |-- t3: integer (nullable = false)
      |-- t1_diff: integer (nullable = false)
      |-- t2_diff: integer (nullable = false)


      and that:



      df.select("t1").show(false) 


      returns ambiguous reference, then how can I state which one I want to select?



      This is not a result of a JOIN, but just based on a Seq definition with .toDF(...) as follows:



      val df = Seq(
      ("2016-04-02",14, null, 9784, 880, 23, 9789, 820, 45, -5, 60),
      ("2016-04-30",14, "FR", 9785, 13, 34, 9785, 9, 67, 90, 4),
      ("2016-04-16",14, "FR", 9785, 13, 34, 9785, 9, 67, -100, -123)
      ).toDF("week", "dim1", "dim2", "t1", "t2", "t3", "t1", "t2", "t3", "t1_diff", "t2_diff")


      Somewhat inconsistent to me, and not something I would do, but I did note this, so more so out of curiosity. Seems an oversight?










      share|improve this question















      Given that we can see the same Col name in a dataframe below - as I noted elsewhere:



      root
      |-- week: string (nullable = true)
      |-- dim1: integer (nullable = false)
      |-- dim2: string (nullable = true)
      |-- t1: integer (nullable = false)
      |-- t2: integer (nullable = false)
      |-- t3: integer (nullable = false)
      |-- t1: integer (nullable = false)
      |-- t2: integer (nullable = false)
      |-- t3: integer (nullable = false)
      |-- t1_diff: integer (nullable = false)
      |-- t2_diff: integer (nullable = false)


      and that:



      df.select("t1").show(false) 


      returns ambiguous reference, then how can I state which one I want to select?



      This is not a result of a JOIN, but just based on a Seq definition with .toDF(...) as follows:



      val df = Seq(
      ("2016-04-02",14, null, 9784, 880, 23, 9789, 820, 45, -5, 60),
      ("2016-04-30",14, "FR", 9785, 13, 34, 9785, 9, 67, 90, 4),
      ("2016-04-16",14, "FR", 9785, 13, 34, 9785, 9, 67, -100, -123)
      ).toDF("week", "dim1", "dim2", "t1", "t2", "t3", "t1", "t2", "t3", "t1_diff", "t2_diff")


      Somewhat inconsistent to me, and not something I would do, but I did note this, so more so out of curiosity. Seems an oversight?







      apache-spark






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 at 14:31

























      asked Nov 17 at 14:18









      thebluephantom

      2,0832823




      2,0832823





























          active

          oldest

          votes











          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
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53352067%2fsame-column-names-in-spark-dataframe-supported-but-how-to-select-individually%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53352067%2fsame-column-names-in-spark-dataframe-supported-but-how-to-select-individually%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

          Costa Masnaga

          Fotorealismo

          Sidney Franklin