Skip to content

Commit

Permalink
DRILL-6496: Added print methods for debugging tests, and fixed missin…
Browse files Browse the repository at this point in the history
…g log statement in VectorUtils.

closes #1336
  • Loading branch information
ilooner authored and Ben-Zvi committed Jul 19, 2018
1 parent 6bb0879 commit 2c92ea2
Show file tree
Hide file tree
Showing 33 changed files with 447 additions and 172 deletions.
Expand Up @@ -55,11 +55,11 @@ protected List<QueryDataBatch> runHBaseSQLlWithResults(String sql) throws Except


protected void runSQLAndVerifyCount(String sql, int expectedRowCount) throws Exception{ protected void runSQLAndVerifyCount(String sql, int expectedRowCount) throws Exception{
List<QueryDataBatch> results = runHBaseSQLlWithResults(sql); List<QueryDataBatch> results = runHBaseSQLlWithResults(sql);
printResultAndVerifyRowCount(results, expectedRowCount); logResultAndVerifyRowCount(results, expectedRowCount);
} }


private void printResultAndVerifyRowCount(List<QueryDataBatch> results, int expectedRowCount) throws SchemaChangeException { private void logResultAndVerifyRowCount(List<QueryDataBatch> results, int expectedRowCount) throws SchemaChangeException {
int rowCount = printResult(results); int rowCount = logResult(results);
if (expectedRowCount != -1) { if (expectedRowCount != -1) {
Assert.assertEquals(expectedRowCount, rowCount); Assert.assertEquals(expectedRowCount, rowCount);
} }
Expand Down
Expand Up @@ -79,7 +79,7 @@ protected String getPlanText(String planFile, String tableName) throws IOExcepti
protected void runHBasePhysicalVerifyCount(String planFile, String tableName, int expectedRowCount) throws Exception{ protected void runHBasePhysicalVerifyCount(String planFile, String tableName, int expectedRowCount) throws Exception{
String physicalPlan = getPlanText(planFile, tableName); String physicalPlan = getPlanText(planFile, tableName);
List<QueryDataBatch> results = testPhysicalWithResults(physicalPlan); List<QueryDataBatch> results = testPhysicalWithResults(physicalPlan);
printResultAndVerifyRowCount(results, expectedRowCount); logResultAndVerifyRowCount(results, expectedRowCount);
} }


protected List<QueryDataBatch> runHBaseSQLlWithResults(String sql) throws Exception { protected List<QueryDataBatch> runHBaseSQLlWithResults(String sql) throws Exception {
Expand All @@ -89,11 +89,11 @@ protected List<QueryDataBatch> runHBaseSQLlWithResults(String sql) throws Except


protected void runHBaseSQLVerifyCount(String sql, int expectedRowCount) throws Exception{ protected void runHBaseSQLVerifyCount(String sql, int expectedRowCount) throws Exception{
List<QueryDataBatch> results = runHBaseSQLlWithResults(sql); List<QueryDataBatch> results = runHBaseSQLlWithResults(sql);
printResultAndVerifyRowCount(results, expectedRowCount); logResultAndVerifyRowCount(results, expectedRowCount);
} }


private void printResultAndVerifyRowCount(List<QueryDataBatch> results, int expectedRowCount) throws SchemaChangeException { private void logResultAndVerifyRowCount(List<QueryDataBatch> results, int expectedRowCount) throws SchemaChangeException {
int rowCount = printResult(results); int rowCount = logResult(results);
if (expectedRowCount != -1) { if (expectedRowCount != -1) {
Assert.assertEquals(expectedRowCount, rowCount); Assert.assertEquals(expectedRowCount, rowCount);
} }
Expand Down
Expand Up @@ -55,7 +55,7 @@ public static void closeMyClient() throws IOException {
public void testColumnFamiliesAsJSONString() throws Exception { public void testColumnFamiliesAsJSONString() throws Exception {
setColumnWidths(new int[] {112, 12}); setColumnWidths(new int[] {112, 12});
List<QueryDataBatch> resultList = runHBaseSQLlWithResults("SELECT f, f2 FROM hbase.`[TABLE_NAME]` tableName LIMIT 1"); List<QueryDataBatch> resultList = runHBaseSQLlWithResults("SELECT f, f2 FROM hbase.`[TABLE_NAME]` tableName LIMIT 1");
printResult(resultList); logResult(resultList);
} }


} }
Expand Up @@ -96,7 +96,7 @@ public void testCastEmptyStrings() throws Exception {
List<QueryDataBatch> resultList = runHBaseSQLlWithResults("SELECT row_key,\n" List<QueryDataBatch> resultList = runHBaseSQLlWithResults("SELECT row_key,\n"
+ " CAST(t.f.c1 as INT) c1, CAST(t.f.c2 as BIGINT) c2, CAST(t.f.c3 as INT) c3,\n" + " CAST(t.f.c1 as INT) c1, CAST(t.f.c2 as BIGINT) c2, CAST(t.f.c3 as INT) c3,\n"
+ " CAST(t.f.c4 as INT) c4 FROM hbase.TestTableNullStr t where row_key='a1'"); + " CAST(t.f.c4 as INT) c4 FROM hbase.TestTableNullStr t where row_key='a1'");
printResult(resultList); logResult(resultList);
} }
finally { finally {
test("alter system reset `drill.exec.functions.cast_empty_string_to_null`;"); test("alter system reset `drill.exec.functions.cast_empty_string_to_null`;");
Expand Down
Expand Up @@ -66,12 +66,12 @@ public List<QueryDataBatch> runKafkaSQLWithResults(String sql) throws Exception


public void runKafkaSQLVerifyCount(String sql, int expectedRowCount) throws Exception { public void runKafkaSQLVerifyCount(String sql, int expectedRowCount) throws Exception {
List<QueryDataBatch> results = runKafkaSQLWithResults(sql); List<QueryDataBatch> results = runKafkaSQLWithResults(sql);
printResultAndVerifyRowCount(results, expectedRowCount); logResultAndVerifyRowCount(results, expectedRowCount);
} }


public void printResultAndVerifyRowCount(List<QueryDataBatch> results, int expectedRowCount) public void logResultAndVerifyRowCount(List<QueryDataBatch> results, int expectedRowCount)
throws SchemaChangeException { throws SchemaChangeException {
int rowCount = printResult(results); int rowCount = logResult(results);
if (expectedRowCount != -1) { if (expectedRowCount != -1) {
Assert.assertEquals(expectedRowCount, rowCount); Assert.assertEquals(expectedRowCount, rowCount);
} }
Expand All @@ -89,4 +89,4 @@ public static void tearDownKafkaTestBase() throws Exception {
TestKafkaSuit.tearDownCluster(); TestKafkaSuit.tearDownCluster();
} }


} }
Expand Up @@ -64,12 +64,12 @@ public List<QueryDataBatch> runMongoSQLWithResults(String sql)
public void runMongoSQLVerifyCount(String sql, int expectedRowCount) public void runMongoSQLVerifyCount(String sql, int expectedRowCount)
throws Exception { throws Exception {
List<QueryDataBatch> results = runMongoSQLWithResults(sql); List<QueryDataBatch> results = runMongoSQLWithResults(sql);
printResultAndVerifyRowCount(results, expectedRowCount); logResultAndVerifyRowCount(results, expectedRowCount);
} }


public void printResultAndVerifyRowCount(List<QueryDataBatch> results, public void logResultAndVerifyRowCount(List<QueryDataBatch> results,
int expectedRowCount) throws SchemaChangeException { int expectedRowCount) throws SchemaChangeException {
int rowCount = printResult(results); int rowCount = logResult(results);
if (expectedRowCount != -1) { if (expectedRowCount != -1) {
Assert.assertEquals(expectedRowCount, rowCount); Assert.assertEquals(expectedRowCount, rowCount);
} }
Expand All @@ -92,4 +92,4 @@ public static void tearDownMongoTestBase() throws Exception {
storagePlugin = null; storagePlugin = null;
} }


} }
37 changes: 37 additions & 0 deletions docs/dev/TestLogging.md
Expand Up @@ -103,3 +103,40 @@ Then, if for some reason you want to see the Logback logging, add the following
-Dlogback.statusListenerClass=ch.qos.logback.core.status.OnConsoleStatusListener -Dlogback.statusListenerClass=ch.qos.logback.core.status.OnConsoleStatusListener
``` ```
The launch configuration option overrides (appears on the Java command line after) the global setting. The launch configuration option overrides (appears on the Java command line after) the global setting.

## Test Logging Configurations

### Default Test Log Levels

There is a global `logback-test.xml` configuration file in [common/src/test/resources/logback-test.xml](../../common/src/test/resources/logback-test.xml). This
logging configuration by default outputs error level logs to stdout.

Debug level logging to lilith can be turned on by adding `-Ddrill.lilith.enable=true` to the command used to run tests.

### Changing Test Log Levels

Often times it is most convenient to output logs to the console for debugging. This is best done programatically
by using the [LogFixture](../../exec/java-exec/src/test/java/org/apache/drill/test/LogFixture.java). The [LogFixture](../../exec/java-exec/src/test/java/org/apache/drill/test/LogFixture.java)
allows temporarily changing log levels for blocks of code programatically for debugging. An example of doing this is
the following.

```
try(LogFixture logFixture = new LogFixture.LogFixtureBuilder()
.logger(MyClass.class, Level.INFO)
.toConsole() // This redirects output to stdout
.build()) {
// Code block with different log levels.
}
```

More details on how to use the [LogFixture](../../exec/java-exec/src/test/java/org/apache/drill/test/LogFixture.java) can be found
int the javadocs for the class. Additionally, there are several methods that allow printing of query results to the console for debugging:

* BaseTestQuery.printResult
* QueryTestUtil.testRunAndPrint
* QueryBuilder.print
* ClusterTest.runAndPrint
* ClientFixture.runQueriesAndPrint

**IMPORTANT NOTE:** The methods described above along with LogFixtureBuilder.toConsole() should only be used for debugging. Code
that uses these methods should not be committed, since it produces excess logging on our build servers.
1 change: 0 additions & 1 deletion docs/dev/Testing.md
Expand Up @@ -149,7 +149,6 @@ Drill uses the [Maven Surefire plugin](http://maven.apache.org/components/surefi
-Ddrill.exec.sys.store.provider.local.write=false -Ddrill.exec.sys.store.provider.local.write=false
-Dorg.apache.drill.exec.server.Drillbit.system_options=\ -Dorg.apache.drill.exec.server.Drillbit.system_options=\
"org.apache.drill.exec.compile.ClassTransformer.scalar_replacement=on" "org.apache.drill.exec.compile.ClassTransformer.scalar_replacement=on"
-Ddrill.test.query.printing.silent=true
-Ddrill.catastrophic_to_standard_out=true -Ddrill.catastrophic_to_standard_out=true
-XX:MaxPermSize=512M -XX:MaxDirectMemorySize=3072M -XX:MaxPermSize=512M -XX:MaxDirectMemorySize=3072M
-Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Stack=true
Expand Down
Expand Up @@ -261,7 +261,7 @@ private void showSingleBatch (VectorAccessibleSerializable vcSerializable, boole
} }


/* show the contents in the batch */ /* show the contents in the batch */
VectorUtil.showVectorAccessibleContent(vectorContainer); VectorUtil.logVectorAccessibleContent(vectorContainer);
} }


/* Get batch meta info : rows, selectedRows, dataSize */ /* Get batch meta info : rows, selectedRows, dataSize */
Expand Down
Expand Up @@ -40,8 +40,8 @@


import io.netty.buffer.DrillBuf; import io.netty.buffer.DrillBuf;


public class PrintingResultsListener implements UserResultsListener { public class LoggingResultsListener implements UserResultsListener {
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PrintingResultsListener.class); private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(LoggingResultsListener.class);


private final AtomicInteger count = new AtomicInteger(); private final AtomicInteger count = new AtomicInteger();
private final Stopwatch w = Stopwatch.createUnstarted(); private final Stopwatch w = Stopwatch.createUnstarted();
Expand All @@ -50,7 +50,7 @@ public class PrintingResultsListener implements UserResultsListener {
private final int columnWidth; private final int columnWidth;
private final BufferAllocator allocator; private final BufferAllocator allocator;


public PrintingResultsListener(DrillConfig config, Format format, int columnWidth) { public LoggingResultsListener(DrillConfig config, Format format, int columnWidth) {
this.allocator = RootAllocatorFactory.newRoot(config); this.allocator = RootAllocatorFactory.newRoot(config);
this.loader = new RecordBatchLoader(allocator); this.loader = new RecordBatchLoader(allocator);
this.format = format; this.format = format;
Expand All @@ -59,15 +59,13 @@ public PrintingResultsListener(DrillConfig config, Format format, int columnWidt


@Override @Override
public void submissionFailed(UserException ex) { public void submissionFailed(UserException ex) {
System.out.println("Exception (no rows returned): " + ex + ". Returned in " + w.elapsed(TimeUnit.MILLISECONDS) logger.info("Exception (no rows returned). Returned in {} ms.", w.elapsed(TimeUnit.MILLISECONDS), ex);
+ "ms.");
} }


@Override @Override
public void queryCompleted(QueryState state) { public void queryCompleted(QueryState state) {
DrillAutoCloseables.closeNoChecked(allocator); DrillAutoCloseables.closeNoChecked(allocator);
System.out.println("Total rows returned : " + count.get() + ". Returned in " + w.elapsed(TimeUnit.MILLISECONDS) logger.info("Total rows returned: {}. Returned in {} ms.", count.get(), w.elapsed(TimeUnit.MILLISECONDS));
+ "ms.");
} }


@Override @Override
Expand All @@ -90,13 +88,13 @@ public void dataArrived(QueryDataBatch result, ConnectionThrottle throttle) {
try { try {
switch(format) { switch(format) {
case TABLE: case TABLE:
VectorUtil.showVectorAccessibleContent(loader, columnWidth); VectorUtil.logVectorAccessibleContent(loader, columnWidth);
break; break;
case TSV: case TSV:
VectorUtil.showVectorAccessibleContent(loader, "\t"); VectorUtil.logVectorAccessibleContent(loader, "\t");
break; break;
case CSV: case CSV:
VectorUtil.showVectorAccessibleContent(loader, ","); VectorUtil.logVectorAccessibleContent(loader, ",");
break; break;
default: default:
throw new IllegalStateException(format.toString()); throw new IllegalStateException(format.toString());
Expand Down
Expand Up @@ -189,7 +189,7 @@ public int submitQuery(DrillClient client, String plan, String type, String form
Stopwatch watch = Stopwatch.createUnstarted(); Stopwatch watch = Stopwatch.createUnstarted();
for (String query : queries) { for (String query : queries) {
AwaitableUserResultsListener listener = AwaitableUserResultsListener listener =
new AwaitableUserResultsListener(new PrintingResultsListener(client.getConfig(), outputFormat, width)); new AwaitableUserResultsListener(new LoggingResultsListener(client.getConfig(), outputFormat, width));
watch.start(); watch.start();
client.runQuery(queryType, query, listener); client.runQuery(queryType, query, listener);
int rows = listener.await(); int rows = listener.await();
Expand Down
@@ -0,0 +1,29 @@
/*
* 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.drill.exec.util;

/**
* The java standard library does not provide a lambda function interface for funtions that take no arguments,
* but that throw an exception. So, we have to define our own here.
* @param <T> The return type of the lambda function.
* @param <E> The type of exception thrown by the lambda function.
*/
@FunctionalInterface
public interface CheckedSupplier<T, E extends Exception> {
T get() throws E;
}
Expand Up @@ -39,7 +39,7 @@ public class VectorUtil {
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(VectorUtil.class); private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(VectorUtil.class);
public static final int DEFAULT_COLUMN_WIDTH = 15; public static final int DEFAULT_COLUMN_WIDTH = 15;


public static void showVectorAccessibleContent(VectorAccessible va, final String delimiter) { public static void logVectorAccessibleContent(VectorAccessible va, final String delimiter) {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
int rows = va.getRecordCount(); int rows = va.getRecordCount();
sb.append(rows).append(" row(s):\n"); sb.append(rows).append(" row(s):\n");
Expand Down Expand Up @@ -133,15 +133,15 @@ public static void appendVectorAccessibleContent(VectorAccessible va, StringBuil
} }
} }


public static void showVectorAccessibleContent(VectorAccessible va) { public static void logVectorAccessibleContent(VectorAccessible va) {
showVectorAccessibleContent(va, DEFAULT_COLUMN_WIDTH); logVectorAccessibleContent(va, DEFAULT_COLUMN_WIDTH);
} }


public static void showVectorAccessibleContent(VectorAccessible va, int columnWidth) { public static void logVectorAccessibleContent(VectorAccessible va, int columnWidth) {
showVectorAccessibleContent(va, new int[]{ columnWidth }); logVectorAccessibleContent(va, new int[]{ columnWidth });
} }


public static void showVectorAccessibleContent(VectorAccessible va, int[] columnWidths) { public static void logVectorAccessibleContent(VectorAccessible va, int[] columnWidths) {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
int width = 0; int width = 0;
int columnIndex = 0; int columnIndex = 0;
Expand Down Expand Up @@ -194,6 +194,8 @@ public static void showVectorAccessibleContent(VectorAccessible va, int[] column
for (VectorWrapper<?> vw : va) { for (VectorWrapper<?> vw : va) {
vw.clear(); vw.clear();
} }

logger.info(sb.toString());
} }


private static String expandMapSchema(MaterializedField mapField) { private static String expandMapSchema(MaterializedField mapField) {
Expand Down
Expand Up @@ -181,7 +181,7 @@ public void run() {


@Test @Test
public void testConcurrentQueries() throws Exception { public void testConcurrentQueries() throws Exception {
QueryTestUtil.testRunAndPrint(client, UserBitShared.QueryType.SQL, alterSession); QueryTestUtil.testRunAndLog(client, UserBitShared.QueryType.SQL, alterSession);


testThread = Thread.currentThread(); testThread = Thread.currentThread();
final QuerySubmitter querySubmitter = new QuerySubmitter(); final QuerySubmitter querySubmitter = new QuerySubmitter();
Expand Down
Expand Up @@ -518,7 +518,7 @@ public void testBigIntVarCharReturnTripConvertLogical() throws Exception {
count += result.getHeader().getRowCount(); count += result.getHeader().getRowCount();
loader.load(result.getHeader().getDef(), result.getData()); loader.load(result.getHeader().getDef(), result.getData());
if (loader.getRecordCount() > 0) { if (loader.getRecordCount() > 0) {
VectorUtil.showVectorAccessibleContent(loader); VectorUtil.logVectorAccessibleContent(loader);
} }
loader.clear(); loader.clear();
result.release(); result.release();
Expand Down

0 comments on commit 2c92ea2

Please sign in to comment.