http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/jdbc/src/test/java/org/apache/zeppelin/jdbc/SqlCompleterTest.java ---------------------------------------------------------------------- diff --git a/jdbc/src/test/java/org/apache/zeppelin/jdbc/SqlCompleterTest.java b/jdbc/src/test/java/org/apache/zeppelin/jdbc/SqlCompleterTest.java index 21e5a6f..1ec3ae4 100644 --- a/jdbc/src/test/java/org/apache/zeppelin/jdbc/SqlCompleterTest.java +++ b/jdbc/src/test/java/org/apache/zeppelin/jdbc/SqlCompleterTest.java @@ -5,20 +5,29 @@ * "License"); you may not use this file except in compliance with the License. You may obtain a * copy of the License at * - * <p>http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * <p>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. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.apache.zeppelin.jdbc; import static com.google.common.collect.Sets.newHashSet; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import com.google.common.base.Joiner; + +import org.apache.commons.lang.StringUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; @@ -27,17 +36,15 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; + import jline.console.completer.ArgumentCompleter; -import org.apache.commons.lang.StringUtils; + import org.apache.zeppelin.completer.CompletionType; import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -/** SQL completer unit tests. */ +/** + * SQL completer unit tests. + */ public class SqlCompleterTest { public class CompleterTester { private SqlCompleter completer; @@ -77,8 +84,8 @@ public class SqlCompleterTest { } } - private void expectedCompletions( - String buffer, int cursor, Set<InterpreterCompletion> expected) { + private void expectedCompletions(String buffer, int cursor, + Set<InterpreterCompletion> expected) { if (StringUtils.isNotEmpty(buffer) && buffer.length() > cursor) { buffer = buffer.substring(0, cursor); } @@ -91,10 +98,8 @@ public class SqlCompleterTest { logger.info(explain); - Assert.assertEquals( - "Buffer [" + buffer.replace(" ", ".") + "] and Cursor[" + cursor + "] " + explain, - expected, - newHashSet(candidates)); + Assert.assertEquals("Buffer [" + buffer.replace(" ", ".") + "] and Cursor[" + cursor + "] " + + explain, expected, newHashSet(candidates)); } private String explain(String buffer, int cursor, List<InterpreterCompletion> candidates) { @@ -194,8 +199,8 @@ public class SqlCompleterTest { @Test public void testFindAliasesInSQL_Simple() { String sql = "select * from prod_emart.financial_account a"; - Map<String, String> res = - sqlCompleter.findAliasesInSQL(delimiter.delimit(sql, 0).getArguments()); + Map<String, String> res = sqlCompleter.findAliasesInSQL( + delimiter.delimit(sql, 0).getArguments()); assertEquals(1, res.size()); assertTrue(res.get("a").equals("prod_emart.financial_account")); } @@ -203,8 +208,7 @@ public class SqlCompleterTest { @Test public void testFindAliasesInSQL_Two() { String sql = "select * from prod_dds.financial_account a, prod_dds.customer b"; - Map<String, String> res = - sqlCompleter.findAliasesInSQL( + Map<String, String> res = sqlCompleter.findAliasesInSQL( sqlCompleter.getSqlDelimiter().delimit(sql, 0).getArguments()); assertEquals(2, res.size()); assertTrue(res.get("a").equals("prod_dds.financial_account")); @@ -214,8 +218,7 @@ public class SqlCompleterTest { @Test public void testFindAliasesInSQL_WrongTables() { String sql = "select * from prod_ddsxx.financial_account a, prod_dds.customerxx b"; - Map<String, String> res = - sqlCompleter.findAliasesInSQL( + Map<String, String> res = sqlCompleter.findAliasesInSQL( sqlCompleter.getSqlDelimiter().delimit(sql, 0).getArguments()); assertEquals(0, res.size()); } @@ -228,34 +231,24 @@ public class SqlCompleterTest { Map<String, String> aliases = new HashMap<>(); sqlCompleter.completeName(buffer, cursor, candidates, aliases); assertEquals(9, candidates.size()); - assertTrue( - candidates.contains( - new InterpreterCompletion("prod_dds", "prod_dds", CompletionType.schema.name()))); - assertTrue( - candidates.contains( - new InterpreterCompletion("prod_emart", "prod_emart", CompletionType.schema.name()))); - assertTrue( - candidates.contains( - new InterpreterCompletion("SUM", "SUM", CompletionType.keyword.name()))); - assertTrue( - candidates.contains( - new InterpreterCompletion("SUBSTRING", "SUBSTRING", CompletionType.keyword.name()))); - assertTrue( - candidates.contains( - new InterpreterCompletion( - "SUBCLASS_ORIGIN", "SUBCLASS_ORIGIN", CompletionType.keyword.name()))); - assertTrue( - candidates.contains( - new InterpreterCompletion("SELECT", "SELECT", CompletionType.keyword.name()))); - assertTrue( - candidates.contains( - new InterpreterCompletion("ORDER", "ORDER", CompletionType.keyword.name()))); - assertTrue( - candidates.contains( - new InterpreterCompletion("LIMIT", "LIMIT", CompletionType.keyword.name()))); - assertTrue( - candidates.contains( - new InterpreterCompletion("FROM", "FROM", CompletionType.keyword.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("prod_dds", "prod_dds", + CompletionType.schema.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("prod_emart", "prod_emart", + CompletionType.schema.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("SUM", "SUM", + CompletionType.keyword.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("SUBSTRING", "SUBSTRING", + CompletionType.keyword.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("SUBCLASS_ORIGIN", "SUBCLASS_ORIGIN", + CompletionType.keyword.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("SELECT", "SELECT", + CompletionType.keyword.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("ORDER", "ORDER", + CompletionType.keyword.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("LIMIT", "LIMIT", + CompletionType.keyword.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("FROM", "FROM", + CompletionType.keyword.name()))); } @Test @@ -266,12 +259,10 @@ public class SqlCompleterTest { Map<String, String> aliases = new HashMap<>(); sqlCompleter.completeName(buffer, cursor, candidates, aliases); assertEquals(2, candidates.size()); - assertTrue( - candidates.contains( - new InterpreterCompletion("prod_dds", "prod_dds", CompletionType.schema.name()))); - assertTrue( - candidates.contains( - new InterpreterCompletion("prod_emart", "prod_emart", CompletionType.schema.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("prod_dds", "prod_dds", + CompletionType.schema.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("prod_emart", "prod_emart", + CompletionType.schema.name()))); } @Test @@ -282,10 +273,9 @@ public class SqlCompleterTest { Map<String, String> aliases = new HashMap<>(); sqlCompleter.completeName(buffer, cursor, candidates, aliases); assertEquals(1, candidates.size()); - assertTrue( - candidates.contains( - new InterpreterCompletion( - "financial_account", "financial_account", CompletionType.table.name()))); + assertTrue(candidates.contains( + new InterpreterCompletion("financial_account", "financial_account", + CompletionType.table.name()))); } @Test @@ -296,12 +286,10 @@ public class SqlCompleterTest { Map<String, String> aliases = new HashMap<>(); sqlCompleter.completeName(buffer, cursor, candidates, aliases); assertEquals(2, candidates.size()); - assertTrue( - candidates.contains( - new InterpreterCompletion("account_rk", "account_rk", CompletionType.column.name()))); - assertTrue( - candidates.contains( - new InterpreterCompletion("account_id", "account_id", CompletionType.column.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("account_rk", "account_rk", + CompletionType.column.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("account_id", "account_id", + CompletionType.column.name()))); } @Test @@ -313,12 +301,10 @@ public class SqlCompleterTest { aliases.put("a", "prod_dds.financial_account"); sqlCompleter.completeName(buffer, cursor, candidates, aliases); assertEquals(2, candidates.size()); - assertTrue( - candidates.contains( - new InterpreterCompletion("account_rk", "account_rk", CompletionType.column.name()))); - assertTrue( - candidates.contains( - new InterpreterCompletion("account_id", "account_id", CompletionType.column.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("account_rk", "account_rk", + CompletionType.column.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("account_id", "account_id", + CompletionType.column.name()))); } @Test @@ -330,127 +316,71 @@ public class SqlCompleterTest { aliases.put("a", "prod_dds.financial_account"); sqlCompleter.completeName(buffer, cursor, candidates, aliases); assertEquals(2, candidates.size()); - assertTrue( - candidates.contains( - new InterpreterCompletion("account_rk", "account_rk", CompletionType.column.name()))); - assertTrue( - candidates.contains( - new InterpreterCompletion("account_id", "account_id", CompletionType.column.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("account_rk", "account_rk", + CompletionType.column.name()))); + assertTrue(candidates.contains(new InterpreterCompletion("account_id", "account_id", + CompletionType.column.name()))); } @Test public void testSchemaAndTable() { String buffer = "select * from prod_emart.fi"; - tester - .buffer(buffer) - .from(20) - .to(23) - .expect( - newHashSet( - new InterpreterCompletion( - "prod_emart", "prod_emart", CompletionType.schema.name()))) - .test(); - tester - .buffer(buffer) - .from(25) - .to(27) - .expect( - newHashSet( - new InterpreterCompletion( - "financial_account", "financial_account", CompletionType.table.name()))) - .test(); + tester.buffer(buffer).from(20).to(23).expect(newHashSet( + new InterpreterCompletion("prod_emart", "prod_emart", + CompletionType.schema.name()))).test(); + tester.buffer(buffer).from(25).to(27).expect(newHashSet( + new InterpreterCompletion("financial_account", "financial_account", + CompletionType.table.name()))).test(); } @Test public void testEdges() { String buffer = " ORDER "; - tester - .buffer(buffer) - .from(3) - .to(7) - .expect( - newHashSet(new InterpreterCompletion("ORDER", "ORDER", CompletionType.keyword.name()))) - .test(); - tester - .buffer(buffer) - .from(0) - .to(1) - .expect( - newHashSet( - new InterpreterCompletion("ORDER", "ORDER", CompletionType.keyword.name()), - new InterpreterCompletion( - "SUBCLASS_ORIGIN", "SUBCLASS_ORIGIN", CompletionType.keyword.name()), - new InterpreterCompletion("SUBSTRING", "SUBSTRING", CompletionType.keyword.name()), - new InterpreterCompletion("prod_emart", "prod_emart", CompletionType.schema.name()), - new InterpreterCompletion("LIMIT", "LIMIT", CompletionType.keyword.name()), - new InterpreterCompletion("SUM", "SUM", CompletionType.keyword.name()), - new InterpreterCompletion("prod_dds", "prod_dds", CompletionType.schema.name()), - new InterpreterCompletion("SELECT", "SELECT", CompletionType.keyword.name()), - new InterpreterCompletion("FROM", "FROM", CompletionType.keyword.name()))) - .test(); + tester.buffer(buffer).from(3).to(7).expect(newHashSet( + new InterpreterCompletion("ORDER", "ORDER", CompletionType.keyword.name()))).test(); + tester.buffer(buffer).from(0).to(1).expect(newHashSet( + new InterpreterCompletion("ORDER", "ORDER", CompletionType.keyword.name()), + new InterpreterCompletion("SUBCLASS_ORIGIN", "SUBCLASS_ORIGIN", + CompletionType.keyword.name()), + new InterpreterCompletion("SUBSTRING", "SUBSTRING", CompletionType.keyword.name()), + new InterpreterCompletion("prod_emart", "prod_emart", CompletionType.schema.name()), + new InterpreterCompletion("LIMIT", "LIMIT", CompletionType.keyword.name()), + new InterpreterCompletion("SUM", "SUM", CompletionType.keyword.name()), + new InterpreterCompletion("prod_dds", "prod_dds", CompletionType.schema.name()), + new InterpreterCompletion("SELECT", "SELECT", CompletionType.keyword.name()), + new InterpreterCompletion("FROM", "FROM", CompletionType.keyword.name()) + )).test(); } @Test public void testMultipleWords() { String buffer = "SELE FRO LIM"; - tester - .buffer(buffer) - .from(2) - .to(4) - .expect( - newHashSet( - new InterpreterCompletion("SELECT", "SELECT", CompletionType.keyword.name()))) - .test(); - tester - .buffer(buffer) - .from(6) - .to(8) - .expect( - newHashSet(new InterpreterCompletion("FROM", "FROM", CompletionType.keyword.name()))) - .test(); - tester - .buffer(buffer) - .from(10) - .to(12) - .expect( - newHashSet(new InterpreterCompletion("LIMIT", "LIMIT", CompletionType.keyword.name()))) - .test(); + tester.buffer(buffer).from(2).to(4).expect(newHashSet( + new InterpreterCompletion("SELECT", "SELECT", CompletionType.keyword.name()))).test(); + tester.buffer(buffer).from(6).to(8).expect(newHashSet( + new InterpreterCompletion("FROM", "FROM", CompletionType.keyword.name()))).test(); + tester.buffer(buffer).from(10).to(12).expect(newHashSet( + new InterpreterCompletion("LIMIT", "LIMIT", CompletionType.keyword.name()))).test(); } @Test public void testMultiLineBuffer() { String buffer = " \n SELE\nFRO"; - tester - .buffer(buffer) - .from(5) - .to(7) - .expect( - newHashSet( - new InterpreterCompletion("SELECT", "SELECT", CompletionType.keyword.name()))) - .test(); - tester - .buffer(buffer) - .from(9) - .to(11) - .expect( - newHashSet(new InterpreterCompletion("FROM", "FROM", CompletionType.keyword.name()))) - .test(); + tester.buffer(buffer).from(5).to(7).expect(newHashSet( + new InterpreterCompletion("SELECT", "SELECT", CompletionType.keyword.name()))).test(); + tester.buffer(buffer).from(9).to(11).expect(newHashSet( + new InterpreterCompletion("FROM", "FROM", CompletionType.keyword.name()))).test(); } @Test public void testMultipleCompletionSuggestions() { String buffer = "SU"; - tester - .buffer(buffer) - .from(2) - .to(2) - .expect( - newHashSet( - new InterpreterCompletion( - "SUBCLASS_ORIGIN", "SUBCLASS_ORIGIN", CompletionType.keyword.name()), - new InterpreterCompletion("SUM", "SUM", CompletionType.keyword.name()), - new InterpreterCompletion("SUBSTRING", "SUBSTRING", CompletionType.keyword.name()))) - .test(); + tester.buffer(buffer).from(2).to(2).expect(newHashSet( + new InterpreterCompletion("SUBCLASS_ORIGIN", "SUBCLASS_ORIGIN", + CompletionType.keyword.name()), + new InterpreterCompletion("SUM", "SUM", CompletionType.keyword.name()), + new InterpreterCompletion("SUBSTRING", "SUBSTRING", CompletionType.keyword.name())) + ).test(); } @Test
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/kylin/pom.xml ---------------------------------------------------------------------- diff --git a/kylin/pom.xml b/kylin/pom.xml index 6f84b08..b70bfb2 100644 --- a/kylin/pom.xml +++ b/kylin/pom.xml @@ -73,6 +73,13 @@ <plugin> <artifactId>maven-resources-plugin</artifactId> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + <configuration> + <skip>false</skip> + </configuration> + </plugin> </plugins> </build> </project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/kylin/src/main/java/org/apache/zeppelin/kylin/KylinErrorResponse.java ---------------------------------------------------------------------- diff --git a/kylin/src/main/java/org/apache/zeppelin/kylin/KylinErrorResponse.java b/kylin/src/main/java/org/apache/zeppelin/kylin/KylinErrorResponse.java index 75ce2ec..04d0479 100644 --- a/kylin/src/main/java/org/apache/zeppelin/kylin/KylinErrorResponse.java +++ b/kylin/src/main/java/org/apache/zeppelin/kylin/KylinErrorResponse.java @@ -21,7 +21,9 @@ import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import org.apache.zeppelin.common.JsonSerializable; -/** class for Kylin Error Response. */ +/** + * class for Kylin Error Response. + */ class KylinErrorResponse implements JsonSerializable { private static final Gson gson = new Gson(); @@ -32,8 +34,8 @@ class KylinErrorResponse implements JsonSerializable { private Object data; private String msg; - KylinErrorResponse( - String stacktrace, String exception, String url, String code, Object data, String msg) { + KylinErrorResponse(String stacktrace, String exception, String url, + String code, Object data, String msg) { this.stacktrace = stacktrace; this.exception = exception; this.url = url; http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/kylin/src/main/java/org/apache/zeppelin/kylin/KylinInterpreter.java ---------------------------------------------------------------------- diff --git a/kylin/src/main/java/org/apache/zeppelin/kylin/KylinInterpreter.java b/kylin/src/main/java/org/apache/zeppelin/kylin/KylinInterpreter.java index 209e030..444f5cb 100755 --- a/kylin/src/main/java/org/apache/zeppelin/kylin/KylinInterpreter.java +++ b/kylin/src/main/java/org/apache/zeppelin/kylin/KylinInterpreter.java @@ -17,11 +17,6 @@ package org.apache.zeppelin.kylin; -import java.io.IOException; -import java.util.List; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; @@ -29,14 +24,23 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.List; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterResult; import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -/** Kylin interpreter for Zeppelin. (http://kylin.apache.org) */ +/** + * Kylin interpreter for Zeppelin. (http://kylin.apache.org) + */ public class KylinInterpreter extends Interpreter { Logger logger = LoggerFactory.getLogger(KylinInterpreter.class); @@ -49,17 +53,21 @@ public class KylinInterpreter extends Interpreter { static final String KYLIN_QUERY_ACCEPT_PARTIAL = "kylin.query.ispartial"; static final Pattern KYLIN_TABLE_FORMAT_REGEX_LABEL = Pattern.compile("\"label\":\"(.*?)\""); static final Pattern KYLIN_TABLE_FORMAT_REGEX_RESULTS = - Pattern.compile("\"results\":\\[\\[(.*?)]]"); + Pattern.compile("\"results\":\\[\\[(.*?)]]"); public KylinInterpreter(Properties property) { super(property); } @Override - public void open() {} + public void open() { + + } @Override - public void close() {} + public void close() { + + } @Override public InterpreterResult interpret(String st, InterpreterContext context) { @@ -72,7 +80,9 @@ public class KylinInterpreter extends Interpreter { } @Override - public void cancel(InterpreterContext context) {} + public void cancel(InterpreterContext context) { + + } @Override public FormType getFormType() { @@ -85,8 +95,8 @@ public class KylinInterpreter extends Interpreter { } @Override - public List<InterpreterCompletion> completion( - String buf, int cursor, InterpreterContext interpreterContext) { + public List<InterpreterCompletion> completion(String buf, int cursor, + InterpreterContext interpreterContext) { return null; } @@ -99,38 +109,14 @@ public class KylinInterpreter extends Interpreter { logger.info("acceptPartial:" + getProperty(KYLIN_QUERY_ACCEPT_PARTIAL)); logger.info("limit:" + getProperty(KYLIN_QUERY_LIMIT)); logger.info("offset:" + getProperty(KYLIN_QUERY_OFFSET)); - byte[] encodeBytes = - Base64.encodeBase64( - new String(getProperty(KYLIN_USERNAME) + ":" + getProperty(KYLIN_PASSWORD)) - .getBytes("UTF-8")); - - String postContent = - new String( - "{\"project\":" - + "\"" - + kylinProject - + "\"" - + "," - + "\"sql\":" - + "\"" - + kylinSql - + "\"" - + "," - + "\"acceptPartial\":" - + "\"" - + getProperty(KYLIN_QUERY_ACCEPT_PARTIAL) - + "\"" - + "," - + "\"offset\":" - + "\"" - + getProperty(KYLIN_QUERY_OFFSET) - + "\"" - + "," - + "\"limit\":" - + "\"" - + getProperty(KYLIN_QUERY_LIMIT) - + "\"" - + "}"); + byte[] encodeBytes = Base64.encodeBase64(new String(getProperty(KYLIN_USERNAME) + + ":" + getProperty(KYLIN_PASSWORD)).getBytes("UTF-8")); + + String postContent = new String("{\"project\":" + "\"" + kylinProject + "\"" + + "," + "\"sql\":" + "\"" + kylinSql + "\"" + + "," + "\"acceptPartial\":" + "\"" + getProperty(KYLIN_QUERY_ACCEPT_PARTIAL) + "\"" + + "," + "\"offset\":" + "\"" + getProperty(KYLIN_QUERY_OFFSET) + "\"" + + "," + "\"limit\":" + "\"" + getProperty(KYLIN_QUERY_LIMIT) + "\"" + "}"); logger.info("post:" + postContent); postContent = postContent.replaceAll("[\u0000-\u001f]", " "); StringEntity entity = new StringEntity(postContent, "UTF-8"); @@ -196,10 +182,9 @@ public class KylinInterpreter extends Interpreter { logger.error("Cannot get json from string: " + result); // when code is 401, the response is html, not json if (code == 401) { - errorMessage.append( - " Error message: Unauthorized. This request requires " - + "HTTP authentication. Please make sure your have set your credentials " - + "correctly."); + errorMessage.append(" Error message: Unauthorized. This request requires " + + "HTTP authentication. Please make sure your have set your credentials " + + "correctly."); } else { errorMessage.append(" Error message: " + result + " ."); } @@ -215,18 +200,19 @@ public class KylinInterpreter extends Interpreter { throw new IOException(e); } - return new InterpreterResult(InterpreterResult.Code.SUCCESS, formatResult(result)); + return new InterpreterResult(InterpreterResult.Code.SUCCESS, + formatResult(result)); } String formatResult(String msg) { StringBuilder res = new StringBuilder("%table "); - + Matcher ml = KYLIN_TABLE_FORMAT_REGEX_LABEL.matcher(msg); while (!ml.hitEnd() && ml.find()) { res.append(ml.group(1) + " \t"); - } + } res.append(" \n"); - + Matcher mr = KYLIN_TABLE_FORMAT_REGEX_RESULTS.matcher(msg); String table = null; while (!mr.hitEnd() && mr.find()) { http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/kylin/src/test/java/org/apache/zeppelin/kylin/KylinInterpreterTest.java ---------------------------------------------------------------------- diff --git a/kylin/src/test/java/org/apache/zeppelin/kylin/KylinInterpreterTest.java b/kylin/src/test/java/org/apache/zeppelin/kylin/KylinInterpreterTest.java index 7cf82ea..66b6f9a 100755 --- a/kylin/src/test/java/org/apache/zeppelin/kylin/KylinInterpreterTest.java +++ b/kylin/src/test/java/org/apache/zeppelin/kylin/KylinInterpreterTest.java @@ -19,12 +19,6 @@ package org.apache.zeppelin.kylin; import static org.junit.Assert.assertEquals; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Locale; -import java.util.Properties; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -32,11 +26,19 @@ import org.apache.http.ProtocolVersion; import org.apache.http.StatusLine; import org.apache.http.client.methods.HttpPost; import org.apache.http.message.AbstractHttpMessage; -import org.apache.zeppelin.interpreter.InterpreterResult; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Locale; +import java.util.Properties; + +import org.apache.zeppelin.interpreter.InterpreterResult; + public class KylinInterpreterTest { static final Properties KYLIN_PROPERTIES = new Properties(); @@ -54,54 +56,38 @@ public class KylinInterpreterTest { @Test public void testWithDefault() { KylinInterpreter t = new MockKylinInterpreter(getDefaultProperties()); - InterpreterResult result = - t.interpret( - "select a.date,sum(b.measure) as measure from kylin_fact_table a " - + "inner join kylin_lookup_table b on a.date=b.date group by a.date", - null); - assertEquals( - "default", - t.getProject( - "select a.date,sum(b.measure) as measure " - + "from kylin_fact_table a inner join kylin_lookup_table b on a.date=b.date " - + "group by a.date")); + InterpreterResult result = t.interpret( + "select a.date,sum(b.measure) as measure from kylin_fact_table a " + + "inner join kylin_lookup_table b on a.date=b.date group by a.date", null); + assertEquals("default", t.getProject("select a.date,sum(b.measure) as measure " + + "from kylin_fact_table a inner join kylin_lookup_table b on a.date=b.date " + + "group by a.date")); assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType()); } @Test public void testWithProject() { KylinInterpreter t = new MockKylinInterpreter(getDefaultProperties()); - assertEquals( - "project2", - t.getProject( - "(project2)\n select a.date,sum(b.measure) " - + "as measure from kylin_fact_table a inner join kylin_lookup_table b on " - + "a.date=b.date group by a.date")); - assertEquals( - "", - t.getProject( - "()\n select a.date,sum(b.measure) as measure " - + "from kylin_fact_table a inner join kylin_lookup_table b on a.date=b.date " - + "group by a.date")); - assertEquals( - "\n select a.date,sum(b.measure) as measure from kylin_fact_table a " + assertEquals("project2", t.getProject("(project2)\n select a.date,sum(b.measure) " + + "as measure from kylin_fact_table a inner join kylin_lookup_table b on " + + "a.date=b.date group by a.date")); + assertEquals("", t.getProject("()\n select a.date,sum(b.measure) as measure " + + "from kylin_fact_table a inner join kylin_lookup_table b on a.date=b.date " + + "group by a.date")); + assertEquals("\n select a.date,sum(b.measure) as measure from kylin_fact_table a " + "inner join kylin_lookup_table b on a.date=b.date group by a.date", - t.getSQL( - "(project2)\n select a.date,sum(b.measure) as measure " - + "from kylin_fact_table a inner join kylin_lookup_table b on a.date=b.date " - + "group by a.date")); - assertEquals( - "\n select a.date,sum(b.measure) as measure from kylin_fact_table a " + t.getSQL("(project2)\n select a.date,sum(b.measure) as measure " + + "from kylin_fact_table a inner join kylin_lookup_table b on a.date=b.date " + + "group by a.date")); + assertEquals("\n select a.date,sum(b.measure) as measure from kylin_fact_table a " + "inner join kylin_lookup_table b on a.date=b.date group by a.date", - t.getSQL( - "()\n select a.date,sum(b.measure) as measure from kylin_fact_table a " - + "inner join kylin_lookup_table b on a.date=b.date group by a.date")); + t.getSQL("()\n select a.date,sum(b.measure) as measure from kylin_fact_table a " + + "inner join kylin_lookup_table b on a.date=b.date group by a.date")); } @Test public void testParseResult() { - String msg = - "{\"columnMetas\":[{\"isNullable\":1,\"displaySize\":256,\"label\":\"COUNTRY\"," + String msg = "{\"columnMetas\":[{\"isNullable\":1,\"displaySize\":256,\"label\":\"COUNTRY\"," + "\"name\":\"COUNTRY\",\"schemaName\":\"DEFAULT\",\"catelogName\":null," + "\"tableName\":\"SALES_TABLE\",\"precision\":256,\"scale\":0,\"columnType\":12," + "\"columnTypeName\":\"VARCHAR\",\"writable\":false,\"readOnly\":true," @@ -123,12 +109,11 @@ public class KylinInterpreterTest { + "\"isException\":false,\"exceptionMessage\":null,\"duration\":134," + "\"totalScanCount\":1,\"hitExceptionCache\":false,\"storageCacheUsed\":false," + "\"partial\":false}"; - String expected = - "%table COUNTRY \tCURRENCY \tCOUNT__ \t \n" - + "AMERICA \tUSD \tnull \t \n" - + "null \tRMB \t0 \t \n" - + "KOR \tnull \t100 \t \n" - + "\\\"abc\\\" \ta,b,c \t-1 \t \n"; + String expected = "%table COUNTRY \tCURRENCY \tCOUNT__ \t \n" + + "AMERICA \tUSD \tnull \t \n" + + "null \tRMB \t0 \t \n" + + "KOR \tnull \t100 \t \n" + + "\\\"abc\\\" \ta,b,c \t-1 \t \n"; KylinInterpreter t = new MockKylinInterpreter(getDefaultProperties()); String actual = t.formatResult(msg); Assert.assertEquals(expected, actual); @@ -136,8 +121,7 @@ public class KylinInterpreterTest { @Test public void testParseEmptyResult() { - String msg = - "{\"columnMetas\":[{\"isNullable\":1,\"displaySize\":256,\"label\":\"COUNTRY\"," + String msg = "{\"columnMetas\":[{\"isNullable\":1,\"displaySize\":256,\"label\":\"COUNTRY\"," + "\"name\":\"COUNTRY\",\"schemaName\":\"DEFAULT\",\"catelogName\":null," + "\"tableName\":\"SALES_TABLE\",\"precision\":256,\"scale\":0,\"columnType\":12," + "\"columnTypeName\":\"VARCHAR\",\"writable\":false,\"readOnly\":true," @@ -154,8 +138,7 @@ public class KylinInterpreterTest { + "\"columnType\":-5,\"columnTypeName\":\"BIGINT\",\"writable\":false," + "\"readOnly\":true,\"definitelyWritable\":false,\"autoIncrement\":false," + "\"caseSensitive\":true,\"searchable\":false,\"currency\":false,\"signed\":true}]," - + "\"results\":[]," - + "\"cube\":\"Sample_Cube\",\"affectedRowCount\":0," + + "\"results\":[]," + "\"cube\":\"Sample_Cube\",\"affectedRowCount\":0," + "\"isException\":false,\"exceptionMessage\":null,\"duration\":134," + "\"totalScanCount\":1,\"hitExceptionCache\":false,\"storageCacheUsed\":false," + "\"partial\":false}"; @@ -190,32 +173,37 @@ class MockKylinInterpreter extends KylinInterpreter { } } -class MockHttpClient { - public MockHttpResponse execute(HttpPost post) { +class MockHttpClient{ + public MockHttpResponse execute(HttpPost post){ return new MockHttpResponse(); } } -class MockHttpResponse extends AbstractHttpMessage implements HttpResponse { +class MockHttpResponse extends AbstractHttpMessage implements HttpResponse{ @Override public StatusLine getStatusLine() { return new MockStatusLine(); } @Override - public void setStatusLine(StatusLine statusLine) {} + public void setStatusLine(StatusLine statusLine) { + } @Override - public void setStatusLine(ProtocolVersion protocolVersion, int i) {} + public void setStatusLine(ProtocolVersion protocolVersion, int i) { + } @Override - public void setStatusLine(ProtocolVersion protocolVersion, int i, String s) {} + public void setStatusLine(ProtocolVersion protocolVersion, int i, String s) { + } @Override - public void setStatusCode(int i) throws IllegalStateException {} + public void setStatusCode(int i) throws IllegalStateException { + } @Override - public void setReasonPhrase(String s) throws IllegalStateException {} + public void setReasonPhrase(String s) throws IllegalStateException { + } @Override public HttpEntity getEntity() { @@ -223,7 +211,8 @@ class MockHttpResponse extends AbstractHttpMessage implements HttpResponse { } @Override - public void setEntity(HttpEntity httpEntity) {} + public void setEntity(HttpEntity httpEntity) { + } @Override public Locale getLocale() { @@ -231,7 +220,8 @@ class MockHttpResponse extends AbstractHttpMessage implements HttpResponse { } @Override - public void setLocale(Locale locale) {} + public void setLocale(Locale locale) { + } @Override public ProtocolVersion getProtocolVersion() { @@ -239,7 +229,7 @@ class MockHttpResponse extends AbstractHttpMessage implements HttpResponse { } } -class MockStatusLine implements StatusLine { +class MockStatusLine implements StatusLine{ @Override public ProtocolVersion getProtocolVersion() { return null; @@ -256,7 +246,7 @@ class MockStatusLine implements StatusLine { } } -class MockEntity implements HttpEntity { +class MockEntity implements HttpEntity{ @Override public boolean isRepeatable() { return false; @@ -284,16 +274,15 @@ class MockEntity implements HttpEntity { @Override public InputStream getContent() throws IOException, IllegalStateException { - return new ByteArrayInputStream( - ("{\"columnMetas\":" - + "[{\"label\":\"PART_DT\"},{\"label\":\"measure\"}]," - + "\"results\":[[\"2012-01-03\",\"917.4138\"]," - + "[\"2012-05-06\",\"592.4823\"]]}") - .getBytes()); + return new ByteArrayInputStream(("{\"columnMetas\":" + + "[{\"label\":\"PART_DT\"},{\"label\":\"measure\"}]," + + "\"results\":[[\"2012-01-03\",\"917.4138\"]," + + "[\"2012-05-06\",\"592.4823\"]]}").getBytes()); } @Override - public void writeTo(OutputStream outputStream) throws IOException {} + public void writeTo(OutputStream outputStream) throws IOException { + } @Override public boolean isStreaming() { @@ -301,5 +290,6 @@ class MockEntity implements HttpEntity { } @Override - public void consumeContent() throws IOException {} + public void consumeContent() throws IOException { + } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/lens/pom.xml ---------------------------------------------------------------------- diff --git a/lens/pom.xml b/lens/pom.xml index a5d86fb..5eb81c2 100644 --- a/lens/pom.xml +++ b/lens/pom.xml @@ -171,6 +171,13 @@ <plugin> <artifactId>maven-resources-plugin</artifactId> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + <configuration> + <skip>false</skip> + </configuration> + </plugin> </plugins> </build> </project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/lens/src/main/java/org/apache/zeppelin/lens/ExecutionDetail.java ---------------------------------------------------------------------- diff --git a/lens/src/main/java/org/apache/zeppelin/lens/ExecutionDetail.java b/lens/src/main/java/org/apache/zeppelin/lens/ExecutionDetail.java index 9029da3..081c3e5 100644 --- a/lens/src/main/java/org/apache/zeppelin/lens/ExecutionDetail.java +++ b/lens/src/main/java/org/apache/zeppelin/lens/ExecutionDetail.java @@ -1,15 +1,18 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at + * 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 * - * <p>http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * <p>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 + * 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.lens; @@ -17,7 +20,9 @@ package org.apache.zeppelin.lens; import org.apache.lens.client.LensClient; import org.springframework.shell.core.JLineShell; -/** Pojo tracking query execution details. Used to cancel the query. */ +/** + * Pojo tracking query execution details. Used to cancel the query. + */ public class ExecutionDetail { private String queryHandle; private LensClient lensClient; http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/lens/src/main/java/org/apache/zeppelin/lens/LensBootstrap.java ---------------------------------------------------------------------- diff --git a/lens/src/main/java/org/apache/zeppelin/lens/LensBootstrap.java b/lens/src/main/java/org/apache/zeppelin/lens/LensBootstrap.java index b0c393f..670ed33 100644 --- a/lens/src/main/java/org/apache/zeppelin/lens/LensBootstrap.java +++ b/lens/src/main/java/org/apache/zeppelin/lens/LensBootstrap.java @@ -1,12 +1,12 @@ /* * Copyright 2011-2012 the original author or authors. - * + * * Licensed 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. @@ -19,13 +19,14 @@ package org.apache.zeppelin.lens; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.support.GenericApplicationContext; - -/** workaround for https://github.com/spring-projects/spring-shell/issues/73. */ + +/** + * workaround for https://github.com/spring-projects/spring-shell/issues/73. + */ public class LensBootstrap extends org.springframework.shell.Bootstrap { public LensBootstrap() { super(); } - public LensJLineShellComponent getLensJLineShellComponent() { GenericApplicationContext ctx = (GenericApplicationContext) getApplicationContext(); RootBeanDefinition rbd = new RootBeanDefinition(); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/lens/src/main/java/org/apache/zeppelin/lens/LensInterpreter.java ---------------------------------------------------------------------- diff --git a/lens/src/main/java/org/apache/zeppelin/lens/LensInterpreter.java b/lens/src/main/java/org/apache/zeppelin/lens/LensInterpreter.java index a132690..17fe931 100644 --- a/lens/src/main/java/org/apache/zeppelin/lens/LensInterpreter.java +++ b/lens/src/main/java/org/apache/zeppelin/lens/LensInterpreter.java @@ -1,19 +1,36 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at + * 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 * - * <p>http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * <p>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 + * 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.lens; +import org.apache.lens.cli.commands.BaseLensCommand; +import org.apache.lens.client.LensClient; +import org.apache.lens.client.LensClientConfig; +import org.apache.lens.client.LensClientSingletonWrapper; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.shell.Bootstrap; +import org.springframework.shell.core.CommandResult; +import org.springframework.shell.core.JLineShell; +import org.springframework.shell.core.JLineShellComponent; +import org.springframework.shell.support.logging.HandlerUtils; + import java.io.ByteArrayOutputStream; import java.util.LinkedHashMap; import java.util.List; @@ -22,10 +39,7 @@ import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.lens.cli.commands.BaseLensCommand; -import org.apache.lens.client.LensClient; -import org.apache.lens.client.LensClientConfig; -import org.apache.lens.client.LensClientSingletonWrapper; + import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterResult; @@ -33,15 +47,10 @@ import org.apache.zeppelin.interpreter.InterpreterResult.Code; import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; import org.apache.zeppelin.scheduler.Scheduler; import org.apache.zeppelin.scheduler.SchedulerFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.shell.Bootstrap; -import org.springframework.shell.core.CommandResult; -import org.springframework.shell.core.JLineShell; -import org.springframework.shell.core.JLineShellComponent; -import org.springframework.shell.support.logging.HandlerUtils; -/** Lens interpreter for Zeppelin. */ +/** + * Lens interpreter for Zeppelin. + */ public class LensInterpreter extends Interpreter { static final Logger LOGGER = LoggerFactory.getLogger(LensInterpreter.class); static final String LENS_CLIENT_DBNAME = "lens.client.dbname"; @@ -51,23 +60,22 @@ public class LensInterpreter extends Interpreter { static final String ZEPPELIN_LENS_RUN_CONCURRENT_SESSION = "zeppelin.lens.run.concurrent"; static final String ZEPPELIN_LENS_CONCURRENT_SESSIONS = "zeppelin.lens.maxThreads"; static final String ZEPPELIN_MAX_ROWS = "zeppelin.lens.maxResults"; - static final Map<String, Pattern> LENS_TABLE_FORMAT_REGEX = - new LinkedHashMap<String, Pattern>() { - { - put("cubes", Pattern.compile(".*show\\s+cube.*")); - put("nativetables", Pattern.compile(".*show\\s+nativetable.*")); - put("storages", Pattern.compile(".*show\\s+storage.*")); - put("facts", Pattern.compile(".*show\\s+fact.*")); - put("dimensions", Pattern.compile(".*show\\s+dimension.*")); - put("params", Pattern.compile(".*show\\s+param.*")); - put("databases", Pattern.compile(".*show\\s+database.*")); - put("query results", Pattern.compile(".*query\\s+results.*")); - } - }; + static final Map<String, Pattern> LENS_TABLE_FORMAT_REGEX = new LinkedHashMap<String, Pattern>() { + { + put("cubes", Pattern.compile(".*show\\s+cube.*")); + put("nativetables", Pattern.compile(".*show\\s+nativetable.*")); + put("storages", Pattern.compile(".*show\\s+storage.*")); + put("facts", Pattern.compile(".*show\\s+fact.*")); + put("dimensions", Pattern.compile(".*show\\s+dimension.*")); + put("params", Pattern.compile(".*show\\s+param.*")); + put("databases", Pattern.compile(".*show\\s+database.*")); + put("query results", Pattern.compile(".*query\\s+results.*")); + } + }; private static Pattern queryExecutePattern = Pattern.compile(".*query\\s+execute\\s+(.*)"); // tracks paragraphId -> Lens QueryHandle - private static Map<String, ExecutionDetail> paraToQH = new ConcurrentHashMap<>(); + private static Map<String, ExecutionDetail> paraToQH = new ConcurrentHashMap<> (); private static Map<LensClient, Boolean> clientMap = new ConcurrentHashMap<>(); private int maxResults; @@ -83,26 +91,22 @@ public class LensInterpreter extends Interpreter { lensClientConfig = new LensClientConfig(); lensClientConfig.set(LENS_SERVER_URL, property.get(LENS_SERVER_URL).toString()); lensClientConfig.set(LENS_CLIENT_DBNAME, property.get(LENS_CLIENT_DBNAME).toString()); - lensClientConfig.set( - LENS_SESSION_CLUSTER_USER, property.get(LENS_SESSION_CLUSTER_USER).toString()); + lensClientConfig.set(LENS_SESSION_CLUSTER_USER, property.get(LENS_SESSION_CLUSTER_USER) + .toString()); lensClientConfig.set(LENS_PERSIST_RESULTSET, property.get(LENS_PERSIST_RESULTSET).toString()); try { maxResults = Integer.parseInt(property.get(ZEPPELIN_MAX_ROWS).toString()); } catch (NumberFormatException | NullPointerException e) { maxResults = 1000; - LOGGER.error( - "unable to parse " + ZEPPELIN_MAX_ROWS + " :" + property.get(ZEPPELIN_MAX_ROWS), e); + LOGGER.error("unable to parse " + ZEPPELIN_MAX_ROWS + " :" + + property.get(ZEPPELIN_MAX_ROWS), e); } try { maxThreads = Integer.parseInt(property.get(ZEPPELIN_LENS_CONCURRENT_SESSIONS).toString()); } catch (NumberFormatException | NullPointerException e) { maxThreads = 10; - LOGGER.error( - "unable to parse " - + ZEPPELIN_LENS_CONCURRENT_SESSIONS - + " :" - + property.get(ZEPPELIN_LENS_CONCURRENT_SESSIONS), - e); + LOGGER.error("unable to parse " + ZEPPELIN_LENS_CONCURRENT_SESSIONS + " :" + + property.get(ZEPPELIN_LENS_CONCURRENT_SESSIONS), e); } LOGGER.info("LensInterpreter created"); } catch (Exception e) { @@ -140,7 +144,7 @@ public class LensInterpreter extends Interpreter { init(); LOGGER.info("LensInterpreter opened"); } - + @Override public void close() { closeConnections(); @@ -167,10 +171,11 @@ public class LensInterpreter extends Interpreter { LensClient lensClient; try { lensClient = new LensClient(lensClientConfig); - + for (String beanName : bs.getApplicationContext().getBeanDefinitionNames()) { if (bs.getApplicationContext().getBean(beanName) instanceof BaseLensCommand) { - ((BaseLensCommand) bs.getApplicationContext().getBean(beanName)).setClient(lensClient); + ((BaseLensCommand) bs.getApplicationContext().getBean(beanName)) + .setClient(lensClient); } } } catch (Exception e) { @@ -183,12 +188,11 @@ public class LensInterpreter extends Interpreter { private InterpreterResult handleHelp(JLineShell shell, String st) { java.util.logging.StreamHandler sh = null; java.util.logging.Logger springLogger = null; - java.util.logging.Formatter formatter = - new java.util.logging.Formatter() { - public String format(java.util.logging.LogRecord record) { - return record.getMessage(); - } - }; + java.util.logging.Formatter formatter = new java.util.logging.Formatter() { + public String format(java.util.logging.LogRecord record) { + return record.getMessage(); + } + }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { sh = new java.util.logging.StreamHandler(baos, formatter); @@ -205,7 +209,7 @@ public class LensInterpreter extends Interpreter { } return new InterpreterResult(Code.SUCCESS, baos.toString()); } - + private String modifyQueryStatement(String st) { Matcher matcher = queryExecutePattern.matcher(st.toLowerCase()); if (!matcher.find()) { @@ -230,40 +234,36 @@ public class LensInterpreter extends Interpreter { } String st = input.replaceAll("\\n", " "); LOGGER.info("LensInterpreter command: " + st); - + Bootstrap bs = createBootstrap(); - JLineShell shell = getJLineShell(bs); + JLineShell shell = getJLineShell(bs); CommandResult res; LensClient lensClient = null; String qh = null; - + if (st.trim().startsWith("help")) { return handleHelp(shell, st); } - + try { lensClient = createAndSetLensClient(bs); clientMap.put(lensClient, true); - + String lensCommand = modifyQueryStatement(st); - + LOGGER.info("executing command : " + lensCommand); res = shell.executeCommand(lensCommand); - - if (!lensCommand.equals(st) - && res != null - && res.getResult() != null + + if (!lensCommand.equals(st) && res != null + && res.getResult() != null && res.getResult().toString().trim().matches("[a-z0-9-]+")) { // setup query progress tracking qh = res.getResult().toString(); paraToQH.put(context.getParagraphId(), new ExecutionDetail(qh, lensClient, shell)); String getResultsCmd = "query results --async false " + qh; - LOGGER.info( - "executing query results command : " - + context.getParagraphId() - + " : " + LOGGER.info("executing query results command : " + context.getParagraphId() + " : " + getResultsCmd); - res = shell.executeCommand(getResultsCmd); + res = shell.executeCommand(getResultsCmd); paraToQH.remove(context.getParagraphId()); } } catch (Exception ex) { @@ -283,7 +283,7 @@ public class LensInterpreter extends Interpreter { } return new InterpreterResult(Code.SUCCESS, formatResult(st, res)); } - + private void closeShell(JLineShell shell) { if (shell instanceof LensJLineShellComponent) { ((LensJLineShellComponent) shell).stop(); @@ -291,7 +291,7 @@ public class LensInterpreter extends Interpreter { ((JLineShellComponent) shell).stop(); } } - + private String formatResult(String st, CommandResult result) { if (result == null) { return "error in interpret, no result object returned"; @@ -299,8 +299,8 @@ public class LensInterpreter extends Interpreter { if (!result.isSuccess() || result.getResult() == null) { if (result.getException() != null) { return result.getException().getMessage(); - // try describe cube (without cube name)- error is written as a warning, - // but not returned to result object + //try describe cube (without cube name)- error is written as a warning, + //but not returned to result object } else { return "error in interpret, unable to execute command"; } @@ -312,15 +312,15 @@ public class LensInterpreter extends Interpreter { break; } } - if (queryExecutePattern.matcher(st.toLowerCase()).find() - && result.getResult().toString().contains(" rows process in (")) { + if (queryExecutePattern.matcher(st.toLowerCase()).find() && + result.getResult().toString().contains(" rows process in (")) { sb.append("%table "); } if (sb.length() > 0) { return sb.append(result.getResult().toString()).toString(); } return result.getResult().toString(); - // Lens sends error messages without setting result.isSuccess() = false. + //Lens sends error messages without setting result.isSuccess() = false. } @Override @@ -339,12 +339,7 @@ public class LensInterpreter extends Interpreter { clientMap.put(lensClient, true); LOGGER.info("invoke query kill (" + context.getParagraphId() + ") " + qh); CommandResult res = shell.executeCommand("query kill " + qh); - LOGGER.info( - "query kill returned (" - + context.getParagraphId() - + ") " - + qh - + " with: " + LOGGER.info("query kill returned (" + context.getParagraphId() + ") " + qh + " with: " + res.getResult()); } catch (Exception e) { LOGGER.error("unable to kill query (" + context.getParagraphId() + ") " + qh, e); @@ -385,7 +380,7 @@ public class LensInterpreter extends Interpreter { clientMap.put(lensClient, true); CommandResult res = shell.executeCommand("query status " + qh); LOGGER.info(context.getParagraphId() + " --> " + res.getResult().toString()); - // change to debug + //change to debug Pattern pattern = Pattern.compile(".*(Progress : (\\d\\.\\d)).*"); Matcher matcher = pattern.matcher(res.getResult().toString().replaceAll("\\n", " ")); if (matcher.find(2)) { @@ -415,11 +410,11 @@ public class LensInterpreter extends Interpreter { } @Override - public List<InterpreterCompletion> completion( - String buf, int cursor, InterpreterContext interpreterContext) { + public List<InterpreterCompletion> completion(String buf, int cursor, + InterpreterContext interpreterContext) { return null; } - + public boolean concurrentRequests() { return Boolean.parseBoolean(getProperty(ZEPPELIN_LENS_RUN_CONCURRENT_SESSION)); } @@ -427,9 +422,8 @@ public class LensInterpreter extends Interpreter { @Override public Scheduler getScheduler() { if (concurrentRequests()) { - return SchedulerFactory.singleton() - .createOrGetParallelScheduler( - LensInterpreter.class.getName() + this.hashCode(), maxThreads); + return SchedulerFactory.singleton().createOrGetParallelScheduler( + LensInterpreter.class.getName() + this.hashCode(), maxThreads); } else { return super.getScheduler(); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/lens/src/main/java/org/apache/zeppelin/lens/LensJLineShellComponent.java ---------------------------------------------------------------------- diff --git a/lens/src/main/java/org/apache/zeppelin/lens/LensJLineShellComponent.java b/lens/src/main/java/org/apache/zeppelin/lens/LensJLineShellComponent.java index 3058116..cba113c 100644 --- a/lens/src/main/java/org/apache/zeppelin/lens/LensJLineShellComponent.java +++ b/lens/src/main/java/org/apache/zeppelin/lens/LensJLineShellComponent.java @@ -1,12 +1,12 @@ /* * Copyright 2011-2012 the original author or authors. - * + * * Licensed 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. @@ -15,9 +15,9 @@ */ package org.apache.zeppelin.lens; -import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.InitializingBean; @@ -37,11 +37,16 @@ import org.springframework.shell.plugin.HistoryFileNameProvider; import org.springframework.shell.plugin.PluginUtils; import org.springframework.shell.plugin.PromptProvider; -/** workaround for https://github.com/spring-projects/spring-shell/issues/73. */ -public class LensJLineShellComponent extends JLineShell - implements SmartLifecycle, ApplicationContextAware, InitializingBean { - @Autowired private CommandLine commandLine; +import java.util.Map; +/** + * workaround for https://github.com/spring-projects/spring-shell/issues/73. + */ +public class LensJLineShellComponent extends JLineShell implements SmartLifecycle, + ApplicationContextAware, InitializingBean { + @Autowired + private CommandLine commandLine; + private volatile boolean running = false; private Thread shellThread; @@ -67,18 +72,18 @@ public class LensJLineShellComponent extends JLineShell public boolean isAutoStartup() { return false; } - + public void stop(Runnable callback) { stop(); callback.run(); } - + public int getPhase() { return 1; } - + public void start() { - // customizePlug must run before start thread to take plugin's configuration into effect + //customizePlug must run before start thread to take plugin's configuration into effect customizePlugin(); shellThread = new Thread(this, "Spring Shell"); shellThread.start(); @@ -95,29 +100,31 @@ public class LensJLineShellComponent extends JLineShell public boolean isRunning() { return running; } - + @SuppressWarnings("rawtypes") public void afterPropertiesSet() { - Map<String, CommandMarker> commands = - BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, CommandMarker.class); + Map<String, CommandMarker> commands = BeanFactoryUtils.beansOfTypeIncludingAncestors( + applicationContext, CommandMarker.class); for (CommandMarker command : commands.values()) { getSimpleParser().add(command); } - Map<String, Converter> converters = - BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, Converter.class); + Map<String, Converter> converters = BeanFactoryUtils.beansOfTypeIncludingAncestors( + applicationContext, Converter.class); for (Converter<?> converter : converters.values()) { getSimpleParser().add(converter); } - + setHistorySize(commandLine.getHistorySize()); if (commandLine.getShellCommandsToExecute() != null) { setPrintBanner(false); } } - /** Wait the shell command to complete by typing "quit" or "exit". */ + /** + * Wait the shell command to complete by typing "quit" or "exit". + */ public void waitForComplete() { try { shellThread.join(); @@ -156,14 +163,13 @@ public class LensJLineShellComponent extends JLineShell } /** - * get history file name from provider. The provider has highest order {@link - * org.springframework.core.Ordered#getOrder()} will win. - * - * @return history file name + * get history file name from provider. The provider has highest order + * {@link org.springframework.core.Ordered#getOrder()} will win. + * + * @return history file name */ protected String getHistoryFileName() { - HistoryFileNameProvider historyFileNameProvider = - PluginUtils.getHighestPriorityProvider( + HistoryFileNameProvider historyFileNameProvider = PluginUtils.getHighestPriorityProvider( this.applicationContext, HistoryFileNameProvider.class); String providerHistoryFileName = historyFileNameProvider.getHistoryFileName(); if (providerHistoryFileName != null) { @@ -174,14 +180,14 @@ public class LensJLineShellComponent extends JLineShell } /** - * get prompt text from provider. The provider has highest order {@link - * org.springframework.core.Ordered#getOrder()} will win. - * + * get prompt text from provider. The provider has highest order + * {@link org.springframework.core.Ordered#getOrder()} will win. + * * @return prompt text */ protected String getPromptText() { - PromptProvider promptProvider = - PluginUtils.getHighestPriorityProvider(this.applicationContext, PromptProvider.class); + PromptProvider promptProvider = PluginUtils.getHighestPriorityProvider(this.applicationContext, + PromptProvider.class); String providerPromptText = promptProvider.getPrompt(); if (providerPromptText != null) { return providerPromptText; @@ -191,16 +197,18 @@ public class LensJLineShellComponent extends JLineShell } /** - * Get Banner and Welcome Message from provider. The provider has highest order {@link - * org.springframework.core.Ordered#getOrder()} will win. + * Get Banner and Welcome Message from provider. The provider has highest order + * {@link org.springframework.core.Ordered#getOrder()} will win. * - * @return BannerText[0]: Banner BannerText[1]: Welcome Message BannerText[2]: Version - * BannerText[3]: Product Name + * @return BannerText[0]: Banner + * BannerText[1]: Welcome Message + * BannerText[2]: Version + * BannerText[3]: Product Name */ private String[] getBannerText() { String[] bannerText = new String[4]; - BannerProvider provider = - PluginUtils.getHighestPriorityProvider(this.applicationContext, BannerProvider.class); + BannerProvider provider = PluginUtils.getHighestPriorityProvider(this.applicationContext, + BannerProvider.class); bannerText[0] = provider.getBanner(); bannerText[1] = provider.getWelcomeMessage(); bannerText[2] = provider.getVersion(); @@ -217,22 +225,24 @@ public class LensJLineShellComponent extends JLineShell /** * get the welcome message at start. - * + * * @return welcome message */ public String getWelcomeMessage() { return this.welcomeMessage; } - /** @param printBanner the printBanner to set */ + /** + * @param printBanner the printBanner to set + */ public void setPrintBanner(boolean printBanner) { this.printBanner = printBanner; } - + protected String getProductName() { return productName; } - + protected String getVersion() { return version; } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/lens/src/main/java/org/apache/zeppelin/lens/LensSimpleExecutionStrategy.java ---------------------------------------------------------------------- diff --git a/lens/src/main/java/org/apache/zeppelin/lens/LensSimpleExecutionStrategy.java b/lens/src/main/java/org/apache/zeppelin/lens/LensSimpleExecutionStrategy.java index 1d9b083..4a802ac 100644 --- a/lens/src/main/java/org/apache/zeppelin/lens/LensSimpleExecutionStrategy.java +++ b/lens/src/main/java/org/apache/zeppelin/lens/LensSimpleExecutionStrategy.java @@ -15,7 +15,6 @@ */ package org.apache.zeppelin.lens; -import java.util.logging.Logger; import org.springframework.shell.core.ExecutionProcessor; import org.springframework.shell.core.ExecutionStrategy; import org.springframework.shell.event.ParseResult; @@ -23,7 +22,11 @@ import org.springframework.shell.support.logging.HandlerUtils; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; -/** workaround for https://github.com/spring-projects/spring-shell/issues/73. */ +import java.util.logging.Logger; + +/** + * workaround for https://github.com/spring-projects/spring-shell/issues/73. + */ public class LensSimpleExecutionStrategy implements ExecutionStrategy { private static final Logger logger = HandlerUtils.getLogger(LensSimpleExecutionStrategy.class); @@ -53,8 +56,8 @@ public class LensSimpleExecutionStrategy implements ExecutionStrategy { private Object invoke(ParseResult parseResult) { try { - return ReflectionUtils.invokeMethod( - parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments()); + return ReflectionUtils.invokeMethod(parseResult.getMethod(), + parseResult.getInstance(), parseResult.getArguments()); } catch (Throwable th) { logger.severe("Command failed " + th); return handleThrowable(th); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/lens/src/test/java/org/apache/zeppelin/lens/LensInterpreterTest.java ---------------------------------------------------------------------- diff --git a/lens/src/test/java/org/apache/zeppelin/lens/LensInterpreterTest.java b/lens/src/test/java/org/apache/zeppelin/lens/LensInterpreterTest.java index 6d84a6e..6f1f18a 100644 --- a/lens/src/test/java/org/apache/zeppelin/lens/LensInterpreterTest.java +++ b/lens/src/test/java/org/apache/zeppelin/lens/LensInterpreterTest.java @@ -1,19 +1,24 @@ /** - * 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 + * 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 * - * <p>http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * <p>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 + * 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.lens; +import static org.junit.Assert.assertEquals; + import static org.apache.zeppelin.lens.LensInterpreter.LENS_CLIENT_DBNAME; import static org.apache.zeppelin.lens.LensInterpreter.LENS_PERSIST_RESULTSET; import static org.apache.zeppelin.lens.LensInterpreter.LENS_SERVER_URL; @@ -21,21 +26,26 @@ import static org.apache.zeppelin.lens.LensInterpreter.LENS_SESSION_CLUSTER_USER import static org.apache.zeppelin.lens.LensInterpreter.ZEPPELIN_LENS_CONCURRENT_SESSIONS; import static org.apache.zeppelin.lens.LensInterpreter.ZEPPELIN_LENS_RUN_CONCURRENT_SESSION; import static org.apache.zeppelin.lens.LensInterpreter.ZEPPELIN_MAX_ROWS; -import static org.junit.Assert.assertEquals; -import java.util.Properties; -import org.apache.zeppelin.interpreter.InterpreterResult; import org.junit.After; import org.junit.Before; import org.junit.Test; -/** Lens interpreter unit tests. */ +import java.util.Properties; + +import org.apache.zeppelin.interpreter.InterpreterResult; + +/** + * Lens interpreter unit tests. + */ public class LensInterpreterTest { @Before - public void setUp() throws Exception {} + public void setUp() throws Exception { + } @After - public void tearDown() throws Exception {} + public void tearDown() throws Exception { + } @Test public void test() { @@ -49,17 +59,17 @@ public class LensInterpreterTest { prop.setProperty(ZEPPELIN_LENS_CONCURRENT_SESSIONS, "10"); LensInterpreter t = new MockLensInterpreter(prop); t.open(); - // simple help test + //simple help test InterpreterResult result = t.interpret("help", null); assertEquals(result.message().get(0).getType(), InterpreterResult.Type.TEXT); - // assertEquals("unable to find 'query execute' in help message", + //assertEquals("unable to find 'query execute' in help message", // result.message().contains("query execute"), result.message()); t.close(); } - + class MockLensInterpreter extends LensInterpreter { MockLensInterpreter(Properties property) { - super(property); + super(property); } @Override http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/livy/pom.xml ---------------------------------------------------------------------- diff --git a/livy/pom.xml b/livy/pom.xml index eddeb83..6c911e1 100644 --- a/livy/pom.xml +++ b/livy/pom.xml @@ -407,6 +407,14 @@ </execution> </executions> </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + <configuration> + <skip>false</skip> + </configuration> + </plugin> </plugins> </build> </project> http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/livy/src/main/java/org/apache/zeppelin/livy/APINotFoundException.java ---------------------------------------------------------------------- diff --git a/livy/src/main/java/org/apache/zeppelin/livy/APINotFoundException.java b/livy/src/main/java/org/apache/zeppelin/livy/APINotFoundException.java index 64c9c7d..3c4b714 100644 --- a/livy/src/main/java/org/apache/zeppelin/livy/APINotFoundException.java +++ b/livy/src/main/java/org/apache/zeppelin/livy/APINotFoundException.java @@ -17,9 +17,12 @@ package org.apache.zeppelin.livy; -/** APINotFoundException happens because we may introduce new apis in new livy version. */ +/** + * APINotFoundException happens because we may introduce new apis in new livy version. + */ public class APINotFoundException extends LivyException { - public APINotFoundException() {} + public APINotFoundException() { + } public APINotFoundException(String message) { super(message); @@ -33,8 +36,8 @@ public class APINotFoundException extends LivyException { super(cause); } - public APINotFoundException( - String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + public APINotFoundException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } }
