Yang, Tong 6182f91ba8 MRS component operation guide_normal 2.0.38.SP20 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Yang, Tong <yangtong2@huawei.com>
Co-committed-by: Yang, Tong <yangtong2@huawei.com>
2022-12-09 14:55:21 +00:00

100 lines
16 KiB
HTML

<a name="mrs_01_1425"></a><a name="mrs_01_1425"></a>
<h1 class="topictitle1">CREATE TABLE</h1>
<div id="body1595920210419"><div class="section" id="mrs_01_1425__s19dc8db6467e4f3baa9a662138ec23e8"><h4 class="sectiontitle">Function</h4><p id="mrs_01_1425__a38185df4acf44342944d97b25a811bfc">This command is used to create a CarbonData table by specifying the list of fields along with the table properties.</p>
</div>
<div class="section" id="mrs_01_1425__s50bc973493d048dca1b9796f3501b588"><h4 class="sectiontitle">Syntax</h4><p id="mrs_01_1425__ab6dc8da59ff04d7e9dedbe9cf587fe69"><b><span class="cmdname" id="mrs_01_1425__cmdname136512120331">CREATE TABLE</span></b> <i><span class="varname" id="mrs_01_1425__vd069c2942ec04e1587051fb2274dca11">[IF NOT EXISTS] [db_name.]table_name</span></i></p>
<p id="mrs_01_1425__ab39ecb770e2a4f429182857a16adc26c"><i><span class="varname" id="mrs_01_1425__va499544d22344c84901097f537d961a1">[(col_name data_type, ...)]</span></i></p>
<p id="mrs_01_1425__a6f403a0c5593455f87e8ebbccd79c5d9"><b><span class="cmdname" id="mrs_01_1425__cmdname1846215603311">STORED AS</span></b> <i><span class="varname" id="mrs_01_1425__ve1aa736435544274905be06d9a93ec49">carbondata</span></i></p>
<p id="mrs_01_1425__af91f6107db894c66a4a724d73ad45fb0"><i><span class="varname" id="mrs_01_1425__v340f0e61959f42cc985d7af916c4ec3c">[TBLPROPERTIES (property_name=property_value, ...)];</span></i></p>
<p id="mrs_01_1425__ab6c75aeec671499998f90439c54b7c4c">Additional attributes of all tables are defined in <strong id="mrs_01_1425__b1562776746811">TBLPROPERTIES</strong>.</p>
</div>
<div class="section" id="mrs_01_1425__sadc8a75e45a940489bdd3c8c56f13ab0"><h4 class="sectiontitle">Parameter Description</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="mrs_01_1425__t6b42300fff2840bfb056a544dc7668f6" frame="border" border="1" rules="all"><caption><b>Table 1 </b>CREATE TABLE parameters</caption><thead align="left"><tr id="mrs_01_1425__r3b448fea562d49e1a73cafd7b09c1dc9"><th align="left" class="cellrowborder" valign="top" width="24.060000000000002%" id="mcps1.3.3.2.2.3.1.1"><p id="mrs_01_1425__aaaf8be0fc53d4336a3cdae9b409856c2"><strong id="mrs_01_1425__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_1425__aa188261f197f4d3c97698b26af1f2e8f"><strong id="mrs_01_1425__afac562deb69e4b39823aef537fac8c5c">Description</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="mrs_01_1425__r4979f315a68742dd9dc817c469f9b7bf"><td class="cellrowborder" valign="top" width="24.060000000000002%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1425__a14edab7d5d4441a68efcc0df676211fd">db_name</p>
</td>
<td class="cellrowborder" valign="top" width="75.94%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1425__a87ecf6a3cbb0403fa6140e8ac3b27cf7">Database name that contains letters, digits, and underscores (_).</p>
</td>
</tr>
<tr id="mrs_01_1425__rfc2c4ac506114e89bd3354a305b5d517"><td class="cellrowborder" valign="top" width="24.060000000000002%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1425__a8be3767c702341ba9260a31de8a5c641">col_name data_type</p>
</td>
<td class="cellrowborder" valign="top" width="75.94%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1425__a837e594fdc4e44fbad141e033fe4f271">List with data types separated by commas (,). The column name contains letters, digits, and underscores (_).</p>
<div class="note" id="mrs_01_1425__n65b394ec4b414dedaba7ba00896e4969"><span class="notetitle"> NOTE: </span><div class="notebody"><p id="mrs_01_1425__a2520fa63330f4d1f8d2d94d2a382bb5a">When creating a CarbonData table, do not use tupleId, PositionId, and PositionReference as column names because columns with these names are internally used by secondary index commands.</p>
</div></div>
</td>
</tr>
<tr id="mrs_01_1425__ra1ea2fa9c3bb407fa4527cbeff860b1d"><td class="cellrowborder" valign="top" width="24.060000000000002%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1425__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_1425__af1a35ab6f75d457fbb1041c02662b280">Table name of a database that contains letters, digits, and underscores (_).</p>
</td>
</tr>
<tr id="mrs_01_1425__r8ff05ad7e7eb46c98852e4d1414d16a4"><td class="cellrowborder" valign="top" width="24.060000000000002%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1425__ab4f11fa96d574add97720b7db2eb2e1a">STORED AS</p>
</td>
<td class="cellrowborder" valign="top" width="75.94%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1425__a15d1808305624e1d99339670b70ebdea">The <strong id="mrs_01_1425__b16832331738">carbondata</strong> parameter defines and creates a CarbonData table.</p>
</td>
</tr>
<tr id="mrs_01_1425__r6caa920b4fb742a9be4c1401ddef052f"><td class="cellrowborder" valign="top" width="24.060000000000002%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1425__a5a974d6904554f65b40a81c47bcb73ff">TBLPROPERTIES</p>
</td>
<td class="cellrowborder" valign="top" width="75.94%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1425__adf528fdf98f3488f95ac2164f0a7f824">List of CarbonData table properties.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="mrs_01_1425__s4539dafd333c46ae855caaa175609f60"><a name="mrs_01_1425__s4539dafd333c46ae855caaa175609f60"></a><a name="s4539dafd333c46ae855caaa175609f60"></a><h4 class="sectiontitle">Precautions</h4><div class="p" id="mrs_01_1425__ac4b21c1777864bd89c2089de5a3268f3">Table attributes are used as follows:<ul id="mrs_01_1425__u2c427d95fbc94a958d8b706becb42d22"><li id="mrs_01_1425__l053c6fa1a366488ea6410cb4bb4fc5d1"><a name="mrs_01_1425__l053c6fa1a366488ea6410cb4bb4fc5d1"></a><a name="l053c6fa1a366488ea6410cb4bb4fc5d1"></a>Block size <p id="mrs_01_1425__a34e6d6ebbd854fdf91e7a117929fc806"><a name="mrs_01_1425__l053c6fa1a366488ea6410cb4bb4fc5d1"></a><a name="l053c6fa1a366488ea6410cb4bb4fc5d1"></a>The block size of a data file can be defined for a single table using <strong id="mrs_01_1425__b566984199811">TBLPROPERTIES</strong>. The larger one between the actual size of the data file and the defined block size is selected as the actual block size of the data file in HDFS. The unit is MB. The default value is 1024 MB. The value ranges from 1 MB to 2048 MB. If the value is beyond the range, the system reports an error.</p>
<p id="mrs_01_1425__a4e376efced3d467885e8211a95ce677f">Once the block size reaches the configured value, the write program starts a new block of CarbonData data. Data is written in multiples of the page size (32,000 records). Therefore, the boundary is not strict at the byte level. If the new page crosses the boundary of the configured block, the page is written to the new block instead of the current block.</p>
<p id="mrs_01_1425__a10c12ea2e5af44ca9de5fe99bf39d995"><i><span class="varname" id="mrs_01_1425__vb3fa9c91323e48058638ddfee423b1f0">TBLPROPERTIES('table_blocksize'='128')</span></i></p>
<div class="note" id="mrs_01_1425__nb6a449fe92fb44658f1874607bc0ef89"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="mrs_01_1425__u30f2210e6a054826a1ccad3c868ed9ec"><li id="mrs_01_1425__l47f9c432135147b69557d1ccf48a5614">If a small block size is configured in the CarbonData table while the size of the data file generated by the loaded data is large, the block size displayed in HDFS is different from the configured value. This is because when data is written to a local block file for the first time, even though the size of the to-be-written data is larger than the configured value of the block size, data will still be written into the block. Therefore, the actual value of block size in HDFS is the larger value between the size of the data to be written and the configured block size.</li><li id="mrs_01_1425__l9367947e71094a7eac0aef884011817f">If <strong id="mrs_01_1425__b163697050811">block.num </strong>is less than the parallelism, the blocks are split into new blocks so that new blocks.num is greater than parallelism and all cores can be used. This optimization is called block distribution.</li></ul>
</div></div>
</li><li id="mrs_01_1425__li1343505014597"><strong id="mrs_01_1425__b697752549811">SORT_SCOPE</strong> specifies the sort scope during table creation. There are four types of sort scopes:<ul id="mrs_01_1425__ul139865713610"><li id="mrs_01_1425__li268232014618"><strong id="mrs_01_1425__b1663679563811">GLOBAL_SORT</strong>: It improves query performance, especially for point queries. <em id="mrs_01_1425__i61785615919">TBLPROPERTIES('SORT_SCOPE'='GLOBAL_SORT'</em>)</li><li id="mrs_01_1425__li2027712291269"><strong id="mrs_01_1425__b12823358139">LOCAL_SORT</strong>: Data is sorted locally (task-level sorting).</li><li id="mrs_01_1425__li766583612619"><strong id="mrs_01_1425__b19247515415">NO_SORT</strong>: The default sorting mode is used. Data is loaded in unsorted manner, which greatly improves loading performance.</li></ul>
</li><li id="mrs_01_1425__l98b6a23d3c8d495594b3af29618bd9d4">SORT_COLUMNS<p id="mrs_01_1425__abd7fc8eacabb4256885b08274062c6c2"><a name="mrs_01_1425__l98b6a23d3c8d495594b3af29618bd9d4"></a><a name="l98b6a23d3c8d495594b3af29618bd9d4"></a>This table property specifies the order of sort columns.</p>
<p id="mrs_01_1425__a387b0f0795c543b6967179ed610b807d"><i><span class="varname" id="mrs_01_1425__v355365deec354a5d9d2ce584eaa54c71">TBLPROPERTIES('SORT_COLUMNS'='column1, column3')</span></i></p>
<div class="note" id="mrs_01_1425__n0296becf465e4b47bd08a9b0fd67cac0"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="mrs_01_1425__u9e3796cb68cb4da1a66af259f697a9d2"><li id="mrs_01_1425__l9b85cd1fef3a4c6bb19bca8ba2b8f9b2">If this attribute is not specified, no columns are sorted by default.</li><li id="mrs_01_1425__la9e1da75e1944b5abd1ac20758b6dcfc">If this property is specified but with empty argument, then the table will be loaded without sort. For example, <i><span class="varname" id="mrs_01_1425__ve2f8399b7a834334953d03c2001426a5">('SORT_COLUMNS'='')</span></i>.</li><li id="mrs_01_1425__lac27a075544b4a98978a1cef6294b6b8"><strong id="mrs_01_1425__b209382424416">SORT_COLUMNS</strong> supports the string, date, timestamp, short, int, long, byte, and boolean data types.</li></ul>
</div></div>
</li></ul>
</div>
</div>
<ul id="mrs_01_1425__ul1882131174220"><li id="mrs_01_1425__li14882131184210">RANGE_COLUMN<p id="mrs_01_1425__p14333152244319"><a name="mrs_01_1425__li14882131184210"></a><a name="li14882131184210"></a>This property is used to specify a column to partition the input data by range. Only one column can be configured. During data import, you can use <strong id="mrs_01_1425__b1683716031811">global_sort_partitions</strong> or <strong id="mrs_01_1425__b914327338811">scale_factor</strong> to avoid generating small files.</p>
<p id="mrs_01_1425__p34631218279"><i><span class="varname" id="mrs_01_1425__varname49287361168">TBLPROPERTIES('RANGE_COLUMN'='column1')</span></i></p>
</li><li id="mrs_01_1425__li175935116177">LONG_STRING_COLUMNS<p id="mrs_01_1425__p201903618177"><a name="mrs_01_1425__li175935116177"></a><a name="li175935116177"></a>The length of a common string cannot exceed 32,000 characters. To store a string of more than 32,000 characters, set <strong id="mrs_01_1425__b5328123414710">LONG_STRING_COLUMNS</strong> to the target column.</p>
<p id="mrs_01_1425__p17845141692612"><i><span class="varname" id="mrs_01_1425__varname17281522132615">TBLPROPERTIES('LONG_STRING_COLUMNS'='column1, column3')</span></i></p>
<div class="note" id="mrs_01_1425__note11157112552710"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="mrs_01_1425__p8996143917431"><strong id="mrs_01_1425__b32711947774">LONG_STRING_COLUMNS</strong> can be set only for columns of the STRING, CHAR, or VARCHAR type.</p>
</div></div>
</li></ul>
<div class="section" id="mrs_01_1425__s6fad7b442a3b4397a32e1d5a047f54fd"><h4 class="sectiontitle">Scenarios</h4><p id="mrs_01_1425__a67b67d674e5b4156a07b125ccb754b0d">Creating a Table by Specifying Columns</p>
<p id="mrs_01_1425__a659e9c4ee06f490a98a8369ea6c7e900">The <strong id="mrs_01_1425__b12419835651">CREATE TABLE</strong> command is the same as that of Hive DDL. The additional configurations of CarbonData are provided as table properties.</p>
<p id="mrs_01_1425__a2acfad759bfe46258cfc72de5dc29722"><b><span class="cmdname" id="mrs_01_1425__cmdname156861959355">CREATE TABLE</span></b> <i><span class="varname" id="mrs_01_1425__v0e5b559852e24af181fd244e33a2b4ab">[IF NOT EXISTS] [db_name.]table_name</span></i></p>
<p id="mrs_01_1425__ac87e63c4ed8747da8a882781cbb14686"><i><span class="varname" id="mrs_01_1425__vac19636b44454e9d94f3c0963ac40453">[(col_name data_type , ...)]</span></i></p>
<p id="mrs_01_1425__a15a47310336b41a8871226ed9ad4074b">STORED AS <i><span class="varname" id="mrs_01_1425__veb5512b70c604cab9572a7de6b116db2">carbondata</span></i></p>
<p id="mrs_01_1425__a231f136e51b74f96b54fddc2e9ff2444"><i><span class="varname" id="mrs_01_1425__vc0dfb53d87704fa795ac4c8ed700b27e">[TBLPROPERTIES (property_name=property_value, ...)];</span></i></p>
</div>
<div class="section" id="mrs_01_1425__sf6bb4c6935b2460ca222e90c82356959"><h4 class="sectiontitle">Examples</h4><p id="mrs_01_1425__a45f91a91791e456283e2d8e586ac0a33"><b><span class="cmdname" id="mrs_01_1425__cmdname5806171516358">CREATE TABLE</span></b> <i><span class="varname" id="mrs_01_1425__vc478f415b82b425b85958edad83224bf">IF NOT EXISTS productdb.productSalesTable (</span></i></p>
<p id="mrs_01_1425__a031b0804fe9b48128717aee214cec9c3"><i><span class="varname" id="mrs_01_1425__vf7b9f862960b418d9c3cb02354381584">productNumber Int,</span></i></p>
<p id="mrs_01_1425__a5543e3ab83464c028d0e5be219181132"><i><span class="varname" id="mrs_01_1425__v3bd1fc92a84144c7911099b38831d98b">productName String,</span></i></p>
<p id="mrs_01_1425__a9cf2f52d35a6444c8d6345de47cfaa2a"><i><span class="varname" id="mrs_01_1425__vfdf866c1ba1344aabb2ad47dc4eda3fd">storeCity String,</span></i></p>
<p id="mrs_01_1425__acdff8aa5ea67485d915ae2a9cae72340"><i><span class="varname" id="mrs_01_1425__vbd306dd7dd644688bc363e50d5cf5f34">storeProvince String,</span></i></p>
<p id="mrs_01_1425__a7f026e27ff8745e6968ffe4eb31a96ea"><i><span class="varname" id="mrs_01_1425__v404cf32e03c7444097ba1c1a9112e650">productCategory String,</span></i></p>
<p id="mrs_01_1425__af55754450d23455ea2cb3d8379deaf88"><i><span class="varname" id="mrs_01_1425__v6f00d5dadf3d4c15b92b567699c07dbd">productBatch String,</span></i></p>
<p id="mrs_01_1425__a5581e46bfe8d4497bcef7dcedbf30700"><i><span class="varname" id="mrs_01_1425__v48c12e6d646f47f7aa2ba5fbb3c4100c">saleQuantity Int,</span></i></p>
<p id="mrs_01_1425__a10b8049ddebe4ef5b1eed29b828d51d8"><i><span class="varname" id="mrs_01_1425__v7b9182c6db9f498781f5d4ae87c8cb90">revenue Int)</span></i></p>
<p id="mrs_01_1425__ac6adabe267f6489fb6f27bbc01402868"><i><span class="varname" id="mrs_01_1425__ve01fc08e38c64a608bc2918d4f0ac704">STORED AS carbondata</span></i></p>
<p id="mrs_01_1425__a16d9f51e00ca4dd68fa0fa91bea0c072"><i><span class="varname" id="mrs_01_1425__v900883305fca44cfb648d588b55425df">TBLPROPERTIES (</span></i></p>
<p id="mrs_01_1425__a41a1e30836534cf080c2171f0dec9b42"><i><span class="varname" id="mrs_01_1425__v934ddbb2c6014a60ba3405e88196b042">'table_blocksize'='128',</span></i></p>
<p id="mrs_01_1425__a1bdb061d9c794e5eacb077d4ba87e93c"><i><span class="varname" id="mrs_01_1425__vdf881c44ecbc4ac3adbcac3b26c80fb7">'SORT_COLUMNS'='productBatch, productName')</span></i></p>
</div>
<div class="section" id="mrs_01_1425__sf6d4f1901bea490caaedcf2ad09d7400"><h4 class="sectiontitle">System Response</h4><p id="mrs_01_1425__abd1aa318b00e4fd8b37db0d0c9746755">A table will be created and the success message will be logged in system logs.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_1424.html">DDL</a></div>
</div>
</div>