Repository: zeppelin Updated Branches: refs/heads/master f786d1387 -> 1c3373937
ZEPPELIN-934 Merge Phoenix interpreter into JDBC interpreter ### What is this PR for? Removing Phoenix interpreter and adding example for using it through JDBC ### What type of PR is it? [Feature] ### Todos * [x] - Merge it into JDBC ### What is the Jira issue? * https://issues.apache.org/jira/browse/ZEPPELIN-934 ### How should this be tested? ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: Jongyoul Lee <[email protected]> Closes #982 from jongyoul/ZEPPELIN-934 and squashes the following commits: 7e6b84f [Jongyoul Lee] - Removed Phoenix Interpreter - Updated example for using Apache Phoenix Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/1c337393 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/1c337393 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/1c337393 Branch: refs/heads/master Commit: 1c3373937aad403a6146451001d262c7778edbf0 Parents: f786d13 Author: Jongyoul Lee <[email protected]> Authored: Fri Jun 10 00:48:29 2016 +0900 Committer: Jongyoul Lee <[email protected]> Committed: Fri Jun 17 17:00:24 2016 +0900 ---------------------------------------------------------------------- conf/zeppelin-site.xml.template | 2 +- docs/interpreter/jdbc.md | 36 +++ docs/rest-api/rest-configuration.md | 2 +- phoenix/pom.xml | 149 ------------ .../zeppelin/phoenix/PhoenixInterpreter.java | 240 ------------------- .../phoenix/PhoenixInterpreterTest.java | 226 ----------------- pom.xml | 1 - zeppelin-distribution/src/bin_license/LICENSE | 1 - .../zeppelin/conf/ZeppelinConfiguration.java | 1 - 9 files changed, 38 insertions(+), 620 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1c337393/conf/zeppelin-site.xml.template ---------------------------------------------------------------------- diff --git a/conf/zeppelin-site.xml.template b/conf/zeppelin-site.xml.template index 11ad866..6c1ff8a 100755 --- a/conf/zeppelin-site.xml.template +++ b/conf/zeppelin-site.xml.template @@ -178,7 +178,7 @@ <property> <name>zeppelin.interpreters</name> - <value>org.apache.zeppelin.spark.SparkInterpreter,org.apache.zeppelin.spark.PySparkInterpreter,org.apache.zeppelin.rinterpreter.RRepl,org.apache.zeppelin.rinterpreter.KnitR,org.apache.zeppelin.spark.SparkRInterpreter,org.apache.zeppelin.spark.SparkSqlInterpreter,org.apache.zeppelin.spark.DepInterpreter,org.apache.zeppelin.markdown.Markdown,org.apache.zeppelin.angular.AngularInterpreter,org.apache.zeppelin.shell.ShellInterpreter,org.apache.zeppelin.file.HDFSFileInterpreter,org.apache.zeppelin.flink.FlinkInterpreter,,org.apache.zeppelin.python.PythonInterpreter,org.apache.zeppelin.lens.LensInterpreter,org.apache.zeppelin.ignite.IgniteInterpreter,org.apache.zeppelin.ignite.IgniteSqlInterpreter,org.apache.zeppelin.cassandra.CassandraInterpreter,org.apache.zeppelin.geode.GeodeOqlInterpreter,org.apache.zeppelin.postgresql.PostgreSqlInterpreter,org.apache.zeppelin.jdbc.JDBCInterpreter,org.apache.zeppelin.phoenix.PhoenixInterpreter,org.apache.zeppelin.kylin.KylinInterpreter,org.apache.zep pelin.elasticsearch.ElasticsearchInterpreter,org.apache.zeppelin.scalding.ScaldingInterpreter,org.apache.zeppelin.alluxio.AlluxioInterpreter,org.apache.zeppelin.hbase.HbaseInterpreter,org.apache.zeppelin.livy.LivySparkInterpreter,org.apache.zeppelin.livy.LivyPySparkInterpreter,org.apache.zeppelin.livy.LivySparkRInterpreter,org.apache.zeppelin.livy.LivySparkSQLInterpreter</value> + <value>org.apache.zeppelin.spark.SparkInterpreter,org.apache.zeppelin.spark.PySparkInterpreter,org.apache.zeppelin.rinterpreter.RRepl,org.apache.zeppelin.rinterpreter.KnitR,org.apache.zeppelin.spark.SparkRInterpreter,org.apache.zeppelin.spark.SparkSqlInterpreter,org.apache.zeppelin.spark.DepInterpreter,org.apache.zeppelin.markdown.Markdown,org.apache.zeppelin.angular.AngularInterpreter,org.apache.zeppelin.shell.ShellInterpreter,org.apache.zeppelin.file.HDFSFileInterpreter,org.apache.zeppelin.flink.FlinkInterpreter,,org.apache.zeppelin.python.PythonInterpreter,org.apache.zeppelin.lens.LensInterpreter,org.apache.zeppelin.ignite.IgniteInterpreter,org.apache.zeppelin.ignite.IgniteSqlInterpreter,org.apache.zeppelin.cassandra.CassandraInterpreter,org.apache.zeppelin.geode.GeodeOqlInterpreter,org.apache.zeppelin.postgresql.PostgreSqlInterpreter,org.apache.zeppelin.jdbc.JDBCInterpreter,org.apache.zeppelin.kylin.KylinInterpreter,org.apache.zeppelin.elasticsearch.ElasticsearchInterpreter,or g.apache.zeppelin.scalding.ScaldingInterpreter,org.apache.zeppelin.alluxio.AlluxioInterpreter,org.apache.zeppelin.hbase.HbaseInterpreter,org.apache.zeppelin.livy.LivySparkInterpreter,org.apache.zeppelin.livy.LivyPySparkInterpreter,org.apache.zeppelin.livy.LivySparkRInterpreter,org.apache.zeppelin.livy.LivySparkSQLInterpreter</value> <description>Comma separated interpreter configurations. First interpreter become a default</description> </property> http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1c337393/docs/interpreter/jdbc.md ---------------------------------------------------------------------- diff --git a/docs/interpreter/jdbc.md b/docs/interpreter/jdbc.md index 6783aac..8220147 100644 --- a/docs/interpreter/jdbc.md +++ b/docs/interpreter/jdbc.md @@ -18,6 +18,7 @@ This interpreter lets you create a JDBC connection to any data source, by now it * Apache Hive * Apache Drill * Details on using [Drill JDBC Driver](https://drill.apache.org/docs/using-the-jdbc-driver) +* Apache Phoenix * Apache Tajo If someone else used another database please report how it works to improve functionality. @@ -236,6 +237,41 @@ To develop this functionality use this [method](http://docs.oracle.com/javase/7/ <td></td> </tr> </table> +#### Phoenix +##### Properties + <table class="table-configuration"> + <tr> + <th>Name</th> + <th>Value</th> + </tr> + <tr> + <td>phoenix.driver</td> + <td>org.apache.phoenix.jdbc.PhoenixDriver</td> + </tr> + <tr> + <td>phoenix.url</td> + <td>jdbc:phoenix:localhost:2181:/hbase-unsecure</td> + </tr> + <tr> + <td>phoenix.user</td> + <td>phoenix_user</td> + </tr> + <tr> + <td>phoenix.password</td> + <td>phoenix_password</td> + </tr> + </table> +##### Dependencies + <table class="table-configuration"> + <tr> + <th>Artifact</th> + <th>Excludes</th> + </tr> + <tr> + <td>org.apache.phoenix:phoenix-core:4.4.0-HBase-1.0</td> + <td></td> + </tr> + </table> #### Tajo ##### Properties <table class="table-configuration"> http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1c337393/docs/rest-api/rest-configuration.md ---------------------------------------------------------------------- diff --git a/docs/rest-api/rest-configuration.md b/docs/rest-api/rest-configuration.md index 45cccec..e445156 100644 --- a/docs/rest-api/rest-configuration.md +++ b/docs/rest-api/rest-configuration.md @@ -73,7 +73,7 @@ limitations under the License. "zeppelin.server.context.path": "/", "zeppelin.ssl.keystore.type": "JKS", "zeppelin.ssl.truststore.path": "truststore", - "zeppelin.interpreters": "org.apache.zeppelin.spark.SparkInterpreter,org.apache.zeppelin.spark.PySparkInterpreter,org.apache.zeppelin.spark.SparkRInterpreter,org.apache.zeppelin.spark.SparkSqlInterpreter,org.apache.zeppelin.spark.DepInterpreter,org.apache.zeppelin.markdown.Markdown,org.apache.zeppelin.angular.AngularInterpreter,org.apache.zeppelin.shell.ShellInterpreter,org.apache.zeppelin.flink.FlinkInterpreter,org.apache.zeppelin.lens.LensInterpreter,org.apache.zeppelin.ignite.IgniteInterpreter,org.apache.zeppelin.ignite.IgniteSqlInterpreter,org.apache.zeppelin.cassandra.CassandraInterpreter,org.apache.zeppelin.geode.GeodeOqlInterpreter,org.apache.zeppelin.postgresql.PostgreSqlInterpreter,org.apache.zeppelin.phoenix.PhoenixInterpreter,org.apache.zeppelin.kylin.KylinInterpreter,org.apache.zeppelin.elasticsearch.ElasticsearchInterpreter,org.apache.zeppelin.scalding.ScaldingInterpreter", + "zeppelin.interpreters": "org.apache.zeppelin.spark.SparkInterpreter,org.apache.zeppelin.spark.PySparkInterpreter,org.apache.zeppelin.spark.SparkRInterpreter,org.apache.zeppelin.spark.SparkSqlInterpreter,org.apache.zeppelin.spark.DepInterpreter,org.apache.zeppelin.markdown.Markdown,org.apache.zeppelin.angular.AngularInterpreter,org.apache.zeppelin.shell.ShellInterpreter,org.apache.zeppelin.flink.FlinkInterpreter,org.apache.zeppelin.lens.LensInterpreter,org.apache.zeppelin.ignite.IgniteInterpreter,org.apache.zeppelin.ignite.IgniteSqlInterpreter,org.apache.zeppelin.cassandra.CassandraInterpreter,org.apache.zeppelin.geode.GeodeOqlInterpreter,org.apache.zeppelin.postgresql.PostgreSqlInterpreter,org.apache.zeppelin.kylin.KylinInterpreter,org.apache.zeppelin.elasticsearch.ElasticsearchInterpreter,org.apache.zeppelin.scalding.ScaldingInterpreter", "zeppelin.ssl": "false", "zeppelin.notebook.autoInterpreterBinding": "true", "zeppelin.notebook.homescreen": "", http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1c337393/phoenix/pom.xml ---------------------------------------------------------------------- diff --git a/phoenix/pom.xml b/phoenix/pom.xml deleted file mode 100644 index de4c104..0000000 --- a/phoenix/pom.xml +++ /dev/null @@ -1,149 +0,0 @@ -<?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/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <artifactId>zeppelin</artifactId> - <groupId>org.apache.zeppelin</groupId> - <version>0.6.0-SNAPSHOT</version> - </parent> - - <groupId>org.apache.zeppelin</groupId> - <artifactId>zeppelin-phoenix</artifactId> - <packaging>jar</packaging> - <version>0.6.0-SNAPSHOT</version> - <name>Zeppelin: Apache Phoenix Interpreter</name> - <description>Zeppelin interprter for Apache Phoenix</description> - <url>http://zeppelin.apache.org</url> - - <properties> - <phoenix.version>4.4.0-HBase-1.0</phoenix.version> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.zeppelin</groupId> - <artifactId>zeppelin-interpreter</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>sqlline</groupId> - <artifactId>sqlline</artifactId> - <version>1.1.9</version> - </dependency> - - <dependency> - <groupId>org.apache.phoenix</groupId> - <artifactId>phoenix-core</artifactId> - <version>${phoenix.version}</version> - </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <version>1.9.5</version> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>com.mockrunner</groupId> - <artifactId>mockrunner-jdbc</artifactId> - <version>1.0.8</version> - <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/phoenix</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/phoenix</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> http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1c337393/phoenix/src/main/java/org/apache/zeppelin/phoenix/PhoenixInterpreter.java ---------------------------------------------------------------------- diff --git a/phoenix/src/main/java/org/apache/zeppelin/phoenix/PhoenixInterpreter.java b/phoenix/src/main/java/org/apache/zeppelin/phoenix/PhoenixInterpreter.java deleted file mode 100644 index 05d5d31..0000000 --- a/phoenix/src/main/java/org/apache/zeppelin/phoenix/PhoenixInterpreter.java +++ /dev/null @@ -1,240 +0,0 @@ -/** - * 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.phoenix; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.List; -import java.util.Properties; - -import org.apache.commons.lang.StringUtils; -import org.apache.zeppelin.interpreter.Interpreter; -import org.apache.zeppelin.interpreter.InterpreterContext; -import org.apache.zeppelin.interpreter.InterpreterPropertyBuilder; -import org.apache.zeppelin.interpreter.InterpreterResult; -import org.apache.zeppelin.interpreter.InterpreterResult.Code; -import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; -import org.apache.zeppelin.scheduler.Scheduler; -import org.apache.zeppelin.scheduler.SchedulerFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Phoenix interpreter for Zeppelin. - */ -public class PhoenixInterpreter extends Interpreter { - Logger logger = LoggerFactory.getLogger(PhoenixInterpreter.class); - - private static final String EXPLAIN_PREDICATE = "EXPLAIN "; - private static final String UPDATE_HEADER = "UPDATES "; - - private static final String WS = " "; - private static final String NEWLINE = "\n"; - private static final String TAB = "\t"; - private static final String TABLE_MAGIC_TAG = "%table "; - - static final String PHOENIX_JDBC_URL = "phoenix.jdbc.url"; - static final String PHOENIX_JDBC_USER = "phoenix.user"; - static final String PHOENIX_JDBC_PASSWORD = "phoenix.password"; - static final String PHOENIX_MAX_RESULT = "phoenix.max.result"; - static final String PHOENIX_JDBC_DRIVER_NAME = "phoenix.driver.name"; - - static final String DEFAULT_JDBC_URL = "jdbc:phoenix:localhost:2181:/hbase-unsecure"; - static final String DEFAULT_JDBC_USER = ""; - static final String DEFAULT_JDBC_PASSWORD = ""; - static final String DEFAULT_MAX_RESULT = "1000"; - static final String DEFAULT_JDBC_DRIVER_NAME = "org.apache.phoenix.jdbc.PhoenixDriver"; - - private Connection jdbcConnection; - private Statement currentStatement; - private Exception exceptionOnConnect; - private int maxResult; - - static { - Interpreter.register( - "sql", - "phoenix", - PhoenixInterpreter.class.getName(), - new InterpreterPropertyBuilder() - .add(PHOENIX_JDBC_URL, DEFAULT_JDBC_URL, "Phoenix JDBC connection string") - .add(PHOENIX_JDBC_USER, DEFAULT_JDBC_USER, "The Phoenix user") - .add(PHOENIX_JDBC_PASSWORD, DEFAULT_JDBC_PASSWORD, "The password for the Phoenix user") - .add(PHOENIX_MAX_RESULT, DEFAULT_MAX_RESULT, "Max number of SQL results to display.") - .add(PHOENIX_JDBC_DRIVER_NAME, DEFAULT_JDBC_DRIVER_NAME, "Phoenix Driver classname.") - .build() - ); - } - - public PhoenixInterpreter(Properties property) { - super(property); - } - - @Override - public void open() { - logger.info("Jdbc open connection called!"); - close(); - - try { - Class.forName(getProperty(PHOENIX_JDBC_DRIVER_NAME)); - - maxResult = Integer.valueOf(getProperty(PHOENIX_MAX_RESULT)); - jdbcConnection = DriverManager.getConnection( - getProperty(PHOENIX_JDBC_URL), - getProperty(PHOENIX_JDBC_USER), - getProperty(PHOENIX_JDBC_PASSWORD) - ); - exceptionOnConnect = null; - logger.info("Successfully created Jdbc connection"); - } - catch (ClassNotFoundException | SQLException e) { - logger.error("Cannot open connection", e); - exceptionOnConnect = e; - } - } - - @Override - public void close() { - logger.info("Jdbc close connection called!"); - - try { - if (getJdbcConnection() != null) { - getJdbcConnection().close(); - } - } catch (SQLException e) { - logger.error("Cannot close connection", e); - } - finally { - exceptionOnConnect = null; - } - } - - private String clean(boolean isExplain, String str){ - return (isExplain || str == null) ? str : str.replace(TAB, WS).replace(NEWLINE, WS); - } - - private InterpreterResult executeSql(String sql) { - try { - if (exceptionOnConnect != null) { - return new InterpreterResult(Code.ERROR, exceptionOnConnect.getMessage()); - } - - currentStatement = getJdbcConnection().createStatement(); - - boolean isExplain = StringUtils.containsIgnoreCase(sql, EXPLAIN_PREDICATE); - StringBuilder msg = (isExplain) ? new StringBuilder() : new StringBuilder(TABLE_MAGIC_TAG); - - ResultSet res = null; - try { - boolean hasResult = currentStatement.execute(sql); - if (hasResult){ //If query had results - res = currentStatement.getResultSet(); - //Append column names - ResultSetMetaData md = res.getMetaData(); - String row = clean(isExplain, md.getColumnName(1)); - for (int i = 2; i < md.getColumnCount() + 1; i++) - row += TAB + clean(isExplain, md.getColumnName(i)); - msg.append(row + NEWLINE); - - //Append rows - int rowCount = 0; - while (res.next() && rowCount < getMaxResult()) { - row = clean(isExplain, res.getString(1)); - for (int i = 2; i < md.getColumnCount() + 1; i++) - row += TAB + clean(isExplain, res.getString(i)); - msg.append(row + NEWLINE); - rowCount++; - } - } - else { // May have been upsert or DDL - msg.append(UPDATE_HEADER + NEWLINE + - "Rows affected: " + currentStatement.getUpdateCount() - + NEWLINE); - } - - } finally { - try { - if (res != null) res.close(); - getJdbcConnection().commit(); - currentStatement.close(); - } finally { - currentStatement = null; - } - } - - return new InterpreterResult(Code.SUCCESS, msg.toString()); - } - catch (SQLException ex) { - logger.error("Can not run " + sql, ex); - return new InterpreterResult(Code.ERROR, ex.getMessage()); - } - } - - @Override - public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) { - logger.info("Run SQL command '" + cmd + "'"); - return executeSql(cmd); - } - - @Override - public void cancel(InterpreterContext context) { - if (currentStatement != null) { - try { - currentStatement.cancel(); - } - catch (SQLException ex) { - } - finally { - currentStatement = null; - } - } - } - - @Override - public FormType getFormType() { - return FormType.SIMPLE; - } - - @Override - public int getProgress(InterpreterContext context) { - return 0; - } - - @Override - public Scheduler getScheduler() { - return SchedulerFactory.singleton().createOrGetFIFOScheduler( - PhoenixInterpreter.class.getName() + this.hashCode()); - } - - @Override - public List<InterpreterCompletion> completion(String buf, int cursor) { - return null; - } - - public Connection getJdbcConnection() { - return jdbcConnection; - } - - public int getMaxResult() { - return maxResult; - } - -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1c337393/phoenix/src/test/java/org/apache/zeppelin/phoenix/PhoenixInterpreterTest.java ---------------------------------------------------------------------- diff --git a/phoenix/src/test/java/org/apache/zeppelin/phoenix/PhoenixInterpreterTest.java b/phoenix/src/test/java/org/apache/zeppelin/phoenix/PhoenixInterpreterTest.java deleted file mode 100644 index 9270d4b..0000000 --- a/phoenix/src/test/java/org/apache/zeppelin/phoenix/PhoenixInterpreterTest.java +++ /dev/null @@ -1,226 +0,0 @@ -/** - * 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.phoenix; - -import static org.apache.zeppelin.phoenix.PhoenixInterpreter.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.times; - -import java.sql.SQLException; -import java.util.Properties; - -import org.apache.zeppelin.interpreter.InterpreterResult; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Matchers; -import org.mockito.Mockito; - -import com.mockrunner.jdbc.BasicJDBCTestCaseAdapter; -import com.mockrunner.jdbc.StatementResultSetHandler; -import com.mockrunner.mock.jdbc.MockConnection; -import com.mockrunner.mock.jdbc.MockResultSet; - -/** - * Phoenix interpreter unit tests - */ -public class PhoenixInterpreterTest extends BasicJDBCTestCaseAdapter { - private PhoenixInterpreter phoenixInterpreter = null; - private MockResultSet result = null; - - @Before - public void beforeTest() { - MockConnection connection = getJDBCMockObjectFactory().getMockConnection(); - - StatementResultSetHandler statementHandler = connection.getStatementResultSetHandler(); - result = statementHandler.createResultSet(); - statementHandler.prepareGlobalResultSet(result); - - Properties properties = new Properties(); - properties.put(PHOENIX_JDBC_DRIVER_NAME, DEFAULT_JDBC_DRIVER_NAME); - properties.put(PHOENIX_JDBC_URL, DEFAULT_JDBC_URL); - properties.put(PHOENIX_JDBC_USER, DEFAULT_JDBC_USER); - properties.put(PHOENIX_JDBC_PASSWORD, DEFAULT_JDBC_PASSWORD); - properties.put(PHOENIX_MAX_RESULT, DEFAULT_MAX_RESULT); - - phoenixInterpreter = spy(new PhoenixInterpreter(properties)); - when(phoenixInterpreter.getJdbcConnection()).thenReturn(connection); - } - - @Test - public void testOpenCommandIdempotency() throws SQLException { - // Ensure that an attempt to open new connection will clean any remaining connections - phoenixInterpreter.open(); - phoenixInterpreter.open(); - phoenixInterpreter.open(); - - verify(phoenixInterpreter, times(3)).open(); - verify(phoenixInterpreter, times(3)).close(); - } - - @Test - public void testDefaultProperties() throws SQLException { - - PhoenixInterpreter phoenixInterpreter = new PhoenixInterpreter(new Properties()); - - assertEquals(DEFAULT_JDBC_DRIVER_NAME, - phoenixInterpreter.getProperty(PHOENIX_JDBC_DRIVER_NAME)); - assertEquals(DEFAULT_JDBC_URL, phoenixInterpreter.getProperty(PHOENIX_JDBC_URL)); - assertEquals(DEFAULT_JDBC_USER, phoenixInterpreter.getProperty(PHOENIX_JDBC_USER)); - assertEquals(DEFAULT_JDBC_PASSWORD, - phoenixInterpreter.getProperty(PHOENIX_JDBC_PASSWORD)); - assertEquals(DEFAULT_MAX_RESULT, phoenixInterpreter.getProperty(PHOENIX_MAX_RESULT)); - } - - @Test - public void testConnectionClose() throws SQLException { - - PhoenixInterpreter phoenixInterpreter = spy(new PhoenixInterpreter(new Properties())); - - when(phoenixInterpreter.getJdbcConnection()).thenReturn( - getJDBCMockObjectFactory().getMockConnection()); - - phoenixInterpreter.close(); - - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - verifyConnectionClosed(); - } - - @Test - public void testStatementCancel() throws SQLException { - - PhoenixInterpreter phoenixInterpreter = spy(new PhoenixInterpreter(new Properties())); - - when(phoenixInterpreter.getJdbcConnection()).thenReturn( - getJDBCMockObjectFactory().getMockConnection()); - - phoenixInterpreter.cancel(null); - - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - assertFalse("Cancel operation should not close the connection", phoenixInterpreter - .getJdbcConnection().isClosed()); - } - - @Test - public void testSelectQuery() throws SQLException { - - when(phoenixInterpreter.getMaxResult()).thenReturn(1000); - - String sqlQuery = "select * from t"; - - result.addColumn("col1", new String[] {"val11", "val12"}); - result.addColumn("col2", new String[] {"val21", "val22"}); - - InterpreterResult interpreterResult = phoenixInterpreter.interpret(sqlQuery, null); - - assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); - assertEquals(InterpreterResult.Type.TABLE, interpreterResult.type()); - assertEquals("col1\tcol2\nval11\tval21\nval12\tval22\n", interpreterResult.message()); - - verifySQLStatementExecuted(sqlQuery); - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - } - - @Test - public void testSelectQueryMaxResult() throws SQLException { - - when(phoenixInterpreter.getMaxResult()).thenReturn(1); - - String sqlQuery = "select * from t"; - - result.addColumn("col1", new String[] {"val11", "val12"}); - result.addColumn("col2", new String[] {"val21", "val22"}); - - InterpreterResult interpreterResult = phoenixInterpreter.interpret(sqlQuery, null); - - assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); - assertEquals(InterpreterResult.Type.TABLE, interpreterResult.type()); - assertEquals("col1\tcol2\nval11\tval21\n", interpreterResult.message()); - - verifySQLStatementExecuted(sqlQuery); - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - } - - @Test - public void testSelectQueryWithSpecialCharacters() throws SQLException { - - when(phoenixInterpreter.getMaxResult()).thenReturn(1000); - - String sqlQuery = "select * from t"; - - result.addColumn("co\tl1", new String[] {"val11", "va\tl1\n2"}); - result.addColumn("co\nl2", new String[] {"v\nal21", "val\t22"}); - - InterpreterResult interpreterResult = phoenixInterpreter.interpret(sqlQuery, null); - - assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); - assertEquals(InterpreterResult.Type.TABLE, interpreterResult.type()); - assertEquals("co l1\tco l2\nval11\tv al21\nva l1 2\tval 22\n", interpreterResult.message()); - - verifySQLStatementExecuted(sqlQuery); - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - } - - @Test - public void testExplainQuery() throws SQLException { - - when(phoenixInterpreter.getMaxResult()).thenReturn(1000); - - String sqlQuery = "explain select * from t"; - - result.addColumn("col1", new String[] {"val11", "val12"}); - - InterpreterResult interpreterResult = phoenixInterpreter.interpret(sqlQuery, null); - - assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); - assertEquals(InterpreterResult.Type.TEXT, interpreterResult.type()); - assertEquals("col1\nval11\nval12\n", interpreterResult.message()); - - verifySQLStatementExecuted(sqlQuery); - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - } - - @Test - public void testExplainQueryWithSpecialCharachters() throws SQLException { - - when(phoenixInterpreter.getMaxResult()).thenReturn(1000); - - String sqlQuery = "explain select * from t"; - - result.addColumn("co\tl\n1", new String[] {"va\nl11", "va\tl\n12"}); - - InterpreterResult interpreterResult = phoenixInterpreter.interpret(sqlQuery, null); - - assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); - assertEquals(InterpreterResult.Type.TEXT, interpreterResult.type()); - assertEquals("co\tl\n1\nva\nl11\nva\tl\n12\n", interpreterResult.message()); - - verifySQLStatementExecuted(sqlQuery); - verifyAllResultSetsClosed(); - verifyAllStatementsClosed(); - } -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1c337393/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index d971d9a..0d4abc5 100755 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,6 @@ <module>shell</module> <module>livy</module> <module>hbase</module> - <module>phoenix</module> <module>postgresql</module> <module>jdbc</module> <module>file</module> http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1c337393/zeppelin-distribution/src/bin_license/LICENSE ---------------------------------------------------------------------- diff --git a/zeppelin-distribution/src/bin_license/LICENSE b/zeppelin-distribution/src/bin_license/LICENSE index 57c7224..a19b7b4 100644 --- a/zeppelin-distribution/src/bin_license/LICENSE +++ b/zeppelin-distribution/src/bin_license/LICENSE @@ -40,7 +40,6 @@ The following components are provided under Apache License. (Apache 2.0) Apache Ignite (http://ignite.apache.org/) (Apache 2.0) Apache Kylin (http://kylin.apache.org/) (Apache 2.0) Apache Lens (http://lens.apache.org/) - (Apache 2.0) Apache Phoenix (http://phoenix.apache.org/) (Apache 2.0) Apache Flink (http://flink.apache.org/) (Apache 2.0) Apache Thrift (http://thrift.apache.org/) (Apache 2.0) Apache Lucene (https://lucene.apache.org/) http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1c337393/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java index a7d4498..45fbba4 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java @@ -493,7 +493,6 @@ public class ZeppelinConfiguration extends XMLConfiguration { + "org.apache.zeppelin.livy.LivySparkRInterpreter," + "org.apache.zeppelin.alluxio.AlluxioInterpreter," + "org.apache.zeppelin.file.HDFSFileInterpreter," - + "org.apache.zeppelin.phoenix.PhoenixInterpreter," + "org.apache.zeppelin.postgresql.PostgreSqlInterpreter," + "org.apache.zeppelin.flink.FlinkInterpreter," + "org.apache.zeppelin.python.PythonInterpreter,"
