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

76 lines
9.1 KiB
HTML

<a name="mrs_01_1409"></a><a name="mrs_01_1409"></a>
<h1 class="topictitle1">Creating a CarbonData Table</h1>
<div id="body1595920209325"><div class="section" id="mrs_01_1409__s1e1672070d2d4d6a9095a5a2ab9eb77f"><h4 class="sectiontitle">Scenario</h4><p id="mrs_01_1409__a7217065fd4da4708aad53cf7d887f65e">A CarbonData table must be created to load and query data. You can run the <b><span class="cmdname" id="mrs_01_1409__cmdname695818234011">Create Table</span></b> command to create a table. This command is used to create a table using custom columns.</p>
</div>
<div class="section" id="mrs_01_1409__s65384e6e05654e68ae554d7aea94f0d9"><h4 class="sectiontitle">Creating a Table with Self-Defined Columns</h4><p id="mrs_01_1409__a6c3abae1fdf94b03ba29ebfbc71adf5c">Users can create a table by specifying its columns and data types.</p>
<p id="mrs_01_1409__afe350197ca664de5892d34d6b3d304f7">Sample command:</p>
<p id="mrs_01_1409__a80d46a8b31684ba884fd0fcbcc847f5d"><b><span class="cmdname" id="mrs_01_1409__cmdname1683310154018">CREATE TABLE</span></b> <i><span class="varname" id="mrs_01_1409__v3c4bca6fad6947678fa02315233f0321">IF NOT EXISTS productdb.productSalesTable (</span></i></p>
<p id="mrs_01_1409__a86aafc753e0f41d2bdf5827c2baa8492"><i><span class="varname" id="mrs_01_1409__va1fd19c45f1c4672b7addc88daf5372e">productNumber Int,</span></i></p>
<p id="mrs_01_1409__a164fd864acac4c2daa9df625414d8bb8"><i><span class="varname" id="mrs_01_1409__vd92f144f61744cb69f624d99d614db2b">productName String,</span></i></p>
<p id="mrs_01_1409__a87d6e67dbdd84982905f21a43acb0fcc"><i><span class="varname" id="mrs_01_1409__v54a7069e430d4bd48c785eb6aa92e7ce">storeCity String,</span></i></p>
<p id="mrs_01_1409__ac379dbed0da74c7c992f1a029e021c80"><i><span class="varname" id="mrs_01_1409__v09ba31b4876847b19db96691335eac58">storeProvince String,</span></i></p>
<p id="mrs_01_1409__acac02c4c50a54059ae4e9c8daddfa835"><i><span class="varname" id="mrs_01_1409__vaba3b0002cb844acaff61bf3191654dc">productCategory String,</span></i></p>
<p id="mrs_01_1409__a84c811ce3c864556b076682834c1c7c7"><i><span class="varname" id="mrs_01_1409__v6512308ff65f4def8acd7fabf03df493">productBatch String,</span></i></p>
<p id="mrs_01_1409__aa77fd36babb64956b6d4557140409b8b"><i><span class="varname" id="mrs_01_1409__vc1c0b1f5373c4e0596fef5a2d4b9ac8a">saleQuantity Int,</span></i></p>
<p id="mrs_01_1409__acff6b543cdea4629a4d92d0d142ae4ed"><i><span class="varname" id="mrs_01_1409__v96546dde261743409542e10998e2e2a0">revenue Int)</span></i></p>
<p id="mrs_01_1409__a7e418ef4b407490bbecf1d0ddb29d0bb">STORED AS <i><span class="varname" id="mrs_01_1409__v920da173d64a47a491008b43e8b00c6c">carbondata</span></i></p>
<p id="mrs_01_1409__a8e322197408f428f8294a55e453ddfc9"><i><span class="varname" id="mrs_01_1409__v0b8225aa6d6f42c297b42a318bee7445">TBLPROPERTIES (</span></i></p>
<p id="mrs_01_1409__ac46c2cc14a25489098bba5e7a301b084"><i><span class="varname" id="mrs_01_1409__v1951b10d63624a53a79a228df1ef9c88">'table_blocksize'='128');</span></i></p>
<p id="mrs_01_1409__a3e7206799f6147a4b2bee76c515a8047">The following table describes parameters of preceding commands.</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="mrs_01_1409__tc729cb893828400ebac60d7f85c8341d" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameter description</caption><thead align="left"><tr id="mrs_01_1409__r62c3e7819ba44f448855b4ed3ffc26ff"><th align="left" class="cellrowborder" valign="top" width="25.91%" id="mcps1.3.2.17.2.3.1.1"><p id="mrs_01_1409__abaeef1fb5ff64ccf9a0838116f951b63">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="74.09%" id="mcps1.3.2.17.2.3.1.2"><p id="mrs_01_1409__a5bbb9ee7675342318aad357a80299094">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="mrs_01_1409__r1b05062b6fb64654a2bfdf4fe559e3f8"><td class="cellrowborder" valign="top" width="25.91%" headers="mcps1.3.2.17.2.3.1.1 "><p id="mrs_01_1409__ad68efe348bcb4cffa18003b26421bbde">productSalesTable</p>
</td>
<td class="cellrowborder" valign="top" width="74.09%" headers="mcps1.3.2.17.2.3.1.2 "><p id="mrs_01_1409__ad214a9438a33487682430e9a325d3928">Table name. The table is used to load data for analysis.</p>
<p id="mrs_01_1409__a17fb33f6dcf44416924afe70dd43b734">The table name consists of letters, digits, and underscores (_).</p>
</td>
</tr>
<tr id="mrs_01_1409__r6a7b8eaa983f432789536c9022706869"><td class="cellrowborder" valign="top" width="25.91%" headers="mcps1.3.2.17.2.3.1.1 "><p id="mrs_01_1409__a401d4ecee01743ba9c032fc5f3f6c8c1">productdb</p>
</td>
<td class="cellrowborder" valign="top" width="74.09%" headers="mcps1.3.2.17.2.3.1.2 "><p id="mrs_01_1409__aa3fcd8e8bfe342c39f37514b58bd1db5">Database name. The database maintains logical connections with tables stored in it to identify and manage the tables.</p>
<p id="mrs_01_1409__a24f1d6de72b64076801bebb6ce2d34fa">The database name consists of letters, digits, and underscores (_).</p>
</td>
</tr>
<tr id="mrs_01_1409__re48da82a38ad486dafd5cb8cf62f2771"><td class="cellrowborder" valign="top" width="25.91%" headers="mcps1.3.2.17.2.3.1.1 "><p id="mrs_01_1409__a24478bc52655492ab1b2bba19abf0d4d">productName</p>
<p id="mrs_01_1409__a42ed6fa588f04cea83a5300a7865300c">storeCity</p>
<p id="mrs_01_1409__aeb58b9b36a374265966f467b7d8b69fa">storeProvince</p>
<p id="mrs_01_1409__a96c7950a6ccc42e5a1b1118a798648ff">procuctCategory</p>
<p id="mrs_01_1409__a26eb8b65bfaa4957a0ec60ec04f54181">productBatch</p>
<p id="mrs_01_1409__a414d1a3dbc2748bf95d7142cd0b21106">saleQuantity</p>
<p id="mrs_01_1409__a4471122bc35d47e99234f5d5c0efe4d9">revenue</p>
</td>
<td class="cellrowborder" valign="top" width="74.09%" headers="mcps1.3.2.17.2.3.1.2 "><p id="mrs_01_1409__a8bb4d5ecf5674008a527d6e54c821a91">Columns in the table. The columns are service entities for data analysis.</p>
<p id="mrs_01_1409__a01b59fda12ab4e788cce8b8c95834eac">The column name (field name) consists of letters, digits, and underscores (_).</p>
</td>
</tr>
<tr id="mrs_01_1409__rc73311d0a1bc492fb2153051bd666f64"><td class="cellrowborder" valign="top" width="25.91%" headers="mcps1.3.2.17.2.3.1.1 "><p id="mrs_01_1409__a98d11e08fc63486bb59155e5c6e51837">table_blocksize</p>
</td>
<td class="cellrowborder" valign="top" width="74.09%" headers="mcps1.3.2.17.2.3.1.2 "><p id="mrs_01_1409__a0bbe19d5af134a1fb58028433d26ce7b">Indicates the block size of data files used by the CarbonData table, in MB. The value ranges from <strong id="mrs_01_1409__b4886176781035">1</strong> to <strong id="mrs_01_1409__b169646867581035">2048</strong>. The default value is <strong id="mrs_01_1409__b158721204681035">1024</strong>.</p>
<p id="mrs_01_1409__a8d918994c1714dc3aacf71f7d92afdf6">If <strong id="mrs_01_1409__b106930878281035">table_blocksize</strong> is too small, a large number of small files will be generated when data is loaded. This may affect the performance of HDFS.</p>
<p id="mrs_01_1409__a93dea2d63d214521a74fb5ba44986909">If <strong id="mrs_01_1409__b133583159781035">table_blocksize</strong> is too large, during data query, the amount of block data that matches the index is large, and some blocks contain a large number of blocklets, affecting read concurrency and lowering query performance.</p>
<p id="mrs_01_1409__acd7cfc49934d47f39463a9ebbdbafb2d">You are advised to set the block size based on the data volume. For example, set the block size to 256 MB for GB-level data, 512 MB for TB-level data, and 1024 MB for PB-level data.</p>
<p id="mrs_01_1409__a9ba185b258894d30a1bf3ea47dce46ee"></p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="note" id="mrs_01_1409__nc2fda174e5de40a4b9d7a54119b85a64"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="mrs_01_1409__u54b97786ea5c41f59081d0ff24eadeb5"><li class="text" id="mrs_01_1409__l918916e9a41b44239baa414034e86903">Measurement of all Integer data is processed and displayed using the <strong id="mrs_01_1409__b80697638181035">BigInt</strong> data type.</li><li id="mrs_01_1409__l04617e73ea82433fa4eb06adbfb546ee">CarbonData parses data strictly. Any data that cannot be parsed is saved as <strong id="mrs_01_1409__b38316309118">null</strong> in the table. For example, if the user loads the <strong id="mrs_01_1409__b170959398181035">double</strong> value (3.14) to the BigInt column, the data is saved as <strong id="mrs_01_1409__b4421935161113">null</strong>.</li><li id="mrs_01_1409__li195661993512">The Short and Long data types used in the <strong id="mrs_01_1409__b212925396981035">Create Table</strong> command are shown as Smallint and BigInt in the <strong id="mrs_01_1409__b128935489581035">DESCRIBE</strong> command, respectively.</li><li id="mrs_01_1409__li6989148163620">You can run the <strong id="mrs_01_1409__b36160425781035">DESCRIBE</strong> command to view the table data size and table index size.</li></ul>
</div></div>
</div>
<div class="section" id="mrs_01_1409__sc09b346eaa7d484abef78a9ca9595ae1"><h4 class="sectiontitle">Operation Result</h4><p id="mrs_01_1409__a0e0ede467f85405184aeeacae4207076">Run the command to create a table.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_1407.html">CarbonData Table Management</a></div>
</div>
</div>