OUTFILE
description
1. The `SELECT INTO OUTFILE` statement can export the query results to a file. Currently supports export to remote storage through Broker process, or directly through S3, HDFS protocol such as HDFS, S3, BOS and COS(Tencent Cloud) through the Broker process. The syntax is as follows:
3. Grammar:
4. query_stmt
5. INTO OUTFILE "file_path"
6. [format_as]
7. [properties]
9. 1. file_path
10. `file_path` specify the file path and file name prefix. Like: `hdfs://path/to/my_file_`.
11. The final file name will be assembled as `my_file_`, file seq no and the format suffix. File seq no starts from 0, determined by the number of split.
12. my_file_abcdefg_0.csv
13. my_file_abcdefg_1.csv
14. my_file_abcdegf_2.csv
16. 2. format_as
17. FORMAT AS CSV
18. Specify the export format. The default is CSV.
21. 3. properties
22. Specify the relevant attributes. Currently it supports exporting through the Broker process, or through the S3, HDFS protocol.
24. Grammar:
25. [PROPERTIES ("key"="value", ...)]
26. The following parameters can be specified:
27. column_separator: Specifies the exported column separator, defaulting to t. Supports invisible characters, such as'\x07'.
28. line_delimiter: Specifies the exported line separator, defaulting to\n. Supports invisible characters, such as'\x07'.
29. max_file_size: max size for each file
31. Broker related attributes need to be prefixed with `broker.`:
32. broker.name: broker name
33. broker.hadoop.security.authentication: Specify authentication as kerberos
34. broker.kerberos_principal: Specify the principal of kerberos
35. broker.kerberos_keytab: Specify the keytab path of kerberos, this file is the path on the broker.
37. HDFS protocal can directly execute HDFS protocal configuration:
38. hdfs.fs.defaultFS: namenode ip and port
39. hdfs.hdfs_user: hdfs user name
41. S3 protocol can directly execute S3 protocol configuration:
42. AWS_ENDPOINT
43. AWS_ACCESS_KEY
44. AWS_SECRET_KEY
45. AWS_REGION
example
1. 1. Export simple query results to the file `hdfs://path/to/result.txt`. Specify the export format as CSV. Use `my_broker` and set kerberos authentication information. Specify the column separator as `,` and the line delimiter as `\n`.
2. SELECT * FROM tbl
3. INTO OUTFILE "hdfs://path/to/result_"
4. FORMAT AS CSV
5. PROPERTIES
6. (
7. "broker.name" = "my_broker",
8. "broker.hadoop.security.authentication" = "kerberos",
9. "broker.kerberos_principal" = "doris@YOUR.COM",
10. "broker.kerberos_keytab" = "/home/doris/my.keytab",
11. "column_separator" = ",",
12. "line_delimiter" = "\n",
13. "max_file_size" = "100MB"
14. );
15. If the result is less than 100MB, file will be: `result_0.csv`.
16. If larger than 100MB, may be: `result_0.csv, result_1.csv, ...`.
18. 2. Export simple query results to the file `hdfs://path/to/result.parquet`. Specify the export format as PARQUET. Use `my_broker` and set kerberos authentication information.
19. SELECT c1, c2, c3 FROM tbl
20. INTO OUTFILE "hdfs://path/to/result_"
21. FORMAT AS PARQUET
22. PROPERTIES
23. (
24. "broker.name" = "my_broker",
25. "broker.hadoop.security.authentication" = "kerberos",
26. "broker.kerberos_principal" = "doris@YOUR.COM",
27. "broker.kerberos_keytab" = "/home/doris/my.keytab",
28. "schema"="required,int32,c1;required,byte_array,c2;required,byte_array,c2"
29. );
30. If the exported file format is PARQUET, `schema` must be specified.
32. 3. Export the query result of the CTE statement to the file `hdfs://path/to/result.txt`. The default export format is CSV. Use `my_broker` and set hdfs high availability information. Use the default column separators and line delimiter.
33. WITH
34. x1 AS
35. (SELECT k1, k2 FROM tbl1),
36. x2 AS
37. (SELECT k3 FROM tbl2)
38. SELEC k1 FROM x1 UNION SELECT k3 FROM x2
39. INTO OUTFILE "hdfs://path/to/result_"
40. PROPERTIES
41. (
42. "broker.name" = "my_broker",
43. "broker.username"="user",
44. "broker.password"="passwd",
45. "broker.dfs.nameservices" = "my_ha",
46. "broker.dfs.ha.namenodes.my_ha" = "my_namenode1, my_namenode2",
47. "broker.dfs.namenode.rpc-address.my_ha.my_namenode1" = "nn1_host:rpc_port",
48. "broker.dfs.namenode.rpc-address.my_ha.my_namenode2" = "nn2_host:rpc_port",
49. "broker.dfs.client.failover.proxy.provider" = "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider"
50. );
51. If the result is less than 1GB, file will be: `result_0.csv`.
52. If larger than 1GB, may be: `result_0.csv, result_1.csv, ...`.
54. 4. Export the query results of the UNION statement to the file `bos://bucket/result.parquet`. Specify the export format as PARQUET. Use `my_broker` and set hdfs high availability information. PARQUET format does not need to specify the column separator and line delimiter.
55. SELECT k1 FROM tbl1 UNION SELECT k2 FROM tbl1
56. INTO OUTFILE "bos://bucket/result_"
57. FORMAT AS PARQUET
58. PROPERTIES
59. (
60. "broker.name" = "my_broker",
61. "broker.bos_endpoint" = "http://bj.bcebos.com",
62. "broker.bos_accesskey" = "xxxxxxxxxxxxxxxxxxxxxxxxxx",
63. "broker.bos_secret_accesskey" = "yyyyyyyyyyyyyyyyyyyyyyyyyy",
64. "schema"="required,int32,k1;required,byte_array,k2"
65. );
67. 5. Export simple query results to the file `cos://${bucket_name}/path/result.txt`. Specify the export format as CSV.
68. And create a mark file after export finished.
69. select k1,k2,v1 from tbl1 limit 100000
70. into outfile "s3a://my_bucket/export/my_file_"
71. FORMAT AS CSV
72. PROPERTIES
73. (
74. "broker.name" = "hdfs_broker",
75. "broker.fs.s3a.access.key" = "xxx",
76. "broker.fs.s3a.secret.key" = "xxxx",
77. "broker.fs.s3a.endpoint" = "https://cos.xxxxxx.myqcloud.com/",
78. "column_separator" = ",",
79. "line_delimiter" = "\n",
80. "max_file_size" = "1024MB",
81. "success_file_name" = "SUCCESS"
82. )
83. Please Note:
84. 1. Paths that do not exist are automatically created.
85. 2. These parameters(access.key/secret.key/endpointneed) need to be confirmed with `Tecent Cloud COS`. In particular, the value of endpoint does not need to be filled in bucket_name.
87. 6. Use the s3 protocol to export to bos, and concurrent export is enabled.
88. set enable_parallel_outfile = true;
89. select k1 from tb1 limit 1000
90. into outfile "s3://my_bucket/export/my_file_"
91. format as csv
92. properties
93. (
94. "AWS_ENDPOINT" = "http://s3.bd.bcebos.com",
95. "AWS_ACCESS_KEY" = "xxxx",
96. "AWS_SECRET_KEY" = "xxx",
97. "AWS_REGION" = "bd"
98. )
99. The final generated file prefix is `my_file_{fragment_instance_id}_`。
101. 7. Use the s3 protocol to export to bos, and enable concurrent export of session variables.
102. set enable_parallel_outfile = true;
103. select k1 from tb1 order by k1 limit 1000
104. into outfile "s3://my_bucket/export/my_file_"
105. format as csv
106. properties
107. (
108. "AWS_ENDPOINT" = "http://s3.bd.bcebos.com",
109. "AWS_ACCESS_KEY" = "xxxx",
110. "AWS_SECRET_KEY" = "xxx",
111. "AWS_REGION" = "bd"
112. )
113. But because the query statement has a top-level sorting node, even if the query is enabled for concurrently exported session variables, it cannot be exported concurrently.
115. 8. Use libhdfs to export to hdfs cluster. Export the query results of the UNION statement to the file `hdfs://path/to/result.txt`
116. Specify the export format as CSV. Use the user name as 'work', the column separators as ',' and line delimiter as '\n'.
117. SELECT * FROM tbl
118. INTO OUTFILE "hdfs://path/to/result_"
119. FORMAT AS CSV
120. PROPERTIES
121. (
122. "hdfs.fs.defaultFS" = "hdfs://ip:port",
123. "hdfs.hdfs_user" = "work"
124. );
125. If the result is less than 1GB, file will be: `my_file_0.csv`.
126. If larger than 1GB, may be: `my_file_0.csv, result_1.csv, ...`.
keyword
1. OUTFILE