From 97bfa65fd82de91da7fd4f727c53add691b9d0b4 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Sat, 21 Nov 2015 00:59:51 +0900 Subject: [PATCH 01/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Enable multiple connection properties --- conf/log4j.properties | 4 +- .../apache/zeppelin/hive/HiveInterpreter.java | 292 ++++++++++++------ .../zeppelin/hive/HiveInterpreterTest.java | 66 +++- .../interpreter/remote/RemoteInterpreter.java | 1 + .../remote/RemoteInterpreterServer.java | 1 + .../apache/zeppelin/notebook/Paragraph.java | 6 +- .../zeppelin/notebook/ParagraphTest.java | 30 ++ 7 files changed, 298 insertions(+), 102 deletions(-) create mode 100644 zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java diff --git a/conf/log4j.properties b/conf/log4j.properties index b132ce1030f..bd067a6774f 100644 --- a/conf/log4j.properties +++ b/conf/log4j.properties @@ -15,14 +15,14 @@ # limitations under the License. # -log4j.rootLogger = INFO, dailyfile +log4j.rootLogger = DEBUG, dailyfile log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%d] ({%t} %F[%M]:%L) - %m%n log4j.appender.dailyfile.DatePattern=.yyyy-MM-dd -log4j.appender.dailyfile.Threshold = INFO +log4j.appender.dailyfile.Threshold = DEBUG log4j.appender.dailyfile = org.apache.log4j.DailyRollingFileAppender log4j.appender.dailyfile.File = ${zeppelin.log.file} log4j.appender.dailyfile.layout = org.apache.log4j.PatternLayout diff --git a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java index 5c3dee37387..4250cb4c1e2 100644 --- a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java +++ b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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. @@ -17,15 +17,10 @@ */ package org.apache.zeppelin.hive; -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 java.sql.*; +import java.util.*; +import com.google.common.base.Joiner; import org.apache.commons.lang.StringUtils; import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterContext; @@ -37,6 +32,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static java.lang.String.format; + /** * Hive interpreter for Zeppelin. */ @@ -44,40 +41,95 @@ public class HiveInterpreter extends Interpreter { Logger logger = LoggerFactory.getLogger(HiveInterpreter.class); int commandTimeOut = 600000; - static final String HIVESERVER_URL = "hive.hiveserver2.url"; - static final String HIVESERVER_USER = "hive.hiveserver2.user"; - static final String HIVESERVER_PASSWORD = "hive.hiveserver2.password"; + static final String DEFAULT_KEY = "default"; + static final String DRIVER_KEY = "driver"; + static final String URL_KEY = "url"; + static final String USER_KEY = "user"; + static final String PASSWORD_KEY = "password"; + static final String DOT = "."; + + static final char TSV_KEY = '\t'; + + static final String DEFAULT_DRIVER = DEFAULT_KEY + DOT + DRIVER_KEY; + static final String DEFAULT_URL = DEFAULT_KEY + DOT + URL_KEY; + static final String DEFAULT_USER = DEFAULT_KEY + DOT + USER_KEY; + static final String DEFAULT_PASSWORD = DEFAULT_KEY + DOT + PASSWORD_KEY; + + private final HashMap propertiesMap = new HashMap<>(); + private final Map keyConnectionMap = new HashMap<>(); + private final Map paragraphIdStatementMap = new HashMap<>(); static { Interpreter.register( - "hql", - "hive", - HiveInterpreter.class.getName(), - new InterpreterPropertyBuilder() - .add(HIVESERVER_URL, "jdbc:hive2://localhost:10000", "The URL for HiveServer2.") - .add(HIVESERVER_USER, "hive", "The hive user") - .add(HIVESERVER_PASSWORD, "", "The password for the hive user").build()); + "hql", + "hive", + HiveInterpreter.class.getName(), + new InterpreterPropertyBuilder() + .add(DEFAULT_DRIVER, "org.apache.hive.jdbc.HiveDriver", "Hive JDBC driver") + .add(DEFAULT_URL, "jdbc:hive2://localhost:10000", "The URL for HiveServer2.") + .add(DEFAULT_USER, "hive", "The hive user") + .add(DEFAULT_PASSWORD, "", "The password for the hive user").build()); } public HiveInterpreter(Properties property) { super(property); } - Connection jdbcConnection; - Exception exceptionOnConnect; + public HashMap getPropertiesMap() { + return propertiesMap; + } + +// Connection jdbcConnection; +// Exception exceptionOnConnect; //Test only method - public Connection getJdbcConnection() + +/* public Connection getJdbcConnection() throws SQLException { - String url = getProperty(HIVESERVER_URL); - String user = getProperty(HIVESERVER_USER); - String password = getProperty(HIVESERVER_PASSWORD); + String url = getProperty(DEFAULT_URL); + String user = getProperty(DEFAULT_USER); + String password = getProperty(DEFAULT_PASSWORD); return DriverManager.getConnection(url, user, password); - } + }*/ @Override public void open() { + logger.debug("property: {}", property); + + for (String propertyKey : property.stringPropertyNames()) { + logger.debug("propertyKey: {}", propertyKey); + String[] keyValue = propertyKey.split("\\.", 2); + if (2 == keyValue.length) { + logger.debug("key: {}, value: {}", keyValue[0], keyValue[1]); + Properties prefixProperties; + if (propertiesMap.containsKey(keyValue[0])) { + prefixProperties = propertiesMap.get(keyValue[0]); + } else { + prefixProperties = new Properties(); + propertiesMap.put(keyValue[0], prefixProperties); + } + prefixProperties.put(keyValue[1], property.getProperty(propertyKey)); + } + } + + Set removeKeySet = new HashSet<>(); + for (String key : propertiesMap.keySet()) { + Properties properties = propertiesMap.get(key); + if (!properties.containsKey(DRIVER_KEY) || !properties.containsKey(URL_KEY)) { + logger.error("{} will be ignored. {}.driver and {}.uri is mandatory.", key, key, key); + removeKeySet.add(key); + } + } + + for (String key : removeKeySet) { + propertiesMap.remove(key); + } + + logger.debug("propertiesMap: {}", propertiesMap); + + // old below +/* logger.info("Jdbc open connection called!"); try { String driverName = "org.apache.hive.jdbc.HiveDriver"; @@ -95,12 +147,23 @@ public void open() { catch (SQLException e) { logger.error("Cannot open connection", e); exceptionOnConnect = e; - } + }*/ } @Override public void close() { try { + for (Statement statement : paragraphIdStatementMap.values()) { + statement.close(); + } + + for (Connection connection : keyConnectionMap.values()) { + connection.close(); + } + } catch (SQLException e) { + logger.error("Error while closing...", e); + } +/* try { if (jdbcConnection != null) { jdbcConnection.close(); } @@ -111,78 +174,133 @@ public void close() { finally { jdbcConnection = null; exceptionOnConnect = null; - } + }*/ } - Statement currentStatement; - private InterpreterResult executeSql(String sql) { - try { - if (exceptionOnConnect != null) { - return new InterpreterResult(Code.ERROR, exceptionOnConnect.getMessage()); + private Connection getConnection(String propertyKey) throws ClassNotFoundException, SQLException { + Connection connection = null; + if (keyConnectionMap.containsKey(propertyKey)) { + connection = keyConnectionMap.get(propertyKey); + if (connection.isClosed() || connection.isValid(10)) { + connection.close(); + connection = null; + keyConnectionMap.remove(propertyKey); } - currentStatement = jdbcConnection.createStatement(); - StringBuilder msg = null; - if (StringUtils.containsIgnoreCase(sql, "EXPLAIN ")) { - //return the explain as text, make this visual explain later - msg = new StringBuilder(); + } + if (null == connection) { + Properties properties = propertiesMap.get(propertyKey); + Class.forName(properties.getProperty(DRIVER_KEY)); + String url = properties.getProperty(URL_KEY); + String user = properties.getProperty(USER_KEY); + String password = properties.getProperty(PASSWORD_KEY); + if (null != user && null != password) { + connection = DriverManager.getConnection(url, user, password); + } else { + connection = DriverManager.getConnection(url, properties); } - else { - msg = new StringBuilder("%table "); + keyConnectionMap.put(propertyKey, connection); + } + return connection; + } + + private Statement getStatement(String propertyKey, String paragraphId) + throws SQLException, ClassNotFoundException { + Statement statement = null; + if (paragraphIdStatementMap.containsKey(paragraphId)) { + statement = paragraphIdStatementMap.get(paragraphId); + if (statement.isClosed()) { + statement = null; + paragraphIdStatementMap.remove(paragraphId); } - ResultSet res = currentStatement.executeQuery(sql); - try { - ResultSetMetaData md = res.getMetaData(); - for (int i = 1; i < md.getColumnCount() + 1; i++) { - if (i == 1) { - msg.append(md.getColumnName(i)); - } else { - msg.append("\t" + md.getColumnName(i)); - } - } - msg.append("\n"); - while (res.next()) { - for (int i = 1; i < md.getColumnCount() + 1; i++) { - msg.append(res.getString(i) + "\t"); - } - msg.append("\n"); - } + } + if (null == statement) { + statement = getConnection(propertyKey).createStatement(); + paragraphIdStatementMap.put(paragraphId, statement); + } + return statement; + } + + private ResultSet executeSql(String propertyKey, + String sql, + InterpreterContext interpreterContext) + throws SQLException, ClassNotFoundException { + String paragraphId = interpreterContext.getParagraphId(); + + Statement statement = getStatement(propertyKey, paragraphId); + ResultSet resultSet = statement.executeQuery(sql); + return resultSet; + } + + @Override + public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) { + String propertyKey = getPropertyKey(cmd); + + if (null != propertyKey) { + cmd = cmd.substring(propertyKey.length() + 2); + } else { + propertyKey = DEFAULT_KEY; + } + + cmd = cmd.trim(); + + logger.info("PropertyKey: {}, SQL command: '{}'", propertyKey, cmd); + + try { + ResultSet resultSet = executeSql(propertyKey, cmd, contextInterpreter); + ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); + + StringBuilder sb = new StringBuilder(); + + if (!StringUtils.containsIgnoreCase(cmd, "explain")) { + sb.append("%table"); } - finally { - try { - res.close(); - currentStatement.close(); - } - finally { - currentStatement = null; + int columnCount = resultSetMetaData.getColumnCount(); + ArrayList fields = new ArrayList<>(); + for (int i = 0; i < columnCount; i++) { + fields.add(resultSetMetaData.getColumnName(i + 1)); + } + + sb.append(Joiner.on(TSV_KEY).join(fields)); + sb.append("\n"); + + while (resultSet.next()) { + fields.clear(); + for (int i = 0; i < columnCount; i++) { + fields.add(resultSet.getString(i + 1)); } + sb.append(Joiner.on(TSV_KEY).join(fields)); + sb.append("\n"); } - InterpreterResult rett = new InterpreterResult(Code.SUCCESS, msg.toString()); - return rett; - } - catch (SQLException ex) { - logger.error("Can not run " + sql, ex); - return new InterpreterResult(Code.ERROR, ex.getMessage()); + return new InterpreterResult(Code.SUCCESS, sb.toString()); + + } catch (ClassNotFoundException | SQLException e) { + return new InterpreterResult(Code.ERROR, + format("%s\n%s", e.getClass().getName(), e.getMessage())); } } - @Override - public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) { - logger.info("Run SQL command '" + cmd + "'"); - return executeSql(cmd); + public String getPropertyKey(String cmd) { + int firstLineIndex = cmd.indexOf("\n"); + if (-1 == firstLineIndex) { + firstLineIndex = cmd.length(); + } + int configStartIndex = cmd.indexOf("("); + int configLastIndex = cmd.indexOf(")"); + if (configStartIndex != -1 && configLastIndex != -1 + && configLastIndex < firstLineIndex && configLastIndex < firstLineIndex) { + return cmd.substring(configStartIndex + 1, configLastIndex); + } + return null; } @Override public void cancel(InterpreterContext context) { - if (currentStatement != null) { - try { - currentStatement.cancel(); - } - catch (SQLException ex) { - } - finally { - currentStatement = null; - } + String paragraphId = context.getParagraphId(); + try { + paragraphIdStatementMap.get(paragraphId).cancel(); + } catch (SQLException e) { + logger.error("Error while cancelling...", e); } } @@ -198,8 +316,8 @@ public int getProgress(InterpreterContext context) { @Override public Scheduler getScheduler() { - return SchedulerFactory.singleton().createOrGetFIFOScheduler( - HiveInterpreter.class.getName() + this.hashCode()); + return SchedulerFactory.singleton().createOrGetParallelScheduler( + HiveInterpreter.class.getName() + this.hashCode(), 10); } @Override diff --git a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java index 41ab1089b52..5804060af24 100644 --- a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java +++ b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java @@ -17,24 +17,26 @@ */ package org.apache.zeppelin.hive; -import static org.junit.Assert.assertEquals; - import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; import java.net.URL; import java.sql.*; -import java.util.Calendar; -import java.util.Map; -import java.util.Properties; +import java.sql.Date; +import java.util.*; import java.util.concurrent.Executor; +import org.apache.zeppelin.display.AngularObjectRegistry; +import org.apache.zeppelin.display.GUI; import org.apache.zeppelin.interpreter.InterpreterContext; +import org.apache.zeppelin.interpreter.InterpreterContextRunner; import org.apache.zeppelin.interpreter.InterpreterResult; import org.junit.After; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.*; + /** * Hive interpreter unit tests */ @@ -61,6 +63,55 @@ public void test() { assertEquals(result.type(), InterpreterResult.Type.TEXT); t.close(); } + + @Test + public void parseMultiplePropertiesMap() { + Properties properties = new Properties(); + properties.setProperty("default.driver", "defaultDriver"); + properties.setProperty("default.url", "defaultUri"); + properties.setProperty("default.user", "defaultUser"); + HiveInterpreter hi = new HiveInterpreter(properties); + assertNotNull("propertiesMap is not null", hi.getPropertiesMap()); + assertNotNull("propertiesMap.get(default) is not null", hi.getPropertiesMap().get("default")); + assertTrue("default exists", "defaultDriver".equals(hi.getPropertiesMap().get("default").getProperty("driver"))); + } + + @Test + public void ignoreInvalidSettings() { + Properties properties = new Properties(); + properties.setProperty("default.driver", "defaultDriver"); + properties.setProperty("default.url", "defaultUri"); + properties.setProperty("default.user", "defaultUser"); + properties.setProperty("presto.driver", "com.facebook.presto.jdbc.PrestoDriver"); + HiveInterpreter hi = new HiveInterpreter(properties); + assertTrue("default exists", hi.getPropertiesMap().containsKey("default")); + assertFalse("presto doesn't exists", hi.getPropertiesMap().containsKey("presto")); + } + + @Test + public void getPropertyKey() { + HiveInterpreter hi = new HiveInterpreter(new Properties()); + String testCommand = "(default)\nshow tables"; + assertEquals("get key of default", "default", hi.getPropertyKey(testCommand)); + testCommand = "(default) show tables"; + assertEquals("get key of default", "default", hi.getPropertyKey(testCommand)); + } + + @Test + public void prestoTest() { + InterpreterContext interpreterContext = new InterpreterContext("", "a", "", "", new HashMap(), new GUI(), new AngularObjectRegistry("", null), new ArrayList()); + + Properties properties = new Properties(); + properties.setProperty("default.driver", "defaultDriver"); + properties.setProperty("default.url", "defaultUri"); + properties.setProperty("default.user", "defaultUser"); + properties.setProperty("presto.driver", "com.facebook.presto.jdbc.PrestoDriver"); + properties.setProperty("presto.url", "jdbc:presto://10.10.36.191:8080/hive"); + HiveInterpreter hi = new HiveInterpreter(properties); + hi.open(); + InterpreterResult interpreterResult = hi.interpret("(presto)\nshow catalogs", interpreterContext); + System.out.println(interpreterResult.message()); + } } class MockHiveInterpreter extends HiveInterpreter { @@ -69,11 +120,6 @@ public MockHiveInterpreter(Properties property) { super(property); } - @Override - public Connection getJdbcConnection() - throws SQLException { - return new MockConnection(); - } } class MockResultSetMetadata implements ResultSetMetaData { diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java index ef1f115dea7..27f4b652531 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java @@ -193,6 +193,7 @@ public void close() { @Override public InterpreterResult interpret(String st, InterpreterContext context) { + logger.debug("st: {}", st); FormType form = getFormType(); RemoteInterpreterProcess interpreterProcess = getInterpreterProcess(); Client client = null; diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java index d6768c9d0fd..737710469dd 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java @@ -203,6 +203,7 @@ public void close(String className) throws TException { @Override public RemoteInterpreterResult interpret(String className, String st, RemoteInterpreterContext interpreterContext) throws TException { + logger.debug("st: {}", st); Interpreter intp = getInterpreter(className); InterpreterContext context = convert(interpreterContext); diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java index 28c49c6f55f..b7b186af99a 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java @@ -103,7 +103,7 @@ public static String getRequiredReplName(String text) { int scriptHeadIndex = 0; for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); - if (ch == ' ' || ch == '\n') { + if (ch == ' ' || ch == '\n' || ch == '(') { scriptHeadIndex = i; break; } @@ -132,10 +132,10 @@ public static String getScriptBody(String text) { if (magic == null) { return text; } - if (magic.length() + 2 >= text.length()) { + if (magic.length() + 1 >= text.length()) { return ""; } - return text.substring(magic.length() + 2); + return text.substring(magic.length() + 1); } public NoteInterpreterLoader getNoteReplLoader() { diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java new file mode 100644 index 00000000000..23e1847c407 --- /dev/null +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java @@ -0,0 +1,30 @@ +/* + * 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.notebook; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ParagraphTest { + @Test + public void scriptBody() { + String text = "%spark(1234567"; + assertEquals("(1234567", Paragraph.getScriptBody(text)); + } +} From 87ee87a0ae3d9a6203537d5d33d32e4873313b27 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Sat, 21 Nov 2015 01:01:37 +0900 Subject: [PATCH 02/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Revert log4j.properties --- conf/log4j.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/log4j.properties b/conf/log4j.properties index bd067a6774f..b132ce1030f 100644 --- a/conf/log4j.properties +++ b/conf/log4j.properties @@ -15,14 +15,14 @@ # limitations under the License. # -log4j.rootLogger = DEBUG, dailyfile +log4j.rootLogger = INFO, dailyfile log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%d] ({%t} %F[%M]:%L) - %m%n log4j.appender.dailyfile.DatePattern=.yyyy-MM-dd -log4j.appender.dailyfile.Threshold = DEBUG +log4j.appender.dailyfile.Threshold = INFO log4j.appender.dailyfile = org.apache.log4j.DailyRollingFileAppender log4j.appender.dailyfile.File = ${zeppelin.log.file} log4j.appender.dailyfile.layout = org.apache.log4j.PatternLayout From df9f3cb76bd95370a0f183a763fa533326870c26 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Sat, 21 Nov 2015 02:34:01 +0900 Subject: [PATCH 03/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Remove commented codes - Fixed license part --- .../apache/zeppelin/hive/HiveInterpreter.java | 69 +++++-------------- 1 file changed, 16 insertions(+), 53 deletions(-) diff --git a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java index 4250cb4c1e2..a3fb1078c7f 100644 --- a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java +++ b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java @@ -6,9 +6,9 @@ * 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 - *

+ * + * 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. @@ -17,8 +17,19 @@ */ package org.apache.zeppelin.hive; -import java.sql.*; -import java.util.*; +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.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; import com.google.common.base.Joiner; import org.apache.commons.lang.StringUtils; @@ -39,7 +50,6 @@ */ public class HiveInterpreter extends Interpreter { Logger logger = LoggerFactory.getLogger(HiveInterpreter.class); - int commandTimeOut = 600000; static final String DEFAULT_KEY = "default"; static final String DRIVER_KEY = "driver"; @@ -79,20 +89,6 @@ public HashMap getPropertiesMap() { return propertiesMap; } -// Connection jdbcConnection; -// Exception exceptionOnConnect; - - //Test only method - -/* public Connection getJdbcConnection() - throws SQLException { - String url = getProperty(DEFAULT_URL); - String user = getProperty(DEFAULT_USER); - String password = getProperty(DEFAULT_PASSWORD); - - return DriverManager.getConnection(url, user, password); - }*/ - @Override public void open() { logger.debug("property: {}", property); @@ -127,27 +123,6 @@ public void open() { } logger.debug("propertiesMap: {}", propertiesMap); - - // old below -/* - logger.info("Jdbc open connection called!"); - try { - String driverName = "org.apache.hive.jdbc.HiveDriver"; - Class.forName(driverName); - } catch (ClassNotFoundException e) { - logger.error("Can not open connection", e); - exceptionOnConnect = e; - return; - } - try { - jdbcConnection = getJdbcConnection(); - exceptionOnConnect = null; - logger.info("Successfully created Jdbc connection"); - } - catch (SQLException e) { - logger.error("Cannot open connection", e); - exceptionOnConnect = e; - }*/ } @Override @@ -163,18 +138,6 @@ public void close() { } catch (SQLException e) { logger.error("Error while closing...", e); } -/* try { - if (jdbcConnection != null) { - jdbcConnection.close(); - } - } - catch (SQLException e) { - logger.error("Cannot close connection", e); - } - finally { - jdbcConnection = null; - exceptionOnConnect = null; - }*/ } private Connection getConnection(String propertyKey) throws ClassNotFoundException, SQLException { From 9293d78fc36c8fe9c5a1a5c6f2377572ba85bd0f Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Mon, 23 Nov 2015 18:11:19 +0900 Subject: [PATCH 04/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Fixed linefeed to variable --- .../apache/zeppelin/hive/HiveInterpreter.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java index a3fb1078c7f..66be012b70e 100644 --- a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java +++ b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java @@ -58,16 +58,17 @@ public class HiveInterpreter extends Interpreter { static final String PASSWORD_KEY = "password"; static final String DOT = "."; - static final char TSV_KEY = '\t'; + static final char TSV = '\t'; + static final char LINEFEED = '\n'; static final String DEFAULT_DRIVER = DEFAULT_KEY + DOT + DRIVER_KEY; static final String DEFAULT_URL = DEFAULT_KEY + DOT + URL_KEY; static final String DEFAULT_USER = DEFAULT_KEY + DOT + USER_KEY; static final String DEFAULT_PASSWORD = DEFAULT_KEY + DOT + PASSWORD_KEY; - private final HashMap propertiesMap = new HashMap<>(); - private final Map keyConnectionMap = new HashMap<>(); - private final Map paragraphIdStatementMap = new HashMap<>(); + private final HashMap propertiesMap; + private final Map keyConnectionMap; + private final Map paragraphIdStatementMap; static { Interpreter.register( @@ -83,6 +84,9 @@ public class HiveInterpreter extends Interpreter { public HiveInterpreter(Properties property) { super(property); + propertiesMap = new HashMap<>(); + keyConnectionMap = new HashMap<>(); + paragraphIdStatementMap = new HashMap<>(); } public HashMap getPropertiesMap() { @@ -113,7 +117,7 @@ public void open() { for (String key : propertiesMap.keySet()) { Properties properties = propertiesMap.get(key); if (!properties.containsKey(DRIVER_KEY) || !properties.containsKey(URL_KEY)) { - logger.error("{} will be ignored. {}.driver and {}.uri is mandatory.", key, key, key); + logger.error("{} will be ignored. {}.{} and {}.{} is mandatory.", key, DRIVER_KEY, key, key, URL_KEY); removeKeySet.add(key); } } @@ -140,7 +144,7 @@ public void close() { } } - private Connection getConnection(String propertyKey) throws ClassNotFoundException, SQLException { + public Connection getConnection(String propertyKey) throws ClassNotFoundException, SQLException { Connection connection = null; if (keyConnectionMap.containsKey(propertyKey)) { connection = keyConnectionMap.get(propertyKey); @@ -166,7 +170,7 @@ private Connection getConnection(String propertyKey) throws ClassNotFoundExcepti return connection; } - private Statement getStatement(String propertyKey, String paragraphId) + public Statement getStatement(String propertyKey, String paragraphId) throws SQLException, ClassNotFoundException { Statement statement = null; if (paragraphIdStatementMap.containsKey(paragraphId)) { @@ -183,7 +187,7 @@ private Statement getStatement(String propertyKey, String paragraphId) return statement; } - private ResultSet executeSql(String propertyKey, + public ResultSet executeSql(String propertyKey, String sql, InterpreterContext interpreterContext) throws SQLException, ClassNotFoundException { @@ -223,23 +227,23 @@ public InterpreterResult interpret(String cmd, InterpreterContext contextInterpr fields.add(resultSetMetaData.getColumnName(i + 1)); } - sb.append(Joiner.on(TSV_KEY).join(fields)); - sb.append("\n"); + sb.append(Joiner.on(TSV).join(fields)); + sb.append(LINEFEED); while (resultSet.next()) { fields.clear(); for (int i = 0; i < columnCount; i++) { fields.add(resultSet.getString(i + 1)); } - sb.append(Joiner.on(TSV_KEY).join(fields)); - sb.append("\n"); + sb.append(Joiner.on(TSV).join(fields)); + sb.append(LINEFEED); } return new InterpreterResult(Code.SUCCESS, sb.toString()); } catch (ClassNotFoundException | SQLException e) { return new InterpreterResult(Code.ERROR, - format("%s\n%s", e.getClass().getName(), e.getMessage())); + format("%s%c%s", e.getClass().getName(), LINEFEED, e.getMessage())); } } @@ -287,5 +291,4 @@ public Scheduler getScheduler() { public List completion(String buf, int cursor) { return null; } - } From 85e4914855e08d4288aaa5e94f8c1899d11d2925 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Mon, 23 Nov 2015 18:54:12 +0900 Subject: [PATCH 05/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Fixed style --- .../main/java/org/apache/zeppelin/hive/HiveInterpreter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java index 66be012b70e..0dd6040092f 100644 --- a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java +++ b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java @@ -117,7 +117,8 @@ public void open() { for (String key : propertiesMap.keySet()) { Properties properties = propertiesMap.get(key); if (!properties.containsKey(DRIVER_KEY) || !properties.containsKey(URL_KEY)) { - logger.error("{} will be ignored. {}.{} and {}.{} is mandatory.", key, DRIVER_KEY, key, key, URL_KEY); + logger.error("{} will be ignored. {}.{} and {}.{} is mandatory.", + key, DRIVER_KEY, key, key, URL_KEY); removeKeySet.add(key); } } From 8aa7601b90e4fbe178e8e97a9456088b21608a68 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Tue, 24 Nov 2015 13:28:53 +0900 Subject: [PATCH 06/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Fixed some tests --- hive/pom.xml | 6 ++ .../apache/zeppelin/hive/HiveInterpreter.java | 4 +- .../zeppelin/hive/HiveInterpreterTest.java | 69 ++++++++++++------- .../zeppelin/notebook/NotebookTest.java | 2 +- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/hive/pom.xml b/hive/pom.xml index f4867d3e150..ca41d3887e6 100644 --- a/hive/pom.xml +++ b/hive/pom.xml @@ -87,6 +87,12 @@ junit test + + com.h2database + h2 + 1.4.190 + test + diff --git a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java index 0dd6040092f..bf3dd401db7 100644 --- a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java +++ b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java @@ -284,8 +284,8 @@ public int getProgress(InterpreterContext context) { @Override public Scheduler getScheduler() { - return SchedulerFactory.singleton().createOrGetParallelScheduler( - HiveInterpreter.class.getName() + this.hashCode(), 10); + return SchedulerFactory.singleton().createOrGetFIFOScheduler( + HiveInterpreter.class.getName() + this.hashCode()); } @Override diff --git a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java index 5804060af24..f8d8685c30a 100644 --- a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java +++ b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java @@ -17,32 +17,53 @@ */ package org.apache.zeppelin.hive; +import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.*; import java.sql.Date; import java.util.*; import java.util.concurrent.Executor; -import org.apache.zeppelin.display.AngularObjectRegistry; -import org.apache.zeppelin.display.GUI; import org.apache.zeppelin.interpreter.InterpreterContext; -import org.apache.zeppelin.interpreter.InterpreterContextRunner; import org.apache.zeppelin.interpreter.InterpreterResult; import org.junit.After; -import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.*; +import static java.lang.String.format; /** * Hive interpreter unit tests */ public class HiveInterpreterTest { - @Before - public void setUp() throws Exception { + static String jdbcConnection; + + private static String getJdbcConnection() throws IOException { + if(null == jdbcConnection) { + Path tmpDir = Files.createTempDirectory("h2-test-"); + tmpDir.toFile().deleteOnExit(); + jdbcConnection = format("jdbc:h2:%s", tmpDir); + } + return jdbcConnection; + } + @BeforeClass + public static void setUp() throws Exception { + + Class.forName("org.h2.Driver"); + Connection connection = DriverManager.getConnection(getJdbcConnection()); + Statement statement = connection.createStatement(); + statement.execute( + "DROP TABLE IF EXISTS test_table; " + + "CREATE TABLE test_table(id varchar(255), name varchar(255));"); + statement.execute( + "insert into test_table(id, name) values ('a', 'a_name'),('b', 'b_name');" + ); } @After @@ -50,16 +71,23 @@ public void tearDown() throws Exception { } @Test - public void test() { - HiveInterpreter t = new MockHiveInterpreter(new Properties()); + public void test() throws IOException { + Properties properties = new Properties(); + properties.setProperty("default.driver", "org.h2.Driver"); + properties.setProperty("default.url", getJdbcConnection()); + properties.setProperty("default.user", ""); + properties.setProperty("default.password", ""); + HiveInterpreter t = new HiveInterpreter(properties); t.open(); + InterpreterContext interpreterContext = new InterpreterContext(null, "a", null, null, null, null, null, null); + //simple select test - InterpreterResult result = t.interpret("select * from t", null); + InterpreterResult result = t.interpret("select * from test_table", interpreterContext); assertEquals(result.type(), InterpreterResult.Type.TABLE); //explain test - result = t.interpret("explain select * from t", null); + result = t.interpret("explain select * from test_table", interpreterContext); assertEquals(result.type(), InterpreterResult.Type.TEXT); t.close(); } @@ -71,9 +99,11 @@ public void parseMultiplePropertiesMap() { properties.setProperty("default.url", "defaultUri"); properties.setProperty("default.user", "defaultUser"); HiveInterpreter hi = new HiveInterpreter(properties); + hi.open(); assertNotNull("propertiesMap is not null", hi.getPropertiesMap()); assertNotNull("propertiesMap.get(default) is not null", hi.getPropertiesMap().get("default")); assertTrue("default exists", "defaultDriver".equals(hi.getPropertiesMap().get("default").getProperty("driver"))); + hi.close(); } @Test @@ -84,8 +114,10 @@ public void ignoreInvalidSettings() { properties.setProperty("default.user", "defaultUser"); properties.setProperty("presto.driver", "com.facebook.presto.jdbc.PrestoDriver"); HiveInterpreter hi = new HiveInterpreter(properties); + hi.open(); assertTrue("default exists", hi.getPropertiesMap().containsKey("default")); assertFalse("presto doesn't exists", hi.getPropertiesMap().containsKey("presto")); + hi.close(); } @Test @@ -95,22 +127,7 @@ public void getPropertyKey() { assertEquals("get key of default", "default", hi.getPropertyKey(testCommand)); testCommand = "(default) show tables"; assertEquals("get key of default", "default", hi.getPropertyKey(testCommand)); - } - - @Test - public void prestoTest() { - InterpreterContext interpreterContext = new InterpreterContext("", "a", "", "", new HashMap(), new GUI(), new AngularObjectRegistry("", null), new ArrayList()); - - Properties properties = new Properties(); - properties.setProperty("default.driver", "defaultDriver"); - properties.setProperty("default.url", "defaultUri"); - properties.setProperty("default.user", "defaultUser"); - properties.setProperty("presto.driver", "com.facebook.presto.jdbc.PrestoDriver"); - properties.setProperty("presto.url", "jdbc:presto://10.10.36.191:8080/hive"); - HiveInterpreter hi = new HiveInterpreter(properties); - hi.open(); - InterpreterResult interpreterResult = hi.interpret("(presto)\nshow catalogs", interpreterContext); - System.out.println(interpreterResult.message()); + hi.close(); } } diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java index ee35773b12f..c0815b66b6e 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java @@ -114,7 +114,7 @@ public void testSelectingReplImplementation() throws IOException { p2.setText("%mock2 hello world"); note.run(p2.getId()); while(p2.isTerminated()==false || p2.getResult()==null) Thread.yield(); - assertEquals("repl2: hello world", p2.getResult().message()); + assertEquals("repl2: hello world", p2.getResult().message()); } @Test From 5fa4fd718241c9388a93c0023c106b7e79edbf45 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Tue, 24 Nov 2015 14:31:47 +0900 Subject: [PATCH 07/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Fixed getScriptBody return after trimming --- .../src/main/java/org/apache/zeppelin/notebook/Paragraph.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java index b7b186af99a..205f834bef2 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java @@ -135,7 +135,7 @@ public static String getScriptBody(String text) { if (magic.length() + 1 >= text.length()) { return ""; } - return text.substring(magic.length() + 1); + return text.substring(magic.length() + 1).trim(); } public NoteInterpreterLoader getNoteReplLoader() { From 26160507ce52983ace9d1ae17420f306ce167dcc Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Tue, 24 Nov 2015 14:44:05 +0900 Subject: [PATCH 08/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Restored some tests from the beginning --- .../test/java/org/apache/zeppelin/notebook/NotebookTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java index c0815b66b6e..ee35773b12f 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java @@ -114,7 +114,7 @@ public void testSelectingReplImplementation() throws IOException { p2.setText("%mock2 hello world"); note.run(p2.getId()); while(p2.isTerminated()==false || p2.getResult()==null) Thread.yield(); - assertEquals("repl2: hello world", p2.getResult().message()); + assertEquals("repl2: hello world", p2.getResult().message()); } @Test From f2b61c0aa76f2a1595a5779af05571c815e285b3 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Tue, 24 Nov 2015 16:13:54 +0900 Subject: [PATCH 09/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Restored ParallelScheduler from FIFOScheduler --- .../main/java/org/apache/zeppelin/hive/HiveInterpreter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java index bf3dd401db7..0dd6040092f 100644 --- a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java +++ b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java @@ -284,8 +284,8 @@ public int getProgress(InterpreterContext context) { @Override public Scheduler getScheduler() { - return SchedulerFactory.singleton().createOrGetFIFOScheduler( - HiveInterpreter.class.getName() + this.hashCode()); + return SchedulerFactory.singleton().createOrGetParallelScheduler( + HiveInterpreter.class.getName() + this.hashCode(), 10); } @Override From dcb65ae1e6b0f17750c233654cede2333c54dec1 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Wed, 25 Nov 2015 13:47:21 +0900 Subject: [PATCH 10/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Revised executeSql from Postgresql.executeSql --- .../apache/zeppelin/hive/HiveInterpreter.java | 165 ++++++++++++------ .../zeppelin/hive/HiveInterpreterTest.java | 71 ++++++++ .../zeppelin/notebook/ParagraphTest.java | 10 +- 3 files changed, 192 insertions(+), 54 deletions(-) diff --git a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java index 0dd6040092f..d70c0489a76 100644 --- a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java +++ b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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. @@ -23,7 +23,6 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; -import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -31,8 +30,6 @@ import java.util.Properties; import java.util.Set; -import com.google.common.base.Joiner; -import org.apache.commons.lang.StringUtils; import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterPropertyBuilder; @@ -43,7 +40,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static java.lang.String.format; +import static org.apache.commons.lang.StringUtils.containsIgnoreCase; /** * Hive interpreter for Zeppelin. @@ -51,6 +48,12 @@ public class HiveInterpreter extends Interpreter { Logger logger = LoggerFactory.getLogger(HiveInterpreter.class); + static final String COMMON_KEY = "common"; + static final String MAX_LINE_KEY = "max_count"; + static final String MAX_LINE_DEFAULT = "1000"; + static final String MAX_RETRY_KEY = "max_retry"; + static final String MAX_RETRY_DEFAULT = "3"; + static final String DEFAULT_KEY = "default"; static final String DRIVER_KEY = "driver"; static final String URL_KEY = "url"; @@ -58,8 +61,14 @@ public class HiveInterpreter extends Interpreter { static final String PASSWORD_KEY = "password"; static final String DOT = "."; - static final char TSV = '\t'; - static final char LINEFEED = '\n'; + static final char TAB = '\t'; + static final char NEWLINE = '\n'; + static final String EXPLAIN_PREDICATE = "EXPLAIN "; + static final String TABLE_MAGIC_TAG = "%table "; + static final String UPDATE_COUNT_HEADER = "Update Count"; + + static final String COMMON_MAX_LINE = COMMON_KEY + DOT + MAX_LINE_KEY; + static final String COMMON_MAX_RETRY = COMMON_KEY + DOT + MAX_RETRY_KEY; static final String DEFAULT_DRIVER = DEFAULT_KEY + DOT + DRIVER_KEY; static final String DEFAULT_URL = DEFAULT_KEY + DOT + URL_KEY; @@ -76,6 +85,8 @@ public class HiveInterpreter extends Interpreter { "hive", HiveInterpreter.class.getName(), new InterpreterPropertyBuilder() + .add(COMMON_MAX_LINE, MAX_LINE_DEFAULT, "Maximum line of results") + .add(COMMON_MAX_RETRY, MAX_RETRY_DEFAULT, "Maximum number of retry while error") .add(DEFAULT_DRIVER, "org.apache.hive.jdbc.HiveDriver", "Hive JDBC driver") .add(DEFAULT_URL, "jdbc:hive2://localhost:10000", "The URL for HiveServer2.") .add(DEFAULT_USER, "hive", "The hive user") @@ -115,11 +126,13 @@ public void open() { Set removeKeySet = new HashSet<>(); for (String key : propertiesMap.keySet()) { - Properties properties = propertiesMap.get(key); - if (!properties.containsKey(DRIVER_KEY) || !properties.containsKey(URL_KEY)) { - logger.error("{} will be ignored. {}.{} and {}.{} is mandatory.", - key, DRIVER_KEY, key, key, URL_KEY); - removeKeySet.add(key); + if (!COMMON_KEY.equals(key)) { + Properties properties = propertiesMap.get(key); + if (!properties.containsKey(DRIVER_KEY) || !properties.containsKey(URL_KEY)) { + logger.error("{} will be ignored. {}.{} and {}.{} is mandatory.", + key, DRIVER_KEY, key, key, URL_KEY); + removeKeySet.add(key); + } } } @@ -136,10 +149,12 @@ public void close() { for (Statement statement : paragraphIdStatementMap.values()) { statement.close(); } + paragraphIdStatementMap.clear(); for (Connection connection : keyConnectionMap.values()) { connection.close(); } + keyConnectionMap.clear(); } catch (SQLException e) { logger.error("Error while closing...", e); } @@ -149,7 +164,7 @@ public Connection getConnection(String propertyKey) throws ClassNotFoundExceptio Connection connection = null; if (keyConnectionMap.containsKey(propertyKey)) { connection = keyConnectionMap.get(propertyKey); - if (connection.isClosed() || connection.isValid(10)) { + if (connection.isClosed() || !connection.isValid(10)) { connection.close(); connection = null; keyConnectionMap.remove(propertyKey); @@ -188,15 +203,81 @@ public Statement getStatement(String propertyKey, String paragraphId) return statement; } - public ResultSet executeSql(String propertyKey, - String sql, - InterpreterContext interpreterContext) - throws SQLException, ClassNotFoundException { + public InterpreterResult executeSql(String propertyKey, + String sql, + InterpreterContext interpreterContext) { String paragraphId = interpreterContext.getParagraphId(); - Statement statement = getStatement(propertyKey, paragraphId); - ResultSet resultSet = statement.executeQuery(sql); - return resultSet; + try { + + Statement statement = getStatement(propertyKey, paragraphId); + + statement.setMaxRows(getMaxResult()); + + StringBuilder msg = null; + + if (containsIgnoreCase(sql, EXPLAIN_PREDICATE)) { + msg = new StringBuilder(); + } else { + msg = new StringBuilder(TABLE_MAGIC_TAG); + } + + ResultSet resultSet = null; + + try { + boolean isResultSetAvailable = statement.execute(sql); + + if (isResultSetAvailable) { + resultSet = statement.getResultSet(); + + ResultSetMetaData md = resultSet.getMetaData(); + + for (int i = 1; i < md.getColumnCount() + 1; i++) { + if (i > 1) { + msg.append(TAB); + } + msg.append(md.getColumnName(i)); + } + msg.append(NEWLINE); + + int displayRowCount = 0; + while (resultSet.next() && displayRowCount < getMaxResult()) { + for (int i = 1; i < md.getColumnCount() + 1; i++) { + msg.append(resultSet.getString(i)); + if (i != md.getColumnCount()) { + msg.append(TAB); + } + } + msg.append(NEWLINE); + displayRowCount++; + } + } else { + // Response contains either an update count or there are no results. + int updateCount = statement.getUpdateCount(); + msg.append(UPDATE_COUNT_HEADER).append(NEWLINE); + msg.append(updateCount).append(NEWLINE); + } + } finally { + try { + if (resultSet != null) { + resultSet.close(); + } + statement.close(); + } finally { + removeStatement(paragraphId); + } + } + + return new InterpreterResult(Code.SUCCESS, msg.toString()); + + } catch (SQLException | ClassNotFoundException ex) { + logger.error("Cannot run " + sql, ex); + return new InterpreterResult(Code.ERROR, ex.getMessage()); + } + } + + private void removeStatement(String paragraphId) { + paragraphIdStatementMap.remove(paragraphId); } @Override @@ -213,39 +294,17 @@ public InterpreterResult interpret(String cmd, InterpreterContext contextInterpr logger.info("PropertyKey: {}, SQL command: '{}'", propertyKey, cmd); - try { - ResultSet resultSet = executeSql(propertyKey, cmd, contextInterpreter); - ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); - - StringBuilder sb = new StringBuilder(); - - if (!StringUtils.containsIgnoreCase(cmd, "explain")) { - sb.append("%table"); - } - int columnCount = resultSetMetaData.getColumnCount(); - ArrayList fields = new ArrayList<>(); - for (int i = 0; i < columnCount; i++) { - fields.add(resultSetMetaData.getColumnName(i + 1)); - } - - sb.append(Joiner.on(TSV).join(fields)); - sb.append(LINEFEED); - - while (resultSet.next()) { - fields.clear(); - for (int i = 0; i < columnCount; i++) { - fields.add(resultSet.getString(i + 1)); - } - sb.append(Joiner.on(TSV).join(fields)); - sb.append(LINEFEED); - } + return executeSql(propertyKey, cmd, contextInterpreter); + } - return new InterpreterResult(Code.SUCCESS, sb.toString()); + private int getMaxResult() { + return Integer.valueOf( + propertiesMap.get(COMMON_KEY).getProperty(MAX_LINE_KEY, MAX_LINE_DEFAULT)); + } - } catch (ClassNotFoundException | SQLException e) { - return new InterpreterResult(Code.ERROR, - format("%s%c%s", e.getClass().getName(), LINEFEED, e.getMessage())); - } + private int getMaxRetry() { + return Integer.valueOf( + propertiesMap.get(COMMON_KEY).getProperty(MAX_RETRY_KEY, MAX_RETRY_DEFAULT)); } public String getPropertyKey(String cmd) { diff --git a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java index f8d8685c30a..b22f930df1b 100644 --- a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java +++ b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java @@ -34,6 +34,8 @@ import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static org.junit.Assert.*; import static java.lang.String.format; @@ -70,9 +72,73 @@ public static void setUp() throws Exception { public void tearDown() throws Exception { } + @Test + public void readTest() throws IOException { + Properties properties = new Properties(); + properties.setProperty("common.max_count", "1000"); + properties.setProperty("common.max_retry", "3"); + properties.setProperty("default.driver", "org.h2.Driver"); + properties.setProperty("default.url", getJdbcConnection()); + properties.setProperty("default.user", ""); + properties.setProperty("default.password", ""); + HiveInterpreter t = new HiveInterpreter(properties); + t.open(); + + assertEquals("SCHEMA_NAME\nINFORMATION_SCHEMA\nPUBLIC\n", + t.interpret("show databases", new InterpreterContext("", "1", "","", null,null,null,null)).message()); + assertEquals("ID\tNAME\na\ta_name\nb\tb_name\n", + t.interpret("select * from test_table", new InterpreterContext("", "1", "","", null,null,null,null)).message()); + } + + @Test + public void readTestWithConfiguration() throws IOException { + Properties properties = new Properties(); + properties.setProperty("common.max_count", "1000"); + properties.setProperty("common.max_retry", "3"); + properties.setProperty("default.driver", "wrong.Driver"); + properties.setProperty("default.url", getJdbcConnection()); + properties.setProperty("default.user", ""); + properties.setProperty("default.password", ""); + properties.setProperty("h2.driver", "org.h2.Driver"); + properties.setProperty("h2.url", getJdbcConnection()); + properties.setProperty("h2.user", ""); + properties.setProperty("h2.password", ""); + HiveInterpreter t = new HiveInterpreter(properties); + t.open(); + + assertEquals("SCHEMA_NAME\nINFORMATION_SCHEMA\nPUBLIC\n", + t.interpret("(h2) show databases", new InterpreterContext("", "1", "","", null,null,null,null)).message()); + assertEquals("ID\tNAME\na\ta_name\nb\tb_name\n", + t.interpret("(h2)\n select * from test_table", new InterpreterContext("", "1", "","", null,null,null,null)).message()); + } + + @Test + public void jdbcRestart() throws IOException, SQLException, ClassNotFoundException { + Properties properties = new Properties(); + properties.setProperty("common.max_count", "1000"); + properties.setProperty("common.max_retry", "3"); + properties.setProperty("default.driver", "org.h2.Driver"); + properties.setProperty("default.url", getJdbcConnection()); + properties.setProperty("default.user", ""); + properties.setProperty("default.password", ""); + HiveInterpreter t = new HiveInterpreter(properties); + t.open(); + + assertEquals("SCHEMA_NAME\nINFORMATION_SCHEMA\nPUBLIC\n", + t.interpret("show databases", new InterpreterContext("", "1", "","", null,null,null,null)).message()); + + t.getConnection("default").close(); + + InterpreterResult interpreterResult = + t.interpret("select * from test_table", new InterpreterContext("", "1", "","", null,null,null,null)); + assertEquals("ID\tNAME\na\ta_name\nb\tb_name\n", interpreterResult.message()); + } + @Test public void test() throws IOException { Properties properties = new Properties(); + properties.setProperty("common.max_count", "1000"); + properties.setProperty("common.max_retry", "3"); properties.setProperty("default.driver", "org.h2.Driver"); properties.setProperty("default.url", getJdbcConnection()); properties.setProperty("default.user", ""); @@ -95,6 +161,8 @@ public void test() throws IOException { @Test public void parseMultiplePropertiesMap() { Properties properties = new Properties(); + properties.setProperty("common.max_count", "1000"); + properties.setProperty("common.max_retry", "3"); properties.setProperty("default.driver", "defaultDriver"); properties.setProperty("default.url", "defaultUri"); properties.setProperty("default.user", "defaultUser"); @@ -109,6 +177,8 @@ public void parseMultiplePropertiesMap() { @Test public void ignoreInvalidSettings() { Properties properties = new Properties(); + properties.setProperty("common.max_count", "1000"); + properties.setProperty("common.max_retry", "3"); properties.setProperty("default.driver", "defaultDriver"); properties.setProperty("default.url", "defaultUri"); properties.setProperty("default.user", "defaultUser"); @@ -123,6 +193,7 @@ public void ignoreInvalidSettings() { @Test public void getPropertyKey() { HiveInterpreter hi = new HiveInterpreter(new Properties()); + hi.open(); String testCommand = "(default)\nshow tables"; assertEquals("get key of default", "default", hi.getPropertyKey(testCommand)); testCommand = "(default) show tables"; diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java index 23e1847c407..87805cef133 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java @@ -23,8 +23,16 @@ public class ParagraphTest { @Test - public void scriptBody() { + public void scriptBodyWithReplName() { String text = "%spark(1234567"; assertEquals("(1234567", Paragraph.getScriptBody(text)); + + text = "%table 1234567"; + assertEquals("1234567", Paragraph.getScriptBody(text)); + } + @Test + public void scriptBodyWithoutReplName() { + String text = "12345678"; + assertEquals(text, Paragraph.getScriptBody(text)); } } From 4867c6fccf1f590b74932271317d3f2c1f080336 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Wed, 25 Nov 2015 14:19:19 +0900 Subject: [PATCH 11/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Fixed test case to be more general --- .../org/apache/zeppelin/hive/HiveInterpreterTest.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java index b22f930df1b..4f9a60e86bd 100644 --- a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java +++ b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java @@ -84,8 +84,7 @@ public void readTest() throws IOException { HiveInterpreter t = new HiveInterpreter(properties); t.open(); - assertEquals("SCHEMA_NAME\nINFORMATION_SCHEMA\nPUBLIC\n", - t.interpret("show databases", new InterpreterContext("", "1", "","", null,null,null,null)).message()); + assertTrue(t.interpret("show databases", new InterpreterContext("", "1", "","", null,null,null,null)).message().contains("SCHEMA_NAME")); assertEquals("ID\tNAME\na\ta_name\nb\tb_name\n", t.interpret("select * from test_table", new InterpreterContext("", "1", "","", null,null,null,null)).message()); } @@ -106,8 +105,7 @@ public void readTestWithConfiguration() throws IOException { HiveInterpreter t = new HiveInterpreter(properties); t.open(); - assertEquals("SCHEMA_NAME\nINFORMATION_SCHEMA\nPUBLIC\n", - t.interpret("(h2) show databases", new InterpreterContext("", "1", "","", null,null,null,null)).message()); + assertTrue(t.interpret("show databases", new InterpreterContext("", "1", "","", null,null,null,null)).message().contains("SCHEMA_NAME")); assertEquals("ID\tNAME\na\ta_name\nb\tb_name\n", t.interpret("(h2)\n select * from test_table", new InterpreterContext("", "1", "","", null,null,null,null)).message()); } @@ -124,8 +122,7 @@ public void jdbcRestart() throws IOException, SQLException, ClassNotFoundExcepti HiveInterpreter t = new HiveInterpreter(properties); t.open(); - assertEquals("SCHEMA_NAME\nINFORMATION_SCHEMA\nPUBLIC\n", - t.interpret("show databases", new InterpreterContext("", "1", "","", null,null,null,null)).message()); + assertTrue(t.interpret("show databases", new InterpreterContext("", "1", "","", null,null,null,null)).message().contains("SCHEMA_NAME")); t.getConnection("default").close(); From b4f1a1c1560c16ef9fb08257d7eee9bd52bbcced Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Wed, 25 Nov 2015 14:42:02 +0900 Subject: [PATCH 12/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Fixed test case to be more general --- .../java/org/apache/zeppelin/hive/HiveInterpreterTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java index 4f9a60e86bd..410673d025e 100644 --- a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java +++ b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java @@ -105,7 +105,6 @@ public void readTestWithConfiguration() throws IOException { HiveInterpreter t = new HiveInterpreter(properties); t.open(); - assertTrue(t.interpret("show databases", new InterpreterContext("", "1", "","", null,null,null,null)).message().contains("SCHEMA_NAME")); assertEquals("ID\tNAME\na\ta_name\nb\tb_name\n", t.interpret("(h2)\n select * from test_table", new InterpreterContext("", "1", "","", null,null,null,null)).message()); } @@ -122,11 +121,13 @@ public void jdbcRestart() throws IOException, SQLException, ClassNotFoundExcepti HiveInterpreter t = new HiveInterpreter(properties); t.open(); - assertTrue(t.interpret("show databases", new InterpreterContext("", "1", "","", null,null,null,null)).message().contains("SCHEMA_NAME")); + InterpreterResult interpreterResult = + t.interpret("select * from test_table", new InterpreterContext("", "1", "","", null,null,null,null)); + assertEquals("ID\tNAME\na\ta_name\nb\tb_name\n", interpreterResult.message()); t.getConnection("default").close(); - InterpreterResult interpreterResult = + interpreterResult = t.interpret("select * from test_table", new InterpreterContext("", "1", "","", null,null,null,null)); assertEquals("ID\tNAME\na\ta_name\nb\tb_name\n", interpreterResult.message()); } From 4e0126511b42f058e5ff6e5a22a9934c8edf3960 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Thu, 26 Nov 2015 12:21:50 +0900 Subject: [PATCH 13/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Updated docs for hive --- docs/docs.md | 2 +- docs/interpreter/hive.md | 105 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 docs/interpreter/hive.md diff --git a/docs/docs.md b/docs/docs.md index 0eebfcf08a2..97cba96d455 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -36,7 +36,7 @@ limitations under the License. * [cassandra](./interpreter/cassandra.html) * [flink](./interpreter/flink.html) * [geode](./interpreter/geode.html) -* [hive](./pleasecontribute.html) +* [hive](./interpreter/hive.html) * [ignite](./interpreter/ignite.html) * [lens](./interpreter/lens.html) * [md](./interpreter/markdown.html) diff --git a/docs/interpreter/hive.md b/docs/interpreter/hive.md new file mode 100644 index 00000000000..f92625ed2ea --- /dev/null +++ b/docs/interpreter/hive.md @@ -0,0 +1,105 @@ +--- +layout: page +title: "Hive Interpreter" +description: "" +group: manual +--- +{% include JB/setup %} + + +## Hive Interpreter for Apache Zeppelin + +### Configuration + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyDefaultDescription
default.driverorg.apache.hive.jdbc.HiveDriverClass path of JDBC driver
default.urljdbc:hive2://localhost:10000Url for connection
default.user(Optional)Username of the connection
default.password(Optional)Password of the connection
default.xxx(Optional)Other properties used by the driver
${prefix}.driverDriver class path of `%hive(${prefix})`
${prefix}.urlUrl of `%hive(${prefix})`
${prefix}.user(Optional)Username of the connection of `%hive(${prefix})`
${prefix}.password(Optional)Password of the connection of `%hive(${prefix})`
${prefix}.xxx(Optional)Other properties used by the driver of `%hive(${prefix})`
+ +This interpreter provides multiple configuration wih ${prefix}. User can set a multiple connection properties by this prefix. It can be used like `%hive(${prefix})`. + +### How to use + +Basically, you can use + +```sql +%hive +select * from my_table; +``` + +or + +```sql +%hive(etl) +-- 'etl' is a ${prefix} +select * from my_table; +``` + +You can also run multiple queries up to 10 by default. Changing these settings is not implemented yet. + +#### Apply Zeppelin Dynamic Forms + +You can leverage [Zepplein Dynamic Form](https://zeppelin.incubator.apache.org/docs/manual/dynamicform.html) inside your queries. You can use both the `text input` and `select form` parametrization features + +```sql +%hive +SELECT ${group_by}, count(*) as count +FROM retail_demo.order_lineitems_pxf +GROUP BY ${group_by=product_id,product_id|product_name|customer_id|store_id} +ORDER BY count ${order=DESC,DESC|ASC} +LIMIT ${limit=10}; +``` From fc33a30311f32c0bb81282f18d89f2cd2c5baa29 Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Thu, 26 Nov 2015 14:10:51 +0900 Subject: [PATCH 14/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Fixed Apaceh license header - Fixed some codestyle - Removed unused codes and classes --- .../apache/zeppelin/hive/HiveInterpreter.java | 36 +- .../zeppelin/hive/HiveInterpreterTest.java | 1594 +---------------- 2 files changed, 19 insertions(+), 1611 deletions(-) diff --git a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java index d70c0489a76..b1f3339674e 100644 --- a/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java +++ b/hive/src/main/java/org/apache/zeppelin/hive/HiveInterpreter.java @@ -1,20 +1,20 @@ -/** - * 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 - *

+/* + * 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.hive; import java.sql.Connection; @@ -51,8 +51,6 @@ public class HiveInterpreter extends Interpreter { static final String COMMON_KEY = "common"; static final String MAX_LINE_KEY = "max_count"; static final String MAX_LINE_DEFAULT = "1000"; - static final String MAX_RETRY_KEY = "max_retry"; - static final String MAX_RETRY_DEFAULT = "3"; static final String DEFAULT_KEY = "default"; static final String DRIVER_KEY = "driver"; @@ -68,7 +66,6 @@ public class HiveInterpreter extends Interpreter { static final String UPDATE_COUNT_HEADER = "Update Count"; static final String COMMON_MAX_LINE = COMMON_KEY + DOT + MAX_LINE_KEY; - static final String COMMON_MAX_RETRY = COMMON_KEY + DOT + MAX_RETRY_KEY; static final String DEFAULT_DRIVER = DEFAULT_KEY + DOT + DRIVER_KEY; static final String DEFAULT_URL = DEFAULT_KEY + DOT + URL_KEY; @@ -86,7 +83,6 @@ public class HiveInterpreter extends Interpreter { HiveInterpreter.class.getName(), new InterpreterPropertyBuilder() .add(COMMON_MAX_LINE, MAX_LINE_DEFAULT, "Maximum line of results") - .add(COMMON_MAX_RETRY, MAX_RETRY_DEFAULT, "Maximum number of retry while error") .add(DEFAULT_DRIVER, "org.apache.hive.jdbc.HiveDriver", "Hive JDBC driver") .add(DEFAULT_URL, "jdbc:hive2://localhost:10000", "The URL for HiveServer2.") .add(DEFAULT_USER, "hive", "The hive user") @@ -203,8 +199,7 @@ public Statement getStatement(String propertyKey, String paragraphId) return statement; } - public InterpreterResult executeSql(String propertyKey, - String sql, + public InterpreterResult executeSql(String propertyKey, String sql, InterpreterContext interpreterContext) { String paragraphId = interpreterContext.getParagraphId(); @@ -214,7 +209,7 @@ public InterpreterResult executeSql(String propertyKey, statement.setMaxRows(getMaxResult()); - StringBuilder msg = null; + StringBuilder msg; if (containsIgnoreCase(sql, EXPLAIN_PREDICATE)) { msg = new StringBuilder(); @@ -302,11 +297,6 @@ private int getMaxResult() { propertiesMap.get(COMMON_KEY).getProperty(MAX_LINE_KEY, MAX_LINE_DEFAULT)); } - private int getMaxRetry() { - return Integer.valueOf( - propertiesMap.get(COMMON_KEY).getProperty(MAX_RETRY_KEY, MAX_RETRY_DEFAULT)); - } - public String getPropertyKey(String cmd) { int firstLineIndex = cmd.indexOf("\n"); if (-1 == firstLineIndex) { diff --git a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java index 410673d025e..c22080d57f0 100644 --- a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java +++ b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java @@ -18,24 +18,19 @@ package org.apache.zeppelin.hive; import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; -import java.sql.*; -import java.sql.Date; -import java.util.*; -import java.util.concurrent.Executor; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterResult; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import static org.junit.Assert.*; import static java.lang.String.format; @@ -198,1581 +193,4 @@ public void getPropertyKey() { assertEquals("get key of default", "default", hi.getPropertyKey(testCommand)); hi.close(); } -} - -class MockHiveInterpreter extends HiveInterpreter { - - public MockHiveInterpreter(Properties property) { - super(property); - } - -} - -class MockResultSetMetadata implements ResultSetMetaData { - - @Override - public int getColumnCount() throws SQLException { - return 0; - } - - @Override - public boolean isAutoIncrement(int column) throws SQLException { - return false; - } - - @Override - public boolean isCaseSensitive(int column) throws SQLException { - return false; - } - - @Override - public boolean isSearchable(int column) throws SQLException { - return false; - } - - @Override - public boolean isCurrency(int column) throws SQLException { - return false; - } - - @Override - public int isNullable(int column) throws SQLException { - return 0; - } - - @Override - public boolean isSigned(int column) throws SQLException { - return false; - } - - @Override - public int getColumnDisplaySize(int column) throws SQLException { - return 0; - } - - @Override - public String getColumnLabel(int column) throws SQLException { - return null; - } - - @Override - public String getColumnName(int column) throws SQLException { - return null; - } - - @Override - public String getSchemaName(int column) throws SQLException { - return null; - } - - @Override - public int getPrecision(int column) throws SQLException { - return 0; - } - - @Override - public int getScale(int column) throws SQLException { - return 0; - } - - @Override - public String getTableName(int column) throws SQLException { - return null; - } - - @Override - public String getCatalogName(int column) throws SQLException { - return null; - } - - @Override - public int getColumnType(int column) throws SQLException { - return 0; - } - - @Override - public String getColumnTypeName(int column) throws SQLException { - return null; - } - - @Override - public boolean isReadOnly(int column) throws SQLException { - return false; - } - - @Override - public boolean isWritable(int column) throws SQLException { - return false; - } - - @Override - public boolean isDefinitelyWritable(int column) throws SQLException { - return false; - } - - @Override - public String getColumnClassName(int column) throws SQLException { - return null; - } - - @Override - public T unwrap(Class iface) throws SQLException { - return null; - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return false; - } -} -class MockResultSet implements ResultSet { - - @Override - public boolean next() throws SQLException { - return false; - } - - @Override - public void close() throws SQLException { - - } - - @Override - public boolean wasNull() throws SQLException { - return false; - } - - @Override - public String getString(int columnIndex) throws SQLException { - return null; - } - - @Override - public boolean getBoolean(int columnIndex) throws SQLException { - return false; - } - - @Override - public byte getByte(int columnIndex) throws SQLException { - return 0; - } - - @Override - public short getShort(int columnIndex) throws SQLException { - return 0; - } - - @Override - public int getInt(int columnIndex) throws SQLException { - return 0; - } - - @Override - public long getLong(int columnIndex) throws SQLException { - return 0; - } - - @Override - public float getFloat(int columnIndex) throws SQLException { - return 0; - } - - @Override - public double getDouble(int columnIndex) throws SQLException { - return 0; - } - - @Override - public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { - return null; - } - - @Override - public byte[] getBytes(int columnIndex) throws SQLException { - return new byte[0]; - } - - @Override - public Date getDate(int columnIndex) throws SQLException { - return null; - } - - @Override - public Time getTime(int columnIndex) throws SQLException { - return null; - } - - @Override - public Timestamp getTimestamp(int columnIndex) throws SQLException { - return null; - } - - @Override - public InputStream getAsciiStream(int columnIndex) throws SQLException { - return null; - } - - @Override - public InputStream getUnicodeStream(int columnIndex) throws SQLException { - return null; - } - - @Override - public InputStream getBinaryStream(int columnIndex) throws SQLException { - return null; - } - - @Override - public String getString(String columnLabel) throws SQLException { - return null; - } - - @Override - public boolean getBoolean(String columnLabel) throws SQLException { - return false; - } - - @Override - public byte getByte(String columnLabel) throws SQLException { - return 0; - } - - @Override - public short getShort(String columnLabel) throws SQLException { - return 0; - } - - @Override - public int getInt(String columnLabel) throws SQLException { - return 0; - } - - @Override - public long getLong(String columnLabel) throws SQLException { - return 0; - } - - @Override - public float getFloat(String columnLabel) throws SQLException { - return 0; - } - - @Override - public double getDouble(String columnLabel) throws SQLException { - return 0; - } - - @Override - public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { - return null; - } - - @Override - public byte[] getBytes(String columnLabel) throws SQLException { - return new byte[0]; - } - - @Override - public Date getDate(String columnLabel) throws SQLException { - return null; - } - - @Override - public Time getTime(String columnLabel) throws SQLException { - return null; - } - - @Override - public Timestamp getTimestamp(String columnLabel) throws SQLException { - return null; - } - - @Override - public InputStream getAsciiStream(String columnLabel) throws SQLException { - return null; - } - - @Override - public InputStream getUnicodeStream(String columnLabel) throws SQLException { - return null; - } - - @Override - public InputStream getBinaryStream(String columnLabel) throws SQLException { - return null; - } - - @Override - public SQLWarning getWarnings() throws SQLException { - return null; - } - - @Override - public void clearWarnings() throws SQLException { - - } - - @Override - public String getCursorName() throws SQLException { - return null; - } - - @Override - public ResultSetMetaData getMetaData() throws SQLException { - return new MockResultSetMetadata(); - } - - @Override - public Object getObject(int columnIndex) throws SQLException { - return null; - } - - @Override - public Object getObject(String columnLabel) throws SQLException { - return null; - } - - @Override - public int findColumn(String columnLabel) throws SQLException { - return 0; - } - - @Override - public Reader getCharacterStream(int columnIndex) throws SQLException { - return null; - } - - @Override - public Reader getCharacterStream(String columnLabel) throws SQLException { - return null; - } - - @Override - public BigDecimal getBigDecimal(int columnIndex) throws SQLException { - return null; - } - - @Override - public BigDecimal getBigDecimal(String columnLabel) throws SQLException { - return null; - } - - @Override - public boolean isBeforeFirst() throws SQLException { - return false; - } - - @Override - public boolean isAfterLast() throws SQLException { - return false; - } - - @Override - public boolean isFirst() throws SQLException { - return false; - } - - @Override - public boolean isLast() throws SQLException { - return false; - } - - @Override - public void beforeFirst() throws SQLException { - - } - - @Override - public void afterLast() throws SQLException { - - } - - @Override - public boolean first() throws SQLException { - return false; - } - - @Override - public boolean last() throws SQLException { - return false; - } - - @Override - public int getRow() throws SQLException { - return 0; - } - - @Override - public boolean absolute(int row) throws SQLException { - return false; - } - - @Override - public boolean relative(int rows) throws SQLException { - return false; - } - - @Override - public boolean previous() throws SQLException { - return false; - } - - @Override - public void setFetchDirection(int direction) throws SQLException { - - } - - @Override - public int getFetchDirection() throws SQLException { - return 0; - } - - @Override - public void setFetchSize(int rows) throws SQLException { - - } - - @Override - public int getFetchSize() throws SQLException { - return 0; - } - - @Override - public int getType() throws SQLException { - return 0; - } - - @Override - public int getConcurrency() throws SQLException { - return 0; - } - - @Override - public boolean rowUpdated() throws SQLException { - return false; - } - - @Override - public boolean rowInserted() throws SQLException { - return false; - } - - @Override - public boolean rowDeleted() throws SQLException { - return false; - } - - @Override - public void updateNull(int columnIndex) throws SQLException { - - } - - @Override - public void updateBoolean(int columnIndex, boolean x) throws SQLException { - - } - - @Override - public void updateByte(int columnIndex, byte x) throws SQLException { - - } - - @Override - public void updateShort(int columnIndex, short x) throws SQLException { - - } - - @Override - public void updateInt(int columnIndex, int x) throws SQLException { - - } - - @Override - public void updateLong(int columnIndex, long x) throws SQLException { - - } - - @Override - public void updateFloat(int columnIndex, float x) throws SQLException { - - } - - @Override - public void updateDouble(int columnIndex, double x) throws SQLException { - - } - - @Override - public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { - - } - - @Override - public void updateString(int columnIndex, String x) throws SQLException { - - } - - @Override - public void updateBytes(int columnIndex, byte[] x) throws SQLException { - - } - - @Override - public void updateDate(int columnIndex, Date x) throws SQLException { - - } - - @Override - public void updateTime(int columnIndex, Time x) throws SQLException { - - } - - @Override - public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { - - } - - @Override - public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { - - } - - @Override - public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { - - } - - @Override - public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { - - } - - @Override - public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { - - } - - @Override - public void updateObject(int columnIndex, Object x) throws SQLException { - - } - - @Override - public void updateNull(String columnLabel) throws SQLException { - - } - - @Override - public void updateBoolean(String columnLabel, boolean x) throws SQLException { - - } - - @Override - public void updateByte(String columnLabel, byte x) throws SQLException { - - } - - @Override - public void updateShort(String columnLabel, short x) throws SQLException { - - } - - @Override - public void updateInt(String columnLabel, int x) throws SQLException { - - } - - @Override - public void updateLong(String columnLabel, long x) throws SQLException { - - } - - @Override - public void updateFloat(String columnLabel, float x) throws SQLException { - - } - - @Override - public void updateDouble(String columnLabel, double x) throws SQLException { - - } - - @Override - public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { - - } - - @Override - public void updateString(String columnLabel, String x) throws SQLException { - - } - - @Override - public void updateBytes(String columnLabel, byte[] x) throws SQLException { - - } - - @Override - public void updateDate(String columnLabel, Date x) throws SQLException { - - } - - @Override - public void updateTime(String columnLabel, Time x) throws SQLException { - - } - - @Override - public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { - - } - - @Override - public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { - - } - - @Override - public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { - - } - - @Override - public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { - - } - - @Override - public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { - - } - - @Override - public void updateObject(String columnLabel, Object x) throws SQLException { - - } - - @Override - public void insertRow() throws SQLException { - - } - - @Override - public void updateRow() throws SQLException { - - } - - @Override - public void deleteRow() throws SQLException { - - } - - @Override - public void refreshRow() throws SQLException { - - } - - @Override - public void cancelRowUpdates() throws SQLException { - - } - - @Override - public void moveToInsertRow() throws SQLException { - - } - - @Override - public void moveToCurrentRow() throws SQLException { - - } - - @Override - public Statement getStatement() throws SQLException { - return new MockStatement(); - } - - @Override - public Object getObject(int columnIndex, Map> map) throws SQLException { - return null; - } - - @Override - public Ref getRef(int columnIndex) throws SQLException { - return null; - } - - @Override - public Blob getBlob(int columnIndex) throws SQLException { - return null; - } - - @Override - public Clob getClob(int columnIndex) throws SQLException { - return null; - } - - @Override - public Array getArray(int columnIndex) throws SQLException { - return null; - } - - @Override - public Object getObject(String columnLabel, Map> map) throws SQLException { - return null; - } - - @Override - public Ref getRef(String columnLabel) throws SQLException { - return null; - } - - @Override - public Blob getBlob(String columnLabel) throws SQLException { - return null; - } - - @Override - public Clob getClob(String columnLabel) throws SQLException { - return null; - } - - @Override - public Array getArray(String columnLabel) throws SQLException { - return null; - } - - @Override - public Date getDate(int columnIndex, Calendar cal) throws SQLException { - return null; - } - - @Override - public Date getDate(String columnLabel, Calendar cal) throws SQLException { - return null; - } - - @Override - public Time getTime(int columnIndex, Calendar cal) throws SQLException { - return null; - } - - @Override - public Time getTime(String columnLabel, Calendar cal) throws SQLException { - return null; - } - - @Override - public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { - return null; - } - - @Override - public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { - return null; - } - - @Override - public URL getURL(int columnIndex) throws SQLException { - return null; - } - - @Override - public URL getURL(String columnLabel) throws SQLException { - return null; - } - - @Override - public void updateRef(int columnIndex, Ref x) throws SQLException { - - } - - @Override - public void updateRef(String columnLabel, Ref x) throws SQLException { - - } - - @Override - public void updateBlob(int columnIndex, Blob x) throws SQLException { - - } - - @Override - public void updateBlob(String columnLabel, Blob x) throws SQLException { - - } - - @Override - public void updateClob(int columnIndex, Clob x) throws SQLException { - - } - - @Override - public void updateClob(String columnLabel, Clob x) throws SQLException { - - } - - @Override - public void updateArray(int columnIndex, Array x) throws SQLException { - - } - - @Override - public void updateArray(String columnLabel, Array x) throws SQLException { - - } - - @Override - public RowId getRowId(int columnIndex) throws SQLException { - return null; - } - - @Override - public RowId getRowId(String columnLabel) throws SQLException { - return null; - } - - @Override - public void updateRowId(int columnIndex, RowId x) throws SQLException { - - } - - @Override - public void updateRowId(String columnLabel, RowId x) throws SQLException { - - } - - @Override - public int getHoldability() throws SQLException { - return 0; - } - - @Override - public boolean isClosed() throws SQLException { - return false; - } - - @Override - public void updateNString(int columnIndex, String nString) throws SQLException { - - } - - @Override - public void updateNString(String columnLabel, String nString) throws SQLException { - - } - - @Override - public void updateNClob(int columnIndex, NClob nClob) throws SQLException { - - } - - @Override - public void updateNClob(String columnLabel, NClob nClob) throws SQLException { - - } - - @Override - public NClob getNClob(int columnIndex) throws SQLException { - return null; - } - - @Override - public NClob getNClob(String columnLabel) throws SQLException { - return null; - } - - @Override - public SQLXML getSQLXML(int columnIndex) throws SQLException { - return null; - } - - @Override - public SQLXML getSQLXML(String columnLabel) throws SQLException { - return null; - } - - @Override - public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { - - } - - @Override - public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { - - } - - @Override - public String getNString(int columnIndex) throws SQLException { - return null; - } - - @Override - public String getNString(String columnLabel) throws SQLException { - return null; - } - - @Override - public Reader getNCharacterStream(int columnIndex) throws SQLException { - return null; - } - - @Override - public Reader getNCharacterStream(String columnLabel) throws SQLException { - return null; - } - - @Override - public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - - } - - @Override - public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { - - } - - @Override - public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { - - } - - @Override - public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - - } - - @Override - public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { - - } - - @Override - public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { - - } - - @Override - public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { - - } - - @Override - public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { - - } - - @Override - public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { - - } - - @Override - public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { - - } - - @Override - public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { - - } - - @Override - public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { - - } - - @Override - public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { - - } - - @Override - public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { - - } - - @Override - public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { - - } - - @Override - public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { - - } - - @Override - public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { - - } - - @Override - public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { - - } - - @Override - public void updateClob(int columnIndex, Reader reader) throws SQLException { - - } - - @Override - public void updateClob(String columnLabel, Reader reader) throws SQLException { - - } - - @Override - public void updateNClob(int columnIndex, Reader reader) throws SQLException { - - } - - @Override - public void updateNClob(String columnLabel, Reader reader) throws SQLException { - - } - - @Override - public T getObject(int columnIndex, Class type) throws SQLException { - return null; - } - - @Override - public T getObject(String columnLabel, Class type) throws SQLException { - return null; - } - - @Override - public T unwrap(Class iface) throws SQLException { - return null; - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return false; - } -} -class MockStatement implements Statement { - - @Override - public ResultSet executeQuery(String sql) throws SQLException { - return new MockResultSet(); - } - - @Override - public int executeUpdate(String sql) throws SQLException { - return 0; - } - - @Override - public void close() throws SQLException { - - } - - @Override - public int getMaxFieldSize() throws SQLException { - return 0; - } - - @Override - public void setMaxFieldSize(int max) throws SQLException { - - } - - @Override - public int getMaxRows() throws SQLException { - return 0; - } - - @Override - public void setMaxRows(int max) throws SQLException { - - } - - @Override - public void setEscapeProcessing(boolean enable) throws SQLException { - - } - - @Override - public int getQueryTimeout() throws SQLException { - return 0; - } - - @Override - public void setQueryTimeout(int seconds) throws SQLException { - - } - - @Override - public void cancel() throws SQLException { - - } - - @Override - public SQLWarning getWarnings() throws SQLException { - return null; - } - - @Override - public void clearWarnings() throws SQLException { - - } - - @Override - public void setCursorName(String name) throws SQLException { - - } - - @Override - public boolean execute(String sql) throws SQLException { - return false; - } - - @Override - public ResultSet getResultSet() throws SQLException { - return new MockResultSet(); - } - - @Override - public int getUpdateCount() throws SQLException { - return 0; - } - - @Override - public boolean getMoreResults() throws SQLException { - return false; - } - - @Override - public void setFetchDirection(int direction) throws SQLException { - - } - - @Override - public int getFetchDirection() throws SQLException { - return 0; - } - - @Override - public void setFetchSize(int rows) throws SQLException { - - } - - @Override - public int getFetchSize() throws SQLException { - return 0; - } - - @Override - public int getResultSetConcurrency() throws SQLException { - return 0; - } - - @Override - public int getResultSetType() throws SQLException { - return 0; - } - - @Override - public void addBatch(String sql) throws SQLException { - - } - - @Override - public void clearBatch() throws SQLException { - - } - - @Override - public int[] executeBatch() throws SQLException { - return new int[0]; - } - - @Override - public Connection getConnection() throws SQLException { - return null; - } - - @Override - public boolean getMoreResults(int current) throws SQLException { - return false; - } - - @Override - public ResultSet getGeneratedKeys() throws SQLException { - return null; - } - - @Override - public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { - return 0; - } - - @Override - public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { - return 0; - } - - @Override - public int executeUpdate(String sql, String[] columnNames) throws SQLException { - return 0; - } - - @Override - public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - return false; - } - - @Override - public boolean execute(String sql, int[] columnIndexes) throws SQLException { - return false; - } - - @Override - public boolean execute(String sql, String[] columnNames) throws SQLException { - return false; - } - - @Override - public int getResultSetHoldability() throws SQLException { - return 0; - } - - @Override - public boolean isClosed() throws SQLException { - return false; - } - - @Override - public void setPoolable(boolean poolable) throws SQLException { - - } - - @Override - public boolean isPoolable() throws SQLException { - return false; - } - - @Override - public void closeOnCompletion() throws SQLException { - - } - - @Override - public boolean isCloseOnCompletion() throws SQLException { - return false; - } - - @Override - public T unwrap(Class iface) throws SQLException { - return null; - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return false; - } -} -class MockConnection implements Connection { - - @Override - public Statement createStatement() throws SQLException { - return new MockStatement(); - } - - @Override - public PreparedStatement prepareStatement(String sql) throws SQLException { - return null; - } - - @Override - public CallableStatement prepareCall(String sql) throws SQLException { - return null; - } - - @Override - public String nativeSQL(String sql) throws SQLException { - return null; - } - - @Override - public void setAutoCommit(boolean autoCommit) throws SQLException { - - } - - @Override - public boolean getAutoCommit() throws SQLException { - return false; - } - - @Override - public void commit() throws SQLException { - - } - - @Override - public void rollback() throws SQLException { - - } - - @Override - public void close() throws SQLException { - - } - - @Override - public boolean isClosed() throws SQLException { - return false; - } - - @Override - public DatabaseMetaData getMetaData() throws SQLException { - return null; - } - - @Override - public void setReadOnly(boolean readOnly) throws SQLException { - - } - - @Override - public boolean isReadOnly() throws SQLException { - return false; - } - - @Override - public void setCatalog(String catalog) throws SQLException { - - } - - @Override - public String getCatalog() throws SQLException { - return null; - } - - @Override - public void setTransactionIsolation(int level) throws SQLException { - - } - - @Override - public int getTransactionIsolation() throws SQLException { - return 0; - } - - @Override - public SQLWarning getWarnings() throws SQLException { - return null; - } - - @Override - public void clearWarnings() throws SQLException { - - } - - @Override - public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { - return null; - } - - @Override - public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { - return null; - } - - @Override - public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { - return null; - } - - @Override - public Map> getTypeMap() throws SQLException { - return null; - } - - @Override - public void setTypeMap(Map> map) throws SQLException { - - } - - @Override - public void setHoldability(int holdability) throws SQLException { - - } - - @Override - public int getHoldability() throws SQLException { - return 0; - } - - @Override - public Savepoint setSavepoint() throws SQLException { - return null; - } - - @Override - public Savepoint setSavepoint(String name) throws SQLException { - return null; - } - - @Override - public void rollback(Savepoint savepoint) throws SQLException { - - } - - @Override - public void releaseSavepoint(Savepoint savepoint) throws SQLException { - - } - - @Override - public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return null; - } - - @Override - public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return null; - } - - @Override - public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return null; - } - - @Override - public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { - return null; - } - - @Override - public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { - return null; - } - - @Override - public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { - return null; - } - - @Override - public Clob createClob() throws SQLException { - return null; - } - - @Override - public Blob createBlob() throws SQLException { - return null; - } - - @Override - public NClob createNClob() throws SQLException { - return null; - } - - @Override - public SQLXML createSQLXML() throws SQLException { - return null; - } - - @Override - public boolean isValid(int timeout) throws SQLException { - return false; - } - - @Override - public void setClientInfo(String name, String value) throws SQLClientInfoException { - - } - - @Override - public void setClientInfo(Properties properties) throws SQLClientInfoException { - - } - - @Override - public String getClientInfo(String name) throws SQLException { - return null; - } - - @Override - public Properties getClientInfo() throws SQLException { - return null; - } - - @Override - public Array createArrayOf(String typeName, Object[] elements) throws SQLException { - return null; - } - - @Override - public Struct createStruct(String typeName, Object[] attributes) throws SQLException { - return null; - } - - @Override - public void setSchema(String schema) throws SQLException { - - } - - @Override - public String getSchema() throws SQLException { - return null; - } - - @Override - public void abort(Executor executor) throws SQLException { - - } - - @Override - public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { - - } - - @Override - public int getNetworkTimeout() throws SQLException { - return 0; - } - - @Override - public T unwrap(Class iface) throws SQLException { - return null; - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return false; - } -} +} \ No newline at end of file From d68bcc5af903b9c2c4182e7ec5af13c511e43b0c Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Mon, 30 Nov 2015 16:30:24 +0900 Subject: [PATCH 15/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Fixed typos on docs --- docs/interpreter/hive.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/interpreter/hive.md b/docs/interpreter/hive.md index f92625ed2ea..b37c421de12 100644 --- a/docs/interpreter/hive.md +++ b/docs/interpreter/hive.md @@ -70,7 +70,7 @@ group: manual -This interpreter provides multiple configuration wih ${prefix}. User can set a multiple connection properties by this prefix. It can be used like `%hive(${prefix})`. +This interpreter provides multiple configuration with ${prefix}. User can set a multiple connection properties by this prefix. It can be used like `%hive(${prefix})`. ### How to use @@ -93,7 +93,7 @@ You can also run multiple queries up to 10 by default. Changing these settings i #### Apply Zeppelin Dynamic Forms -You can leverage [Zepplein Dynamic Form](https://zeppelin.incubator.apache.org/docs/manual/dynamicform.html) inside your queries. You can use both the `text input` and `select form` parametrization features +You can leverage [Zeppelin Dynamic Form]({{BASE_PATH}}/manual/dynamicform.html) inside your queries. You can use both the `text input` and `select form` parameterization features ```sql %hive From af4c64bf36aad9ef3b9f8ab885746275f3b462db Mon Sep 17 00:00:00 2001 From: Jongyoul Lee Date: Mon, 30 Nov 2015 19:15:33 +0900 Subject: [PATCH 16/16] ZEPPELIN-440 HiveInterpreter with multiple configuration - Rebased and fixed links of docs --- docs/_includes/themes/zeppelin/_navigation.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_includes/themes/zeppelin/_navigation.html b/docs/_includes/themes/zeppelin/_navigation.html index 5d5cf713d43..efd0e10d6df 100644 --- a/docs/_includes/themes/zeppelin/_navigation.html +++ b/docs/_includes/themes/zeppelin/_navigation.html @@ -38,7 +38,7 @@

  • Cassandra
  • Flink
  • Geode
  • -
  • Hive
  • +
  • Hive
  • Ignite
  • Lens
  • Markdown