Rename nested struct columns in a Spark DataFrame [duplicate]Rename nested field in spark dataframeHow to sort a dataframe by multiple column(s)Selecting multiple columns in a pandas dataframeRenaming columns in pandasAdding new column to existing DataFrame in Python pandasHow to change the order of DataFrame columns?Delete column from pandas DataFrameHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headersscala.MatchError during Spark 2.0.2 DataFrame union

Reduce column width of table while also aligning values at decimal point

Why are there not any MRI machines available in Interstellar?

How may I concisely assign different values to a variable, depending on another variable?

What is the meaning of "you has the wind of me"?

"I you already know": is this proper English?

Is dd if=/dev/urandom of=/dev/mem safe?

401(k) investment after being fired. Do I own it?

What does "see" in "the Holy See" mean?

Is it legal to use cash pulled from a credit card to pay the monthly payment on that credit card?

How acidic does a mixture have to be for milk to curdle?

Other than a swing wing, what types of variable geometry have flown?

Why are so many countries still in the Commonwealth?

Explanation for a joke about a three-legged dog that walks into a bar

How can I receive packages while in France?

How do we explain the E major chord in this progression?

What is the lowest-speed bogey a jet fighter can intercept/escort?

Spin vs orbital angular momenta in QFT

Is it correct to translate English noun adjuncts into adjectives?

Area of parallelogram = Area of square. Shear transform

Automatic Habit of Meditation

Why isn't my platform event chain working?

Print sums of all subsets

Why was Sauron not trying to find the Ring, and instead of preparing for war?

How do I run a game when my PCs have different approaches to combat?



Rename nested struct columns in a Spark DataFrame [duplicate]


Rename nested field in spark dataframeHow to sort a dataframe by multiple column(s)Selecting multiple columns in a pandas dataframeRenaming columns in pandasAdding new column to existing DataFrame in Python pandasHow to change the order of DataFrame columns?Delete column from pandas DataFrameHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headersscala.MatchError during Spark 2.0.2 DataFrame union






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3
















This question already has an answer here:



  • Rename nested field in spark dataframe

    1 answer



I am trying to change the names of a DataFrame columns in scala. I am easily able to change the column names for direct fields but I'm facing difficulty while converting array struct columns.



Below is my DataFrame schema.



|-- _VkjLmnVop: string (nullable = true)
|-- _KaTasLop: string (nullable = true)
|-- AbcDef: struct (nullable = true)
| |-- UvwXyz: struct (nullable = true)
| | |-- _MnoPqrstUv: string (nullable = true)
| | |-- _ManDevyIxyz: string (nullable = true)


But I need the schema like below



|-- vkj_lmn_vop: string (nullable = true)
|-- ka_tas_lop: string (nullable = true)
|-- abc_def: struct (nullable = true)
| |-- uvw_xyz: struct (nullable = true)
| | |-- mno_pqrst_uv: string (nullable = true)
| | |-- man_devy_ixyz: string (nullable = true)


For Non Struct columns I'm changing column names by below



def aliasAllColumns(df: DataFrame): DataFrame = 
df.select(df.columns.map c =>
df.col(c)
.as(
c.replaceAll("_", "")
.replaceAll("([A-Z])", "_$1")
.toLowerCase
.replaceFirst("_", ""))
: _*)

aliasAllColumns(file_data_df).show(1)


How I can change Struct column names dynamically?










share|improve this question















marked as duplicate by eliasah apache-spark
Users with the  apache-spark badge can single-handedly close apache-spark questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 15:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • do you have the rename columns like Maps(_VkjLmnVop => vkj_lmn_vop, _KaTasLop => ka_tas_lop ) ?.

    – stack0114106
    Mar 26 at 17:21











  • @stack0114106, I've plenty of columns. So I'm thinking to change column names dynamically.

    – Vijay
    Mar 26 at 17:30

















3
















This question already has an answer here:



  • Rename nested field in spark dataframe

    1 answer



