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
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
add a comment |
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
add a comment |
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
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
apache-spark apache-spark-sql apache-spark-dataset
asked Mar 7 at 4:50
svk 041994svk 041994
487
487
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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