Yang, Tong 3f5759eed2 MRS comp-lts 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>
2023-01-19 17:08:45 +00:00

67 lines
9.2 KiB
HTML

<a name="mrs_01_1635"></a><a name="mrs_01_1635"></a>
<h1 class="topictitle1">Using a Secondary Index</h1>
<div id="body8662426"><div class="section" id="mrs_01_1635__en-us_topic_0000001173630834_section954715451361"><h4 class="sectiontitle">Scenario</h4><p id="mrs_01_1635__en-us_topic_0000001173630834_p1433149163119">HIndex enables HBase indexing based on specific column values, making the retrieval of data highly efficient and fast.</p>
</div>
<div class="section" id="mrs_01_1635__en-us_topic_0000001173630834_section7855729133712"><h4 class="sectiontitle">Constraints</h4><ul id="mrs_01_1635__en-us_topic_0000001173630834_ul105041439141515"><li id="mrs_01_1635__en-us_topic_0000001173630834_li11504339111518">Column families are separated by semicolons (;).</li><li id="mrs_01_1635__en-us_topic_0000001173630834_li97741343181516">Columns and data types must be contained in square brackets ([]).</li><li id="mrs_01_1635__en-us_topic_0000001173630834_li84359471152">The column data type is specified by using -&gt; after the column name.</li><li id="mrs_01_1635__en-us_topic_0000001173630834_li9238151101515">If the column data type is not specified, the default data type (string) is used.</li><li id="mrs_01_1635__en-us_topic_0000001173630834_li165161254101514">The number sign (#) is used to separate two index details.</li><li id="mrs_01_1635__en-us_topic_0000001173630834_li1592995912154">The following is an optional parameter:<p id="mrs_01_1635__en-us_topic_0000001173630834_p12199164620126"><a name="mrs_01_1635__en-us_topic_0000001173630834_li1592995912154"></a><a name="en-us_topic_0000001173630834_li1592995912154"></a>-Dscan.caching: number of cached rows when the data table is scanned.</p>
<p id="mrs_01_1635__en-us_topic_0000001173630834_p1199124615129">The default value is set to 1000.</p>
</li></ul>
<ul id="mrs_01_1635__en-us_topic_0000001173630834_ul1581765131616"><li id="mrs_01_1635__en-us_topic_0000001173630834_li9817250163">Indexes are created for a single region to repair damaged indexes.<p id="mrs_01_1635__en-us_topic_0000001173630834_p1619984612121"><a name="mrs_01_1635__en-us_topic_0000001173630834_li9817250163"></a><a name="en-us_topic_0000001173630834_li9817250163"></a>This function is not used to generate new indexes.</p>
</li></ul>
</div>
<div class="section" id="mrs_01_1635__en-us_topic_0000001173630834_section1996718416373"><h4 class="sectiontitle">Procedure</h4><ol id="mrs_01_1635__en-us_topic_0000001173630834_ol10359157104419"><li id="mrs_01_1635__en-us_topic_0000001173630834_l7abda99f80f24f0688eb6eee97f38f07"><span>Install the HBase client. For details, see <a href="mrs_01_24041.html">Using an HBase Client</a>.</span></li><li id="mrs_01_1635__en-us_topic_0000001173630834_li86514275154"><span>Go to the client installation directory, for example, <strong id="mrs_01_1635__en-us_topic_0000001173630834_b19508182142318">/opt/client</strong>.</span><p><p id="mrs_01_1635__en-us_topic_0000001173630834_p1454417303156"><strong id="mrs_01_1635__en-us_topic_0000001173630834_b6595143020160">cd /opt/client</strong></p>
</p></li><li id="mrs_01_1635__en-us_topic_0000001173630834_li22404390156"><span>Run the following command to configure environment variables:</span><p><p id="mrs_01_1635__en-us_topic_0000001173630834_p267075113155"><strong id="mrs_01_1635__en-us_topic_0000001173630834_b15744143311168">source bigdata_env</strong></p>
</p></li><li id="mrs_01_1635__en-us_topic_0000001173630834_li331414455455"><span>If the cluster is in security mode, run the following command to authenticate the user. In normal mode, user authentication is not required.</span><p><p id="mrs_01_1635__en-us_topic_0000001173630834_a30822cebdc7142fbbbf794f2bd4689e4"><strong id="mrs_01_1635__en-us_topic_0000001173630834_b6589530134617">kinit</strong> <em id="mrs_01_1635__en-us_topic_0000001173630834_i18589130144616">Component service user</em></p>
</p></li><li id="mrs_01_1635__en-us_topic_0000001173630834_li168519353465"><span>Run the following command to access HIndex:</span><p><p id="mrs_01_1635__en-us_topic_0000001173630834_p2010083710461"><strong id="mrs_01_1635__en-us_topic_0000001173630834_b8277115094910">hbase org.apache.hadoop.hbase.hindex.mapreduce.TableIndexer</strong></p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="mrs_01_1635__en-us_topic_0000001173630834_table186598010737" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Common HIndex commands</caption><thead align="left"><tr id="mrs_01_1635__en-us_topic_0000001173630834_row5799438510737"><th align="left" class="cellrowborder" valign="top" width="19.62%" id="mcps1.3.3.2.5.2.2.2.3.1.1"><p id="mrs_01_1635__en-us_topic_0000001173630834_p6643176810737">Description</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="80.38%" id="mcps1.3.3.2.5.2.2.2.3.1.2"><p id="mrs_01_1635__en-us_topic_0000001173630834_p1226413310737">Command</p>
</th>
</tr>
</thead>
<tbody><tr id="mrs_01_1635__en-us_topic_0000001173630834_row4326833910737"><td class="cellrowborder" valign="top" width="19.62%" headers="mcps1.3.3.2.5.2.2.2.3.1.1 "><p id="mrs_01_1635__en-us_topic_0000001173630834_p2579995610817">Add Index</p>
</td>
<td class="cellrowborder" valign="top" width="80.38%" headers="mcps1.3.3.2.5.2.2.2.3.1.2 "><p id="mrs_01_1635__en-us_topic_0000001173630834_p131950010939">TableIndexer-Dtablename.to.index=table1-Dindexspecs.to.add='IDX1=&gt;cf1:[q1-&gt;datatype],[q2],[q3];cf2:[q1-&gt;datatype],[q2-&gt;datatype]#IDX2=&gt;cf1:[q5]'</p>
</td>
</tr>
<tr id="mrs_01_1635__en-us_topic_0000001173630834_row5061698410737"><td class="cellrowborder" valign="top" width="19.62%" headers="mcps1.3.3.2.5.2.2.2.3.1.1 "><p id="mrs_01_1635__en-us_topic_0000001173630834_p633501510737">Create Index</p>
</td>
<td class="cellrowborder" valign="top" width="80.38%" headers="mcps1.3.3.2.5.2.2.2.3.1.2 "><p id="mrs_01_1635__en-us_topic_0000001173630834_p79033422919">TableIndexer -Dtablename.to.index=table1 -Dindexnames.to.build='IDX1#IDX2'</p>
</td>
</tr>
<tr id="mrs_01_1635__en-us_topic_0000001173630834_row5482343510737"><td class="cellrowborder" valign="top" width="19.62%" headers="mcps1.3.3.2.5.2.2.2.3.1.1 "><p id="mrs_01_1635__en-us_topic_0000001173630834_p1151321210737">Delete Index</p>
</td>
<td class="cellrowborder" valign="top" width="80.38%" headers="mcps1.3.3.2.5.2.2.2.3.1.2 "><p id="mrs_01_1635__en-us_topic_0000001173630834_p157326501398">TableIndexer -Dtablename.to.index=table1 -Dindexnames.to.drop='IDX1#IDX2'</p>
</td>
</tr>
<tr id="mrs_01_1635__en-us_topic_0000001173630834_row452385610737"><td class="cellrowborder" valign="top" width="19.62%" headers="mcps1.3.3.2.5.2.2.2.3.1.1 "><p id="mrs_01_1635__en-us_topic_0000001173630834_p3088809410737">Disable Index</p>
</td>
<td class="cellrowborder" valign="top" width="80.38%" headers="mcps1.3.3.2.5.2.2.2.3.1.2 "><p id="mrs_01_1635__en-us_topic_0000001173630834_p16300155151016">TableIndexer -Dtablename.to.index=table1 -Dindexnames.to.disable='IDX1#IDX2'</p>
</td>
</tr>
<tr id="mrs_01_1635__en-us_topic_0000001173630834_row3595154310737"><td class="cellrowborder" valign="top" width="19.62%" headers="mcps1.3.3.2.5.2.2.2.3.1.1 "><p id="mrs_01_1635__en-us_topic_0000001173630834_p2639383410737">Add and Create Index</p>
</td>
<td class="cellrowborder" valign="top" width="80.38%" headers="mcps1.3.3.2.5.2.2.2.3.1.2 "><p id="mrs_01_1635__en-us_topic_0000001173630834_p0810131518104">TableIndexer -Dtablename.to.index=table1 -Dindexspecs.to.add='IDX1=&gt;cf1:[q1-&gt;datatype],[q2],[q3];cf2:[q1-&gt;datatype],[q2-&gt;datatype]#IDX2=&gt;cf1:[q5] -Dindexnames.to.build='IDX1'</p>
</td>
</tr>
<tr id="mrs_01_1635__en-us_topic_0000001173630834_row4797057810737"><td class="cellrowborder" valign="top" width="19.62%" headers="mcps1.3.3.2.5.2.2.2.3.1.1 "><p id="mrs_01_1635__en-us_topic_0000001173630834_p1646513195911">Create Index for a Single Region</p>
</td>
<td class="cellrowborder" valign="top" width="80.38%" headers="mcps1.3.3.2.5.2.2.2.3.1.2 "><p id="mrs_01_1635__en-us_topic_0000001173630834_p10368724161012">TableIndexer -Dtablename.to.index=table1 -Dregion.to.index=regionEncodedName -Dindexnames.to.build='IDX1#IDX2'</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="note" id="mrs_01_1635__en-us_topic_0000001173630834_note86531388471"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="mrs_01_1635__en-us_topic_0000001173630834_ul082015407429"><li id="mrs_01_1635__en-us_topic_0000001173630834_li782064054220"><strong id="mrs_01_1635__en-us_topic_0000001173630834_b137391157184710">IDX1</strong>: indicates the index name.</li><li id="mrs_01_1635__en-us_topic_0000001173630834_li382074015424"><strong id="mrs_01_1635__en-us_topic_0000001173630834_b11941105919473">cf1</strong>: indicates the column family name.</li><li id="mrs_01_1635__en-us_topic_0000001173630834_li138217402424"><strong id="mrs_01_1635__en-us_topic_0000001173630834_b063351015489">q1</strong>: indicates the column name.</li><li id="mrs_01_1635__en-us_topic_0000001173630834_li14821104074216"><strong id="mrs_01_1635__en-us_topic_0000001173630834_b152652384816">datatype</strong>: indicates the data type, including String, Integer, Double, Float, Long, Short, Byte and Char.</li></ul>
</div></div>
</p></li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_0500.html">Using HBase</a></div>
</div>
</div>