I am trying to change the names of a DataFrame columns in scala. I am easily able to change the column names for direct fields but I'm facing difficulty while converting array struct columns.



Below is my DataFrame schema.



|-- _VkjLmnVop: string (nullable = true)
|-- _KaTasLop: string (nullable = true)
|-- AbcDef: struct (nullable = true)
| |-- UvwXyz: struct (nullable = true)
| | |-- _MnoPqrstUv: string (nullable = true)
| | |-- _ManDevyIxyz: string (nullable = true)


But I need the schema like below



|-- vkj_lmn_vop: string (nullable = true)
|-- ka_tas_lop: string (nullable = true)
|-- abc_def: struct (nullable = true)
| |-- uvw_xyz: struct (nullable = true)
| | |-- mno_pqrst_uv: string (nullable = true)
| | |-- man_devy_ixyz: string (nullable = true)


For Non Struct columns I'm changing column names by below



def aliasAllColumns(df: DataFrame): DataFrame = 
df.select(df.columns.map c =>
df.col(c)
.as(
c.replaceAll("_", "")
.replaceAll("([A-Z])", "_$1")
.toLowerCase
.replaceFirst("_", ""))
: _*)

aliasAllColumns(file_data_df).show(1)


How I can change Struct column names dynamically?










share|improve this question















marked as duplicate by eliasah apache-spark
Users with the  apache-spark badge can single-handedly close apache-spark questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 15:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • do you have the rename columns like Maps(_VkjLmnVop => vkj_lmn_vop, _KaTasLop => ka_tas_lop ) ?.

    – stack0114106
    Mar 26 at 17:21











  • @stack0114106, I've plenty of columns. So I'm thinking to change column names dynamically.

    – Vijay
    Mar 26 at 17:30













3












3








3


1







This question already has an answer here:



  • Rename nested field in spark dataframe

    1 answer



I am trying to change the names of a DataFrame columns in scala. I am easily able to change the column names for direct fields but I'm facing difficulty while converting array struct columns.



Below is my DataFrame schema.



|-- _VkjLmnVop: string (nullable = true)
|-- _KaTasLop: string (nullable = true)
|-- AbcDef: struct (nullable = true)
| |-- UvwXyz: struct (nullable = true)
| | |-- _MnoPqrstUv: string (nullable = true)
| | |-- _ManDevyIxyz: string (nullable = true)


But I need the schema like below



|-- vkj_lmn_vop: string (nullable = true)
|-- ka_tas_lop: string (nullable = true)
|-- abc_def: struct (nullable = true)
| |-- uvw_xyz: struct (nullable = true)
| | |-- mno_pqrst_uv: string (nullable = true)
| | |-- man_devy_ixyz: string (nullable = true)


For Non Struct columns I'm changing column names by below



def aliasAllColumns(df: DataFrame): DataFrame = 
df.select(df.columns.map c =>
df.col(c)
.as(
c.replaceAll("_", "")
.replaceAll("([A-Z])", "_$1")
.toLowerCase
.replaceFirst("_", ""))
: _*)

aliasAllColumns(file_data_df).show(1)


How I can change Struct column names dynamically?










share|improve this question

















This question already has an answer here:



  • Rename nested field in spark dataframe

    1 answer



I am trying to change the names of a DataFrame columns in scala. I am easily able to change the column names for direct fields but I'm facing difficulty while converting array struct columns.



Below is my DataFrame schema.



|-- _VkjLmnVop: string (nullable = true)
|-- _KaTasLop: string (nullable = true)
|-- AbcDef: struct (nullable = true)
| |-- UvwXyz: struct (nullable = true)
| | |-- _MnoPqrstUv: string (nullable = true)
| | |-- _ManDevyIxyz: string (nullable = true)


But I need the schema like below



