Yang, Tong 48706b7552 MRS COMP-LTS 320-lts.1 version
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>
2024-04-12 12:51:10 +00:00

169 lines
14 KiB
HTML

<a name="mrs_01_24264"></a><a name="mrs_01_24264"></a>
<h1 class="topictitle1">CREATE Hudi TABLE</h1>
<div id="body8662426"><div class="section" id="mrs_01_24264__en-us_topic_0000001219029097_section8443834142611"><h4 class="sectiontitle">Function</h4><p id="mrs_01_24264__en-us_topic_0000001219029097_p4248103862816">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_24264__en-us_topic_0000001219029097_section63041048132618"><h4 class="sectiontitle">Syntax</h4><p id="mrs_01_24264__en-us_topic_0000001219029097_p1541955152613"><strong id="mrs_01_24264__en-us_topic_0000001219029097_b16910151872715">CREATE TABLE</strong> <em id="mrs_01_24264__en-us_topic_0000001219029097_i14515122372719">[ IF NOT EXISTS] [database_name.]table_name</em></p>
<p id="mrs_01_24264__en-us_topic_0000001219029097_p5541195515260"><em id="mrs_01_24264__en-us_topic_0000001219029097_i10676133032710">[ (columnTypeList)]</em></p>
<p id="mrs_01_24264__en-us_topic_0000001219029097_p15541755152611"><strong id="mrs_01_24264__en-us_topic_0000001219029097_b919513672710">USING hudi</strong></p>
<p id="mrs_01_24264__en-us_topic_0000001219029097_p105415557268"><em id="mrs_01_24264__en-us_topic_0000001219029097_i312634092720">[ COMMENT table_comment ]</em></p>
<p id="mrs_01_24264__en-us_topic_0000001219029097_p45411755112617"><em id="mrs_01_24264__en-us_topic_0000001219029097_i513184019273">[ LOCATION location_path ]</em></p>
<p id="mrs_01_24264__en-us_topic_0000001219029097_p10541135515264"><em id="mrs_01_24264__en-us_topic_0000001219029097_i113214015276">[ OPTIONS (options_list) ]</em></p>
</div>
<div class="section" id="mrs_01_24264__en-us_topic_0000001219029097_section586684692720"><h4 class="sectiontitle">Parameter Description</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="mrs_01_24264__en-us_topic_0000001219029097_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_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_r3b448fea562d49e1a73cafd7b09c1dc9"><th align="left" class="cellrowborder" valign="top" width="30%" id="mcps1.3.3.2.2.3.1.1"><p id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_aaaf8be0fc53d4336a3cdae9b409856c2"><strong id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_a46902e5e15ff49c493be1bc9b01e64bf">Parameter</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="70%" id="mcps1.3.3.2.2.3.1.2"><p id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_aa188261f197f4d3c97698b26af1f2e8f"><strong id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_afac562deb69e4b39823aef537fac8c5c">Description</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_r4979f315a68742dd9dc817c469f9b7bf"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_a14edab7d5d4441a68efcc0df676211fd">database_name</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_a87ecf6a3cbb0403fa6140e8ac3b27cf7">Database name that contains letters, digits, and underscores (_).</p>
</td>
</tr>
<tr id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_ra1ea2fa9c3bb407fa4527cbeff860b1d"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_a21692ed3e5a0468f897f115e712de5ab">table_name</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_af1a35ab6f75d457fbb1041c02662b280">Database table name that contains letters, digits, and underscores (_).</p>
</td>
</tr>
<tr id="mrs_01_24264__en-us_topic_0000001219029097_row186966274293"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p2696727172918">columnTypeList</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p1869682716291">List of comma-separated columns with data types. The column name contains letters, digits, and underscores (_).</p>
</td>
</tr>
<tr id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_r8ff05ad7e7eb46c98852e4d1414d16a4"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_ab4f11fa96d574add97720b7db2eb2e1a">using</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_a15d1808305624e1d99339670b70ebdea">Uses <strong id="mrs_01_24264__en-us_topic_0000001219029097_b1714339284101123">hudi</strong> to define and create a Hudi table.</p>
</td>
</tr>
<tr id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_r6caa920b4fb742a9be4c1401ddef052f"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p149611926153012">table_comment</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_adf528fdf98f3488f95ac2164f0a7f824">Description of the table.</p>
</td>
</tr>
<tr id="mrs_01_24264__en-us_topic_0000001219029097_row75691010192913"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p656951012291">location_path</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24264__en-us_topic_0000001219029097_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_24264__en-us_topic_0000001219029097_row19315172912330"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p8315142943314">options_list</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p203152029123312">List of Hudi table options.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="mrs_01_24264__en-us_topic_0000001219029097_table817112562342" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Table options</caption><thead align="left"><tr id="mrs_01_24264__en-us_topic_0000001219029097_row2017214563341"><th align="left" class="cellrowborder" valign="top" width="30%" id="mcps1.3.4.2.3.1.1"><p id="mrs_01_24264__en-us_topic_0000001219029097_p11172756103412"><strong id="mrs_01_24264__en-us_topic_0000001219029097_b4172195673419">Parameter</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="70%" id="mcps1.3.4.2.3.1.2"><p id="mrs_01_24264__en-us_topic_0000001219029097_p1117285615346"><strong id="mrs_01_24264__en-us_topic_0000001219029097_b91721356193414">Description</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="mrs_01_24264__en-us_topic_0000001219029097_row1917216567341"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.4.2.3.1.1 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p10172145615340">primaryKey</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.4.2.3.1.2 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p1517205619341">Name of the primary key with fields separated by commas (,).</p>
</td>
</tr>
<tr id="mrs_01_24264__en-us_topic_0000001219029097_row20172135617344"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.4.2.3.1.1 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p033218400363">type</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.4.2.3.1.2 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p16172656133412">Type of the table. <strong id="mrs_01_24264__en-us_topic_0000001219029097_b1865851475216">'cow'</strong> indicates a copy-on-write (COW) table, and <strong id="mrs_01_24264__en-us_topic_0000001219029097_b19928185716525">'mor'</strong> indicates a merge-on-read (MOR) table. If this parameter is not specified, the default value is <strong id="mrs_01_24264__en-us_topic_0000001219029097_b318457734">'cow'</strong>.</p>
</td>
</tr>
<tr id="mrs_01_24264__en-us_topic_0000001219029097_row8172125616349"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.4.2.3.1.1 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p2298440143912">preCombineField</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.4.2.3.1.2 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p2017211568341">Pre-Combine field in the table.</p>
</td>
</tr>
<tr id="mrs_01_24264__en-us_topic_0000001219029097_row3671139122413"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.4.2.3.1.1 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p1468143962411">payloadClass</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.4.2.3.1.2 "><p id="mrs_01_24264__en-us_topic_0000001219029097_p568439112414">Payload classes for data filtering, including default <strong id="mrs_01_24264__en-us_topic_0000001219029097_b17293163514546">OverwriteWithLatestAvroPayload</strong> and multiple preset payloads, such as <strong id="mrs_01_24264__en-us_topic_0000001219029097_b42214520541">OverwriteNonDefaultsWithLatestAvroPayload</strong>, <strong id="mrs_01_24264__en-us_topic_0000001219029097_b98043577547">DefaultHoodieRecordPayload</strong>, and <strong id="mrs_01_24264__en-us_topic_0000001219029097_b128111929555">EmptyHoodieRecordPayload</strong>.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="mrs_01_24264__en-us_topic_0000001219029097_section9500230102813"><h4 class="sectiontitle">Examples</h4><ul id="mrs_01_24264__en-us_topic_0000001219029097_ul113151847152819"><li id="mrs_01_24264__en-us_topic_0000001219029097_li123159476283"><strong id="mrs_01_24264__en-us_topic_0000001219029097_b1137982615513">Create a non-partitioned table</strong>.<pre class="screen" id="mrs_01_24264__en-us_topic_0000001219029097_screen1569493023015">-- Create an internal COW table.
<em id="mrs_01_24264__en-us_topic_0000001219029097_i57162305303">create</em> <em id="mrs_01_24264__en-us_topic_0000001219029097_i371663015300">table</em> <em id="mrs_01_24264__en-us_topic_0000001219029097_i471617309302">if</em> not <em id="mrs_01_24264__en-us_topic_0000001219029097_i671663012301">exists</em> hudi_table0 (
id <em id="mrs_01_24264__en-us_topic_0000001219029097_i37161302309">int</em>,
name string,
price <em id="mrs_01_24264__en-us_topic_0000001219029097_i18716430193010">double</em>
) <em id="mrs_01_24264__en-us_topic_0000001219029097_i11716183003013">using</em> hudi
options (
<em id="mrs_01_24264__en-us_topic_0000001219029097_i10716173063012">type</em> = 'cow',
primaryKey = 'id'
);</pre>
<pre class="screen" id="mrs_01_24264__en-us_topic_0000001219029097_screen276020422306">-- Create an external MOR table.
create table if not exists hudi_table1 (
id int,
name string,
price double,
ts bigint
) using hudi
location '/tmp/hudi/hudi_table1'
options (
type = 'mor',
primaryKey = 'id,name',
preCombineField = 'ts'
);</pre>
<pre class="screen" id="mrs_01_24264__en-us_topic_0000001219029097_screen9928101113115">-- Create a table without primary keys.
create table if not exists hudi_table2(
id int,
name string,
price double
) using hudi
options (
type = 'cow'
);</pre>
</li></ul>
<ul id="mrs_01_24264__en-us_topic_0000001219029097_ul9191174612328"><li id="mrs_01_24264__en-us_topic_0000001219029097_li1191184603215"><strong id="mrs_01_24264__en-us_topic_0000001219029097_b1054619212208">Create a partitioned table</strong>.<pre class="screen" id="mrs_01_24264__screen116651479331">create table if not exists hudi_table_p0 (
id bigint,
name string,
ts <em id="mrs_01_24264__i941195116">bigint</em>,
dt string,
hh string
) using hudi
location '/tmp/hudi/hudi_table_p0'
options (
type = 'cow',
primaryKey = 'id',
preCombineField = 'ts'
)
partitioned by (dt, hh);</pre>
</li><li id="mrs_01_24264__en-us_topic_0000001219029097_li598118186332"><strong id="mrs_01_24264__en-us_topic_0000001219029097_b13181720162217">Create an external table for the Hudi table created using spark-shell or deltastreamer before Hudi 0.9.0.</strong><pre class="screen" id="mrs_01_24264__en-us_topic_0000001219029097_screen3395122973319">create table h_p1
using hudi
options (
primaryKey = 'id',
preCombineField = 'ts'
)
partitioned by (dt)
location '/path/to/hudi';</pre>
</li></ul>
</div>
<ul id="mrs_01_24264__en-us_topic_0000001219029097_ul175371520102212"><li id="mrs_01_24264__en-us_topic_0000001219029097_li135371120102215">Create a table and specify table options.<pre class="screen" id="mrs_01_24264__en-us_topic_0000001219029097_screen07631716122813">create table if not exists h3(
id bigint,
name string,
price double
) using hudi
options (
primaryKey = 'id',
type = 'mor',
hoodie.cleaner.fileversions.retained = '20',
hoodie.keep.max.commits = '20'
);</pre>
</li></ul>
<div class="section" id="mrs_01_24264__en-us_topic_0000001219029097_section815018015286"><h4 class="sectiontitle">Precautions</h4><p id="mrs_01_24264__en-us_topic_0000001219029097_p18846739284">Currently, Hudi does not support the CHAR, VARCHAR, TINYINT, and SMALLINT data types. You are advised to use the string or INT data type.</p>
</div>
<div class="section" id="mrs_01_24264__en-us_topic_0000001219029097_en-us_topic_0265792784_sf6d4f1901bea490caaedcf2ad09d7400"><h4 class="sectiontitle">System Response</h4><p id="mrs_01_24264__en-us_topic_0000001219029097_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>