How to Order/Sort the structType based on the field names in Java Spark 2.1.12019 Community Moderator ElectionSpark - How to add a StructField at the beginning of a StructType in scalaDataFrame partitionBy on nested columnsSpark Struct structfield names getting changed in UDFHow to group by on a field inside an array of an array of records?How do I apply schema with nullable = false to json readingSpark read avroSpark custom sort column in JavaHow to cast all columns of a DataFrame (with Nested StructTypes) to string in SparkSpark FlatMapGroupsWithStateFunction throws cannot resolve 'named_struct()' due to data type mismatch 'SerializeFromObjectPySpark sql dataframe pandas UDF - java.lang.IllegalArgumentException: requirement failed: Decimal precision 8 exceeds max precision 7

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

Giving a career talk in my old university, how prominently should I tell students my salary?

How does Ehrenfest's theorem apply to the quantum harmonic oscillator?

Finitely many repeated replacements

Shifting between bemols and diesis in the key signature

What would be the most expensive material to an intergalactic society?

Dynamic Linkage of LocatorPane and InputField

MySQL importing CSV files really slow

Expressing logarithmic equations without logs

Why restrict private health insurance?

Recommendation letter by significant other if you worked with them professionally?

How exactly does an Ethernet collision happen in the cable, since nodes use different circuits for Tx and Rx?

ER diagram relationship node size adjustment

What is Tony Stark injecting into himself in Iron Man 3?

Is it possible that a question has only two answers?

Does Christianity allow for believing on someone else's behalf?

Why do we say ‘pairwise disjoint’, rather than ‘disjoint’?

How do spaceships determine each other's mass in space?

Is it possible to find 2014 distinct positive integers whose sum is divisible by each of them?

Is this Paypal Github SDK reference really a dangerous site?

Why is a very small peak with larger m/z not considered to be the molecular ion?

Street obstacles in New Zealand

What do *foreign films* mean for an American?

Does "Until when" sound natural for native speakers?



How to Order/Sort the structType based on the field names in Java Spark 2.1.1



2019 Community Moderator ElectionSpark - How to add a StructField at the beginning of a StructType in scalaDataFrame partitionBy on nested columnsSpark Struct structfield names getting changed in UDFHow to group by on a field inside an array of an array of records?How do I apply schema with nullable = false to json readingSpark read avroSpark custom sort column in JavaHow to cast all columns of a DataFrame (with Nested StructTypes) to string in SparkSpark FlatMapGroupsWithStateFunction throws cannot resolve 'named_struct()' due to data type mismatch 'SerializeFromObjectPySpark sql dataframe pandas UDF - java.lang.IllegalArgumentException: requirement failed: Decimal precision 8 exceeds max precision 7










-1















I have a structType schema, i need to order / sort the schema based on the field name, below i am sharing the StructType.



StructType schema = StructType(StructField(zzz,StringType,true), 
StructField(kkk,StringType,true),
StructField(aaa,StringType,true),
StructField(lll,StringType,true))


i would like to get the above structType, as below



StructType schema = StructType(StructField(aaa,StringType,true), 
StructField(kkk,StringType,true),
StructField(lll,StringType,true),
StructField(zzz,StringType,true))