|-- vkj_lmn_vop: string (nullable = true)
|-- ka_tas_lop: string (nullable = true)
|-- abc_def: struct (nullable = true)
| |-- uvw_xyz: struct (nullable = true)
| | |-- mno_pqrst_uv: string (nullable = true)
| | |-- man_devy_ixyz: string (nullable = true)


For Non Struct columns I'm changing column names by below



def aliasAllColumns(df: DataFrame): DataFrame = 
df.select(df.columns.map c =>
df.col(c)
.as(
c.replaceAll("_", "")
.replaceAll("([A-Z])", "_$1")
.toLowerCase
.replaceFirst("_", ""))
: _*)

aliasAllColumns(file_data_df).show(1)


How I can change Struct column names dynamically?





This question already has an answer here:



  • Rename nested field in spark dataframe

    1 answer







scala apache-spark dataframe column-alias






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 19:13









Leo C

13.8k2 gold badges10 silver badges20 bronze badges




13.8k2 gold badges10 silver badges20 bronze badges










asked Mar 26 at 16:53









VijayVijay

4515 silver badges21 bronze badges




4515 silver badges21 bronze badges




marked as duplicate by eliasah apache-spark
Users with the  apache-spark badge can single-handedly close apache-spark questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 15:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by eliasah apache-spark
Users with the  apache-spark badge can single-handedly close apache-spark questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 15:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • do you have the rename columns like Maps(_VkjLmnVop => vkj_lmn_vop, _KaTasLop => ka_tas_lop ) ?.

    – stack0114106
    Mar 26 at 17:21











  • @stack0114106, I've plenty of columns. So I'm thinking to change column names dynamically.

    – Vijay
    Mar 26 at 17:30

















  • do you have the rename columns like Maps(_VkjLmnVop => vkj_lmn_vop, _KaTasLop => ka_tas_lop ) ?.

    – stack0114106
    Mar 26 at 17:21











  • @stack0114106, I've plenty of columns. So I'm thinking to change column names dynamically.

    – Vijay
    Mar 26 at 17:30
















do you have the rename columns like Maps(_VkjLmnVop => vkj_lmn_vop, _KaTasLop => ka_tas_lop ) ?.

– stack0114106
Mar 26 at 17:21





do you have the rename columns like Maps(_VkjLmnVop => vkj_lmn_vop, _KaTasLop => ka_tas_lop ) ?.

– stack0114106
Mar 26 at 17:21













@stack0114106, I've plenty of columns. So I'm thinking to change column names dynamically.

– Vijay
Mar 26 at 17:30





@stack0114106, I've plenty of columns. So I'm thinking to change column names dynamically.

– Vijay
Mar 26 at 17:30












2 Answers
2






active

oldest

votes


















4














You can create a recursive method to traverse the DataFrame schema for renaming the columns:



import org.apache.spark.sql.types._

def renameAllCols(schema: StructType, rename: String => String): StructType =
def recurRename(schema: StructType): Seq[StructField] = schema.fields.map
case StructField(name, dtype: StructType, nullable, meta) =>
StructField(rename(name), StructType(recurRename(dtype)), nullable, meta)
case StructField(name, dtype, nullable, meta) =>
StructField(rename(name), dtype, nullable, meta)

StructType(recurRename(schema))



Testing it with the following example:



import org.apache.spark.sql.functions._
import spark.implicits._

val renameFcn = (s: String) =>
s.replace("_", "").replaceAll("([A-Z])", "_$1").toLowerCase.dropWhile(_ == '_')

case class C(A_Bc: Int, D_Ef: Int)

val df = Seq(
(10, "a", C(1, 2)),
(20, "b", C(3, 4))
).toDF("_VkjLmnVop", "_KaTasLop", "AbcDef")

val newDF = spark.createDataFrame(df.rdd, renameAllCols(df.schema, renameFcn))

newDF.printSchema
// root
// |-- vkj_lmn_vop: integer (nullable = false)
// |-- ka_tas_lop: string (nullable = true)
// |-- abc_def: struct (nullable = true)
// | |-- a_bc: integer (nullable = false)
// | |-- d_ef: integer (nullable = false)





