title: Merging multiple parquet files and creating a larger parquet file in s3 using AWS glue
body: <p>I am trying to merge multiple parquet files using aws glue job. I am aware of the similar <a href="https://stackoverflow.com/questions/60826563/merge-multiple-parquet-files-to-single-parquet-file-in-aws-s3-using-aws-glue-etl">question</a> and the possible solution mentioned <a href="https://github.com/aws-samples/aws-glue-samples/blob/master/FAQ_and_How_to.md" rel="nofollow noreferrer">here</a>. I have tried it and it doesn't seem to work. Here is my sample code:</p>
  <pre><code>import sys
  from awsglue.transforms import *
  from awsglue.utils import getResolvedOptions
  from pyspark.context import SparkContext
  from awsglue.context import GlueContext
  from awsglue.job import Job
  from awsglue.dynamicframe import DynamicFrame
  
  ## @params: [JOB_NAME]
  args = getResolvedOptions(sys.argv, ['JOB_NAME'])
  
  sc = SparkContext()
  glueContext = GlueContext(sc)
  spark = glueContext.spark_session
  job = Job(glueContext)
  
  job.init(args['JOB_NAME'], args)
  
  df = glueContext.create_dynamic_frame.from_options(connection_type=&quot;parquet&quot;, connection_options={'paths': [&quot;s3://bucket-name/parquet/2021/02/15/15/&quot;]})
  partitioned_df=df.toDF().repartition(1)
  partitioned_dynamic_df=DynamicFrame.fromDF(partitioned_df,glueContext,&quot;partitioned_df&quot;)
  
  datasink0=glueContext.write_dynamic_frame.from_options(frame=partitioned_dynamic_df,connection_type=&quot;s3&quot;, connection_options={'paths':[&quot;s3://bucket-name/output/&quot;]}, format=&quot;parquet&quot;)
  
  job.commit()
  </code></pre>
  <p>I have printed <code>partitioned_dynamic_df</code> and it is the combined df of all the parquets. But I keep getting this error message, and don't know how to resolve.</p>
  <pre><code>Traceback (most recent call last):
  File &quot;/opt/amazon/spark/python/lib/pyspark.zip/pyspark/sql/utils.py&quot;, line 63, in deco return f(*a, **kw) File &quot;/opt/amazon/spark/python/lib/py4j-0.10.7-src.zip/py4j/protocol.py&quot;, line 328, in get_return_value format(target_id, &quot;.&quot;, name), value) py4j.protocol.Py4JJavaError: An error occurred while calling o76.pyWriteDynamicFrame. : java.lang.IllegalArgumentException: Expected exactly one path to be specified, but got: at org.apache.spark.sql.execution.datasources.DataSource.planForWritingFileFormat(DataSource.scala:427
   at org.apache.spark.sql.execution.datasources.DataSource.planForWriting(DataSource.scala:524
   at org.apache.spark.sql.DataFrameWriter.saveToV1Source(DataFrameWriter.scala:290
   at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:271
   at com.amazonaws.services.glue.SparkSQLDataSink$$anonfun$writeDynamicFrame$1.apply(DataSink.scala:535
   at com.amazonaws.services.glue.SparkSQLDataSink$$anonfun$writeDynamicFrame$1.apply(DataSink.scala:522
   at com.amazonaws.services.glue.util.FileSchemeWrapper$$anonfun$executeWithQualifiedScheme$1.apply(FileSchemeWrapper.scala:66
   at com.amazonaws.services.glue.util.FileSchemeWrapper$$anonfun$executeWithQualifiedScheme$1.apply(FileSchemeWrapper.scala:66
   at com.amazonaws.services.glue.util.FileSchemeWrapper.executeWith(FileSchemeWrapper.scala:58
   at com.amazonaws.services.glue.util.FileSchemeWrapper.executeWithQualifiedScheme(FileSchemeWrapper.scala:66
   at com.amazonaws.services.glue.SparkSQLDataSink.writeDynamicFrame(DataSink.scala:521
   at com.amazonaws.services.glue.DataSink.pyWriteDynamicFrame(DataSink.scala:63
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43
   at java.lang.reflect.Method.invoke(Method.java:498
   at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244
   at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357
   at py4j.Gateway.invoke(Gateway.java:282
   at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132
   at py4j.commands.CallCommand.execute(CallCommand.java:79
   at py4j.GatewayConnection.run(GatewayConnection.java:238
   at java.lang.Thread.run(Thread.java:748) During handling of the above exception, another exception occurred: Traceback (most recent call last): File &quot;/tmp/job-name&quot;, line 33, in &lt;module&gt; datasink0=glueContext.write_dynamic_frame.from_options(frame=partitioned_dynamic_df,connection_type=&quot;s3&quot;, connection_options={'paths':[&quot;s3://bucket-name/output/&quot;]}, format=&quot;parquet&quot;) File &quot;/opt/amazon/lib/python3.6/site-packages/awsglue/dynamicframe.py&quot;, line 640, in from_options format_options, transformation_ctx) File &quot;/opt/amazon/lib/python3.6/site-packages/awsglue/context.py&quot;, line 242, in write_dynamic_frame_from_options format, format_options, transformation_ctx) File &quot;/opt/amazon/lib/python3.6/site-packages/awsglue/context.py&quot;, line 265, in w
  rite_from_options return sink.write(frame_or_dfc) File &quot;/opt/amazon/lib/python3.6/site-packages/awsglue/data_sink.py&quot;, line 35, in write return self.writeFrame(dynamic_frame_or_dfc, info) File &quot;/opt/amazon/lib/python3.6/site-packages/awsglue/data_sink.py&quot;, line 31, in writeFrame return DynamicFrame(self._jsink.pyWriteDynamicFrame(dynamic_frame._jdf, callsite(), info), dynamic_frame.glue_ctx, dynamic_frame.name + &quot;_errors&quot;)
  File &quot;/opt/amazon/spark/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py&quot;, line 1257, in __call__ answer, self.gateway_client, self.target_id, self.name) File &quot;/opt/amazon/spark/python/lib/pyspark.zip/pyspark/sql/utils.py&quot;, line 79, in deco raise IllegalArgumentException(s.split(': ', 1)[1], stackTrace)
  pyspark.sql.utils.IllegalArgumentException: 'Expected exactly one path to be specified, but got: '
  </code></pre>
  <p>The data format is something like this:</p>
  <pre><code>{&quot;lead:objectid&quot;: 21345, &quot;contactdetails:name&quot;: &quot;Ruben Dias&quot;, &quot;contactdetails:contactnumber&quot;: 9838942345}
  {&quot;lead:objectid&quot;: 41335, &quot;contactdetails:name&quot;: &quot;Nick Pope&quot;, &quot;contactdetails:contactnumber&quot;: 9228672345}
  {&quot;lead:objectid&quot;: 4132, &quot;contactdetails:name&quot;: &quot;Edison Cavani&quot;, &quot;contactdetails:contactnumber&quot;: 9228633345}
  {&quot;lead:objectid&quot;: 21335, &quot;contactdetails:name&quot;: &quot;James Justin&quot;, &quot;contactdetails:contactnumber&quot;: 9838672345}
  {&quot;lead:objectid&quot;: null, &quot;contactdetails:name&quot;: &quot;James Maddison&quot;, &quot;contactdetails:contactnumber&quot;: null}
  {&quot;lead:objectid&quot;: null, &quot;contactdetails:name&quot;: &quot;Jack Grealish&quot;, &quot;contactdetails:contactnumber&quot;: null}
  {&quot;lead:objectid&quot;: 3214, &quot;contactdetails:name&quot;: &quot;Harry Kane&quot;, &quot;contactdetails:contactnumber&quot;: null}
  {&quot;lead:objectid&quot;: 34143, &quot;contactdetails:name&quot;: null, &quot;contactdetails:contactnumber&quot;: null}
  </code></pre>
  <p>Any help/suggestions?</p>