when unloading a table from amazon redshift to s3, how do I make it generate only one file

白昼怎懂夜的黑 提交于 2019-12-23 09:55:31

问题


When I unload a table from amazon redshift to S3, it always splits the table into two parts no matter how small the table. I have read the redshift documentation regarding unloading, but no answers other than it says sometimes it splits the table (I've never seen it not do that). I have two questions:

  • Has anybody every seen a case where only one file is created?

  • Is there a way to force redshift to unload into a single file?


回答1:


Amazon recently added support for unloading to a single file by using PARALLEL OFF in the UNLOAD statement. Note that you still can end up with more than one file if it is bigger than 6.2GB.




回答2:


As of May 6, 2014 UNLOAD queries support a new PARALLEL options. Passing PARALLEL OFF will output a single file if your data is less than 6.2 gigs (data is split into 6.2 GB chunks).




回答3:


By default, each slice creates one file (explanation below). There is a known workaround - adding a LIMIT to the outermost query will force the leader node to process whole response - thus it will create only one file.

SELECT * FROM (YOUR_QUERY) LIMIT 2147483647;

This only works as long as your inner query returns fewer than 2^31 - 1 records, as a LIMIT clause takes an unsigned integer argument.

How files are created? http://docs.aws.amazon.com/redshift/latest/dg/t_Unloading_tables.html

Amazon Redshift splits the results of a select statement across a set of files, one or more files per node slice, to simplify parallel reloading of the data.

So now we know that at least one file per slice is created. But what is a slice? http://docs.aws.amazon.com/redshift/latest/dg/t_Distributing_data.html

The number of slices is equal to the number of processor cores on the node. For example, each XL compute node has two slices, and each 8XL compute node has 16 slices.

It seems that the minimal number of slices is 2, and it will grow larger when more nodes or more powerful nodes is added.



来源:https://stackoverflow.com/questions/18223832/when-unloading-a-table-from-amazon-redshift-to-s3-how-do-i-make-it-generate-onl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!