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

125 lines
20 KiB
HTML

<a name="mrs_01_0952"></a><a name="mrs_01_0952"></a>
<h1 class="topictitle1">Using a Hive Client</h1>
<div id="body1590395281693"><div class="section" id="mrs_01_0952__s189a552b8b4942fdb075311d135d088e"><h4 class="sectiontitle">Scenario</h4><p id="mrs_01_0952__a729b5025be954c9a8178d86f5aabe1de">This section guides users to use a Hive client in an O&amp;M or service scenario. </p>
</div>
<div class="section" id="mrs_01_0952__sa6b9ccb3f042427eb19b43be2a0b2132"><h4 class="sectiontitle">Prerequisites</h4><ul id="mrs_01_0952__u24e1c44d76e440009e57c7db31df8b7d"><li id="mrs_01_0952__lb075a551ae0e4087abaa6b5b20999b49">The client has been installed. For example, the client is installed in the <strong id="mrs_01_0952__b1303122513442">/opt/hadoopclient</strong> directory. The client directory in the following operations is only an example. Change it to the actual installation directory.</li><li id="mrs_01_0952__la8a352e20c414015a0e60f8023ecc0a5">Service component users are created by the administrator as required. In security mode, machine-machine users need to download the keytab file. A human-machine user must change the password upon the first login.</li></ul>
</div>
<div class="section" id="mrs_01_0952__s2bf83637be514738a9c473ff512bf1e8"><h4 class="sectiontitle">Using the Hive Client (Versions Earlier Than MRS 3.x)</h4><ol id="mrs_01_0952__ob42d0205e4a24acfa712dfa54121455f"><li id="mrs_01_0952__li7228846162216"><span>Log in to the node where the client is installed as the client installation user.</span></li><li id="mrs_01_0952__l8276fb953ede48e3bcae37889eabd834"><span>Run the following command to go to the client installation directory:</span><p><p id="mrs_01_0952__a7734bbc033c24c0e96a22957af2f367f"><strong id="mrs_01_0952__af1de2390d4ec4df6b0e28574d3329dff">cd </strong><strong id="mrs_01_0952__b499310479379">/opt/hadoopclient</strong></p>
</p></li><li id="mrs_01_0952__l5597fd376c554a00a433496294b4b278"><span>Run the following command to configure environment variables:</span><p><p id="mrs_01_0952__a988e7b87692b4a528f97f0da18a8f07e"><strong id="mrs_01_0952__a32ecf708d4cb4e4d9c017de49ec5b482">source bigdata_env</strong></p>
</p></li><li id="mrs_01_0952__ld661d1bcf5d74879a7d849cd7c0c1385"><span>Log in to the Hive client based on the cluster authentication mode.</span><p><ul id="mrs_01_0952__u3aa29e5ff09943f4beea98856990f774"><li id="mrs_01_0952__l33866974acd3485d91b1ab7b09109770">In security mode, run the following command to complete user authentication and log in to the Hive client:<p id="mrs_01_0952__af6d25c71dd8b42918f2ee66ce22fcb54"><a name="mrs_01_0952__l33866974acd3485d91b1ab7b09109770"></a><a name="l33866974acd3485d91b1ab7b09109770"></a><strong id="mrs_01_0952__b8790165018410">kinit</strong> <em id="mrs_01_0952__i1579617507419">Component service user</em></p>
<p id="mrs_01_0952__ae31bf0ac43b54ae1ad6015a618753c1d"><strong id="mrs_01_0952__af8eb14eb0f8242beab8dcd59b314375c">beeline</strong></p>
</li><li id="mrs_01_0952__l9401eeec55ec40748da9e0b42341df6f">In common mode, run the following command to log in to the Hive client. If no component service user is specified, the current OS user is used to log in to the Hive client.<p id="mrs_01_0952__a0d9dfb7ce9a4433c9e1e7d2924bb790a"><a name="mrs_01_0952__l9401eeec55ec40748da9e0b42341df6f"></a><a name="l9401eeec55ec40748da9e0b42341df6f"></a><strong id="mrs_01_0952__b784911315514">beeline -n</strong> <em id="mrs_01_0952__i11854101311515">component service user</em></p>
</li></ul>
<div class="note" id="mrs_01_0952__note12138175362714"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="mrs_01_0952__p19138155392718">After a beeline connection is established, you can compile and submit HQL statements to execute related tasks. To run the Catalog client command, you need to run the <strong id="mrs_01_0952__b9384181912288">!q</strong> command first to exit the beeline environment.</p>
</div></div>
</p></li><li id="mrs_01_0952__l32b8658f263f4afaba25e5f745bf16f7"><span>Run the following command to execute the HCatalog client command:</span><p><p id="mrs_01_0952__a7e4e2c3c5eb34dc39175e63fc1ddc626"><strong id="mrs_01_0952__a074191eb14004c8db3772f43a870aa8a">hcat -e </strong><em id="mrs_01_0952__a890e2be1f4e74b98987a42443f80bf1a">"cmd"</em></p>
<p id="mrs_01_0952__a741a334e035f4330a3e48fc35e7515e8"><em id="mrs_01_0952__i1380817171486">cmd</em> must be a Hive DDL statement, for example, <strong id="mrs_01_0952__acaf313f6c0dd41b0a7a267716535abaa">hcat -e "show tables"</strong>.</p>
<div class="note" id="mrs_01_0952__n56ed1c57eeba4349b6ab6baa81131a57"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="mrs_01_0952__ue477c4393f9642cd9f3c187df07df071"><li id="mrs_01_0952__l46cbe7ab7b174db48a06d59656e913de">To use the HCatalog client, choose <strong id="mrs_01_0952__b1063714249719">More</strong> &gt; <strong id="mrs_01_0952__b395210292075">Download Client</strong> on the service page to download the clients of all services. This restriction does not apply to the beeline client.</li><li id="mrs_01_0952__li1909844614444">Due to permission model incompatibility, tables created using the HCatalog client cannot be accessed on the HiveServer client. However, the tables can be accessed on the WebHCat client.</li><li id="mrs_01_0952__l31d20a74c46c4e3d8edf0843f8c26c9b">If you use the HCatalog client in Normal mode, the system performs DDL commands using the current user who has logged in to the operating system.</li><li id="mrs_01_0952__lc25a7754cdd943daa9b362fa3914cdc7">Exit the beeline client by running the <strong id="mrs_01_0952__ac3611993bc8c4f9193aaf22ad0b4ae0e">!q</strong> command instead of by pressing <strong id="mrs_01_0952__b12129162841212">Ctrl + c</strong>. Otherwise, the temporary files generated by the connection cannot be deleted and a large number of junk files will be generated as a result.</li><li id="mrs_01_0952__l37f1937ff4b849139459a640110818be">If multiple statements need to be entered during the use of beeline clients, separate the statements from each other using semicolons (<span class="parmname" id="mrs_01_0952__pf76a6997fa5f4b8eb865a1879e11f751"><b>;</b></span>) and set the value of <span class="parmname" id="mrs_01_0952__p28e4092ed8344f2d843d95f114af7a62"><b>entireLineAsCommand</b></span> to <span class="parmvalue" id="mrs_01_0952__p022e8e97a7c44285bb1f9191f7cf308c"><b>false</b></span>. <p id="mrs_01_0952__a90553c6698c94a5a823757fa04e814e7">Setting method: If beeline has not been started, run the <strong id="mrs_01_0952__a5a1205daa5b1416aa271209b3431f859">beeline --entireLineAsCommand=false</strong> command. If the beeline has been started, run the <strong id="mrs_01_0952__a6bfcfbb8dcf9427ca1ce8a3d362aff34">!set entireLineAsCommand false</strong> command.</p>
<p id="mrs_01_0952__a3b76c6d5326c41e88f8989661255e719">After the setting, if a statement contains semicolons (<span class="parmname" id="mrs_01_0952__pc1bb13a2248d4c489047459602e2a905"><b>;</b></span>) that do not indicate the end of the statement, escape characters must be added, for example, <strong id="mrs_01_0952__ae21e06ad43394a74bb8c181b90cc2c32">select concat_ws('\;', collect_set(col1)) from tbl</strong>. </p>
</li></ul>
</div></div>
</p></li></ol>
</div>
<div class="section" id="mrs_01_0952__section363014973119"><h4 class="sectiontitle">Using the Hive Client (MRS 3.x or Later)</h4><ol id="mrs_01_0952__ol1971420121338"><li id="mrs_01_0952__li12714181212336"><span>Log in to the node where the client is installed as the client installation user.</span></li><li id="mrs_01_0952__li15714512153310"><span>Run the following command to go to the client installation directory:</span><p><p id="mrs_01_0952__p271414125334"><strong id="mrs_01_0952__b10714171283313">cd </strong><strong id="mrs_01_0952__b168141171381">/opt/hadoopclient</strong></p>
</p></li><li id="mrs_01_0952__li177141412133318"><span>Run the following command to configure environment variables:</span><p><p id="mrs_01_0952__p771411126331"><strong id="mrs_01_0952__b10714512113313">source bigdata_env</strong></p>
</p></li><li id="mrs_01_0952__li87147128336"><span>MRS 3.<em id="mrs_01_0952__i20935104812311">X</em> supports multiple Hive instances. If you use the client to connect to a specific Hive instance in a scenario when multiple Hive instances are installed, run the following command to load the environment variables of the instance. Otherwise, skip this step. For example, load the environment variables of the Hive2 instance.</span><p><p id="mrs_01_0952__p27155125339"><strong id="mrs_01_0952__b271510126330">source Hive2/component_env</strong></p>
</p></li><li id="mrs_01_0952__li37151412133313"><span>Log in to the Hive client based on the cluster authentication mode.</span><p><ul id="mrs_01_0952__ul18715412113315"><li id="mrs_01_0952__li57154129333">In security mode, run the following command to complete user authentication and log in to the Hive client:<p id="mrs_01_0952__p971519128331"><a name="mrs_01_0952__li57154129333"></a><a name="li57154129333"></a><strong id="mrs_01_0952__b67386476">kinit</strong> <em id="mrs_01_0952__i1264153937">Component service user</em></p>
<p id="mrs_01_0952__p18715201283320"><strong id="mrs_01_0952__b1571571214334">beeline</strong></p>
</li><li id="mrs_01_0952__li8715212193313">In common mode, run the following command to log in to the Hive client. If no component service user is specified, the current OS user is used to log in to the Hive client.<p id="mrs_01_0952__p107153129338"><a name="mrs_01_0952__li8715212193313"></a><a name="li8715212193313"></a><strong id="mrs_01_0952__b1340229213">beeline -n</strong> <em id="mrs_01_0952__i18544790">component service user</em></p>
</li></ul>
</p></li><li id="mrs_01_0952__li1771521253313"><span>Run the following command to execute the HCatalog client command:</span><p><p id="mrs_01_0952__p11715171253312"><strong id="mrs_01_0952__b177155128334">hcat -e </strong><em id="mrs_01_0952__i07155127331">"cmd"</em></p>
<p id="mrs_01_0952__p7715111243314"><em id="mrs_01_0952__i1364192001">cmd</em> must be a Hive DDL statement, for example, <strong id="mrs_01_0952__b548759080">hcat -e "show tables"</strong>.</p>
<div class="note" id="mrs_01_0952__note871512128335"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="mrs_01_0952__ul1271561213314"><li id="mrs_01_0952__li2071512120333">To use the HCatalog client, choose <strong id="mrs_01_0952__b8681479152239">More </strong>&gt; <strong id="mrs_01_0952__b157685956052239">Download Client</strong> on the service page to download the clients of all services. This restriction does not apply to the beeline client.</li><li id="mrs_01_0952__li177151512103316">Due to permission model incompatibility, tables created using the HCatalog client cannot be accessed on the HiveServer client. However, the tables can be accessed on the WebHCat client.</li><li id="mrs_01_0952__li19715912143317">If you use the HCatalog client in Normal mode, the system performs DDL commands using the current user who has logged in to the operating system.</li><li id="mrs_01_0952__li117154124331">Exit the beeline client by running the <strong id="mrs_01_0952__b1135237241">!q</strong> command instead of by pressing <strong id="mrs_01_0952__b854961442">Ctrl + C</strong>. Otherwise, the temporary files generated by the connection cannot be deleted and a large number of junk files will be generated as a result.</li><li id="mrs_01_0952__li37151812133319">If multiple statements need to be entered during the use of beeline clients, separate the statements from each other using semicolons (<span class="parmname" id="mrs_01_0952__parmname704254238"><b>;</b></span>) and set the value of <span class="parmname" id="mrs_01_0952__parmname499809070"><b>entireLineAsCommand</b></span> to <span class="parmvalue" id="mrs_01_0952__parmvalue301660392"><b>false</b></span>. <p id="mrs_01_0952__p671612123335">Setting method: If beeline has not been started, run the <strong id="mrs_01_0952__b1162970878">beeline --entireLineAsCommand=false</strong> command. If the beeline has been started, run the <strong id="mrs_01_0952__b1575693071">!set entireLineAsCommand false</strong> command.</p>
<p id="mrs_01_0952__p147167126334">After the setting, if a statement contains semicolons (<span class="parmname" id="mrs_01_0952__parmname332865619"><b>;</b></span>) that do not indicate the end of the statement, escape characters must be added, for example, <strong id="mrs_01_0952__b603845753">select concat_ws('\;', collect_set(col1)) from tbl</strong>. </p>
</li></ul>
</div></div>
</p></li></ol>
</div>
<div class="section" id="mrs_01_0952__section1462718419"><h4 class="sectiontitle">Common Hive Client Commands</h4><p id="mrs_01_0952__p10844101962010">The following table lists common Hive Beeline commands.</p>
<p id="mrs_01_0952__p13576181674114">For more commands, see <a href="https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-BeelineCommands" target="_blank" rel="noopener noreferrer">https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-BeelineCommands</a>.</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="mrs_01_0952__table122538012428" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Common Hive Beeline commands</caption><thead align="left"><tr id="mrs_01_0952__row142532012426"><th align="left" class="cellrowborder" valign="top" width="34.94%" id="mcps1.3.5.4.2.3.1.1"><p id="mrs_01_0952__p122532016422">Command</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="65.06%" id="mcps1.3.5.4.2.3.1.2"><p id="mrs_01_0952__p162532064218">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="mrs_01_0952__row2021434171115"><td class="cellrowborder" valign="top" width="34.94%" headers="mcps1.3.5.4.2.3.1.1 "><p id="mrs_01_0952__p71342032665">set &lt;key&gt;=&lt;value&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="65.06%" headers="mcps1.3.5.4.2.3.1.2 "><p id="mrs_01_0952__p19842133413116">Sets the value of a specific configuration variable (key).</p>
<div class="note" id="mrs_01_0952__note2835203419111"><span class="notetitle"> NOTE: </span><div class="notebody"><p id="mrs_01_0952__p913842513334">If the variable name is incorrectly spelled, the Beeline does not display an error.</p>
</div></div>
</td>
</tr>
<tr id="mrs_01_0952__row1960353171115"><td class="cellrowborder" valign="top" width="34.94%" headers="mcps1.3.5.4.2.3.1.1 "><p id="mrs_01_0952__p313417325616">set</p>
</td>
<td class="cellrowborder" valign="top" width="65.06%" headers="mcps1.3.5.4.2.3.1.2 "><p id="mrs_01_0952__p789933320337">Prints the list of configuration variables overwritten by users or Hive.</p>
</td>
</tr>
<tr id="mrs_01_0952__row47651428141117"><td class="cellrowborder" valign="top" width="34.94%" headers="mcps1.3.5.4.2.3.1.1 "><p id="mrs_01_0952__p813483215614">set -v</p>
</td>
<td class="cellrowborder" valign="top" width="65.06%" headers="mcps1.3.5.4.2.3.1.2 "><p id="mrs_01_0952__p1321154133317">Prints all configuration variables of Hadoop and Hive.</p>
</td>
</tr>
<tr id="mrs_01_0952__row11871191912314"><td class="cellrowborder" valign="top" width="34.94%" headers="mcps1.3.5.4.2.3.1.1 "><p id="mrs_01_0952__p31341132960">add FILE[S] &lt;filepath&gt; &lt;filepath&gt;*add JAR[S] &lt;filepath&gt; &lt;filepath&gt;*add ARCHIVE[S] &lt;filepath&gt; &lt;filepath&gt;*</p>
</td>
<td class="cellrowborder" valign="top" width="65.06%" headers="mcps1.3.5.4.2.3.1.2 "><p id="mrs_01_0952__p17685948163315">Adds one or more files, JAR files, or ARCHIVE files to the resource list of the distributed cache.</p>
</td>
</tr>
<tr id="mrs_01_0952__row1215814241538"><td class="cellrowborder" valign="top" width="34.94%" headers="mcps1.3.5.4.2.3.1.1 "><p id="mrs_01_0952__p1913473212611">add FILE[S] &lt;ivyurl&gt; &lt;ivyurl&gt;*</p>
<p id="mrs_01_0952__p111341327612">add JAR[S] &lt;ivyurl&gt; &lt;ivyurl&gt;*</p>
<p id="mrs_01_0952__p15134183219611">add ARCHIVE[S] &lt;ivyurl&gt; &lt;ivyurl&gt;*</p>
</td>
<td class="cellrowborder" valign="top" width="65.06%" headers="mcps1.3.5.4.2.3.1.2 "><p id="mrs_01_0952__p5652814103420">Adds one or more files, JAR files, or ARCHIVE files to the resource list of the distributed cache using the lvy URL in the <strong id="mrs_01_0952__b847441392411">ivy://goup:module:version?query_string</strong> format.</p>
</td>
</tr>
<tr id="mrs_01_0952__row2333428433"><td class="cellrowborder" valign="top" width="34.94%" headers="mcps1.3.5.4.2.3.1.1 "><p id="mrs_01_0952__p151351032766">list FILE[S]list JAR[S]list ARCHIVE[S]</p>
</td>
<td class="cellrowborder" valign="top" width="65.06%" headers="mcps1.3.5.4.2.3.1.2 "><p id="mrs_01_0952__p3838194153516">Lists the resources that have been added to the distributed cache.</p>
</td>
</tr>
<tr id="mrs_01_0952__row78354332312"><td class="cellrowborder" valign="top" width="34.94%" headers="mcps1.3.5.4.2.3.1.1 "><p id="mrs_01_0952__p613563211618">list FILE[S] &lt;filepath&gt;*list JAR[S] &lt;filepath&gt;*list ARCHIVE[S] &lt;filepath&gt;*</p>
</td>
<td class="cellrowborder" valign="top" width="65.06%" headers="mcps1.3.5.4.2.3.1.2 "><p id="mrs_01_0952__p2997121114351">Checks whether given resources have been added to the distributed cache.</p>
</td>
</tr>
<tr id="mrs_01_0952__row167295557319"><td class="cellrowborder" valign="top" width="34.94%" headers="mcps1.3.5.4.2.3.1.1 "><p id="mrs_01_0952__p313514321965">delete FILE[S] &lt;filepath&gt;*delete JAR[S] &lt;filepath&gt;*delete ARCHIVE[S] &lt;filepath&gt;*</p>
</td>
<td class="cellrowborder" valign="top" width="65.06%" headers="mcps1.3.5.4.2.3.1.2 "><p id="mrs_01_0952__p16659182119354">Deletes resources from the distributed cache.</p>
</td>
</tr>
<tr id="mrs_01_0952__row188142041049"><td class="cellrowborder" valign="top" width="34.94%" headers="mcps1.3.5.4.2.3.1.1 "><p id="mrs_01_0952__p91351732261">delete FILE[S] &lt;ivyurl&gt; &lt;ivyurl&gt;*</p>
<p id="mrs_01_0952__p5135432261">delete JAR[S] &lt;ivyurl&gt; &lt;ivyurl&gt;*</p>
<p id="mrs_01_0952__p1413510321561">delete ARCHIVE[S] &lt;ivyurl&gt; &lt;ivyurl&gt;*</p>
</td>
<td class="cellrowborder" valign="top" width="65.06%" headers="mcps1.3.5.4.2.3.1.2 "><p id="mrs_01_0952__p792102913516">Delete the resource added using <strong id="mrs_01_0952__b1341711513289">&lt;ivyurl&gt;</strong> from the distributed cache.</p>
</td>
</tr>
<tr id="mrs_01_0952__row76481095413"><td class="cellrowborder" valign="top" width="34.94%" headers="mcps1.3.5.4.2.3.1.1 "><p id="mrs_01_0952__p0135193220611">reload</p>
</td>
<td class="cellrowborder" valign="top" width="65.06%" headers="mcps1.3.5.4.2.3.1.2 "><p id="mrs_01_0952__p15404113783515">Enable HiveServer2 to discover the change of the JAR file <strong id="mrs_01_0952__b9564173716282">hive.reloadable.aux.jars.path</strong> in the specified path. (You do not need to restart HiveServer2.) Change actions include adding, deleting, or updating JAR files.</p>
</td>
</tr>
<tr id="mrs_01_0952__row3287141815420"><td class="cellrowborder" valign="top" width="34.94%" headers="mcps1.3.5.4.2.3.1.1 "><p id="mrs_01_0952__p191359321863">dfs &lt;dfs command&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="65.06%" headers="mcps1.3.5.4.2.3.1.2 "><p id="mrs_01_0952__p1383010912360">Runs the <strong id="mrs_01_0952__b2492632132913">dfs</strong> command.</p>
</td>
</tr>
<tr id="mrs_01_0952__row74947138419"><td class="cellrowborder" valign="top" width="34.94%" headers="mcps1.3.5.4.2.3.1.1 "><p id="mrs_01_0952__p813717320611">&lt;query string&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="65.06%" headers="mcps1.3.5.4.2.3.1.2 "><p id="mrs_01_0952__p14213131616365">Executes the Hive query and prints the result to the standard output.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_0581.html">Using Hive</a></div>
</div>
</div>