Using JDBC with SQuirreL on Windows
You can use the JDBC driver to connect to Drill from SQuirrel and run SQL queries. Verify that your system meets the prerequisites and then follow the steps listed.
Note: Drill interprets a wildcard in an SQL query as a multiline comment (/…/), which SQuirreL supports. As a result, SQuirreL tries to remove what it interprets as comments and submits an abruptly truncated query. To resolve this issue in SQuirreL, go to the menu and select File > New Session Properties > Tab SQL and uncheck the “Remove multi-line comment (/…/) from SQL before sending to database” option located in the lower portion of the window. See https://sourceforge.net/p/squirrel-sql/bugs/1300/ for more information.
- SQuirreL requires JRE 7
- Drill installed in distributed mode on one or multiple nodes in a cluster. Refer to the Install Drill documentation for more information.
- The client must be able to resolve the actual hostname of the Drill node(s) with the IP(s). Verify that a DNS entry was created on the client machine for the Drill node(s).
If a DNS entry does not exist, create an entry for the Drill node(s).
* For Windows, create an entry in the %WINDIR%\system32\drivers\etc\hosts file. * For Linux and Mac, create an entry in /etc/hosts. <drill-machine-IP> <drill-machine-hostname>
Step 1: Getting the Drill JDBC Driver
The Drill JDBC Driver
JAR file must exist in a directory on your Windows
machine in order to configure the driver in the SQuirreL client.
You can copy the Drill JDBC
JAR file from the following Drill installation
directory on the node with Drill installed, to a directory on your Windows
Or, download a TAR file for the latest Drill release to a location on your Windows machine, and extract the contents of the file. You may need to use a decompression utility, such as 7-zip to extract the archive. Once extracted, you can locate the driver in the following directory:
Step 2: Installing and Starting SQuirreL
To install and start SQuirreL, complete the following steps:
- Download the SQuirreL JAR file for Windows from the following location:
- Double-click the SQuirreL
JARfile. The SQuirreL installation wizard walks you through the installation process.
- When installation completes, navigate to the SQuirreL installation folder and then double-click
squirrel-sql.batto start SQuirreL.
Step 3: Adding the Drill JDBC Driver to SQuirreL
To add the Drill JDBC Driver to SQuirreL, define the driver and create a database alias. The alias is a specific instance of the driver configuration. SQuirreL uses the driver definition and alias to connect to Drill so you can access data sources that you have registered with Drill.
A. Define the Driver
To define the Drill JDBC Driver, complete the following steps:
In the SQuirreL toolbar, select Drivers > New Driver. The Add Driver dialog box appears.
Enter the following information:
Option Description Name Name for the Drill JDBC Driver Example URL jdbc:drill:zk= [;schema= ]Example: jdbc:drill:zk=maprdemo:5181Note: The default ZooKeeper port is 2181. In a MapR cluster, the ZooKeeper port is 5181. Website URL jdbc:drill:zk= [;schema= ]Example: jdbc:drill:zk=maprdemo:5181Note: The default ZooKeeper port is 2181. In a MapR cluster, the ZooKeeper port is 5181. Extra Class Path Click Add and navigate to the JDBC JAR file location in the Windows directory: /jars/jdbc-driver/drill-jdbc-all-0.6.0-incubating.jar Select the JAR file, click Open, and then click List Drivers. Class Name Select org.apache.drill.jdbc.Driver from the drop-down menu.
Click OK. The SQuirreL client displays a message stating that the driver registration is successful, and you can see the driver in the Drivers panel.
B. Create an Alias
To create an alias, complete the following steps:
- Select the Aliases tab.
In the SQuirreL toolbar, select Aliases >New Alias. The Add Alias dialog box appears.
Enter the following information:
- Alias Name: A unique name for the Drill JDBC Driver alias
- Driver: Select the Drill JDBC Driver
- URL: Enter the connection URL with the name of the Drill directory stored in ZooKeeper and the cluster ID, as shown in the next section.
- User Name: admin
- Password: admin
Click Ok. The Connect to: dialog box appears.
Click Connect. SQuirreL displays a message stating that the connection is successful.
- Click OK. SQuirreL displays a series of tabs.
Entering the Connection URL
In step 3 of the procedure to create an alias, use the following syntax to enter the connection URL that includes the name of the Drill directory stored in ZooKeeper and the cluster ID:
The following examples show URLs for Drill installed on a single node:
The following example shows a URL for Drill installed in distributed mode with a connection to a ZooKeeper quorum:
- Including a default schema is optional.
- The ZooKeeper port is 2181. In a MapR cluster, the ZooKeeper port is 5181.
- The Drill directory stored in ZooKeeper is
- The Drill default cluster ID is drillbits1.
Step 4: Running a Drill Query from SQuirreL
Once you have SQuirreL successfully connected to your cluster through the Drill JDBC Driver, you can issue queries from the SQuirreL client. You can run a test query on some sample data included in the Drill installation to try out SQuirreL with Drill.
To query sample data with Squirrel, complete the following steps:
- Click the SQL tab.
Enter the following query in the query box:
SELECT * FROM cp.`employee.json`;
Press Ctrl+Enter to run the query. The following query results display:
You have successfully run a Drill query from the SQuirreL client.