在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):onefoursix/Cloudera-Impala-JDBC-Example开源软件地址(OpenSource Url):https://github.com/onefoursix/Cloudera-Impala-JDBC-Example开源编程语言(OpenSource Language):Java 92.2%开源软件介绍(OpenSource Introduction):###Cloudera Impala JDBC Example Apache Impala (Incubating) is an open source, analytic MPP database for Apache Hadoop. This example shows how to build and run a Maven-based project to execute SQL queries on Impala using JDBC This example was tested using Impala 2.3 included with CDH 5.5.2 and the Impala JDBC Driver v2.5.30 When you download the Impala JDBC Driver from the link above, it is packaged as a zip file with separate distributions for JDBC3, JDBC4 and JDBC4.1. This example uses the distribution for JDBC4.1 on RHEL6 x86_64. The downloaded zip file contains the following eleven jar files:
The JDBC driver's installation instructions say only that "...you must set the class path to include all the JAR files from the ZIP archive containing the driver that you are using..." While this works fine for one-off projects, it's a little loose for shops that would rather manage their dependencies using Maven or other build systems. Part of the challenge in building a project using those jars with Maven is that some of the jars are not available in public repos and some of them do not have obvious version numbers. My approach in this example will be to use a local Maven repo to manage the first five jars in the list above and to rely on publicly available Maven repos for jars 6 - 11 (as they have version numbers in their name). I will use the community version of the Nexus Repository Manager OSS as a local Maven repo I downloaded Nexus Repository Manager OSS v2.12 from the link here and followed the installation instructions here Here is the view of my local Nexus repo available after launching it for the first time. Note there is already a repo named "3rd party" which I will use to manage the first five JDBC driver jars: To add jars to the repo, login to the local Nexus repo, go to the 3rd party repo's "upload artifacts" tab and select the desired jar to upload. I specified a group of "com.cloudera.impala.jdbc" and a version number of "2.5.30" for each of the five jars I uploaded, like this: Click on the 3rd party repo's URL link and you can browse the uploaded artifacts: Drill into any of the links and you can see the version number has been appended to each jar: Now that we have a local repo available hosting the JDBC jars, all we need to do is add that repo to our pom with an entry like this:
For example, in my case my local repo entry looks like this:
And you can refer to the JDBC artifacts with entries like this:
Jars 6 - 11 will be retrieved from the Cloudera and Maven Central repos and will have traditional dependency elements like this:
See the pom.xml for details ####Dependencies To build the project you must have Maven 2.x or higher installed. Maven info is here. To run the project you must have access to a Hadoop cluster running Impala with at least one populated table defined in the Hive Metastore. Configuring the exampleMake sure to set your local repo in pom.xml as described above Edit the file src/main/resources/ClouderaImpalaJdbcExample.conf and set an Impala daemon's host and port in the connection.url (Impala's default JDBC port is 21050) and set the appropriate JDBC driver class. I am using JDBC4.1 so my conf file looks like this:
See the JDBC driver's docs for more details. Building the exampleBuild the project like this:
If this is the first time you are building the project you should see messages like this showing that Maven is retrieving the JDBC jars from your local repo:
Whereas the other jars (and their dependencies) are downloaded from the public repos:
If your build is successful you should see messages like this:
Note that pom.xml is configured to have Maven build an "uber jar" will all dependencies packaged in a single jar and with the main class set The uber jar will be located at target/cloudera-impala-jdbc-example-uber.jar Running the example using the uber jarOne can run the example using the uber jar with a "java -jar" command with a SQL statement as an argument like this:
There is a "run.sh" script provided with that command Running the example using MavenOne can also run the example using Maven using the run-with-maven.sh script which by default passes a SQL statement as an argument:
Your output should look like this:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论