Member since
04-20-2015
2
Posts
0
Kudos Received
0
Solutions
04-23-2015
10:15 AM
1 Kudo
Here are 2 ways to constrain the output to only be a single file. You can set the query option NUM_NODES=1, and all work is done on the coordinator node. You can put a large LIMIT on the query, bigger than the number of rows you are actually inserting, and all the intermediate results are combined on the coordinator node. (I have not looked into the mechanics enough to say which way is more efficient.) Here's an example where, by default, a CREATE TABLE AS SELECT operation would produce 4 output files, because I'm on a 4-node cluster. (The source table BILLION_NUMBERS has 113 files and 2.79 GB, enough data so that it won't go into a single output file by accident.) Setting NUM_NODES=1 produces a single output file. Setting NUM_NODES back to 0 and then doing CTAS+LIMIT produces a single output file. [localhost:21000] > show table stats billion_numbers; +-------+--------+--------+--------------+-------------------+--------+-------------------+ | #Rows | #Files | Size | Bytes Cached | Cache Replication | Format | Incremental stats | +-------+--------+--------+--------------+-------------------+--------+-------------------+ | -1 | 113 | 2.79GB | NOT CACHED | NOT CACHED | TEXT | false | +-------+--------+--------+--------------+-------------------+--------+-------------------+ [localhost:21000] > set; Query options (defaults shown in []): ... NUM_NODES: [0] ... [localhost:21000] > create table num_nodes_0 as select * from billion_numbers; +----------------------------+ | summary | +----------------------------+ | Inserted 1000000000 row(s) | +----------------------------+ [localhost:21000] > show table stats num_nodes_0; +-------+--------+--------+--------------+-------------------+--------+-------------------+ | #Rows | #Files | Size | Bytes Cached | Cache Replication | Format | Incremental stats | +-------+--------+--------+--------------+-------------------+--------+-------------------+ | -1 | 4 | 2.79GB | NOT CACHED | NOT CACHED | TEXT | false | +-------+--------+--------+--------------+-------------------+--------+-------------------+ [localhost:21000] > set num_nodes=1; [localhost:21000] > create table num_nodes_1 as select * from oreilly.billion_numbers; +----------------------------+ | summary | +----------------------------+ | Inserted 1000000000 row(s) | +----------------------------+ [localhost:21000] > show table stats num_nodes_1; +-------+--------+--------+--------------+-------------------+--------+-------------------+ | #Rows | #Files | Size | Bytes Cached | Cache Replication | Format | Incremental stats | +-------+--------+--------+--------------+-------------------+--------+-------------------+ | -1 | 1 | 2.79GB | NOT CACHED | NOT CACHED | TEXT | false | +-------+--------+--------+--------------+-------------------+--------+-------------------+ [localhost:21000] > set num_nodes=0; [localhost:21000] > create table ctas_with_limit as select * from billion_numbers limit 100000000000000; +----------------------------+ | summary | +----------------------------+ | Inserted 1000000000 row(s) | +----------------------------+ [localhost:21000] > show table stats ctas_with_limit; +-------+--------+--------+--------------+-------------------+--------+-------------------+ | #Rows | #Files | Size | Bytes Cached | Cache Replication | Format | Incremental stats | +-------+--------+--------+--------------+-------------------+--------+-------------------+ | -1 | 1 | 2.79GB | NOT CACHED | NOT CACHED | TEXT | false | +-------+--------+--------+--------------+-------------------+--------+-------------------+
... View more