share|improve this question


























    -1















    I have a structType schema, i need to order / sort the schema based on the field name, below i am sharing the StructType.



    StructType schema = StructType(StructField(zzz,StringType,true), 
    StructField(kkk,StringType,true),
    StructField(aaa,StringType,true),
    StructField(lll,StringType,true))


    i would like to get the above structType, as below



    StructType schema = StructType(StructField(aaa,StringType,true), 
    StructField(kkk,StringType,true),
    StructField(lll,StringType,true),
    StructField(zzz,StringType,true))









    share|improve this question
























      -1












      -1








      -1








      I have a structType schema, i need to order / sort the schema based on the field name, below i am sharing the StructType.



      StructType schema = StructType(StructField(zzz,StringType,true), 
      StructField(kkk,StringType,true),
      StructField(aaa,StringType,true),
      StructField(lll,StringType,true))


      i would like to get the above structType, as below



      StructType schema = StructType(StructField(aaa,StringType,true), 
      StructField(kkk,StringType,true),
      StructField(lll,StringType,true),
      StructField(zzz,StringType,true))









      share|improve this question














      I have a structType schema, i need to order / sort the schema based on the field name, below i am sharing the StructType.



      StructType schema = StructType(StructField(zzz,StringType,true), 
      StructField(kkk,StringType,true),
      StructField(aaa,StringType,true),
      StructField(lll,StringType,true))


      i would like to get the above structType, as below



      StructType schema = StructType(StructField(aaa,StringType,true), 
      StructField(kkk,StringType,true),
      StructField(lll,StringType,true),
      StructField(zzz,StringType,true))






      apache-spark apache-spark-sql apache-spark-dataset






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 4:50









      svk 041994svk 041994

      487




      487






















          1 Answer
          1






          active

          oldest

          votes


















          1














          In scala



          var schema = StructType(Seq(StructField("zzz",StringType,true), 
          StructField("kkk",StringType,true),
          StructField("aaa",StringType,true),
          StructField("lll",StringType,true)))
          def reorderSchema: StructType => StructType = schema => StructType(schema.sortBy(_.name))

          var newSchema = reorderSchema(schema)


          In java,
          You can do something like,



           new StructType(Stream.of(schema.fields())
          .sorted(Comparator.comparing(StructField::name))
          .collect(Collectors.toList()).toArray(new StructField[schema.fields().length]))


          Please accept the answer if it solves.






          share|improve this answer

























          • As i am using java, the mentioned answer is not working. we should pass the two parameters for sortBy(function f, order)

            – svk 041994
            Mar 7 at 6:22











          • updated the answer to work with java

            – deo
            Mar 7 at 7:01










          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',
          autoActivateHeartbeat: false,
          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%2f55036314%2fhow-to-order-sort-the-structtype-based-on-the-field-names-in-java-spark-2-1-1%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









          1














          In scala



          var schema = StructType(Seq(StructField("zzz",StringType,true), 
          StructField("kkk",StringType,true),
          StructField("aaa",StringType,true),
          StructField("lll",StringType,true)))
          def reorderSchema: StructType => StructType = schema => StructType(schema.sortBy(_.name))

          var newSchema = reorderSchema(schema)


          In java,
          You can do something like,



           new StructType(Stream.of(schema.fields())
          .sorted(Comparator.comparing(StructField::name))
          .collect(Collectors.toList()).toArray(new StructField[schema.fields().length]))


          Please accept the answer if it solves.






          share|improve this answer

























          • As i am using java, the mentioned answer is not working. we should pass the two parameters for sortBy(function f, order)

            – svk 041994
            Mar 7 at 6:22











          • updated the answer to work with java

            – deo
            Mar 7 at 7:01















          1














          In scala



          var schema = StructType(Seq(StructField("zzz",StringType,true), 
          StructField("kkk",StringType,true),
          StructField("aaa",StringType,true),
          StructField("lll",StringType,true)))
          def reorderSchema: StructType => StructType = schema => StructType(schema.sortBy(_.name))

          var newSchema = reorderSchema(schema)


          In java,
          You can do something like,



           new StructType(Stream.of(schema.fields())
          .sorted(Comparator.comparing(StructField::name))
          .collect(Collectors.toList()).toArray(new StructField[schema.fields().length]))


          Please accept the answer if it solves.






          share|improve this answer

























          • As i am using java, the mentioned answer is not working. we should pass the two parameters for sortBy(function f, order)

            – svk 041994
            Mar 7 at 6:22











          • updated the answer to work with java

            – deo
            Mar 7 at 7:01













          1












          1








          1







          In scala



          var schema = StructType(Seq(StructField("zzz",StringType,true), 
          StructField("kkk",StringType,true),
          StructField("aaa",StringType,true),
          StructField("lll",StringType,true)))
          def reorderSchema: StructType => StructType = schema => StructType(schema.sortBy(_.name))

          var newSchema = reorderSchema(schema)


          In java,
          You can do something like,



           new StructType(Stream.of(schema.fields())
          .sorted(Comparator.comparing(StructField::name))
          .collect(Collectors.toList()).toArray(new StructField[schema.fields().length]))


          Please accept the answer if it solves.






          share|improve this answer















          In scala



          var schema = StructType(Seq(StructField("zzz",StringType,true), 
          StructField("kkk",StringType,true),
          StructField("aaa",StringType,true),
          StructField("lll",StringType,true)))
          def reorderSchema: StructType => StructType = schema => StructType(schema.sortBy(_.name))

          var newSchema = reorderSchema(schema)


          In java,
          You can do something like,



           new StructType(Stream.of(schema.fields())
          .sorted(Comparator.comparing(StructField::name))
          .collect(Collectors.toList()).toArray(new StructField[schema.fields().length]))


          Please accept the answer if it solves.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 7 at 7:00

























          answered Mar 7 at 6:09









          deodeo

          8615




          8615












          • As i am using java, the mentioned answer is not working. we should pass the two parameters for sortBy(function f, order)

            – svk 041994
            Mar 7 at 6:22











          • updated the answer to work with java

            – deo
            Mar 7 at 7:01

















          • As i am using java, the mentioned answer is not working. we should pass the two parameters for sortBy(function f, order)

            – svk 041994
            Mar 7 at 6:22











          • updated the answer to work with java

            – deo
            Mar 7 at 7:01
















          As i am using java, the mentioned answer is not working. we should pass the two parameters for sortBy(function f, order)

          – svk 041994
          Mar 7 at 6:22





          As i am using java, the mentioned answer is not working. we should pass the two parameters for sortBy(function f, order)

          – svk 041994
          Mar 7 at 6:22













          updated the answer to work with java

          – deo
          Mar 7 at 7:01





          updated the answer to work with java

          – deo
          Mar 7 at 7:01



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55036314%2fhow-to-order-sort-the-structtype-based-on-the-field-names-in-java-spark-2-1-1%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

          How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229