-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add JDBC Interpreter for Mysql #60
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # | ||
| # 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. | ||
| # | ||
| # @Author Hyungu Roh <[email protected]> | ||
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| <?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-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <groupId>org.apache.zeppelin</groupId> | ||
| <artifactId>zeppelin-jdbc</artifactId> | ||
| <packaging>jar</packaging> | ||
| <version>0.5.0-SNAPSHOT</version> | ||
| <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> | ||
|
|
||
| <dependency> | ||
| <groupId>mysql</groupId> | ||
| <artifactId>mysql-connector-java</artifactId> | ||
| <version>5.1.35</version> | ||
| </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> | ||
36 changes: 36 additions & 0 deletions
36
jdbc/src/main/java/org/apache/zeppelin/jdbc/DBConnection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * 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 org.apache.zeppelin.interpreter.InterpreterResult; | ||
|
|
||
| /** | ||
| * DBConnection | ||
| * | ||
| * @author Hyungu Roh [email protected] | ||
| * | ||
| */ | ||
|
|
||
| public interface DBConnection { | ||
| void open(); | ||
| void close(); | ||
| InterpreterResult executeSql(String sql); | ||
| void cancel(); | ||
| } | ||
|
|
76 changes: 76 additions & 0 deletions
76
jdbc/src/main/java/org/apache/zeppelin/jdbc/DBConnectionFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * 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 org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import java.sql.Connection; | ||
|
|
||
| /** | ||
| * DBConnectionFactory | ||
| * | ||
| * @author Hyungu Roh [email protected] | ||
| * | ||
| */ | ||
|
|
||
| public class DBConnectionFactory { | ||
| Logger logger = LoggerFactory.getLogger(DBConnectionFactory.class); | ||
|
|
||
| String jdbc = ""; | ||
| String host = ""; | ||
| String port = ""; | ||
| String user = ""; | ||
| String password = ""; | ||
|
|
||
| public DBConnectionFactory(Properties currentProperty) { | ||
| for (Object k : currentProperty.keySet()) { | ||
| String key = (String) k; | ||
| String value = (String) currentProperty.get(key); | ||
|
|
||
| if ( key.equals("jdbc") ) { | ||
| this.jdbc = value.toLowerCase(); | ||
| } else if ( key.equals("host") ) { | ||
| this.host = value; | ||
| } else if ( key.equals("password") ) { | ||
| this.password = value; | ||
| } else if ( key.equals("user") ) { | ||
| this.user = value; | ||
| } else if ( key.equals("port") ) { | ||
| this.port = value; | ||
| } else { | ||
| logger.info("else key : " + key); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public DBConnection getDBConnection() { | ||
| DBConnection currentConnection; | ||
|
|
||
| // add other jdbc | ||
| if ( jdbc.equals("mysql") ) { | ||
| currentConnection = new MysqlConnection(host, port, user, password); | ||
| } else { | ||
| currentConnection = null; | ||
| } | ||
|
|
||
| return currentConnection; | ||
| } | ||
| } | ||
|
|
110 changes: 110 additions & 0 deletions
110
jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* | ||
| * 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.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Properties; | ||
| import java.util.Vector; | ||
|
|
||
| import org.apache.commons.lang.StringUtils; | ||
| import org.apache.zeppelin.interpreter.Interpreter; | ||
| import org.apache.zeppelin.interpreter.InterpreterContext; | ||
| import org.apache.zeppelin.interpreter.InterpreterResult; | ||
| import org.apache.zeppelin.interpreter.InterpreterResult.Code; | ||
| import org.apache.zeppelin.scheduler.Scheduler; | ||
| import org.apache.zeppelin.scheduler.SchedulerFactory; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.DriverManager; | ||
| import java.sql.ResultSet; | ||
| import java.sql.ResultSetMetaData; | ||
| import java.sql.SQLException; | ||
| import java.sql.Statement; | ||
|
|
||
| /** | ||
| * JDBC interpreter for Zeppelin. | ||
| * | ||
| * @author Hyungu Roh [email protected] | ||
| * | ||
| */ | ||
|
|
||
| public class JDBCInterpreter extends Interpreter { | ||
| Logger logger = LoggerFactory.getLogger(JDBCInterpreter.class); | ||
| int commandTimeOut = 600000; | ||
|
|
||
| static { | ||
| Interpreter.register("jdbc", JDBCInterpreter.class.getName()); | ||
| } | ||
|
|
||
| DBConnection jdbcConnection; | ||
|
|
||
| public JDBCInterpreter(Properties property) { | ||
| super(property); | ||
| Properties currentProperty = getProperty(); | ||
| DBConnectionFactory DBFactory = new DBConnectionFactory(currentProperty); | ||
| this.jdbcConnection = DBFactory.getDBConnection(); | ||
| } | ||
|
|
||
| @Override | ||
| public void open() { | ||
| jdbcConnection.open(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| jdbcConnection.close(); | ||
| } | ||
|
|
||
| @Override | ||
| public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) { | ||
| logger.info("Run SQL command '" + cmd + "'"); | ||
| return jdbcConnection.executeSql(cmd); | ||
| } | ||
|
|
||
| @Override | ||
| public void cancel(InterpreterContext context) { | ||
| jdbcConnection.cancel(); | ||
| } | ||
|
|
||
| @Override | ||
| public FormType getFormType() { | ||
| return FormType.SIMPLE; | ||
| } | ||
|
|
||
| @Override | ||
| public int getProgress(InterpreterContext context) { | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public Scheduler getScheduler() { | ||
| return SchedulerFactory.singleton().createOrGetFIFOScheduler( | ||
| JDBCInterpreter.class.getName() + this.hashCode()); | ||
| } | ||
|
|
||
| @Override | ||
| public List<String> completion(String buf, int cursor) { | ||
| return null; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 should be
0.5.0-incubating-SNAPSHOTand line 31, too. (check #59)