Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

When the beeline-hs2-connection.xml is present and when no other arguments are provided BeeLine automatically connects to the URL generated using configuration files. When connection arguments (-u, -n or -p) are provided BeeLine uses them and does not use beeline-hs2-connection.xml to automatically connect. Removing or renaming the beeline-hs2-connection.xml disables this feature.

Using beeline-site.xml to automatically connect to HiveServer2

In addition to the above method of using hive-site.xml and beeline-hs2-connection.xml for deriving the jdbc connection url to use when connecting to HiveServer2 from beeline, a user can optionally add beeline-site.xml to their classpath, and within beeline-site.xml, she can specify complete jdbc urls. A user can also specify multiple named urls and use beeline -c <named_url>}} to connect to a specific url. This is particularly useful when the same cluster has multiple HiveServer2 instances running with different configurations. One of the named url is treated as default (which is the url that gets used when the user simply types beeline). An example beeline-site.xml is shown below:

Code Block
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
  <name>beeline.hs2.jdbc.url.tcpUrl</name>
  <value>jdbc:hive2://localhost:10000/default;user=hive;password=hive</value>
</property>

<property>
  <name>beeline.hs2.jdbc.url.httpUrl</name>
  <value>jdbc:hive2://localhost:10000/default;user=hive;password=hive;transportMode=http;httpPath=cliservice</value>
</property>

<property>
  <name>beeline.hs2.jdbc.url.default</name>
  <value>tcpUrl</value>
</property>
</configuration>

In the above example, simply typing beeline opens a new jdbc connection to jdbc:hive2://localhost:10000/default;user=hive;password=hive. If both beeline-site.xml and beeline-hs2-connection.xml are present in the classpath, the final url is created by applying the properties specified in beeline-hs2-connection.xml on top of the url properties derived from beeline-site.xml. As an example consider the following beeline-hs2-connection.xml:

Code Block
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
  <name>beeline.hs2.connection.user</name>
  <value>hive</value>
</property>
<property>
  <name>beeline.hs2.connection.password</name>
  <value>hive</value>
</property>
</configuration>

Consider the following beeline-site.xml:

Code Block
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
  <name>beeline.hs2.jdbc.url.tcpUrl</name>
  <value>jdbc:hive2://localhost:10000/default</value>
</property>

<property>
  <name>beeline.hs2.jdbc.url.httpUrl</name>
  <value>jdbc:hive2://localhost:10000/default;transportMode=http;httpPath=cliservice</value>
</property>

<property>
  <name>beeline.hs2.jdbc.url.default</name>
  <value>tcpUrl</value>
</property>
</configuration>

In the above example, simply typing beeline opens a new jdbc connection to {{jdbc:hive2://localhost:10000/default;user=hive;password=hive}}. When the user types beeline -c httpUrl, a connection to jdbc:hive2://localhost:10000/default;transportMode=http;httpPath=cliservice;user=hive;password=hive is opened. 

Using JDBC

You can use JDBC to access data stored in a relational database or other tabular format.

...