blob: 13b1323f2faad803d3783fd1f1bd226e62c94d17 [file]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="copyright" content="(C) Copyright 2025" />
<meta name="DC.rights.owner" content="(C) Copyright 2025" />
<meta name="DC.Type" content="concept" />
<meta name="DC.Title" content="Connecting to Impala Daemon from impala-shell" />
<meta name="DC.Relation" scheme="URI" content="../topics/impala_impala_shell.html" />
<meta name="prodname" content="Impala" />
<meta name="prodname" content="Impala" />
<meta name="version" content="Impala 3.4.x" />
<meta name="version" content="Impala 3.4.x" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="connecting" />
<link rel="stylesheet" type="text/css" href="../commonltr.css" />
<title>Connecting to Impala Daemon from impala-shell</title>
</head>
<body id="connecting">
<h1 class="title topictitle1" id="ariaid-title1">Connecting to Impala Daemon from impala-shell</h1>
<div class="body conbody">
<div class="p"> Within an <span class="keyword cmdname">impala-shell</span> session, you can only issue
queries while connected to an instance of the <span class="keyword cmdname">impalad</span>
daemon. You can specify the connection information: <ul class="ul">
<li class="li"> Through command-line options when you run the
<span class="keyword cmdname">impala-shell</span> command. </li>
<li class="li"> Through a configuration file that is read when you run the
<span class="keyword cmdname">impala-shell</span> command. </li>
<li class="li"> During an <span class="keyword cmdname">impala-shell</span> session, by issuing a
<code class="ph codeph">CONNECT</code> command. </li>
</ul>
<div class="note note"><span class="notetitle">Note:</span> You cannot connect to the 3.2 or earlier versions of Impala
using the <code class="ph codeph">'hs2'</code> or <code class="ph codeph">'hs2-http'</code> protocol
(<code class="ph codeph">--protocol</code> option).</div>
See <a class="xref" href="impala_shell_options.html">impala-shell Configuration Options</a> for the command-line and configuration
file options you can use. </div>
<p class="p"> You can connect to any Impala daemon (<span class="keyword cmdname">impalad</span>), and
that daemon coordinates the execution of all queries sent to it. </p>
<p class="p">
For simplicity during development, you might always connect to the same host, perhaps running <span class="keyword cmdname">impala-shell</span> on
the same host as <span class="keyword cmdname">impalad</span> and specifying the hostname as <code class="ph codeph">localhost</code>.
</p>
<p class="p"> In a production environment, you might enable load balancing, in which
you connect to specific host/port combination but queries are forwarded to
arbitrary hosts. This technique spreads the overhead of acting as the
coordinator node among all the Impala daemons in the cluster. See <a class="xref" href="impala_proxy.html">Using Impala through a Proxy for High Availability</a> for details. </p>
<p class="p">
<strong class="ph b">To connect to an Impala during shell startup:</strong>
</p>
<ol class="ol">
<li class="li"> Locate the hostname that is running an instance of the
<span class="keyword cmdname">impalad</span> daemon. If that <span class="keyword cmdname">impalad</span>
uses a non-default port (something other than port 21000) for
<span class="keyword cmdname">impala-shell</span> connections, find out the port number
also. </li>
<li class="li"> Use the <code class="ph codeph">-i</code> option to the
<span class="keyword cmdname">impala-shell</span> interpreter to specify the connection
information for that instance of <span class="keyword cmdname">impalad</span>:
<pre class="pre codeblock"><code># When you are connecting to an impalad running on the same machine.
# The prompt will reflect the current hostname.
$ impala-shell
# When you are connecting to an impalad running on a remote machine, and impalad is listening
# on a non-default port over the HTTP HiveServer2 protocol.
$ impala-shell -i <var class="keyword varname">some.other.hostname</var>:<var class="keyword varname">port_number</var> --protocol='hs2-http'
# When you are connecting to an impalad running on a remote machine, and impalad is listening
# on a non-default port.
$ impala-shell -i <var class="keyword varname">some.other.hostname</var>:<var class="keyword varname">port_number</var>
</code></pre>
</li>
</ol>
<p class="p">
<strong class="ph b">To connect to an Impala in the<span class="keyword cmdname">impala-shell</span>
session:</strong>
</p>
<ol class="ol">
<li class="li"> Start the Impala shell with no connection:
<pre class="pre codeblock"><code>$ impala-shell</code></pre></li>
<li class="li"> Locate the hostname that is running the <span class="keyword cmdname">impalad</span>
daemon. If that <span class="keyword cmdname">impalad</span> uses a non-default port
(something other than port 21000) for <span class="keyword cmdname">impala-shell</span>
connections, find out the port number also. </li>
<li class="li"> Use the <code class="ph codeph">connect</code> command to connect to an Impala
instance. Enter a command of the form:
<pre class="pre codeblock"><code>[Not connected] &gt; connect <var class="keyword varname">impalad-host</var></code></pre><div class="note note"><span class="notetitle">Note:</span>
Replace <var class="keyword varname">impalad-host</var> with the hostname you have
configured to run Impala in your environment. The changed prompt
indicates a successful connection. </div>
</li>
</ol>
<p class="p">
<strong class="ph b">To start <span class="keyword cmdname">impala-shell</span> in a specific database:</strong>
</p>
<p class="p"> You can use all the same connection options as in previous examples. For
simplicity, these examples assume that you are logged into one of the
Impala daemons. </p>
<ol class="ol">
<li class="li">
Find the name of the database containing the relevant tables, views, and so
on that you want to operate on.
</li>
<li class="li">
Use the <code class="ph codeph">-d</code> option to the
<span class="keyword cmdname">impala-shell</span> interpreter to connect and immediately
switch to the specified database, without the need for a <code class="ph codeph">USE</code>
statement or fully qualified names:
<pre class="pre codeblock"><code># Subsequent queries with unqualified names operate on
# tables, views, and so on inside the database named 'staging'.
$ impala-shell -i localhost -d staging
# It is common during development, ETL, benchmarking, and so on
# to have different databases containing the same table names
# but with different contents or layouts.
$ impala-shell -i localhost -d parquet_snappy_compression
$ impala-shell -i localhost -d parquet_gzip_compression
</code></pre>
</li>
</ol>
<p class="p">
<strong class="ph b">To run one or several statements in non-interactive mode:</strong>
</p>
<p class="p"> You can use all the same connection options as in previous examples. For
simplicity, these examples assume that you are logged into one of the
Impala daemons. </p>
<ol class="ol">
<li class="li">
Construct a statement, or a file containing a sequence of statements,
that you want to run in an automated way, without typing or copying
and pasting each time.
</li>
<li class="li">
Invoke <span class="keyword cmdname">impala-shell</span> with the <code class="ph codeph">-q</code> option to run a single statement, or
the <code class="ph codeph">-f</code> option to run a sequence of statements from a file.
The <span class="keyword cmdname">impala-shell</span> command returns immediately, without going into
the interactive interpreter.
<pre class="pre codeblock"><code># A utility command that you might run while developing shell scripts
# to manipulate HDFS files.
$ impala-shell -i localhost -d database_of_interest -q 'show tables'
# A sequence of CREATE TABLE, CREATE VIEW, and similar DDL statements
# can go into a file to make the setup process repeatable.
$ impala-shell -i localhost -d database_of_interest -f recreate_tables.sql
</code></pre>
</li>
</ol>
</div>
<div class="related-links">
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a class="link" href="../topics/impala_impala_shell.html">Using the Impala Shell (impala-shell Command)</a></div>
</div>
</div></body>
</html>