share|improve this answer























  • Hi Leo , This what I'm looking for. This is really great stuff. Thanks a lot. I'm accepting this answer.

    – Vijay
    Mar 26 at 17:47


















0














as far as I know, it's not possible to rename nested fields directly.



From one side, you could try moving to a flat object.



However, if you need to keep the structure, you can play with spark.sql.functions.struct(*cols).



Creates a new struct column.
Parameters: cols – list of column names (string) or list of Column expressions


You will need to decompose all the schema, generate the aliases that you need and then compose it again using the struct function.



It's not the best solution. But it's something :)



Pd: I'm attaching the PySpark doc since it contains a better explanation than the Scala one.






share|improve this answer























  • But I've 10 struct columns having 18 attributes in each struct? Is there any other better approach?

    – Vijay
    Mar 26 at 17:16











  • I would recommend you to code a tail recursive function, that given a schema, it generates all the replace/struct methods.

    – Franzi
    Mar 26 at 17:20




















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














You can create a recursive method to traverse the DataFrame schema for renaming the columns:



import org.apache.spark.sql.types._

def renameAllCols(schema: StructType, rename: String => String): StructType =
def recurRename(schema: StructType): Seq[StructField] = schema.fields.map
case StructField(name, dtype: StructType, nullable, meta) =>
StructField(rename(name), StructType(recurRename(dtype)), nullable, meta)
case StructField(name, dtype, nullable, meta) =>
StructField(rename(name), dtype, nullable, meta)

StructType(recurRename(schema))



Testing it with the following example:



import org.apache.spark.sql.functions._
import spark.implicits._

val renameFcn = (s: String) =>
s.replace("_", "").replaceAll("([A-Z])", "_$1").toLowerCase.dropWhile(_ == '_')

case class C(A_Bc: Int, D_Ef: Int)

val df = Seq(
(10, "a", C(1, 2)),
(20, "b", C(3, 4))
).toDF("_VkjLmnVop", "_KaTasLop", "AbcDef")

val newDF = spark.createDataFrame(df.rdd, renameAllCols(df.schema, renameFcn))

newDF.printSchema
// root
// |-- vkj_lmn_vop: integer (nullable = false)
// |-- ka_tas_lop: string (nullable = true)
// |-- abc_def: struct (nullable = true)
// | |-- a_bc: integer (nullable = false)
// | |-- d_ef: integer (nullable = false)





share|improve this answer























  • Hi Leo , This what I'm looking for. This is really great stuff. Thanks a lot. I'm accepting this answer.

    – Vijay
    Mar 26 at 17:47















4














You can create a recursive method to traverse the DataFrame schema for renaming the columns:



import org.apache.spark.sql.types._

def renameAllCols(schema: StructType, rename: String => String): StructType =
def recurRename(schema: StructType): Seq[StructField] = schema.fields.map
case StructField(name, dtype: StructType, nullable, meta) =>
StructField(rename(name), StructType(recurRename(dtype)), nullable, meta)
case StructField(name, dtype, nullable, meta) =>
StructField(rename(name), dtype, nullable, meta)

StructType(recurRename(schema))



Testing it with the following example:



import org.apache.spark.sql.functions._
import spark.implicits._

val renameFcn = (s: String) =>
s.replace("_", "").replaceAll("([A-Z])", "_$1").toLowerCase.dropWhile(_ == '_')

case class C(A_Bc: Int, D_Ef: Int)

val df = Seq(
(10, "a", C(1, 2)),
(20, "b", C(3, 4))
).toDF("_VkjLmnVop", "_KaTasLop", "AbcDef")

val newDF = spark.createDataFrame(df.rdd, renameAllCols(df.schema, renameFcn))

