DRILL-3598: use a factory to create the root allocator. - made the constructor for TopLevelAllocator package private to enforce this
Delete a test that had been commented out for over a year, it no longer compiles due to interface changes and there is plenty of other testing for hash aggregate. Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/bfe6cfad Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/bfe6cfad Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/bfe6cfad Branch: refs/heads/master Commit: bfe6cfadc084d8ebba52236bbe2556d77ae357e0 Parents: e39fa83 Author: Chris Westin <[email protected]> Authored: Tue Aug 4 06:26:57 2015 -0700 Committer: Jason Altekruse <[email protected]> Committed: Wed Sep 2 14:05:28 2015 -0700 ---------------------------------------------------------------------- .../apache/drill/exec/TestMemoryRetention.java | 54 ++-- .../apache/drill/exec/client/DrillClient.java | 33 +-- .../org/apache/drill/exec/client/DumpCat.java | 62 ++--- .../exec/client/PrintingResultsListener.java | 4 +- .../drill/exec/memory/RootAllocatorFactory.java | 67 +++++ .../drill/exec/memory/TopLevelAllocator.java | 8 +- .../drill/exec/server/BootStrapContext.java | 11 +- .../java/org/apache/drill/BaseTestQuery.java | 39 +-- .../java/org/apache/drill/PlanningBase.java | 24 +- .../apache/drill/exec/client/DumpCatTest.java | 55 ++-- .../apache/drill/exec/expr/ExpressionTest.java | 27 +- .../fn/impl/TestByteComparisonFunctions.java | 83 +++--- .../drill/exec/fn/impl/TestMathFunctions.java | 69 +++-- .../exec/fn/impl/TestNewMathFunctions.java | 47 ++-- .../exec/fn/impl/TestRepeatedFunction.java | 44 ++-- .../apache/drill/exec/memory/TestEndianess.java | 23 +- .../exec/physical/impl/TestCastFunctions.java | 263 +++++++++---------- .../physical/impl/TestComparisonFunctions.java | 25 +- .../impl/TestImplicitCastFunctions.java | 37 ++- .../exec/physical/impl/TestOptiqPlans.java | 161 ++++++------ .../physical/impl/TestSimpleFragmentRun.java | 46 ++-- .../exec/physical/impl/TestSimpleFunctions.java | 109 ++++---- .../exec/physical/impl/TestStringFunctions.java | 116 ++++---- .../drill/exec/physical/impl/agg/TestAgg.java | 63 ++--- .../physical/impl/common/TestHashTable.java | 53 ++-- .../physical/impl/filter/TestSimpleFilter.java | 51 ++-- .../exec/physical/impl/join/TestHashJoin.java | 75 +++--- .../exec/physical/impl/join/TestMergeJoin.java | 148 +++++------ .../physical/impl/limit/TestSimpleLimit.java | 56 ++-- .../impl/project/TestSimpleProjection.java | 30 +-- .../exec/physical/impl/sort/TestSimpleSort.java | 14 +- .../impl/trace/TestTraceMultiRecordBatch.java | 58 ++-- .../impl/trace/TestTraceOutputDump.java | 113 ++++---- .../physical/impl/union/TestSimpleUnion.java | 36 ++- .../drill/exec/record/vector/TestLoad.java | 33 +-- .../exec/record/vector/TestValueVector.java | 10 +- .../exec/server/TestDrillbitResilience.java | 8 +- .../exec/store/TestDirectCodecFactory.java | 51 ++-- .../store/parquet/ParquetRecordReaderTest.java | 10 +- .../drill/exec/testing/TestResourceLeak.java | 14 +- .../drill/exec/vector/TestSplitAndTransfer.java | 31 +-- .../vector/complex/TestEmptyPopulation.java | 8 +- .../vector/complex/writer/TestRepeated.java | 6 +- .../drill/jdbc/impl/DrillConnectionImpl.java | 8 +- 44 files changed, 1111 insertions(+), 1172 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/main/java/org/apache/drill/exec/TestMemoryRetention.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/TestMemoryRetention.java b/exec/java-exec/src/main/java/org/apache/drill/exec/TestMemoryRetention.java index 37e5389..f632125 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/TestMemoryRetention.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/TestMemoryRetention.java @@ -25,29 +25,30 @@ import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; import org.apache.drill.common.config.DrillConfig; -import org.apache.drill.exec.memory.TopLevelAllocator; +import org.apache.drill.exec.memory.BufferAllocator; +import org.apache.drill.exec.memory.RootAllocatorFactory; import com.google.common.collect.Lists; public class TestMemoryRetention { - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestMemoryRetention.class); + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestMemoryRetention.class); - static final int SMALL_AVERAGE_BYTES = 1024 * 32; - static final int LARGE_BYTES = 32 * 1024 * 1024; - static final int PARALLEL_THREADS = 32; - static final double SMALL_ALLOCATION_MEM = 0.20; - static final double OVERHEAD_ALLOWANCE = 0.20; - static final List<Integer> ALLOCATIONS; - static final int MAX_ALLOCS = 100; - static final AtomicInteger ALLOCS = new AtomicInteger(0); + private static final int SMALL_AVERAGE_BYTES = 1024 * 32; + private static final int LARGE_BYTES = 32 * 1024 * 1024; + private static final int PARALLEL_THREADS = 32; + private static final double SMALL_ALLOCATION_MEM = 0.20; + private static final double OVERHEAD_ALLOWANCE = 0.20; + private static final List<Integer> ALLOCATIONS; + private static final int MAX_ALLOCS = 100; + private static final AtomicInteger ALLOCS = new AtomicInteger(0); static { - Random r = new Random(); - long maxMemory = DrillConfig.getMaxDirectMemory(); - long maxPerThread = maxMemory / PARALLEL_THREADS; - double smallCount = (maxPerThread * SMALL_ALLOCATION_MEM) / SMALL_AVERAGE_BYTES; - double largeCount = (maxPerThread * (1 - SMALL_ALLOCATION_MEM - OVERHEAD_ALLOWANCE)) / LARGE_BYTES; - List<Integer> allocations = Lists.newArrayList(); + final Random r = new Random(); + final long maxMemory = DrillConfig.getMaxDirectMemory(); + final long maxPerThread = maxMemory / PARALLEL_THREADS; + final double smallCount = (maxPerThread * SMALL_ALLOCATION_MEM) / SMALL_AVERAGE_BYTES; + final double largeCount = (maxPerThread * (1 - SMALL_ALLOCATION_MEM - OVERHEAD_ALLOWANCE)) / LARGE_BYTES; + final List<Integer> allocations = Lists.newArrayList(); for (int i = 0; i < smallCount; i++) { allocations.add(SMALL_AVERAGE_BYTES / 2 + r.nextInt(SMALL_AVERAGE_BYTES)); @@ -63,7 +64,7 @@ public class TestMemoryRetention { public static void main(String[] args) throws Exception { final DrillConfig config = DrillConfig.create(); - final TopLevelAllocator a = new TopLevelAllocator(config); + final BufferAllocator a = RootAllocatorFactory.newRoot(config); for (int i = 0; i < PARALLEL_THREADS; i++) { Alloc alloc = new Alloc(a); alloc.start(); @@ -71,15 +72,15 @@ public class TestMemoryRetention { } private static class Alloc extends Thread { - final TopLevelAllocator allocator; + final BufferAllocator allocator; - Alloc(TopLevelAllocator allocator) { + Alloc(BufferAllocator allocator) { this.allocator = allocator; } @Override public void run() { - Random r = new Random(); + final Random r = new Random(); try { if (ALLOCS.incrementAndGet() > MAX_ALLOCS) { @@ -93,7 +94,7 @@ public class TestMemoryRetention { logger.info("Starting alloc."); final List<DrillBuf> bufs = Lists.newLinkedList(); - for (Integer i : ALLOCATIONS) { + for (final Integer i : ALLOCATIONS) { bufs.add(allocator.buffer(i)); } Collections.shuffle(bufs); @@ -107,25 +108,24 @@ public class TestMemoryRetention { } else { d.run(); } - } - } private static class Dealloc extends Thread { final List<DrillBuf> bufs; - final TopLevelAllocator a; + final BufferAllocator a; - public Dealloc(List<DrillBuf> bufs, TopLevelAllocator a) { + public Dealloc(List<DrillBuf> bufs, BufferAllocator a) { this.bufs = bufs; this.a = a; } + @Override public void run() { try { Thread.sleep(8000); logger.info("Starting release."); - for (DrillBuf buf : bufs) { + for (final DrillBuf buf : bufs) { buf.release(); } logger.info("Finished release."); @@ -139,6 +139,4 @@ public class TestMemoryRetention { alloc.start(); } } - - } http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java b/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java index c642c4a..911828a 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java @@ -37,7 +37,7 @@ import org.apache.drill.exec.ExecConstants; import org.apache.drill.exec.coord.ClusterCoordinator; import org.apache.drill.exec.coord.zk.ZKClusterCoordinator; import org.apache.drill.exec.memory.BufferAllocator; -import org.apache.drill.exec.memory.TopLevelAllocator; +import org.apache.drill.exec.memory.RootAllocatorFactory; import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint; import org.apache.drill.exec.proto.GeneralRPCProtos.Ack; import org.apache.drill.exec.proto.UserBitShared; @@ -123,7 +123,7 @@ public class DrillClient implements Closeable, ConnectionThrottle { this.isDirectConnection = isDirect; this.ownsZkConnection = coordinator == null && !isDirect; this.ownsAllocator = allocator == null; - this.allocator = ownsAllocator ? new TopLevelAllocator(config) : allocator; + this.allocator = ownsAllocator ? RootAllocatorFactory.newRoot(config) : allocator; this.config = config; this.clusterCoordinator = coordinator; this.reconnectTimes = config.getInt(ExecConstants.BIT_RETRY_TIMES); @@ -173,8 +173,8 @@ public class DrillClient implements Closeable, ConnectionThrottle { final DrillbitEndpoint endpoint; if (isDirectConnection) { - String[] connectInfo = props.getProperty("drillbit").split(":"); - String port = connectInfo.length==2?connectInfo[1]:config.getString(ExecConstants.INITIAL_USER_PORT); + final String[] connectInfo = props.getProperty("drillbit").split(":"); + final String port = connectInfo.length==2?connectInfo[1]:config.getString(ExecConstants.INITIAL_USER_PORT); endpoint = DrillbitEndpoint.newBuilder() .setAddress(connectInfo[0]) .setUserPort(Integer.parseInt(port)) @@ -189,7 +189,7 @@ public class DrillClient implements Closeable, ConnectionThrottle { } } - ArrayList<DrillbitEndpoint> endpoints = new ArrayList<>(clusterCoordinator.getAvailableEndpoints()); + final ArrayList<DrillbitEndpoint> endpoints = new ArrayList<>(clusterCoordinator.getAvailableEndpoints()); checkState(!endpoints.isEmpty(), "No DrillbitEndpoint can be found"); // shuffle the collection then get the first endpoint Collections.shuffle(endpoints); @@ -197,8 +197,8 @@ public class DrillClient implements Closeable, ConnectionThrottle { } if (props != null) { - UserProperties.Builder upBuilder = UserProperties.newBuilder(); - for (String key : props.stringPropertyNames()) { + final UserProperties.Builder upBuilder = UserProperties.newBuilder(); + for (final String key : props.stringPropertyNames()) { upBuilder.addProperties(Property.newBuilder().setKey(key).setValue(props.getProperty(key))); } @@ -225,7 +225,7 @@ public class DrillClient implements Closeable, ConnectionThrottle { retry--; try { Thread.sleep(this.reconnectDelay); - ArrayList<DrillbitEndpoint> endpoints = new ArrayList<>(clusterCoordinator.getAvailableEndpoints()); + final ArrayList<DrillbitEndpoint> endpoints = new ArrayList<>(clusterCoordinator.getAvailableEndpoints()); if (endpoints.isEmpty()) { continue; } @@ -240,7 +240,7 @@ public class DrillClient implements Closeable, ConnectionThrottle { } private void connect(DrillbitEndpoint endpoint) throws RpcException { - FutureHandler f = new FutureHandler(); + final FutureHandler f = new FutureHandler(); client.connect(f, endpoint, props, getUserCredentials()); f.checkedGet(); } @@ -285,8 +285,8 @@ public class DrillClient implements Closeable, ConnectionThrottle { * @throws RpcException */ public List<QueryDataBatch> runQuery(QueryType type, String plan) throws RpcException { - UserProtos.RunQuery query = newBuilder().setResultsMode(STREAM_FULL).setType(type).setPlan(plan).build(); - ListHoldingResultsListener listener = new ListHoldingResultsListener(query); + final UserProtos.RunQuery query = newBuilder().setResultsMode(STREAM_FULL).setType(type).setPlan(plan).build(); + final ListHoldingResultsListener listener = new ListHoldingResultsListener(query); client.submitQuery(listener, query); return listener.getResults(); } @@ -329,17 +329,15 @@ public class DrillClient implements Closeable, ConnectionThrottle { * Submits a Logical plan for direct execution (bypasses parsing) * * @param plan the plan to execute - * @return a handle for the query result - * @throws RpcException */ public void runQuery(QueryType type, String plan, UserResultsListener resultsListener) { client.submitQuery(resultsListener, newBuilder().setResultsMode(STREAM_FULL).setType(type).setPlan(plan).build()); } private class ListHoldingResultsListener implements UserResultsListener { - private Vector<QueryDataBatch> results = new Vector<>(); - private SettableFuture<List<QueryDataBatch>> future = SettableFuture.create(); - private UserProtos.RunQuery query ; + private final Vector<QueryDataBatch> results = new Vector<>(); + private final SettableFuture<List<QueryDataBatch>> future = SettableFuture.create(); + private final UserProtos.RunQuery query ; public ListHoldingResultsListener(UserProtos.RunQuery query) { logger.debug( "Listener created for query \"\"\"{}\"\"\"", query ); @@ -395,11 +393,9 @@ public class DrillClient implements Closeable, ConnectionThrottle { logger.debug("Query ID arrived: {}", QueryIdHelper.getQueryId(queryId)); } } - } private class FutureHandler extends AbstractCheckedFuture<Void, RpcException> implements RpcConnectionHandler<ServerConnection>, DrillRpcFuture<Void>{ - protected FutureHandler() { super( SettableFuture.<Void>create()); } @@ -427,6 +423,5 @@ public class DrillClient implements Closeable, ConnectionThrottle { public DrillBuf getBuffer() { return null; } - } } http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/main/java/org/apache/drill/exec/client/DumpCat.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/client/DumpCat.java b/exec/java-exec/src/main/java/org/apache/drill/exec/client/DumpCat.java index 55d9cf3..54a61c8 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/client/DumpCat.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/client/DumpCat.java @@ -21,9 +21,10 @@ import java.io.File; import java.io.FileInputStream; import java.util.List; +import org.apache.drill.common.config.DrillConfig; import org.apache.drill.exec.cache.VectorAccessibleSerializable; import org.apache.drill.exec.memory.BufferAllocator; -import org.apache.drill.exec.memory.TopLevelAllocator; +import org.apache.drill.exec.memory.RootAllocatorFactory; import org.apache.drill.exec.record.BatchSchema; import org.apache.drill.exec.record.BatchSchema.SelectionVectorMode; import org.apache.drill.exec.record.MaterializedField; @@ -39,20 +40,20 @@ import com.beust.jcommander.ParameterException; import com.google.common.collect.Lists; public class DumpCat { - - private final static BufferAllocator allocator = new TopLevelAllocator(); + private final static DrillConfig drillConfig = DrillConfig.create(); + private final static BufferAllocator allocator = RootAllocatorFactory.newRoot(drillConfig); public static void main(String args[]) throws Exception { - DumpCat dumpCat = new DumpCat(); + final DumpCat dumpCat = new DumpCat(); - Options o = new Options(); + final Options o = new Options(); JCommander jc = null; try { jc = new JCommander(o, args); jc.setProgramName("./drill_dumpcat"); } catch (ParameterException e) { System.out.println(e.getMessage()); - String[] valid = {"-f", "file"}; + final String[] valid = {"-f", "file"}; new JCommander(o, valid).usage(); System.exit(-1); } @@ -62,21 +63,19 @@ public class DumpCat { } /*Check if dump file exists*/ - File file = new File(o.location); + final File file = new File(o.location); if (!file.exists()) { System.out.println(String.format("Trace file %s not created", o.location)); System.exit(-1); } - FileInputStream input = new FileInputStream(file.getAbsoluteFile()); - - if (o.batch < 0) { - dumpCat.doQuery(input); - } else { - dumpCat.doBatch(input, o.batch, o.include_headers); + try (final FileInputStream input = new FileInputStream(file.getAbsoluteFile())) { + if (o.batch < 0) { + dumpCat.doQuery(input); + } else { + dumpCat.doBatch(input, o.batch, o.include_headers); + } } - - input.close(); } /** @@ -86,7 +85,7 @@ public class DumpCat { @Override public void validate(String name, String value) throws ParameterException { try { - int batch = Integer.parseInt(value); + final int batch = Integer.parseInt(value); if (batch < 0) { throw new ParameterException("Parameter " + name + " should be non-negative number."); } @@ -140,7 +139,7 @@ public class DumpCat { @Override public String toString() { String avgRecSizeStr = null; - if (this.rows>0) { + if (this.rows > 0) { avgRecSizeStr = String.format("Average Record Size : %d ", this.dataSize/this.rows); } else { avgRecSizeStr = "Average Record Size : 0"; @@ -169,14 +168,14 @@ public class DumpCat { int batchNum = 0; int emptyBatchNum = 0; BatchSchema prevSchema = null; - List<Integer> schemaChangeIdx = Lists.newArrayList(); + final List<Integer> schemaChangeIdx = Lists.newArrayList(); - BatchMetaInfo aggBatchMetaInfo = new BatchMetaInfo(); + final BatchMetaInfo aggBatchMetaInfo = new BatchMetaInfo(); while (input.available() > 0) { - VectorAccessibleSerializable vcSerializable = new VectorAccessibleSerializable(DumpCat.allocator); + final VectorAccessibleSerializable vcSerializable = new VectorAccessibleSerializable(DumpCat.allocator); vcSerializable.readFromStream(input); - VectorContainer vectorContainer = (VectorContainer) vcSerializable.get(); + final VectorContainer vectorContainer = (VectorContainer) vcSerializable.get(); aggBatchMetaInfo.add(getBatchMetaInfo(vcSerializable)); @@ -225,7 +224,7 @@ public class DumpCat { vcSerializable.readFromStream(input); if (batchNum != targetBatchNum) { - VectorContainer vectorContainer = (VectorContainer) vcSerializable.get(); + final VectorContainer vectorContainer = (VectorContainer) vcSerializable.get(); vectorContainer.zeroVectors(); } } @@ -238,22 +237,21 @@ public class DumpCat { if (vcSerializable != null) { showSingleBatch(vcSerializable, showHeader); - VectorContainer vectorContainer = (VectorContainer) vcSerializable.get(); + final VectorContainer vectorContainer = (VectorContainer) vcSerializable.get(); vectorContainer.zeroVectors(); } } - private void showSingleBatch (VectorAccessibleSerializable vcSerializable, boolean showHeader) { - VectorContainer vectorContainer = (VectorContainer)vcSerializable.get(); + final VectorContainer vectorContainer = (VectorContainer) vcSerializable.get(); /* show the header of the batch */ if (showHeader) { System.out.println(getBatchMetaInfo(vcSerializable).toString()); System.out.println("Schema Information"); - for (VectorWrapper w : vectorContainer) { - MaterializedField field = w.getValueVector().getField(); + for (final VectorWrapper w : vectorContainer) { + final MaterializedField field = w.getValueVector().getField(); System.out.println (String.format("name : %s, minor_type : %s, data_mode : %s", field.toExpr(), field.getType().getMinorType().toString(), @@ -266,12 +264,11 @@ public class DumpCat { VectorUtil.showVectorAccessibleContent(vectorContainer); } - /* Get batch meta info : rows, selectedRows, dataSize */ private BatchMetaInfo getBatchMetaInfo(VectorAccessibleSerializable vcSerializable) { - VectorAccessible vectorContainer = vcSerializable.get(); + final VectorAccessible vectorContainer = vcSerializable.get(); - int rows =0; + int rows = 0; int selectedRows = 0; int totalDataSize = 0; @@ -282,11 +279,10 @@ public class DumpCat { selectedRows = vcSerializable.getSv2().getCount(); } - for (VectorWrapper w : vectorContainer) { + for (final VectorWrapper w : vectorContainer) { totalDataSize += w.getValueVector().getBufferSize(); } - return new BatchMetaInfo(rows, selectedRows, totalDataSize); + return new BatchMetaInfo(rows, selectedRows, totalDataSize); } - } http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/main/java/org/apache/drill/exec/client/PrintingResultsListener.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/client/PrintingResultsListener.java b/exec/java-exec/src/main/java/org/apache/drill/exec/client/PrintingResultsListener.java index 8cb4a0b..212e8b0 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/client/PrintingResultsListener.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/client/PrintingResultsListener.java @@ -28,7 +28,7 @@ import org.apache.drill.common.exceptions.UserException; import org.apache.drill.exec.client.QuerySubmitter.Format; import org.apache.drill.exec.exception.SchemaChangeException; import org.apache.drill.exec.memory.BufferAllocator; -import org.apache.drill.exec.memory.TopLevelAllocator; +import org.apache.drill.exec.memory.RootAllocatorFactory; import org.apache.drill.exec.proto.UserBitShared.QueryData; import org.apache.drill.exec.proto.UserBitShared.QueryId; import org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState; @@ -54,7 +54,7 @@ public class PrintingResultsListener implements UserResultsListener { Stopwatch w = new Stopwatch(); public PrintingResultsListener(DrillConfig config, Format format, int columnWidth) { - this.allocator = new TopLevelAllocator(config); + this.allocator = RootAllocatorFactory.newRoot(config); loader = new RecordBatchLoader(allocator); this.format = format; this.columnWidth = columnWidth; http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/main/java/org/apache/drill/exec/memory/RootAllocatorFactory.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/memory/RootAllocatorFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/memory/RootAllocatorFactory.java new file mode 100644 index 0000000..a413e4a --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/memory/RootAllocatorFactory.java @@ -0,0 +1,67 @@ +/** + * 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.memory; + +import org.apache.drill.common.config.DrillConfig; + +import com.google.common.annotations.VisibleForTesting; + +public class RootAllocatorFactory { + /** + * Constructor to prevent instantiation of this static utility class. + */ + private RootAllocatorFactory() {} + + /** + * Factory method. + * + * @param drillConfig the DrillConfig + * @return a new root allocator + */ + public static BufferAllocator newRoot(final DrillConfig drillConfig) { +/* TODO(DRILL-1942) + if (BaseAllocator.DEBUG) { + return new TopLevelAllocator(drillConfig); + } +*/ + + return new TopLevelAllocator(drillConfig); + } + + /** + * Factory method for testing, where a DrillConfig may not be available. + * + * @param allocationPolicy the allocation policy + * @param initAllocation initial allocation from parent + * @param maxReservation maximum amount of memory this can hand out + * @param flags one of BufferAllocator's F_* flags + * @return a new root allocator + */ +/* TODO(DRILL-1942) + @VisibleForTesting + public static BufferAllocator newRoot( + final AllocationPolicy allocationPolicy, + final long initAllocation, final long maxReservation, final int flags) { + if (BaseAllocator.DEBUG) { + return new RootAllocatorDebug(allocationPolicy, initAllocation, maxReservation, flags); + } + + return new RootAllocator(allocationPolicy, initAllocation, maxReservation, flags); + } +*/ +} http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java b/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java index 05849ea..6e23402 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/memory/TopLevelAllocator.java @@ -51,15 +51,17 @@ public class TopLevelAllocator implements BufferAllocator { private final DrillBuf empty; private final DrillConfig config; + /* TODO(cwestin) remove @Deprecated - public TopLevelAllocator() { + TopLevelAllocator() { this(DrillConfig.getMaxDirectMemory()); } @Deprecated - public TopLevelAllocator(long maximumAllocation) { + TopLevelAllocator(long maximumAllocation) { this(null, maximumAllocation, true); } + */ private TopLevelAllocator(DrillConfig config, long maximumAllocation, boolean errorOnLeak){ MAXIMUM_DIRECT_MEMORY = maximumAllocation; @@ -70,7 +72,7 @@ public class TopLevelAllocator implements BufferAllocator { this.childrenMap = ENABLE_ACCOUNTING ? new IdentityHashMap<ChildAllocator, StackTraceElement[]>() : null; } - public TopLevelAllocator(DrillConfig config) { + TopLevelAllocator(DrillConfig config) { this(config, Math.min(DrillConfig.getMaxDirectMemory(), config.getLong(ExecConstants.TOP_LEVEL_MAX_ALLOC)), config.getBoolean(ExecConstants.ERROR_ON_MEMORY_LEAK) ); http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/main/java/org/apache/drill/exec/server/BootStrapContext.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/BootStrapContext.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/BootStrapContext.java index d0a998e..120c0d0 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/BootStrapContext.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/BootStrapContext.java @@ -24,15 +24,15 @@ import java.io.Closeable; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.exec.ExecConstants; import org.apache.drill.exec.memory.BufferAllocator; -import org.apache.drill.exec.memory.TopLevelAllocator; +import org.apache.drill.exec.memory.RootAllocatorFactory; import org.apache.drill.exec.metrics.DrillMetrics; import org.apache.drill.exec.rpc.TransportCheck; import com.codahale.metrics.MetricRegistry; // TODO: Doc. What kind of context? (For what aspects, RPC? What kind of data?) -public class BootStrapContext implements Closeable{ - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BootStrapContext.class); +public class BootStrapContext implements Closeable { + //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BootStrapContext.class); private final DrillConfig config; private final EventLoopGroup loop; @@ -41,12 +41,11 @@ public class BootStrapContext implements Closeable{ private final BufferAllocator allocator; public BootStrapContext(DrillConfig config) { - super(); this.config = config; this.loop = TransportCheck.createEventLoopGroup(config.getInt(ExecConstants.BIT_SERVER_RPC_THREADS), "BitServer-"); this.loop2 = TransportCheck.createEventLoopGroup(config.getInt(ExecConstants.BIT_SERVER_RPC_THREADS), "BitClient-"); this.metrics = DrillMetrics.getInstance(); - this.allocator = new TopLevelAllocator(config); + this.allocator = RootAllocatorFactory.newRoot(config); } public DrillConfig getConfig() { @@ -69,10 +68,10 @@ public class BootStrapContext implements Closeable{ return allocator; } + @Override public void close() { DrillMetrics.resetMetrics(); loop.shutdownGracefully(); allocator.close(); } - } http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java index d428920..eaf8765 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java +++ b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java @@ -27,6 +27,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; import com.google.common.io.Files; + import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.exceptions.UserException; import org.apache.drill.exec.ExecConstants; @@ -34,7 +35,7 @@ import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.client.DrillClient; import org.apache.drill.exec.exception.SchemaChangeException; import org.apache.drill.exec.memory.BufferAllocator; -import org.apache.drill.exec.memory.TopLevelAllocator; +import org.apache.drill.exec.memory.RootAllocatorFactory; import org.apache.drill.exec.proto.UserBitShared; import org.apache.drill.exec.proto.UserBitShared.QueryId; import org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState; @@ -166,7 +167,7 @@ public class BaseTestQuery extends ExecTest { } private static void openClient() throws Exception { - allocator = new TopLevelAllocator(config); + allocator = RootAllocatorFactory.newRoot(config); if (config.hasPath(ENABLE_FULL_CACHE) && config.getBoolean(ENABLE_FULL_CACHE)) { serviceSet = RemoteServiceSet.getServiceSetWithFullCache(config, allocator); } else { @@ -228,13 +229,13 @@ public class BaseTestQuery extends ExecTest { } @AfterClass - public static void closeClient() throws IOException, InterruptedException { + public static void closeClient() throws IOException { if (client != null) { client.close(); } if (bits != null) { - for(Drillbit bit : bits) { + for(final Drillbit bit : bits) { if (bit != null) { bit.close(); } @@ -256,7 +257,7 @@ public class BaseTestQuery extends ExecTest { } protected static void runSQL(String sql) throws Exception { - SilentListener listener = new SilentListener(); + final SilentListener listener = new SilentListener(); testWithListener(QueryType.SQL, sql, listener); listener.waitForCompletion(); } @@ -294,8 +295,8 @@ public class BaseTestQuery extends ExecTest { query = String.format(query, args); logger.debug("Running query:\n--------------\n" + query); for (int i = 0; i < interation; i++) { - List<QueryDataBatch> results = client.runQuery(QueryType.SQL, query); - for (QueryDataBatch queryDataBatch : results) { + final List<QueryDataBatch> results = client.runQuery(QueryType.SQL, query); + for (final QueryDataBatch queryDataBatch : results) { queryDataBatch.release(); } } @@ -366,7 +367,7 @@ public class BaseTestQuery extends ExecTest { } public static String getFile(String resource) throws IOException{ - URL url = Resources.getResource(resource); + final URL url = Resources.getResource(resource); if (url == null) { throw new IOException(String.format("Unable to find path %s.", resource)); } @@ -376,13 +377,13 @@ public class BaseTestQuery extends ExecTest { /** * Copy the resource (ex. file on classpath) to a physical file on FileSystem. * @param resource - * @return + * @return the file path * @throws IOException */ public static String getPhysicalFileFromResource(final String resource) throws IOException { final File file = File.createTempFile("tempfile", ".txt"); file.deleteOnExit(); - PrintWriter printWriter = new PrintWriter(file); + final PrintWriter printWriter = new PrintWriter(file); printWriter.write(BaseTestQuery.getFile(resource)); printWriter.close(); @@ -395,7 +396,7 @@ public class BaseTestQuery extends ExecTest { * @return Full path including temp parent directory and given directory name. */ public static String getTempDir(final String dirName) { - File dir = Files.createTempDir(); + final File dir = Files.createTempDir(); dir.deleteOnExit(); return dir.getAbsolutePath() + File.separator + dirName; @@ -412,8 +413,8 @@ public class BaseTestQuery extends ExecTest { private static class SilentListener implements UserResultsListener { private volatile UserException exception; - private AtomicInteger count = new AtomicInteger(); - private CountDownLatch latch = new CountDownLatch(1); + private final AtomicInteger count = new AtomicInteger(); + private final CountDownLatch latch = new CountDownLatch(1); @Override public void submissionFailed(UserException ex) { @@ -430,7 +431,7 @@ public class BaseTestQuery extends ExecTest { @Override public void dataArrived(QueryDataBatch result, ConnectionThrottle throttle) { - int rows = result.getHeader().getRowCount(); + final int rows = result.getHeader().getRowCount(); if (result.getData() != null) { count.addAndGet(rows); } @@ -459,8 +460,8 @@ public class BaseTestQuery extends ExecTest { protected int printResult(List<QueryDataBatch> results) throws SchemaChangeException { int rowCount = 0; - RecordBatchLoader loader = new RecordBatchLoader(getAllocator()); - for(QueryDataBatch result : results) { + final RecordBatchLoader loader = new RecordBatchLoader(getAllocator()); + for(final QueryDataBatch result : results) { rowCount += result.getHeader().getRowCount(); loader.load(result.getHeader().getDef(), result.getData()); // TODO: Clean: DRILL-2933: That load(...) no longer throws @@ -478,10 +479,10 @@ public class BaseTestQuery extends ExecTest { protected static String getResultString(List<QueryDataBatch> results, String delimiter) throws SchemaChangeException { - StringBuilder formattedResults = new StringBuilder(); + final StringBuilder formattedResults = new StringBuilder(); boolean includeHeader = true; - RecordBatchLoader loader = new RecordBatchLoader(getAllocator()); - for(QueryDataBatch result : results) { + final RecordBatchLoader loader = new RecordBatchLoader(getAllocator()); + for(final QueryDataBatch result : results) { loader.load(result.getHeader().getDef(), result.getData()); if (loader.getRecordCount() <= 0) { continue; http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java b/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java index da033f7..05b7238 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java +++ b/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java @@ -22,14 +22,15 @@ import java.net.URL; import mockit.Mocked; import mockit.NonStrictExpectations; + import org.apache.calcite.schema.SchemaPlus; import org.apache.calcite.jdbc.SimpleCalciteSchema; - import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.util.TestTools; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.memory.TopLevelAllocator; +import org.apache.drill.exec.memory.BufferAllocator; +import org.apache.drill.exec.memory.RootAllocatorFactory; import org.apache.drill.exec.ops.QueryContext; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.planner.physical.PlannerSettings; @@ -54,7 +55,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.io.Resources; public class PlanningBase extends ExecTest{ - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PlanningBase.class); + //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PlanningBase.class); @Rule public final TestRule TIMEOUT = TestTools.getTimeoutRule(10000); @@ -63,16 +64,14 @@ public class PlanningBase extends ExecTest{ @Mocked QueryContext context; - TopLevelAllocator allocator = new TopLevelAllocator(); + BufferAllocator allocator = RootAllocatorFactory.newRoot(config); protected void testSqlPlanFromFile(String file) throws Exception { testSqlPlan(getFile(file)); } protected void testSqlPlan(String sqlCommands) throws Exception { - String[] sqlStrings = sqlCommands.split(";"); - - + final String[] sqlStrings = sqlCommands.split(";"); final LocalPStoreProvider provider = new LocalPStoreProvider(config); provider.start(); @@ -134,18 +133,17 @@ public class PlanningBase extends ExecTest{ } }; - for (String sql : sqlStrings) { + for (final String sql : sqlStrings) { if (sql.trim().isEmpty()) { continue; } - DrillSqlWorker worker = new DrillSqlWorker(context); - PhysicalPlan p = worker.getPlan(sql); + final DrillSqlWorker worker = new DrillSqlWorker(context); + final PhysicalPlan p = worker.getPlan(sql); } - } - protected String getFile(String resource) throws IOException{ - URL url = Resources.getResource(resource); + protected static String getFile(String resource) throws IOException { + final URL url = Resources.getResource(resource); if (url == null) { throw new IOException(String.format("Unable to find path %s.", resource)); } http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java index 7c58b19..6b6bd64 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java @@ -30,7 +30,7 @@ import org.apache.drill.exec.ExecConstants; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.compile.CodeCompiler; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.memory.TopLevelAllocator; +import org.apache.drill.exec.memory.RootAllocatorFactory; import org.apache.drill.exec.ops.FragmentContext; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; @@ -58,9 +58,9 @@ import com.google.common.io.Files; * which will produce a dump file. The dump file will be input into DumpCat to test query mode and batch mode. */ -public class DumpCatTest extends ExecTest{ - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DumpCatTest.class); - DrillConfig c = DrillConfig.create(); +public class DumpCatTest extends ExecTest { + //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DumpCatTest.class); + private final DrillConfig c = DrillConfig.create(); @Test public void testDumpCat(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable @@ -68,22 +68,22 @@ public class DumpCatTest extends ExecTest{ new NonStrictExpectations(){{ bitContext.getMetrics(); result = new MetricRegistry(); - bitContext.getAllocator(); result = new TopLevelAllocator(); + bitContext.getAllocator(); result = RootAllocatorFactory.newRoot(c); bitContext.getConfig(); result = c; bitContext.getCompiler(); result = CodeCompiler.getTestCompiler(c); bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c); }}; - PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance()); - PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/trace/simple_trace.json"), Charsets.UTF_8)); - FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); - SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); + final PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance()); + final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/trace/simple_trace.json"), Charsets.UTF_8)); + final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); + final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); - while(exec.next()){ + while(exec.next()) { } - if(context.getFailureCause() != null){ + if(context.getFailureCause() != null) { throw context.getFailureCause(); } assertTrue(!context.isFailed()); @@ -95,37 +95,34 @@ public class DumpCatTest extends ExecTest{ /* Form the file name to which the trace output will dump the record batches */ String qid = QueryIdHelper.getQueryId(handle.getQueryId()); - int majorFragmentId = handle.getMajorFragmentId(); - int minorFragmentId = handle.getMinorFragmentId(); + final int majorFragmentId = handle.getMajorFragmentId(); + final int minorFragmentId = handle.getMinorFragmentId(); - String logLocation = c.getString(ExecConstants.TRACE_DUMP_DIRECTORY); + final String logLocation = c.getString(ExecConstants.TRACE_DUMP_DIRECTORY); System.out.println("Found log location: " + logLocation); - String filename = String.format("%s//%s_%d_%d_mock-scan", logLocation, qid, majorFragmentId, minorFragmentId); + final String filename = String.format("%s//%s_%d_%d_mock-scan", logLocation, qid, majorFragmentId, minorFragmentId); System.out.println("File Name: " + filename); - Configuration conf = new Configuration(); + final Configuration conf = new Configuration(); conf.set(FileSystem.FS_DEFAULT_NAME_KEY, c.getString(ExecConstants.TRACE_DUMP_FILESYSTEM)); - FileSystem fs = FileSystem.get(conf); - Path path = new Path(filename); + final FileSystem fs = FileSystem.get(conf); + final Path path = new Path(filename); assertTrue("Trace file does not exist", fs.exists(path)); - DumpCat dumpCat = new DumpCat(); + final DumpCat dumpCat = new DumpCat(); //Test Query mode - FileInputStream input = new FileInputStream(filename); - - dumpCat.doQuery(input); - input.close(); + try (final FileInputStream input = new FileInputStream(filename)) { + dumpCat.doQuery(input); + } //Test Batch mode - input = new FileInputStream(filename); - dumpCat.doBatch(input,0,true); - - input.close(); + try(final FileInputStream input = new FileInputStream(filename)) { + dumpCat.doBatch(input, 0, true); + } } - } http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java index 5e50189..cf6fb69 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java @@ -36,14 +36,12 @@ import org.apache.drill.common.expression.SchemaPath; import org.apache.drill.common.expression.parser.ExprLexer; import org.apache.drill.common.expression.parser.ExprParser; import org.apache.drill.common.expression.parser.ExprParser.parse_return; -import org.apache.drill.common.types.MajorType; import org.apache.drill.common.types.TypeProtos; import org.apache.drill.common.types.TypeProtos.MinorType; import org.apache.drill.common.types.Types; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.memory.BufferAllocator; -import org.apache.drill.exec.memory.TopLevelAllocator; +import org.apache.drill.exec.memory.RootAllocatorFactory; import org.apache.drill.exec.physical.impl.project.Projector; import org.apache.drill.exec.record.MaterializedField; import org.apache.drill.exec.record.RecordBatch; @@ -54,10 +52,10 @@ import org.apache.drill.exec.vector.ValueVector; import org.junit.Test; public class ExpressionTest extends ExecTest { - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ExpressionTest.class); + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ExpressionTest.class); - DrillConfig c = DrillConfig.create(); - FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); + private final DrillConfig c = DrillConfig.create(); + private final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); @Test public void testBasicExpression(@Injectable RecordBatch batch) throws Exception { @@ -87,7 +85,7 @@ public class ExpressionTest extends ExecTest { batch.getValueAccessorById(IntVector.class, tfid.getFieldIds()); result = wrapper; wrapper.getValueVector(); - result = new IntVector(MaterializedField.create("result", type), new TopLevelAllocator(0)); + result = new IntVector(MaterializedField.create("result", type), RootAllocatorFactory.newRoot(c)); } }; @@ -123,25 +121,24 @@ public class ExpressionTest extends ExecTest { // HELPER METHODS // private LogicalExpression parseExpr(String expr) throws RecognitionException { - ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr)); - CommonTokenStream tokens = new CommonTokenStream(lexer); - ExprParser parser = new ExprParser(tokens); + final ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr)); + final CommonTokenStream tokens = new CommonTokenStream(lexer); + final ExprParser parser = new ExprParser(tokens); parse_return ret = parser.parse(); return ret.e; } private String getExpressionCode(String expression, RecordBatch batch) throws Exception { - LogicalExpression expr = parseExpr(expression); - ErrorCollector error = new ErrorCollectorImpl(); - LogicalExpression materializedExpr = ExpressionTreeMaterializer.materialize(expr, batch, error, registry); + final LogicalExpression expr = parseExpr(expression); + final ErrorCollector error = new ErrorCollectorImpl(); + final LogicalExpression materializedExpr = ExpressionTreeMaterializer.materialize(expr, batch, error, registry); if (error.getErrorCount() != 0) { logger.error("Failure while materializing expression [{}]. Errors: {}", expression, error); assertEquals(0, error.getErrorCount()); } - ClassGenerator<Projector> cg = CodeGenerator.get(Projector.TEMPLATE_DEFINITION, new FunctionImplementationRegistry(DrillConfig.create())).getRoot(); + final ClassGenerator<Projector> cg = CodeGenerator.get(Projector.TEMPLATE_DEFINITION, new FunctionImplementationRegistry(DrillConfig.create())).getRoot(); cg.addExpr(new ValueVectorWriteExpression(new TypedFieldId(materializedExpr.getMajorType(), -1), materializedExpr)); return cg.getCodeGenerator().generateAndGet(); } - } http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestByteComparisonFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestByteComparisonFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestByteComparisonFunctions.java index 1e9a47c..d8ce7c2 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestByteComparisonFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestByteComparisonFunctions.java @@ -23,25 +23,26 @@ import org.apache.drill.common.config.DrillConfig; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.impl.ByteFunctionHelpers; import org.apache.drill.exec.expr.holders.VarCharHolder; -import org.apache.drill.exec.memory.TopLevelAllocator; +import org.apache.drill.exec.memory.BufferAllocator; +import org.apache.drill.exec.memory.RootAllocatorFactory; import org.apache.drill.exec.vector.ValueHolderHelper; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -public class TestByteComparisonFunctions extends ExecTest{ - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestByteComparisonFunctions.class); +public class TestByteComparisonFunctions extends ExecTest { + //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestByteComparisonFunctions.class); - static TopLevelAllocator allocator; - static VarCharHolder hello; - static VarCharHolder goodbye; - static VarCharHolder helloLong; - static VarCharHolder goodbyeLong; + private static BufferAllocator allocator; + private static VarCharHolder hello; + private static VarCharHolder goodbye; + private static VarCharHolder helloLong; + private static VarCharHolder goodbyeLong; @BeforeClass - public static void setup(){ + public static void setup() { DrillConfig c= DrillConfig.create(); - allocator = new TopLevelAllocator(c); + allocator = RootAllocatorFactory.newRoot(c); hello = ValueHolderHelper.getVarCharHolder(allocator, "hello"); goodbye = ValueHolderHelper.getVarCharHolder(allocator, "goodbye"); helloLong = ValueHolderHelper.getVarCharHolder(allocator, "hellomyfriend"); @@ -49,7 +50,7 @@ public class TestByteComparisonFunctions extends ExecTest{ } @AfterClass - public static void teardown(){ + public static void teardown() { hello.buffer.release(); helloLong.buffer.release(); goodbye.buffer.release(); @@ -58,72 +59,72 @@ public class TestByteComparisonFunctions extends ExecTest{ } @Test - public void testAfter(){ - VarCharHolder left = hello; - VarCharHolder right = goodbye; + public void testAfter() { + final VarCharHolder left = hello; + final VarCharHolder right = goodbye; assertTrue(ByteFunctionHelpers.compare(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == 1); } @Test - public void testBefore(){ - VarCharHolder left = goodbye; - VarCharHolder right = hello; + public void testBefore() { + final VarCharHolder left = goodbye; + final VarCharHolder right = hello; assertTrue(ByteFunctionHelpers.compare(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == -1); } @Test - public void testEqualCompare(){ - VarCharHolder left = hello; - VarCharHolder right = hello; + public void testEqualCompare() { + final VarCharHolder left = hello; + final VarCharHolder right = hello; assertTrue(ByteFunctionHelpers.compare(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == 0); } @Test - public void testEqual(){ - VarCharHolder left = hello; - VarCharHolder right = hello; + public void testEqual() { + final VarCharHolder left = hello; + final VarCharHolder right = hello; assertTrue(ByteFunctionHelpers.equal(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == 1); } @Test - public void testNotEqual(){ - VarCharHolder left = hello; - VarCharHolder right = goodbye; + public void testNotEqual() { + final VarCharHolder left = hello; + final VarCharHolder right = goodbye; assertTrue(ByteFunctionHelpers.equal(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == 0); } @Test - public void testAfterLong(){ - VarCharHolder left = helloLong; - VarCharHolder right = goodbyeLong; + public void testAfterLong() { + final VarCharHolder left = helloLong; + final VarCharHolder right = goodbyeLong; assertTrue(ByteFunctionHelpers.compare(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == 1); } @Test - public void testBeforeLong(){ - VarCharHolder left = goodbyeLong; - VarCharHolder right = helloLong; + public void testBeforeLong() { + final VarCharHolder left = goodbyeLong; + final VarCharHolder right = helloLong; assertTrue(ByteFunctionHelpers.compare(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == -1); } @Test - public void testEqualCompareLong(){ - VarCharHolder left = helloLong; - VarCharHolder right = helloLong; + public void testEqualCompareLong() { + final VarCharHolder left = helloLong; + final VarCharHolder right = helloLong; assertTrue(ByteFunctionHelpers.compare(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == 0); } @Test - public void testEqualLong(){ - VarCharHolder left = helloLong; - VarCharHolder right = helloLong; + public void testEqualLong() { + final VarCharHolder left = helloLong; + final VarCharHolder right = helloLong; assertTrue(ByteFunctionHelpers.equal(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == 1); } @Test - public void testNotEqualLong(){ - VarCharHolder left = helloLong; - VarCharHolder right = goodbyeLong; + public void testNotEqualLong() { + final VarCharHolder left = helloLong; + final VarCharHolder right = goodbyeLong; assertTrue(ByteFunctionHelpers.equal(left.buffer, left.start, left.end, right.buffer, right.start, right.end) == 0); } } http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java index 4f06a9d..99ee904 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java @@ -30,7 +30,7 @@ import org.apache.drill.common.util.FileUtils; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.compile.CodeCompiler; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.memory.TopLevelAllocator; +import org.apache.drill.exec.memory.RootAllocatorFactory; import org.apache.drill.exec.ops.FragmentContext; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; @@ -52,44 +52,41 @@ import com.google.common.io.Files; public class TestMathFunctions extends ExecTest { + //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestMathFunctions.class); + private final DrillConfig c = DrillConfig.create(); - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestMathFunctions.class); - DrillConfig c = DrillConfig.create(); + @Test + public void testBasicMathFunctions(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable + { + new NonStrictExpectations() {{ + bitContext.getMetrics(); result = new MetricRegistry(); + bitContext.getAllocator(); result = RootAllocatorFactory.newRoot(c); + bitContext.getConfig(); result = c; + bitContext.getCompiler(); result = CodeCompiler.getTestCompiler(c); + bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c); + }}; + final PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance()); + final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/functions/simple_math_functions.json"), Charsets.UTF_8)); + final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); + final FragmentContext context = new FragmentContext(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry); + final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); - @Test - public void testBasicMathFunctions(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable - { - - new NonStrictExpectations(){{ - bitContext.getMetrics(); result = new MetricRegistry(); - bitContext.getAllocator(); result = new TopLevelAllocator(); - bitContext.getConfig(); result = c; - bitContext.getCompiler(); result = CodeCompiler.getTestCompiler(c); - bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c); - }}; - - PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance()); - PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/functions/simple_math_functions.json"), Charsets.UTF_8)); - FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - FragmentContext context = new FragmentContext(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry); - SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); - - while(exec.next()) { - IntVector intMulVector = exec.getValueVectorById(new SchemaPath("INTMUL", ExpressionPosition.UNKNOWN), IntVector.class); - Float8Vector floatMulVector = exec.getValueVectorById(new SchemaPath("FLOATMUL", ExpressionPosition.UNKNOWN), Float8Vector.class); - IntVector intAddVector = exec.getValueVectorById(new SchemaPath("INTADD", ExpressionPosition.UNKNOWN), IntVector.class); - Float8Vector floatAddVector = exec.getValueVectorById(new SchemaPath("FLOATADD", ExpressionPosition.UNKNOWN), Float8Vector.class); - assertEquals(exec.getRecordCount(), 1); - assertEquals(intMulVector.getAccessor().get(0), 2); - assertEquals(floatMulVector.getAccessor().get(0), (1.1 * 2.2), 0); - assertEquals(intAddVector.getAccessor().get(0), 3); - assertEquals(floatAddVector.getAccessor().get(0), (1.1 + 2.2), 0); - } + while(exec.next()) { + final IntVector intMulVector = exec.getValueVectorById(new SchemaPath("INTMUL", ExpressionPosition.UNKNOWN), IntVector.class); + final Float8Vector floatMulVector = exec.getValueVectorById(new SchemaPath("FLOATMUL", ExpressionPosition.UNKNOWN), Float8Vector.class); + final IntVector intAddVector = exec.getValueVectorById(new SchemaPath("INTADD", ExpressionPosition.UNKNOWN), IntVector.class); + final Float8Vector floatAddVector = exec.getValueVectorById(new SchemaPath("FLOATADD", ExpressionPosition.UNKNOWN), Float8Vector.class); + assertEquals(exec.getRecordCount(), 1); + assertEquals(intMulVector.getAccessor().get(0), 2); + assertEquals(floatMulVector.getAccessor().get(0), (1.1 * 2.2), 0); + assertEquals(intAddVector.getAccessor().get(0), 3); + assertEquals(floatAddVector.getAccessor().get(0), (1.1 + 2.2), 0); + } - if(context.getFailureCause() != null){ - throw context.getFailureCause(); - } - assertTrue(!context.isFailed()); + if(context.getFailureCause() != null) { + throw context.getFailureCause(); } + assertTrue(!context.isFailed()); + } } http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java index 880184e..3447dae 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java @@ -29,7 +29,7 @@ import mockit.NonStrictExpectations; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.exec.compile.CodeCompiler; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.memory.TopLevelAllocator; +import org.apache.drill.exec.memory.RootAllocatorFactory; import org.apache.drill.exec.ops.FragmentContext; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; @@ -50,23 +50,21 @@ import com.google.common.base.Charsets; import com.google.common.io.Resources; public class TestNewMathFunctions { - - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestNewMathFunctions.class); - - DrillConfig c = DrillConfig.create(); - PhysicalPlanReader reader; - FunctionImplementationRegistry registry; - FragmentContext context; + //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestNewMathFunctions.class); + private final DrillConfig c = DrillConfig.create(); + private PhysicalPlanReader reader; + private FunctionImplementationRegistry registry; + private FragmentContext context; public Object[] getRunResult(SimpleRootExec exec) { int size = 0; - for (ValueVector v : exec) { + for (final ValueVector v : exec) { size++; } - Object[] res = new Object [size]; + final Object[] res = new Object[size]; int i = 0; - for (ValueVector v : exec) { + for (final ValueVector v : exec) { if (v instanceof VarCharVector) { res[i++] = new String( ((VarCharVector) v).getAccessor().get(0)); } else { @@ -78,16 +76,15 @@ public class TestNewMathFunctions { public void runTest(@Injectable final DrillbitContext bitContext, @Injectable UserServer.UserClientConnection connection, Object[] expectedResults, String planPath) throws Throwable { - new NonStrictExpectations() {{ bitContext.getMetrics(); result = new MetricRegistry(); - bitContext.getAllocator(); result = new TopLevelAllocator(); + bitContext.getAllocator(); result = RootAllocatorFactory.newRoot(c); bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c); bitContext.getConfig(); result = c; bitContext.getCompiler(); result = CodeCompiler.getTestCompiler(c); }}; - String planString = Resources.toString(Resources.getResource(planPath), Charsets.UTF_8); + final String planString = Resources.toString(Resources.getResource(planPath), Charsets.UTF_8); if (reader == null) { reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance()); } @@ -97,12 +94,12 @@ public class TestNewMathFunctions { if (context == null) { context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); //new FragmentContext(bitContext, ExecProtos.FragmentHandle.getDefaultInstance(), connection, registry); } - PhysicalPlan plan = reader.readPhysicalPlan(planString); - SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); + final PhysicalPlan plan = reader.readPhysicalPlan(planString); + final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); exec.next(); // skip schema batch while (exec.next()) { - Object [] res = getRunResult(exec); + final Object [] res = getRunResult(exec); assertEquals("return count does not match", expectedResults.length, res.length); for (int i = 0; i<res.length; i++) { @@ -119,17 +116,16 @@ public class TestNewMathFunctions { @Test public void testTrigoMathFunc(@Injectable final DrillbitContext bitContext, - @Injectable UserServer.UserClientConnection connection) throws Throwable{ - Object [] expected = new Object[] {Math.sin(45), Math.cos(45), Math.tan(45),Math.asin(45), Math.acos(45), Math.atan(45),Math.sinh(45), Math.cosh(45), Math.tanh(45)}; + @Injectable UserServer.UserClientConnection connection) throws Throwable { + final Object [] expected = new Object[] {Math.sin(45), Math.cos(45), Math.tan(45),Math.asin(45), Math.acos(45), Math.atan(45),Math.sinh(45), Math.cosh(45), Math.tanh(45)}; runTest(bitContext, connection, expected, "functions/testTrigoMathFunctions.json"); } @Test public void testExtendedMathFunc(@Injectable final DrillbitContext bitContext, - @Injectable UserServer.UserClientConnection connection) throws Throwable{ - BigDecimal d = new BigDecimal("100111111111111111111111111111111111.00000000000000000000000000000000000000000000000000001"); - - Object [] expected = new Object[] {Math.cbrt(1000), Math.log(10), (Math.log(64.0)/Math.log(2.0)), Math.exp(10), Math.toDegrees(0.5), Math.toRadians(45.0), Math.PI, Math.cbrt(d.doubleValue()), Math.log(d.doubleValue()), (Math.log(d.doubleValue())/Math.log(2)), Math.exp(d.doubleValue()), Math.toDegrees(d.doubleValue()), Math.toRadians(d.doubleValue())}; + @Injectable UserServer.UserClientConnection connection) throws Throwable { + final BigDecimal d = new BigDecimal("100111111111111111111111111111111111.00000000000000000000000000000000000000000000000000001"); + final Object [] expected = new Object[] {Math.cbrt(1000), Math.log(10), (Math.log(64.0)/Math.log(2.0)), Math.exp(10), Math.toDegrees(0.5), Math.toRadians(45.0), Math.PI, Math.cbrt(d.doubleValue()), Math.log(d.doubleValue()), (Math.log(d.doubleValue())/Math.log(2)), Math.exp(d.doubleValue()), Math.toDegrees(d.doubleValue()), Math.toRadians(d.doubleValue())}; runTest(bitContext, connection, expected, "functions/testExtendedMathFunctions.json"); } @@ -137,15 +133,14 @@ public class TestNewMathFunctions { @Test public void testTruncDivMod(@Injectable final DrillbitContext bitContext, @Injectable UserServer.UserClientConnection connection) throws Throwable{ - Object [] expected = new Object[] {101.0, 0, 101, 1010.0, 101, 481.0, 0.001099999999931267}; + final Object [] expected = new Object[] {101.0, 0, 101, 1010.0, 101, 481.0, 0.001099999999931267}; runTest(bitContext, connection, expected, "functions/testDivModTruncFunctions.json"); } @Test public void testIsNumeric(@Injectable final DrillbitContext bitContext, @Injectable UserServer.UserClientConnection connection) throws Throwable{ - Object [] expected = new Object[] {1, 1, 1, 0}; + final Object [] expected = new Object[] {1, 1, 1, 0}; runTest(bitContext, connection, expected, "functions/testIsNumericFunction.json"); } - } http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java index 73c7508..68c3b9c 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java @@ -29,7 +29,7 @@ import org.apache.drill.common.util.FileUtils; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.compile.CodeCompiler; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.memory.TopLevelAllocator; +import org.apache.drill.exec.memory.RootAllocatorFactory; import org.apache.drill.exec.ops.FragmentContext; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; @@ -50,42 +50,38 @@ import com.google.common.base.Charsets; import com.google.common.io.Files; public class TestRepeatedFunction extends ExecTest{ - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestRepeatedFunction.class); - DrillConfig c = DrillConfig.create(); - + //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestRepeatedFunction.class); + private final DrillConfig c = DrillConfig.create(); @Test - public void testRepeated(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable{ + public void testRepeated(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { // System.out.println(System.getProperty("java.class.path")); - - - new NonStrictExpectations(){{ + new NonStrictExpectations() {{ bitContext.getMetrics(); result = new MetricRegistry(); - bitContext.getAllocator(); result = new TopLevelAllocator(); + bitContext.getAllocator(); result = RootAllocatorFactory.newRoot(c); bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c); bitContext.getConfig(); result = c; bitContext.getCompiler(); result = CodeCompiler.getTestCompiler(c); }}; - - PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance()); - PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/physical_repeated_1.json"), Charsets.UTF_8)); - FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); - SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); + final PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance()); + final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/physical_repeated_1.json"), Charsets.UTF_8)); + final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); + final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); boolean oneIsOne = false; int size = 0; - int[] sizes = {1,2,0,6}; + final int[] sizes = {1, 2, 0, 6}; - while(exec.next()){ - IntVector c1 = exec.getValueVectorById(new SchemaPath("cnt", ExpressionPosition.UNKNOWN), IntVector.class); - BitVector c2 = exec.getValueVectorById(new SchemaPath("has_min", ExpressionPosition.UNKNOWN), BitVector.class); + while(exec.next()) { + final IntVector c1 = exec.getValueVectorById(new SchemaPath("cnt", ExpressionPosition.UNKNOWN), IntVector.class); + final BitVector c2 = exec.getValueVectorById(new SchemaPath("has_min", ExpressionPosition.UNKNOWN), BitVector.class); - for(int i =0; i < exec.getRecordCount(); i++){ - int curSize = sizes[size % sizes.length]; + for(int i = 0; i < exec.getRecordCount(); i++) { + final int curSize = sizes[size % sizes.length]; assertEquals(curSize, c1.getAccessor().get(i)); - switch(curSize){ + switch(curSize) { case 1: assertEquals(oneIsOne, 1 == c2.getAccessor().get(i)); oneIsOne = !oneIsOne; @@ -104,11 +100,9 @@ public class TestRepeatedFunction extends ExecTest{ } } - if(context.getFailureCause() != null){ + if(context.getFailureCause() != null) { throw context.getFailureCause(); } assertTrue(!context.isFailed()); - } - } http://git-wip-us.apache.org/repos/asf/drill/blob/bfe6cfad/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestEndianess.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestEndianess.java b/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestEndianess.java index 48ddada..f6fe79e 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestEndianess.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestEndianess.java @@ -20,22 +20,23 @@ package org.apache.drill.exec.memory; import static org.junit.Assert.assertEquals; import io.netty.buffer.ByteBuf; +import org.apache.drill.common.config.DrillConfig; import org.apache.drill.exec.ExecTest; import org.junit.Test; - -public class TestEndianess extends ExecTest{ - +public class TestEndianess extends ExecTest { @Test - public void testLittleEndian(){ - TopLevelAllocator a = new TopLevelAllocator(Long.MAX_VALUE); - ByteBuf b = a.buffer(4); + public void testLittleEndian() { + final DrillConfig drillConfig = DrillConfig.create(); + final BufferAllocator a = RootAllocatorFactory.newRoot(drillConfig); + final ByteBuf b = a.buffer(4); b.setInt(0, 35); - assertEquals((int) b.getByte(0), 35); - assertEquals((int) b.getByte(1), 0); - assertEquals((int) b.getByte(2), 0); - assertEquals((int) b.getByte(3), 0); + assertEquals(b.getByte(0), 35); + assertEquals(b.getByte(1), 0); + assertEquals(b.getByte(2), 0); + assertEquals(b.getByte(3), 0); + b.release(); + a.close(); } - }
