<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Manipulate Column that is an array of objects in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/manipulate-column-that-is-an-array-of-objects/m-p/20062#M13541</link>
    <description>&lt;P&gt;@Raymond Garcia​&amp;nbsp;, Please just use the Spark transform function. It will get every element from your array, and you can concatenate it with string as in your example. Here is an example of a transform function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df = spark.createDataFrame([(1, [1, 2, 3, 4])], ("key", "values"))
&amp;nbsp;
df.select(transform("values", lambda x: x * 2).alias("doubled")).show()
+------------+
|     doubled|
+------------+
|[2, 4, 6, 8]|
+------------+&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 21 May 2022 09:52:15 GMT</pubDate>
    <dc:creator>Hubert-Dudek</dc:creator>
    <dc:date>2022-05-21T09:52:15Z</dc:date>
    <item>
      <title>Manipulate Column that is an array of objects</title>
      <link>https://community.databricks.com/t5/data-engineering/manipulate-column-that-is-an-array-of-objects/m-p/20061#M13540</link>
      <description>&lt;P&gt;I have a column that is an array of objects, let's call it ARRAY, and  now I would like to query / manipulate, the elements object without using explode function, this is an example, for each element in that column I would like to create a path. .&lt;B&gt;withColumn("image_path", concat_ws("", lit(imagePath), lit("/"), $"ARRAY[*].attribute.attribute1", lit("/"), $"ARRAY[*].attribute.attribute2", lit(".jpg")))&lt;/B&gt;&amp;nbsp; I would a column that contains a array of images paths like  &lt;B&gt;[imagePath1, imagePath2]. &lt;/B&gt;Do you have any suggestion?. Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2022 22:50:16 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/manipulate-column-that-is-an-array-of-objects/m-p/20061#M13540</guid>
      <dc:creator>Raymond_Garcia</dc:creator>
      <dc:date>2022-05-20T22:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulate Column that is an array of objects</title>
      <link>https://community.databricks.com/t5/data-engineering/manipulate-column-that-is-an-array-of-objects/m-p/20062#M13541</link>
      <description>&lt;P&gt;@Raymond Garcia​&amp;nbsp;, Please just use the Spark transform function. It will get every element from your array, and you can concatenate it with string as in your example. Here is an example of a transform function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df = spark.createDataFrame([(1, [1, 2, 3, 4])], ("key", "values"))
&amp;nbsp;
df.select(transform("values", lambda x: x * 2).alias("doubled")).show()
+------------+
|     doubled|
+------------+
|[2, 4, 6, 8]|
+------------+&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 21 May 2022 09:52:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/manipulate-column-that-is-an-array-of-objects/m-p/20062#M13541</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2022-05-21T09:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulate Column that is an array of objects</title>
      <link>https://community.databricks.com/t5/data-engineering/manipulate-column-that-is-an-array-of-objects/m-p/20063#M13542</link>
      <description>&lt;P&gt;Thanks! I am going to test it, and I will come back&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 14:13:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/manipulate-column-that-is-an-array-of-objects/m-p/20063#M13542</guid>
      <dc:creator>Raymond_Garcia</dc:creator>
      <dc:date>2022-05-23T14:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulate Column that is an array of objects</title>
      <link>https://community.databricks.com/t5/data-engineering/manipulate-column-that-is-an-array-of-objects/m-p/20064#M13543</link>
      <description>&lt;P&gt;Hello I am working with Scala, and I used somehing similar:&lt;/P&gt;&lt;P&gt;def play(col: Column): Column = {&lt;/P&gt;&lt;P&gt;&amp;nbsp;concat_ws("", lit(imagePath), lit("/"), col("field1"), lit("/"), col("field2"), lit(".ext"))&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;val variable = spark.lot_of_stuff.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.withColumn("image_path", transform(col("column1.field1"), play(_)))&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 19:29:17 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/manipulate-column-that-is-an-array-of-objects/m-p/20064#M13543</guid>
      <dc:creator>Raymond_Garcia</dc:creator>
      <dc:date>2022-05-23T19:29:17Z</dc:date>
    </item>
  </channel>
</rss>

