-
Notifications
You must be signed in to change notification settings - Fork 2.8k
added jdbc interpreter #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Interpreter Overview # | ||
|
|
||
| The Zeppelin JDBC interpreter is meant to connect to JDBC backends whose drivers cannot be packaged with | ||
| Zeppelin due to licensing concerns. Examples are: SQL Server, Mysql. This interpreter is currently | ||
| only compatible with those and Postgresql, although it is easy to add support for your favorite JDBC backend. | ||
|
|
||
| ### Setting up a driver | ||
|
|
||
| You should download your JDBC driver and place the .jar file somewhere that the interpreter can locate it, | ||
| e.g., "your_zeppelin_home"/interpreter/jdbc/. The interpreter will load and register your driver dynamically. | ||
|
|
||
| ### Interpreter Settings | ||
|
|
||
| After launching Zeppelin, go to the interpreter settings menu, create a '%jdbc' interpreter, and set your | ||
| driver name, type, and location. | ||
|
|
||
| ### Adding support for a JDBC backend | ||
|
|
||
| Since this interpreter uses java.sql.DriverManager, it supports all JDBC drivers with the same java code. | ||
| However, JDBC driver names and connection url formats vary. The only thing needed to support a new backend | ||
| is to modify JDBCConnectionUrlBuilder.java, and add a connection url method to use the right format for | ||
| your backend. | ||
|
|
||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| ~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
| ~ contributor license agreements. See the NOTICE file distributed with | ||
| ~ this work for additional information regarding copyright ownership. | ||
| ~ The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| ~ (the "License"); you may not use this file except in compliance with | ||
| ~ the License. You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, software | ||
| ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| ~ See the License for the specific language governing permissions and | ||
| ~ limitations under the License. | ||
| --> | ||
|
|
||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <artifactId>zeppelin</artifactId> | ||
| <groupId>org.apache.zeppelin</groupId> | ||
| <version>0.5.0-incubating-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <groupId>org.apache.zeppelin</groupId> | ||
| <artifactId>zeppelin-jdbc</artifactId> | ||
| <packaging>jar</packaging> | ||
| <version>0.5.0-incubating-SNAPSHOT</version> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one also need to be '0.6.0-incubating-SNAPSHOT' |
||
| <name>Zeppelin: JDBC interpreter</name> | ||
| <url>http://zeppelin.incubator.apache.org</url> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>zeppelin-interpreter</artifactId> | ||
| <version>${project.version}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.apache.commons</groupId> | ||
| <artifactId>commons-exec</artifactId> | ||
| <version>1.1</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-api</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-log4j12</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-deploy-plugin</artifactId> | ||
| <version>2.7</version> | ||
| <configuration> | ||
| <skip>true</skip> | ||
| </configuration> | ||
| </plugin> | ||
|
|
||
| <plugin> | ||
| <artifactId>maven-enforcer-plugin</artifactId> | ||
| <version>1.3.1</version> | ||
| <executions> | ||
| <execution> | ||
| <id>enforce</id> | ||
| <phase>none</phase> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
|
|
||
| <plugin> | ||
| <artifactId>maven-dependency-plugin</artifactId> | ||
| <version>2.8</version> | ||
| <executions> | ||
| <execution> | ||
| <id>copy-dependencies</id> | ||
| <phase>package</phase> | ||
| <goals> | ||
| <goal>copy-dependencies</goal> | ||
| </goals> | ||
| <configuration> | ||
| <outputDirectory>${project.build.directory}/../../interpreter/jdbc</outputDirectory> | ||
| <overWriteReleases>false</overWriteReleases> | ||
| <overWriteSnapshots>false</overWriteSnapshots> | ||
| <overWriteIfNewer>true</overWriteIfNewer> | ||
| <includeScope>runtime</includeScope> | ||
| </configuration> | ||
| </execution> | ||
| <execution> | ||
| <id>copy-artifact</id> | ||
| <phase>package</phase> | ||
| <goals> | ||
| <goal>copy</goal> | ||
| </goals> | ||
| <configuration> | ||
| <outputDirectory>${project.build.directory}/../../interpreter/jdbc</outputDirectory> | ||
| <overWriteReleases>false</overWriteReleases> | ||
| <overWriteSnapshots>false</overWriteSnapshots> | ||
| <overWriteIfNewer>true</overWriteIfNewer> | ||
| <includeScope>runtime</includeScope> | ||
| <artifactItems> | ||
| <artifactItem> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>${project.artifactId}</artifactId> | ||
| <version>${project.version}</version> | ||
| <type>${project.packaging}</type> | ||
| </artifactItem> | ||
| </artifactItems> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.apache.zeppelin.jdbc; | ||
|
|
||
| import java.util.Properties; | ||
| import java.util.logging.Logger; | ||
| import java.sql.*; | ||
|
|
||
| /** | ||
| * JDBC interpreter for Zeppelin. | ||
| * | ||
| * @author Andres Celis t-ancel@microsoft.com | ||
| * | ||
| */ | ||
| public class DriverShim implements Driver { | ||
| private Driver driver; | ||
| DriverShim(Driver d) { | ||
| this.driver = d; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NullArgumentException check for parameter d |
||
| } | ||
| public boolean acceptsURL(String u) throws SQLException { | ||
| return this.driver.acceptsURL(u); | ||
| } | ||
| public Connection connect(String u, Properties p) throws SQLException { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better parameter variable names would help readability. What does u stand for? |
||
| return this.driver.connect(u, p); | ||
| } | ||
| public int getMajorVersion() { | ||
| return this.driver.getMajorVersion(); | ||
| } | ||
| public int getMinorVersion() { | ||
| return this.driver.getMinorVersion(); | ||
| } | ||
| public DriverPropertyInfo[] getPropertyInfo(String u, Properties p) throws SQLException { | ||
| return this.driver.getPropertyInfo(u, p); | ||
| } | ||
| public Logger getParentLogger() { | ||
| return null; | ||
| } | ||
| public boolean jdbcCompliant() { | ||
| return this.driver.jdbcCompliant(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.apache.zeppelin.jdbc; | ||
|
|
||
| /** | ||
| * JDBC connection url builder for Zeppelin. | ||
| * | ||
| * @author Andres Celis t-ancel@microsoft.com | ||
| * | ||
| */ | ||
|
|
||
| // add case and connection url method to support other jdbc backends | ||
| public class JDBCConnectionUrlBuilder { | ||
|
|
||
| private String connectionUrl; | ||
|
|
||
| public JDBCConnectionUrlBuilder(String driverType, String host, String port, | ||
| String dbName, String windowsAuth) { | ||
| // determine format | ||
| switch(driverType) { | ||
| case "sqlserver": | ||
| buildSqlserverConnectionUrl(host, port, dbName, windowsAuth); | ||
| break; | ||
| case "postgresql": | ||
| buildPostgresqlConnectionUrl(host, port, dbName); | ||
| break; | ||
| case "mysql": | ||
| buildMysqlConnectionUrl(host, port, dbName); | ||
| break; | ||
| default: | ||
| this.connectionUrl = null; | ||
| } | ||
| } | ||
|
|
||
| private void buildSqlserverConnectionUrl(String host, String port, | ||
| String dbName, String windowsAuth) { | ||
| this.connectionUrl = "jdbc:sqlserver://"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. null check for parameters please. |
||
| this.connectionUrl += (host.equals("")) ? "localhost" : host; | ||
| this.connectionUrl += (port.equals("")) ? ":1433;" : ":" + port + ";"; | ||
| this.connectionUrl += (dbName.equals("")) ? "" : "database=" + dbName + ";"; | ||
| // assume false or empty is SQL authentication | ||
| this.connectionUrl += (windowsAuth.equals("true")) ? "integratedsecurity=true;" : ""; | ||
| } | ||
|
|
||
| private void buildPostgresqlConnectionUrl(String host, String port, String dbName) { | ||
| this.connectionUrl = "jdbc:postgresql://"; | ||
| this.connectionUrl += (host.equals("")) ? "localhost" : host; | ||
| this.connectionUrl += (port.equals("")) ? "" : ":" + port; | ||
| this.connectionUrl += (dbName.equals("")) ? "" : "/" + dbName; | ||
| } | ||
|
|
||
| private void buildMysqlConnectionUrl(String host, String port, String dbName) { | ||
| this.connectionUrl = "jdbc:mysql://"; | ||
| this.connectionUrl += host; | ||
| this.connectionUrl += (port.equals("")) ? "" : ":" + port; | ||
| this.connectionUrl += (dbName.equals("")) ? "" : "/" + dbName; | ||
| } | ||
|
|
||
| public String getConnectionUrl() { | ||
| return this.connectionUrl; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version of current master branch is '0.6.0-incubating-SNAPSHOT'