title: How to convert array type of dataset into string type in Apache Spark Java
body: <p>I have an array type in my dataset need to convert into string type.
  I have tried in a conventional way.
  I feel we can do it in better way. Can you please guide me.
  Input Dataset1</p>
  
  <pre><code>    +---------------------------+-----------+-------------------------------------------------------------------------------------------------+
      ManufacturerSource         |upcSource  |productDescriptionSource                                                                          |                                                                                                                                                                            |
      +---------------------------+-----------+-------------------------------------------------------------------------------------------------+
      |3M                         |51115665883|[c, gdg, whl, t27, 5, x, 1, 4, x, 7, 8, grindig, flap, wheels, 36, grit, 12, 250, rpm]           |                                                                                                                                                                            |
      |3M                         |51115665937|[c, gdg, whl, t27, q, c, 6, x, 1, 4, x, 5, 8, 11, grinding, flap, wheels, 36, grit, 10, 200, rpm]|                                                                                                                                                                             |
      |3M                         |0          |[3mite, rb, cloth, 3, x, 2, wd]                                                                  |                                                                                                                                                                             |
      |3M                         |0          |[trizact, disc, cloth, 237aaa16x5, hole]                                                         |                                                                                                                                                                             |
      -------------------------------------------------------------------------------------------------------------------------------------------
  </code></pre>
  
  <p>Expected Output DataSet</p>
  
  <pre><code>     +---------------------------+-----------+---------------------------------------------------------------------------------------------------|
       |ManufacturerSource         |upcSource  |productDescriptionSource                                                                           |                                                                                                                                                                           |
       +---------------------------+-----------+---------------------------------------------------------------------------------------------------|
       |3M                         |51115665883|c gdg whl t27 5 x 1 4 x 7 8 grinding flap wheels 36 grit 12 250 rpm               |                |                                                                                                                                                         |
       |3M                         |51115665937|c gdg whl t27 q c 6 x 1 4 x 5 8 11 grinding flap wheels 36 grit 10 200 rpm                         |                                                                                                                                                                        |
       |3M                         |0          |3mite  rb  cloth  3  x  2  wd                                                                      |                                                                                                                                                                          |
       |3M                         |0          |trizact  disc  cloth  237aaa16x5  hole                                                             |                                                                                                                                                                          |
       +-------------------------------------------------------------------------------------------------------------------------------------------|
  </code></pre>
  
  <p>conventional  Approach 1</p>
  
  <pre><code>        Dataset&lt;Row&gt; afterstopwordsRemoved = 
           stopwordsRemoved.select("productDescriptionSource");
            stopwordsRemoved.show();
  
          List&lt;Row&gt; individaulRows= afterstopwordsRemoved.collectAsList();
  
          System.out.println("After flatmap\n");
          List&lt;String&gt; temp;
          for(Row individaulRow:individaulRows){
           temp=individaulRow.getList(0);
          System.out.println(String.join(" ",temp));
          }
  </code></pre>
  
  <p>Approach2 (Not yielding result)</p>
  
  <p>Exception : Failed to execute user defined function($anonfun$27: 
  (array) => string)</p>
  
  <pre><code>       UDF1 untoken = new UDF1&lt;String,String[]&gt;() {
          public String call(String[] token) throws Exception {
              //return types.replaceAll("[^a-zA-Z0-9\\s+]", "");
               return Arrays.toString(token); 
          }
  
          @Override
          public String[] call(String t1) throws Exception {
              // TODO Auto-generated method stub
              return null;
          }
      };
  
      sqlContext.udf().register("unTokenize", untoken, DataTypes.StringType);
  
      source.createOrReplaceTempView("DataSetOfTokenize");
      Dataset&lt;Row&gt; newDF = sqlContext.sql("select *,unTokenize(productDescriptionSource)FROM DataSetOfTokenize");
      newDF.show(4000,false);
  </code></pre>