newDF.printSchema
// root
// |-- vkj_lmn_vop: integer (nullable = false)
// |-- ka_tas_lop: string (nullable = true)
// |-- abc_def: struct (nullable = true)
// | |-- a_bc: integer (nullable = false)
// | |-- d_ef: integer (nullable = false)





share|improve this answer























  • Hi Leo , This what I'm looking for. This is really great stuff. Thanks a lot. I'm accepting this answer.

    – Vijay
    Mar 26 at 17:47













4












4








4







You can create a recursive method to traverse the DataFrame schema for renaming the columns:



import org.apache.spark.sql.types._

def renameAllCols(schema: StructType, rename: String => String): StructType =
def recurRename(schema: StructType): Seq[StructField] = schema.fields.map
case StructField(name, dtype: StructType, nullable, meta) =>
StructField(rename(name), StructType(recurRename(dtype)), nullable, meta)
case StructField(name, dtype, nullable, meta) =>
StructField(rename(name), dtype, nullable, meta)

StructType(recurRename(schema))



Testing it with the following example:



import org.apache.spark.sql.functions._
import spark.implicits._

val renameFcn = (s: String) =>
s.replace("_", "").replaceAll("([A-Z])", "_$1").toLowerCase.dropWhile(_ == '_')

case class C(A_Bc: Int, D_Ef: Int)

val df = Seq(
(10, "a", C(1, 2)),
(20, "b", C(3, 4))
).toDF("_VkjLmnVop", "_KaTasLop", "AbcDef")

val newDF = spark.createDataFrame(df.rdd, renameAllCols(df.schema, renameFcn))

newDF.printSchema
// root
// |-- vkj_lmn_vop: integer (nullable = false)
// |-- ka_tas_lop: string (nullable = true)
// |-- abc_def: struct (nullable = true)
// | |-- a_bc: integer (nullable = false)
// | |-- d_ef: integer (nullable = false)





share|improve this answer













You can create a recursive method to traverse the DataFrame schema for renaming the columns:



import org.apache.spark.sql.types._

def renameAllCols(schema: StructType, rename: String => String): StructType =
def recurRename(schema: StructType): Seq[StructField] = schema.fields.map
case StructField(name, dtype: StructType, nullable, meta) =>
StructField(rename(name), StructType(recurRename(dtype)), nullable, meta)
case StructField(name, dtype, nullable, meta) =>
StructField(rename(name), dtype, nullable, meta)

StructType(recurRename(schema))



Testing it with the following example:



import org.apache.spark.sql.functions._
import spark.implicits._

val renameFcn = (s: String) =>
s.replace("_", "").replaceAll("([A-Z])", "_$1").toLowerCase.dropWhile(_ == '_')

case class C(A_Bc: Int, D_Ef: Int)

val df = Seq(
(10, "a", C(1, 2)),
(20, "b", C(3, 4))
).toDF("_VkjLmnVop", "_KaTasLop", "AbcDef")

val newDF = spark.createDataFrame(df.rdd, renameAllCols(df.schema, renameFcn))

newDF.printSchema
// root
// |-- vkj_lmn_vop: integer (nullable = false)
// |-- ka_tas_lop: string (nullable = true)
// |-- abc_def: struct (nullable = true)
// | |-- a_bc: integer (nullable = false)
// | |-- d_ef: integer (nullable = false)






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 26 at 17:34









Leo CLeo C

13.8k2 gold badges10 silver badges20 bronze badges




13.8k2 gold badges10 silver badges20 bronze badges












  • Hi Leo , This what I'm looking for. This is really great stuff. Thanks a lot. I'm accepting this answer.

    – Vijay
    Mar 26 at 17:47

















  • Hi Leo , This what I'm looking for. This is really great stuff. Thanks a lot. I'm accepting this answer.

    – Vijay
    Mar 26 at 17:47
















Hi Leo , This what I'm looking for. This is really great stuff. Thanks a lot. I'm accepting this answer.

– Vijay
Mar 26 at 17:47





Hi Leo , This what I'm looking for. This is really great stuff. Thanks a lot. I'm accepting this answer.

– Vijay
Mar 26 at 17:47













0














as far as I know, it's not possible to rename nested fields directly.



From one side, you could try moving to a flat object.



However, if you need to keep the structure, you can play with spark.sql.functions.struct(*cols).



Creates a new struct column.
Parameters: cols – list of column names (string) or list of Column expressions


You will need to decompose all the schema, generate the aliases that you need and then compose it again using the struct function.



It's not the best solution. But it's something :)



Pd: I'm attaching the PySpark doc since it contains a better explanation than the Scala one.






share|improve this answer























  • But I've 10 struct columns having 18 attributes in each struct? Is there any other better approach?

    – Vijay
    Mar 26 at 17:16











  • I would recommend you to code a tail recursive function, that given a schema, it generates all the replace/struct methods.

    – Franzi
    Mar 26 at 17:20
















0














as far as I know, it's not possible to rename nested fields directly.



From one side, you could try moving to a flat object.



However, if you need to keep the structure, you can play with spark.sql.functions.struct(*cols).



Creates a new struct column.
Parameters: cols – list of column names (string) or list of Column expressions


You will need to decompose all the schema, generate the aliases that you need and then compose it again using the struct function.



It's not the best solution. But it's something :)



Pd: I'm attaching the PySpark doc since it contains a better explanation than the Scala one.






share|improve this answer























  • But I've 10 struct columns having 18 attributes in each struct? Is there any other better approach?

    – Vijay
    Mar 26 at 17:16











  • I would recommend you to code a tail recursive function, that given a schema, it generates all the replace/struct methods.

    – Franzi
    Mar 26 at 17:20














0












0








0







as far as I know, it's not possible to rename nested fields directly.



From one side, you could try moving to a flat object.



However, if you need to keep the structure, you can play with spark.sql.functions.struct(*cols).



Creates a new struct column.
Parameters: cols – list of column names (string) or list of Column expressions


You will need to decompose all the schema, generate the aliases that you need and then compose it again using the struct function.



It's not the best solution. But it's something :)



Pd: I'm attaching the PySpark doc since it contains a better explanation than the Scala one.






share|improve this answer













as far as I know, it's not possible to rename nested fields directly.



From one side, you could try moving to a flat object.



However, if you need to keep the structure, you can play with spark.sql.functions.struct(*cols).



Creates a new struct column.
Parameters: cols – list of column names (string) or list of Column expressions


You will need to decompose all the schema, generate the aliases that you need and then compose it again using the struct function.



It's not the best solution. But it's something :)



Pd: I'm attaching the PySpark doc since it contains a better explanation than the Scala one.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 26 at 17:06









FranziFranzi

1,03217 silver badges17 bronze badges




1,03217 silver badges17 bronze badges












  • But I've 10 struct columns having 18 attributes in each struct? Is there any other better approach?

    – Vijay
    Mar 26 at 17:16











  • I would recommend you to code a tail recursive function, that given a schema, it generates all the replace/struct methods.

    – Franzi
    Mar 26 at 17:20


















  • But I've 10 struct columns having 18 attributes in each struct? Is there any other better approach?

    – Vijay
    Mar 26 at 17:16











  • I would recommend you to code a tail recursive function, that given a schema, it generates all the replace/struct methods.

    – Franzi
    Mar 26 at 17:20

















But I've 10 struct columns having 18 attributes in each struct? Is there any other better approach?

– Vijay
Mar 26 at 17:16





But I've 10 struct columns having 18 attributes in each struct? Is there any other better approach?

– Vijay
Mar 26 at 17:16













I would recommend you to code a tail recursive function, that given a schema, it generates all the replace/struct methods.

– Franzi
Mar 26 at 17:20






I would recommend you to code a tail recursive function, that given a schema, it generates all the replace/struct methods.

– Franzi
Mar 26 at 17:20




Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript