forked from docs/doc-exports
Reviewed-by: Kacur, Michal <michal.kacur@t-systems.com> Co-authored-by: Yang, Tong <yangtong2@huawei.com> Co-committed-by: Yang, Tong <yangtong2@huawei.com>
92 lines
8.8 KiB
HTML
92 lines
8.8 KiB
HTML
<a name="mrs_01_24265"></a><a name="mrs_01_24265"></a>
|
|
|
|
<h1 class="topictitle1">CREATE Hudi TABLE AS SELECT</h1>
|
|
<div id="body8662426"><div class="section" id="mrs_01_24265__en-us_topic_0000001173949332_section1695555153318"><h4 class="sectiontitle">Function</h4><p id="mrs_01_24265__en-us_topic_0000001173949332_p327319366569">This command is used to create a Hudi table by specifying the list of fields along with the table options.</p>
|
|
</div>
|
|
<div class="section" id="mrs_01_24265__en-us_topic_0000001173949332_section12626151918349"><h4 class="sectiontitle">Syntax</h4><p id="mrs_01_24265__en-us_topic_0000001173949332_p1688522713420"><strong id="mrs_01_24265__en-us_topic_0000001173949332_b3526193223417">CREATE TABLE</strong> <em id="mrs_01_24265__en-us_topic_0000001173949332_i28813763415">[ IF NOT EXISTS] [database_name.]table_name</em></p>
|
|
<p id="mrs_01_24265__en-us_topic_0000001173949332_p208851827103414"><strong id="mrs_01_24265__en-us_topic_0000001173949332_b08843413344">USING hudi</strong></p>
|
|
<p id="mrs_01_24265__en-us_topic_0000001173949332_p288532714346"><em id="mrs_01_24265__en-us_topic_0000001173949332_i104451945113414">[ COMMENT table_comment ]</em></p>
|
|
<p id="mrs_01_24265__en-us_topic_0000001173949332_p12885527173420"><em id="mrs_01_24265__en-us_topic_0000001173949332_i947217459345">[ LOCATION location_path ]</em></p>
|
|
<p id="mrs_01_24265__en-us_topic_0000001173949332_p158851627163417"><em id="mrs_01_24265__en-us_topic_0000001173949332_i18473174516346">[ OPTIONS (options_list) ]</em></p>
|
|
<p id="mrs_01_24265__en-us_topic_0000001173949332_p5885527103410"><em id="mrs_01_24265__en-us_topic_0000001173949332_i19475245143413">[ AS query_statement ]</em></p>
|
|
</div>
|
|
<div class="section" id="mrs_01_24265__en-us_topic_0000001173949332_section9188195203414"><h4 class="sectiontitle">Parameter Description</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_t6b42300fff2840bfb056a544dc7668f6" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameters</caption><thead align="left"><tr id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_r3b448fea562d49e1a73cafd7b09c1dc9"><th align="left" class="cellrowborder" valign="top" width="24.060000000000002%" id="mcps1.3.3.2.2.3.1.1"><p id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_aaaf8be0fc53d4336a3cdae9b409856c2"><strong id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_a46902e5e15ff49c493be1bc9b01e64bf">Parameter</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="75.94%" id="mcps1.3.3.2.2.3.1.2"><p id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_aa188261f197f4d3c97698b26af1f2e8f"><strong id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_afac562deb69e4b39823aef537fac8c5c">Description</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_r4979f315a68742dd9dc817c469f9b7bf"><td class="cellrowborder" valign="top" width="24.060000000000002%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_a14edab7d5d4441a68efcc0df676211fd">database_name</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="75.94%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_a87ecf6a3cbb0403fa6140e8ac3b27cf7">Database name that contains letters, digits, and underscores (_).</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_ra1ea2fa9c3bb407fa4527cbeff860b1d"><td class="cellrowborder" valign="top" width="24.060000000000002%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_a21692ed3e5a0468f897f115e712de5ab">table_name</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="75.94%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_af1a35ab6f75d457fbb1041c02662b280">Database table name that contains letters, digits, and underscores (_).</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_r8ff05ad7e7eb46c98852e4d1414d16a4"><td class="cellrowborder" valign="top" width="24.060000000000002%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_ab4f11fa96d574add97720b7db2eb2e1a">using</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="75.94%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_a15d1808305624e1d99339670b70ebdea">Uses <strong id="mrs_01_24265__en-us_topic_0000001173949332_b1652650856101140">hudi</strong> to define and create a Hudi table.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_r6caa920b4fb742a9be4c1401ddef052f"><td class="cellrowborder" valign="top" width="24.060000000000002%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24265__en-us_topic_0000001173949332_p149611926153012">table_comment</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="75.94%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_adf528fdf98f3488f95ac2164f0a7f824">Description of the table.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_24265__en-us_topic_0000001173949332_row75691010192913"><td class="cellrowborder" valign="top" width="24.060000000000002%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24265__en-us_topic_0000001173949332_p656951012291">location_path</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="75.94%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24265__en-us_topic_0000001173949332_p7569101010297">HDFS path. If this parameter is set, the Hudi table will be created as an external table.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_24265__en-us_topic_0000001173949332_row19315172912330"><td class="cellrowborder" valign="top" width="24.060000000000002%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24265__en-us_topic_0000001173949332_p8315142943314">options_list</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="75.94%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24265__en-us_topic_0000001173949332_p203152029123312">List of Hudi table options.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_24265__en-us_topic_0000001173949332_row5584161719473"><td class="cellrowborder" valign="top" width="24.060000000000002%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24265__en-us_topic_0000001173949332_p12584121714473">query_statement</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="75.94%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24265__en-us_topic_0000001173949332_p165841217154718">SELECT statement</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="mrs_01_24265__en-us_topic_0000001173949332_section195519116356"><h4 class="sectiontitle">Examples</h4><ul id="mrs_01_24265__en-us_topic_0000001173949332_ul86431233143510"><li id="mrs_01_24265__en-us_topic_0000001173949332_li146481733113516">Create a partitioned table.<pre class="screen" id="mrs_01_24265__en-us_topic_0000001173949332_screen18931211183515">create table h2 using hudi
|
|
options (type = 'cow', primaryKey = 'id')
|
|
partitioned by (dt)
|
|
as
|
|
select 1 as id, 'a1' as name, 10 as price, 1000 as dt;</pre>
|
|
</li><li id="mrs_01_24265__en-us_topic_0000001173949332_li112681939203512">Create a non-partitioned table.<pre class="screen" id="mrs_01_24265__en-us_topic_0000001173949332_screen14265185411354">create table h3 using hudi
|
|
as
|
|
select 1 as id, 'a1' as name, 10 as price;
|
|
|
|
Load data from a parquet table to the Hudi table.
|
|
# Create a parquet table.
|
|
create table parquet_mngd using parquet options(path='hdfs:///tmp/parquet_dataset/*.parquet');
|
|
|
|
# Create a Hudi table by Creating a Table from Query Results (CTAS).
|
|
create table hudi_tbl using hudi location 'hdfs:///tmp/hudi/hudi_tbl/' options (
|
|
type = 'cow',
|
|
primaryKey = 'id',
|
|
preCombineField = 'ts'
|
|
)
|
|
partitioned by (datestr) as select * from parquet_mngd;</pre>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="mrs_01_24265__en-us_topic_0000001173949332_section16247105316235"><h4 class="sectiontitle">Precautions</h4><p id="mrs_01_24265__en-us_topic_0000001173949332_p9767165172413">For better data loading performance, CTAS uses <strong id="mrs_01_24265__en-us_topic_0000001173949332_b47011116707">bulk insert</strong> to write data.</p>
|
|
</div>
|
|
<div class="section" id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_sf6d4f1901bea490caaedcf2ad09d7400"><h4 class="sectiontitle">System Response</h4><p id="mrs_01_24265__en-us_topic_0000001173949332_en-us_topic_0265792784_abd1aa318b00e4fd8b37db0d0c9746755">The table is successfully created, and the success message is logged in the system.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_24263.html">Hudi DDL</a></div>
|
|
</div>
|
|
</div>
|
|
|