You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ad...@apache.org on 2015/09/15 14:12:32 UTC
[3/5] drill git commit: DRILL-1942-hygiene: - add AutoCloseable to
many classes - minor fixes - formatting
DRILL-1942-hygiene:
- add AutoCloseable to many classes
- minor fixes
- formatting
this closes #133
Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/dca98ef6
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/dca98ef6
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/dca98ef6
Branch: refs/heads/master
Commit: dca98ef6a3c675526597f4fdc203bc606168695c
Parents: e45d096
Author: Chris Westin <cw...@yahoo.com>
Authored: Tue Aug 25 16:45:35 2015 -0700
Committer: adeneche <ad...@gmail.com>
Committed: Mon Sep 14 07:59:54 2015 -0700
----------------------------------------------------------------------
.../exec/cache/AbstractStreamSerializable.java | 6 +-
.../cache/LoopedAbstractDrillSerializable.java | 18 +-
.../cache/VectorAccessibleSerializable.java | 31 +-
.../exec/expr/fn/impl/StringFunctions.java | 310 ++++++++++---------
.../apache/drill/exec/ops/BufferManager.java | 13 +-
.../drill/exec/physical/impl/ImplCreator.java | 8 +-
.../drill/exec/physical/impl/ScreenCreator.java | 24 +-
.../exec/physical/impl/SingleSenderCreator.java | 23 +-
.../impl/TopN/PriorityQueueTemplate.java | 13 +-
.../exec/physical/impl/WriterRecordBatch.java | 37 ++-
.../impl/aggregate/StreamingAggBatch.java | 52 ++--
.../BroadcastSenderRootExec.java | 7 +-
.../physical/impl/filter/FilterRecordBatch.java | 32 +-
.../exec/physical/impl/join/HashJoinBatch.java | 96 +++---
.../physical/impl/join/NestedLoopJoinBatch.java | 14 +-
.../physical/impl/limit/LimitRecordBatch.java | 42 ++-
.../OrderedPartitionRecordBatch.java | 4 +-
.../PartitionSenderRootExec.java | 14 +-
.../impl/producer/ProducerConsumerBatch.java | 5 +-
.../exec/physical/impl/sort/SortBatch.java | 4 +-
.../impl/svremover/RemovingRecordBatch.java | 2 +-
.../impl/window/WindowFrameRecordBatch.java | 8 +-
.../physical/impl/xsort/ExternalSortBatch.java | 6 +-
.../exec/physical/impl/xsort/MSortTemplate.java | 12 +-
.../impl/xsort/PriorityQueueCopier.java | 17 +-
.../impl/xsort/PriorityQueueCopierTemplate.java | 8 +-
.../drill/exec/record/AbstractRecordBatch.java | 12 +-
.../exec/record/AbstractSingleRecordBatch.java | 8 +-
.../drill/exec/record/RawFragmentBatch.java | 14 +-
.../drill/exec/record/RecordBatchLoader.java | 25 +-
.../drill/exec/store/AbstractRecordReader.java | 2 +-
31 files changed, 425 insertions(+), 442 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/drill/blob/dca98ef6/exec/java-exec/src/main/java/org/apache/drill/exec/cache/AbstractStreamSerializable.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/cache/AbstractStreamSerializable.java b/exec/java-exec/src/main/java/org/apache/drill/exec/cache/AbstractStreamSerializable.java
index ef488d6..1888e3b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/cache/AbstractStreamSerializable.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/cache/AbstractStreamSerializable.java
@@ -21,14 +21,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-public abstract class AbstractStreamSerializable extends LoopedAbstractDrillSerializable{
- static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(AbstractStreamSerializable.class);
+public abstract class AbstractStreamSerializable extends LoopedAbstractDrillSerializable {
+ //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(AbstractStreamSerializable.class);
@Override
public abstract void readFromStream(InputStream input) throws IOException;
@Override
public abstract void writeToStream(OutputStream output) throws IOException;
-
-
}
http://git-wip-us.apache.org/repos/asf/drill/blob/dca98ef6/exec/java-exec/src/main/java/org/apache/drill/exec/cache/LoopedAbstractDrillSerializable.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/cache/LoopedAbstractDrillSerializable.java b/exec/java-exec/src/main/java/org/apache/drill/exec/cache/LoopedAbstractDrillSerializable.java
index d2a7458..8200436 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/cache/LoopedAbstractDrillSerializable.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/cache/LoopedAbstractDrillSerializable.java
@@ -33,23 +33,23 @@ import org.apache.drill.common.util.DataInputInputStream;
import org.apache.drill.common.util.DataOutputOutputStream;
/**
- * Helper class that holds the basic functionality to interchangably use the different Drill serializble interfaces.
- * This is package private as users should utilize either AbstractDataSerializable or AbstractStreamSerializable instead
- * to avoid infinite loops.
+ * Helper class that holds the basic functionality to interchangeably use
+ * the different Drill serializble interfaces. This is package private as
+ * users should utilize either AbstractDataSerializable or AbstractStreamSerializable
+ * instead to avoid infinite loops.
*/
abstract class LoopedAbstractDrillSerializable implements DrillSerializable {
- static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(LoopedAbstractDrillSerializable.class);
+// private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(LoopedAbstractDrillSerializable.class);
@Override
public void writeExternal(ObjectOutput out) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
writeToStream(baos);
- byte[] ba = baos.toByteArray();
+ final byte[] ba = baos.toByteArray();
out.writeInt(ba.length);
out.write(ba);
}
-
@Override
public void read(DataInput input) throws IOException {
readFromStream(DataInputInputStream.constructInputStream(input));
@@ -72,8 +72,8 @@ abstract class LoopedAbstractDrillSerializable implements DrillSerializable {
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- int len = in.readInt();
- byte[] bytes = new byte[len];
+ final int len = in.readInt();
+ final byte[] bytes = new byte[len];
in.readFully(bytes);
readFromStream(new ByteArrayInputStream(bytes));
}
http://git-wip-us.apache.org/repos/asf/drill/blob/dca98ef6/exec/java-exec/src/main/java/org/apache/drill/exec/cache/VectorAccessibleSerializable.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/cache/VectorAccessibleSerializable.java b/exec/java-exec/src/main/java/org/apache/drill/exec/cache/VectorAccessibleSerializable.java
index a5d2ce8..71c904d 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/cache/VectorAccessibleSerializable.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/cache/VectorAccessibleSerializable.java
@@ -52,7 +52,7 @@ public class VectorAccessibleSerializable extends AbstractStreamSerializable {
private VectorContainer va;
private WritableBatch batch;
- private BufferAllocator allocator;
+ private final BufferAllocator allocator;
private int recordCount = -1;
private BatchSchema.SelectionVectorMode svMode = BatchSchema.SelectionVectorMode.NONE;
private SelectionVector2 sv2;
@@ -61,7 +61,7 @@ public class VectorAccessibleSerializable extends AbstractStreamSerializable {
public VectorAccessibleSerializable(BufferAllocator allocator) {
this.allocator = allocator;
- this.va = new VectorContainer();
+ va = new VectorContainer();
}
public VectorAccessibleSerializable(WritableBatch batch, BufferAllocator allocator) {
@@ -77,16 +77,13 @@ public class VectorAccessibleSerializable extends AbstractStreamSerializable {
*/
public VectorAccessibleSerializable(WritableBatch batch, SelectionVector2 sv2, BufferAllocator allocator) {
this.allocator = allocator;
- if (batch != null) {
- this.batch = batch;
- }
+ this.batch = batch;
if (sv2 != null) {
this.sv2 = sv2;
- this.svMode = BatchSchema.SelectionVectorMode.TWO_BYTE;
+ svMode = BatchSchema.SelectionVectorMode.TWO_BYTE;
}
}
-
/**
* Reads from an InputStream and parses a RecordBatchDef. From this, we construct a SelectionVector2 if it exits
* and construct the vectors and add them to a vector container
@@ -95,8 +92,8 @@ public class VectorAccessibleSerializable extends AbstractStreamSerializable {
*/
@Override
public void readFromStream(InputStream input) throws IOException {
- VectorContainer container = new VectorContainer();
- UserBitShared.RecordBatchDef batchDef = UserBitShared.RecordBatchDef.parseDelimitedFrom(input);
+ final VectorContainer container = new VectorContainer();
+ final UserBitShared.RecordBatchDef batchDef = UserBitShared.RecordBatchDef.parseDelimitedFrom(input);
recordCount = batchDef.getRecordCount();
if (batchDef.hasCarriesTwoByteSelectionVector() && batchDef.getCarriesTwoByteSelectionVector()) {
@@ -107,12 +104,12 @@ public class VectorAccessibleSerializable extends AbstractStreamSerializable {
sv2.getBuffer().setBytes(0, input, recordCount * SelectionVector2.RECORD_SIZE);
svMode = BatchSchema.SelectionVectorMode.TWO_BYTE;
}
- List<ValueVector> vectorList = Lists.newArrayList();
- List<SerializedField> fieldList = batchDef.getFieldList();
+ final List<ValueVector> vectorList = Lists.newArrayList();
+ final List<SerializedField> fieldList = batchDef.getFieldList();
for (SerializedField metaData : fieldList) {
- int dataLength = metaData.getBufferLength();
- MaterializedField field = MaterializedField.create(metaData);
- DrillBuf buf = allocator.buffer(dataLength);
+ final int dataLength = metaData.getBufferLength();
+ final MaterializedField field = MaterializedField.create(metaData);
+ final DrillBuf buf = allocator.buffer(dataLength);
final ValueVector vector;
try {
buf.writeBytes(input, dataLength);
@@ -129,7 +126,6 @@ public class VectorAccessibleSerializable extends AbstractStreamSerializable {
va = container;
}
-
public void writeToStreamAndRetain(OutputStream output) throws IOException {
retain = true;
writeToStream(output);
@@ -145,8 +141,8 @@ public class VectorAccessibleSerializable extends AbstractStreamSerializable {
Preconditions.checkNotNull(output);
final Timer.Context timerContext = metrics.timer(WRITER_TIMER).time();
- DrillBuf[] incomingBuffers = batch.getBuffers();
- UserBitShared.RecordBatchDef batchDef = batch.getDef();
+ final DrillBuf[] incomingBuffers = batch.getBuffers();
+ final UserBitShared.RecordBatchDef batchDef = batch.getDef();
/* DrillBuf associated with the selection vector */
DrillBuf svBuf = null;
@@ -202,5 +198,4 @@ public class VectorAccessibleSerializable extends AbstractStreamSerializable {
public SelectionVector2 getSv2() {
return sv2;
}
-
}
http://git-wip-us.apache.org/repos/asf/drill/blob/dca98ef6/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
index 49f581f..f5aeaf6 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
@@ -35,7 +35,6 @@ import org.apache.drill.exec.expr.annotations.Workspace;
import org.apache.drill.exec.expr.holders.BigIntHolder;
import org.apache.drill.exec.expr.holders.BitHolder;
import org.apache.drill.exec.expr.holders.IntHolder;
-import org.apache.drill.exec.expr.holders.NullableIntHolder;
import org.apache.drill.exec.expr.holders.NullableVarCharHolder;
import org.apache.drill.exec.expr.holders.VarBinaryHolder;
import org.apache.drill.exec.expr.holders.VarCharHolder;
@@ -50,18 +49,20 @@ public class StringFunctions{
*/
@FunctionTemplate(name = "like", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Like implements DrillSimpleFunc{
+ public static class Like implements DrillSimpleFunc {
@Param VarCharHolder input;
@Param(constant=true) VarCharHolder pattern;
@Output BitHolder out;
@Workspace java.util.regex.Matcher matcher;
+ @Override
public void setup() {
matcher = java.util.regex.Pattern.compile(org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlToRegexLike( //
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start, pattern.end, pattern.buffer))).matcher("");
}
+ @Override
public void eval() {
String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
matcher.reset(i);
@@ -70,7 +71,7 @@ public class StringFunctions{
}
@FunctionTemplate(name = "like", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class LikeWithEscape implements DrillSimpleFunc{
+ public static class LikeWithEscape implements DrillSimpleFunc {
@Param VarCharHolder input;
@Param(constant=true) VarCharHolder pattern;
@@ -78,12 +79,14 @@ public class StringFunctions{
@Output BitHolder out;
@Workspace java.util.regex.Matcher matcher;
+ @Override
public void setup() {
matcher = java.util.regex.Pattern.compile(org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlToRegexLike( //
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start, pattern.end, pattern.buffer),
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(escape.start, escape.end, escape.buffer))).matcher("");
}
+ @Override
public void eval() {
String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
matcher.reset(i);
@@ -92,19 +95,21 @@ public class StringFunctions{
}
@FunctionTemplate(name = "ilike", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class ILike implements DrillSimpleFunc{
+ public static class ILike implements DrillSimpleFunc {
@Param VarCharHolder input;
@Param(constant=true) VarCharHolder pattern;
@Output BitHolder out;
@Workspace java.util.regex.Matcher matcher;
+ @Override
public void setup() {
matcher = java.util.regex.Pattern.compile(org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlToRegexLike( //
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start, pattern.end, pattern.buffer)),
java.util.regex.Pattern.CASE_INSENSITIVE).matcher("");
}
+ @Override
public void eval() {
String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
matcher.reset(i);
@@ -113,7 +118,7 @@ public class StringFunctions{
}
@FunctionTemplate(name = "ilike", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class ILikeWithEscape implements DrillSimpleFunc{
+ public static class ILikeWithEscape implements DrillSimpleFunc {
@Param VarCharHolder input;
@Param(constant=true) VarCharHolder pattern;
@@ -121,6 +126,7 @@ public class StringFunctions{
@Output BitHolder out;
@Workspace java.util.regex.Matcher matcher;
+ @Override
public void setup() {
matcher = java.util.regex.Pattern.compile(org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlToRegexLike( //
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start, pattern.end, pattern.buffer),
@@ -128,6 +134,7 @@ public class StringFunctions{
java.util.regex.Pattern.CASE_INSENSITIVE).matcher("");
}
+ @Override
public void eval() {
String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
matcher.reset(i);
@@ -136,17 +143,18 @@ public class StringFunctions{
}
@FunctionTemplate(names = {"similar", "similar_to"}, scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Similar implements DrillSimpleFunc{
+ public static class Similar implements DrillSimpleFunc {
@Param VarCharHolder input;
@Param(constant=true) VarCharHolder pattern;
@Output BitHolder out;
@Workspace java.util.regex.Matcher matcher;
+ @Override
public void setup() {
-
matcher = java.util.regex.Pattern.compile(org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlToRegexSimilar(org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start, pattern.end, pattern.buffer))).matcher("");
}
+ @Override
public void eval() {
String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
matcher.reset(i);
@@ -155,20 +163,21 @@ public class StringFunctions{
}
@FunctionTemplate(names = {"similar", "similar_to"}, scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class SimilarWithEscape implements DrillSimpleFunc{
+ public static class SimilarWithEscape implements DrillSimpleFunc {
@Param VarCharHolder input;
@Param(constant=true) VarCharHolder pattern;
@Param(constant=true) VarCharHolder escape;
@Output BitHolder out;
@Workspace java.util.regex.Matcher matcher;
+ @Override
public void setup() {
-
matcher = java.util.regex.Pattern.compile(org.apache.drill.exec.expr.fn.impl.RegexpUtil.sqlToRegexSimilar(
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start, pattern.end, pattern.buffer),
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(escape.start, escape.end, escape.buffer))).matcher("");
}
+ @Override
public void eval() {
String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
matcher.reset(i);
@@ -180,7 +189,7 @@ public class StringFunctions{
* Replace all substring that match the regular expression with replacement.
*/
@FunctionTemplate(name = "regexp_replace", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class RegexpReplace implements DrillSimpleFunc{
+ public static class RegexpReplace implements DrillSimpleFunc {
@Param VarCharHolder input;
@Param(constant=true) VarCharHolder pattern;
@@ -189,16 +198,17 @@ public class StringFunctions{
@Workspace java.util.regex.Matcher matcher;
@Output VarCharHolder out;
+ @Override
public void setup() {
matcher = java.util.regex.Pattern.compile(org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start, pattern.end, pattern.buffer)).matcher("");
}
+ @Override
public void eval() {
-
out.start = 0;
- String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
- String r = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(replacement.start, replacement.end, replacement.buffer);
- byte [] bytea = matcher.reset(i).replaceAll(r).getBytes(java.nio.charset.Charset.forName("UTF-8"));
+ final String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
+ final String r = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(replacement.start, replacement.end, replacement.buffer);
+ final byte [] bytea = matcher.reset(i).replaceAll(r).getBytes(java.nio.charset.Charset.forName("UTF-8"));
out.buffer = buffer = buffer.reallocIfNeeded(bytea.length);
out.buffer.setBytes(out.start, bytea);
out.end = bytea.length;
@@ -206,52 +216,56 @@ public class StringFunctions{
}
@FunctionTemplate(names = {"char_length", "character_length", "length"}, scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class CharLength implements DrillSimpleFunc{
-
+ public static class CharLength implements DrillSimpleFunc {
@Param VarCharHolder input;
@Output BigIntHolder out;
+ @Override
public void setup() {}
+ @Override
public void eval() {
out.value = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(input.buffer, input.start, input.end);
}
}
@FunctionTemplate(name = "lengthUtf8", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class ByteLength implements DrillSimpleFunc{
-
+ public static class ByteLength implements DrillSimpleFunc {
@Param VarBinaryHolder input;
@Output BigIntHolder out;
+ @Override
public void setup() {}
+ @Override
public void eval() {
out.value = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(input.buffer, input.start, input.end);
}
}
@FunctionTemplate(name = "octet_length", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class OctetLength implements DrillSimpleFunc{
-
+ public static class OctetLength implements DrillSimpleFunc {
@Param VarCharHolder input;
@Output BigIntHolder out;
+ @Override
public void setup() {}
+ @Override
public void eval() {
out.value = input.end - input.start;
}
}
@FunctionTemplate(name = "bit_length", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class BitLength implements DrillSimpleFunc{
-
+ public static class BitLength implements DrillSimpleFunc {
@Param VarCharHolder input;
@Output BigIntHolder out;
+ @Override
public void setup() {}
+ @Override
public void eval() {
out.value = (input.end - input.start) * 8;
}
@@ -266,18 +280,19 @@ public class StringFunctions{
* position('', '') 1 0
*/
@FunctionTemplate(name = "position", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Position implements DrillSimpleFunc{
-
+ public static class Position implements DrillSimpleFunc {
@Param VarCharHolder substr;
@Param VarCharHolder str;
@Output BigIntHolder out;
+ @Override
public void setup() {}
+ @Override
public void eval() {
//Do string match.
- int pos = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.stringLeftMatchUTF8(str.buffer, str.start, str.end,
+ final int pos = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.stringLeftMatchUTF8(str.buffer, str.start, str.end,
substr.buffer, substr.start, substr.end);
if (pos < 0) {
out.value = 0; //indicate not found a matched substr.
@@ -291,15 +306,16 @@ public class StringFunctions{
// same as function "position(substr, str) ", except the reverse order of argument.
@FunctionTemplate(name = "strpos", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Strpos implements DrillSimpleFunc{
-
+ public static class Strpos implements DrillSimpleFunc {
@Param VarCharHolder str;
@Param VarCharHolder substr;
@Output BigIntHolder out;
+ @Override
public void setup() {}
+ @Override
public void eval() {
//Do string match.
int pos = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.stringLeftMatchUTF8(str.buffer, str.start, str.end,
@@ -311,22 +327,22 @@ public class StringFunctions{
out.value = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(str.buffer, str.start, pos) + 1;
}
}
-
}
/*
* Convert string to lower case.
*/
@FunctionTemplate(name = "lower", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class LowerCase implements DrillSimpleFunc{
-
+ public static class LowerCase implements DrillSimpleFunc {
@Param VarCharHolder input;
@Output VarCharHolder out;
@Inject DrillBuf buffer;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = buffer = buffer.reallocIfNeeded(input.end- input.start);
out.start = 0;
@@ -349,22 +365,24 @@ public class StringFunctions{
* Convert string to upper case.
*/
@FunctionTemplate(name = "upper", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class UpperCase implements DrillSimpleFunc{
+ public static class UpperCase implements DrillSimpleFunc {
@Param VarCharHolder input;
@Output VarCharHolder out;
@Inject DrillBuf buffer;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = buffer = buffer.reallocIfNeeded(input.end- input.start);
out.start = 0;
out.end = input.end - input.start;
for (int id = input.start; id < input.end; id++) {
- byte currentByte = input.buffer.getByte(id);
+ byte currentByte = input.buffer.getByte(id);
// 'A - Z' : 0x41 - 0x5A
// 'a - z' : 0x61 - 0x7A
@@ -381,8 +399,7 @@ public class StringFunctions{
// -- Valid "offset": [1, string_length],
// -- Valid "length": [1, up to string_length - offset + 1], if length > string_length - offset +1, get the substr up to the string_lengt.
@FunctionTemplate(names = {"substring", "substr"}, scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Substring implements DrillSimpleFunc{
-
+ public static class Substring implements DrillSimpleFunc {
@Param VarCharHolder string;
@Param BigIntHolder offset;
@Param BigIntHolder length;
@@ -390,10 +407,11 @@ public class StringFunctions{
@Output VarCharHolder out;
@Workspace ByteBuf buffer;
+ @Override
public void setup() {
-
}
+ @Override
public void eval() {
out.buffer = string.buffer;
// if length is NOT positive, or offset is NOT positive, or input string is empty, return empty string.
@@ -401,9 +419,8 @@ public class StringFunctions{
out.start = out.end = 0;
} else {
//Do 1st scan to counter # of character in string.
- int charCount = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(string.buffer, string.start, string.end);
-
- int fromCharIdx = (int) offset.value; //the start position of char (inclusive)
+ final int charCount = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(string.buffer, string.start, string.end);
+ final int fromCharIdx = (int) offset.value; //the start position of char (inclusive)
if (fromCharIdx > charCount ) { // invalid length, return empty string.
out.start = out.end = 0;
@@ -417,21 +434,21 @@ public class StringFunctions{
}
}
}
-
}
@FunctionTemplate(names = {"substring", "substr"}, scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class SubstringOffset implements DrillSimpleFunc{
-
+ public static class SubstringOffset implements DrillSimpleFunc {
@Param VarCharHolder string;
@Param BigIntHolder offset;
@Output VarCharHolder out;
@Workspace ByteBuf buffer;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = string.buffer;
// if length is NOT positive, or offset is NOT positive, or input string is empty, return empty string.
@@ -439,9 +456,8 @@ public class StringFunctions{
out.start = out.end = 0;
} else {
//Do 1st scan to counter # of character in string.
- int charCount = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(string.buffer, string.start, string.end);
-
- int fromCharIdx = (int) offset.value; //the start position of char (inclusive)
+ final int charCount = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(string.buffer, string.start, string.end);
+ final int fromCharIdx = (int) offset.value; //the start position of char (inclusive)
if (fromCharIdx > charCount ) { // invalid length, return empty string.
out.start = out.end = 0;
@@ -451,25 +467,25 @@ public class StringFunctions{
}
}
}
-
}
@FunctionTemplate(names = {"substring", "substr" }, scope = FunctionScope.SIMPLE, nulls = NullHandling.INTERNAL)
- public static class SubstringRegex implements DrillSimpleFunc{
-
+ public static class SubstringRegex implements DrillSimpleFunc {
@Param VarCharHolder input;
@Param(constant=true) VarCharHolder pattern;
@Output NullableVarCharHolder out;
@Workspace java.util.regex.Matcher matcher;
+ @Override
public void setup() {
matcher = java.util.regex.Pattern.compile(
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start, pattern.end, pattern.buffer))
.matcher("");
}
+ @Override
public void eval() {
- String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
+ final String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
matcher.reset(i);
if (matcher.find()) {
out.isSet = 1;
@@ -481,24 +497,25 @@ public class StringFunctions{
}
@FunctionTemplate(names = {"substring", "substr" }, scope = FunctionScope.SIMPLE, nulls = NullHandling.INTERNAL)
- public static class SubstringRegexNullable implements DrillSimpleFunc{
-
+ public static class SubstringRegexNullable implements DrillSimpleFunc {
@Param NullableVarCharHolder input;
@Param(constant=true) VarCharHolder pattern;
@Output NullableVarCharHolder out;
@Workspace java.util.regex.Matcher matcher;
+ @Override
public void setup() {
matcher = java.util.regex.Pattern.compile(
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(pattern.start, pattern.end, pattern.buffer))
.matcher("");
}
+ @Override
public void eval() {
if (input.isSet == 0) {
out.isSet = 0;
} else {
- String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
+ final String i = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start, input.end, input.buffer);
matcher.reset(i);
if (matcher.find()) {
out.isSet = 1;
@@ -517,17 +534,18 @@ public class StringFunctions{
// If length = 0, return empty
// If length < 0, and |length| > total charcounts, return empty.
@FunctionTemplate(name = "left", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Left implements DrillSimpleFunc{
-
+ public static class Left implements DrillSimpleFunc {
@Param VarCharHolder string;
@Param BigIntHolder length;
@Output VarCharHolder out;
@Workspace ByteBuf buffer;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = string.buffer;
// if length is 0, or input string is empty, return empty string.
@@ -535,13 +553,14 @@ public class StringFunctions{
out.start = out.end = 0;
} else {
//Do 1st scan to counter # of character in string.
- int charCount = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(string.buffer, string.start, string.end);
-
- int charLen = 0;
+ final int charCount = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(string.buffer, string.start, string.end);
+ final int charLen;
if (length.value > 0) {
charLen = Math.min((int)length.value, charCount); //left('abc', 5) -> 'abc'
} else if (length.value < 0) {
charLen = Math.max(0, charCount + (int)length.value) ; // left('abc', -5) ==> ''
+ } else {
+ charLen = 0;
}
out.start = string.start; //Starting from the left of input string.
@@ -552,17 +571,18 @@ public class StringFunctions{
//Return last 'length' characters in the string. When 'length' is negative, return all but first |length| characters.
@FunctionTemplate(name = "right", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Right implements DrillSimpleFunc{
-
+ public static class Right implements DrillSimpleFunc {
@Param VarCharHolder string;
@Param BigIntHolder length;
@Output VarCharHolder out;
@Workspace ByteBuf buffer;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = string.buffer;
// invalid length.
@@ -570,10 +590,9 @@ public class StringFunctions{
out.start = out.end = 0;
} else {
//Do 1st scan to counter # of character in string.
- int charCount = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(string.buffer, string.start, string.end);
-
- int fromCharIdx; //the start position of char (inclusive)
- int charLen; // the end position of char (inclusive)
+ final int charCount = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(string.buffer, string.start, string.end);
+ final int fromCharIdx; //the start position of char (inclusive)
+ final int charLen; // the end position of char (inclusive)
if (length.value > 0) {
fromCharIdx = Math.max(charCount - (int) length.value + 1, 1); // right('abc', 5) ==> 'abc' fromCharIdx=1.
charLen = charCount - fromCharIdx + 1;
@@ -583,7 +602,7 @@ public class StringFunctions{
}
// invalid length : right('abc', -5) -> ''
- if (charLen <=0) {
+ if (charLen <= 0) {
out.start = out.end = 0;
} else {
//Do 2nd scan of string. Get bytes corresponding chars in range.
@@ -596,15 +615,16 @@ public class StringFunctions{
@FunctionTemplate(name = "initcap", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class InitCap implements DrillSimpleFunc{
-
+ public static class InitCap implements DrillSimpleFunc {
@Param VarCharHolder input;
@Output VarCharHolder out;
@Inject DrillBuf buffer;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = buffer = buffer.reallocIfNeeded(input.end - input.start);
out.start = 0;
@@ -616,18 +636,19 @@ public class StringFunctions{
//Replace all occurrences in 'text' of substring 'from' with substring 'to'
@FunctionTemplate(name = "replace", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Replace implements DrillSimpleFunc{
-
+ public static class Replace implements DrillSimpleFunc {
@Param VarCharHolder text;
@Param VarCharHolder from;
@Param VarCharHolder to;
@Inject DrillBuf buffer;
@Output VarCharHolder out;
+ @Override
public void setup() {
buffer = buffer.reallocIfNeeded(8000);
}
+ @Override
public void eval() {
out.buffer = buffer;
out.start = out.end = 0;
@@ -638,9 +659,9 @@ public class StringFunctions{
//If "from" is not empty and it's length is no longer than text's length
//then, we may find a match, and do replace.
int i = text.start;
- for (; i<=text.end - fromL; ) {
+ for (; i <= text.end - fromL; ) {
int j = from.start;
- for (; j<from.end; j++) {
+ for (; j < from.end; j++) {
if (text.buffer.getByte(i + j - from.start) != from.buffer.getByte(j)) {
break;
}
@@ -648,7 +669,7 @@ public class StringFunctions{
if (j == from.end ) {
//find a true match ("from" is not empty), copy entire "to" string to out buffer
- for (int k = to.start ; k< to.end; k++) {
+ for (int k = to.start ; k < to.end; k++) {
out.buffer.setByte(out.end++, to.buffer.getByte(k));
}
@@ -661,7 +682,7 @@ public class StringFunctions{
}
//Copy the tail part of text (length < fromL).
- for (; i< text.end; i++) {
+ for (; i < text.end; i++) {
out.buffer.setByte(out.end++, text.buffer.getByte(i));
}
} else {
@@ -671,9 +692,7 @@ public class StringFunctions{
out.start = text.start;
out.end = text.end;
}
-
} // end of eval()
-
}
/*
@@ -681,8 +700,7 @@ public class StringFunctions{
* If the string is already longer than length, then it is truncated (on the right).
*/
@FunctionTemplate(name = "lpad", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Lpad implements DrillSimpleFunc{
-
+ public static class Lpad implements DrillSimpleFunc {
@Param VarCharHolder text;
@Param BigIntHolder length;
@Param VarCharHolder fill;
@@ -690,11 +708,15 @@ public class StringFunctions{
@Output VarCharHolder out;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
- buffer = buffer.reallocIfNeeded((int) length.value*2);
+ final long theLength = length.value;
+ final int lengthNeeded = (int) (theLength <= 0 ? 0 : theLength * 2);
+ buffer = buffer.reallocIfNeeded(lengthNeeded);
byte currentByte = 0;
int id = 0;
//get the char length of text.
@@ -703,29 +725,29 @@ public class StringFunctions{
//get the char length of fill.
int fillCharCount = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(fill.buffer, fill.start, fill.end);
- if (length.value <= 0) {
+ if (theLength <= 0) {
//case 1: target length is <=0, then return an empty string.
out.buffer = buffer;
out.start = out.end = 0;
- } else if (length.value == textCharCount || (length.value > textCharCount && fillCharCount == 0) ) {
+ } else if (theLength == textCharCount || (theLength > textCharCount && fillCharCount == 0) ) {
//case 2: target length is same as text's length, or need fill into text but "fill" is empty, then return text directly.
out.buffer = text.buffer;
out.start = text.start;
out.end = text.end;
- } else if (length.value < textCharCount) {
+ } else if (theLength < textCharCount) {
//case 3: truncate text on the right side. It's same as substring(text, 1, length).
out.buffer = text.buffer;
out.start = text.start;
- out.end = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharPosition(text.buffer, text.start, text.end, (int)length.value);
- } else if (length.value > textCharCount) {
- //case 4: copy "fill" on left. Total # of char to copy : length.value - textCharCount
+ out.end = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharPosition(text.buffer, text.start, text.end, (int) theLength);
+ } else if (theLength > textCharCount) {
+ //case 4: copy "fill" on left. Total # of char to copy : theLength - textCharCount
int count = 0;
out.buffer = buffer;
out.start = out.end = 0;
- while (count < length.value - textCharCount) {
+ while (count < theLength - textCharCount) {
for (id = fill.start; id < fill.end; id++) {
- if (count == length.value - textCharCount) {
+ if (count == theLength - textCharCount) {
break;
}
@@ -746,7 +768,6 @@ public class StringFunctions{
}
}
} // end of eval
-
}
/**
@@ -754,8 +775,7 @@ public class StringFunctions{
* If the string is already longer than length then it is truncated.
*/
@FunctionTemplate(name = "rpad", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Rpad implements DrillSimpleFunc{
-
+ public static class Rpad implements DrillSimpleFunc {
@Param VarCharHolder text;
@Param BigIntHolder length;
@Param VarCharHolder fill;
@@ -763,11 +783,15 @@ public class StringFunctions{
@Output VarCharHolder out;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
- buffer = buffer.reallocIfNeeded((int) length.value*2);
+ final long theLength = length.value;
+ final int lengthNeeded = (int) (theLength <= 0 ? 0 : theLength * 2);
+ buffer = buffer.reallocIfNeeded(lengthNeeded);
byte currentByte = 0;
int id = 0;
@@ -777,21 +801,21 @@ public class StringFunctions{
//get the char length of fill.
int fillCharCount = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharLength(fill.buffer, fill.start, fill.end);
- if (length.value <= 0) {
+ if (theLength <= 0) {
//case 1: target length is <=0, then return an empty string.
out.buffer = buffer;
out.start = out.end = 0;
- } else if (length.value == textCharCount || (length.value > textCharCount && fillCharCount == 0) ) {
+ } else if (theLength == textCharCount || (theLength > textCharCount && fillCharCount == 0) ) {
//case 2: target length is same as text's length, or need fill into text but "fill" is empty, then return text directly.
out.buffer = text.buffer;
out.start = text.start;
out.end = text.end;
- } else if (length.value < textCharCount) {
+ } else if (theLength < textCharCount) {
//case 3: truncate text on the right side. It's same as substring(text, 1, length).
out.buffer = text.buffer;
out.start = text.start;
- out.end = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharPosition(text.buffer, text.start, text.end, (int)length.value);
- } else if (length.value > textCharCount) {
+ out.end = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.getUTF8CharPosition(text.buffer, text.start, text.end, (int) theLength);
+ } else if (theLength > textCharCount) {
//case 4: copy "text" into "out", then copy "fill" on the right.
out.buffer = buffer;
out.start = out.end = 0;
@@ -800,12 +824,12 @@ public class StringFunctions{
out.buffer.setByte(out.end++, text.buffer.getByte(id));
}
- //copy "fill" on right. Total # of char to copy : length.value - textCharCount
+ //copy "fill" on right. Total # of char to copy : theLength - textCharCount
int count = 0;
- while (count < length.value - textCharCount) {
+ while (count < theLength - textCharCount) {
for (id = fill.start; id < fill.end; id++) {
- if (count == length.value - textCharCount) {
+ if (count == theLength - textCharCount) {
break;
}
@@ -822,23 +846,23 @@ public class StringFunctions{
}
} // end of eval
-
}
/**
* Remove the longest string containing only characters from "from" from the start of "text"
*/
@FunctionTemplate(name = "ltrim", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Ltrim implements DrillSimpleFunc{
-
+ public static class Ltrim implements DrillSimpleFunc {
@Param VarCharHolder text;
@Param VarCharHolder from;
@Output VarCharHolder out;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = text.buffer;
out.start = out.end = text.end;
@@ -855,23 +879,23 @@ public class StringFunctions{
}
}
} // end of eval
-
}
/**
* Remove the longest string containing only characters from "from" from the end of "text"
*/
@FunctionTemplate(name = "rtrim", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Rtrim implements DrillSimpleFunc{
-
+ public static class Rtrim implements DrillSimpleFunc {
@Param VarCharHolder text;
@Param VarCharHolder from;
@Output VarCharHolder out;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = text.buffer;
out.start = out.end = text.start;
@@ -897,16 +921,17 @@ public class StringFunctions{
* Remove the longest string containing only characters from "from" from the start of "text"
*/
@FunctionTemplate(name = "btrim", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class Btrim implements DrillSimpleFunc{
-
+ public static class Btrim implements DrillSimpleFunc {
@Param VarCharHolder text;
@Param VarCharHolder from;
@Output VarCharHolder out;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = text.buffer;
out.start = out.end = text.start;
@@ -929,10 +954,10 @@ public class StringFunctions{
id--;
}
bytePerChar = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.utf8CharLen(text.buffer, id);
- int pos = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.stringLeftMatchUTF8(from.buffer, from.start, from.end,
+ final int pos = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.stringLeftMatchUTF8(from.buffer, from.start, from.end,
text.buffer, id, id + bytePerChar);
if (pos < 0) { // Found the 1st char not in "from", stop
- out.end = id+ bytePerChar;
+ out.end = id + bytePerChar;
break;
}
}
@@ -940,15 +965,17 @@ public class StringFunctions{
}
@FunctionTemplate(name = "concatOperator", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
- public static class ConcatOperator implements DrillSimpleFunc{
+ public static class ConcatOperator implements DrillSimpleFunc {
@Param VarCharHolder left;
@Param VarCharHolder right;
@Output VarCharHolder out;
@Inject DrillBuf buffer;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = buffer = buffer.reallocIfNeeded( (left.end - left.start) + (right.end - right.start));
out.start = out.end = 0;
@@ -967,17 +994,17 @@ public class StringFunctions{
//Concatenate the text representations of the arguments. NULL arguments are ignored.
//TODO: NullHanding.INTERNAL for DrillSimpleFunc requires change in code generation.
@FunctionTemplate(name = "concat", scope = FunctionScope.SIMPLE, nulls = NullHandling.INTERNAL)
- public static class Concat implements DrillSimpleFunc{
-
+ public static class Concat implements DrillSimpleFunc {
@Param VarCharHolder left;
@Param VarCharHolder right;
@Output VarCharHolder out;
@Inject DrillBuf buffer;
-
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = buffer = buffer.reallocIfNeeded( (left.end - left.start) + (right.end - right.start));
out.start = out.end = 0;
@@ -994,17 +1021,17 @@ public class StringFunctions{
}
@FunctionTemplate(name = "concat", scope = FunctionScope.SIMPLE, nulls = NullHandling.INTERNAL)
- public static class ConcatRightNullInput implements DrillSimpleFunc{
-
+ public static class ConcatRightNullInput implements DrillSimpleFunc {
@Param VarCharHolder left;
@Param NullableVarCharHolder right;
@Output VarCharHolder out;
@Inject DrillBuf buffer;
-
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = buffer = buffer.reallocIfNeeded( (left.end - left.start) + (right.end - right.start));;
out.start = out.end = 0;
@@ -1015,25 +1042,25 @@ public class StringFunctions{
}
if (right.isSet == 1) {
- for (id = right.start; id < right.end; id++) {
- out.buffer.setByte(out.end++, right.buffer.getByte(id));
- }
+ for (id = right.start; id < right.end; id++) {
+ out.buffer.setByte(out.end++, right.buffer.getByte(id));
+ }
}
}
}
@FunctionTemplate(name = "concat", scope = FunctionScope.SIMPLE, nulls = NullHandling.INTERNAL)
- public static class ConcatLeftNullInput implements DrillSimpleFunc{
-
+ public static class ConcatLeftNullInput implements DrillSimpleFunc {
@Param NullableVarCharHolder left;
@Param VarCharHolder right;
@Output VarCharHolder out;
@Inject DrillBuf buffer;
-
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = buffer.reallocIfNeeded( (left.end - left.start) + (right.end - right.start));
out.start = out.end = 0;
@@ -1052,17 +1079,17 @@ public class StringFunctions{
}
@FunctionTemplate(name = "concat", scope = FunctionScope.SIMPLE, nulls = NullHandling.INTERNAL)
- public static class ConcatBothNullInput implements DrillSimpleFunc{
-
+ public static class ConcatBothNullInput implements DrillSimpleFunc {
@Param NullableVarCharHolder left;
@Param NullableVarCharHolder right;
@Output VarCharHolder out;
@Inject DrillBuf buffer;
-
+ @Override
public void setup() {
}
+ @Override
public void eval() {
out.buffer = buffer.reallocIfNeeded( (left.end - left.start) + (right.end - right.start));
out.start = out.end = 0;
@@ -1086,12 +1113,13 @@ public class StringFunctions{
// "\xca\xfe\xba\xbe" => (byte[]) {(byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe}
@FunctionTemplate(name = "binary_string", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
public static class BinaryString implements DrillSimpleFunc {
-
@Param VarCharHolder in;
@Output VarBinaryHolder out;
- public void setup() { }
+ @Override
+ public void setup() {}
+ @Override
public void eval() {
out.buffer = in.buffer;
out.start = in.start;
@@ -1104,16 +1132,17 @@ public class StringFunctions{
// (byte[]) {(byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe} => "\xca\xfe\xba\xbe"
@FunctionTemplate(name = "string_binary", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
public static class StringBinary implements DrillSimpleFunc {
-
@Param VarBinaryHolder in;
@Output VarCharHolder out;
@Workspace Charset charset;
@Inject DrillBuf buffer;
+ @Override
public void setup() {
charset = java.nio.charset.Charset.forName("UTF-8");
}
+ @Override
public void eval() {
byte[] buf = org.apache.drill.common.util.DrillStringUtils.toBinaryString(in.buffer, in.start, in.end).getBytes(charset);
buffer.setBytes(0, buf);
@@ -1130,12 +1159,13 @@ public class StringFunctions{
*/
@FunctionTemplate(name = "ascii", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
public static class AsciiString implements DrillSimpleFunc {
-
@Param VarCharHolder in;
@Output IntHolder out;
- public void setup() { }
+ @Override
+ public void setup() {}
+ @Override
public void eval() {
out.value = in.buffer.getByte(in.start);
}
@@ -1146,15 +1176,16 @@ public class StringFunctions{
*/
@FunctionTemplate(name = "chr", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
public static class AsciiToChar implements DrillSimpleFunc {
-
@Param IntHolder in;
@Output VarCharHolder out;
@Inject DrillBuf buf;
+ @Override
public void setup() {
buf = buf.reallocIfNeeded(1);
}
+ @Override
public void eval() {
out.buffer = buf;
out.start = out.end = 0;
@@ -1174,12 +1205,14 @@ public class StringFunctions{
@Output VarCharHolder out;
@Inject DrillBuf buffer;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
final int len = in.end - in.start;
- int num = nTimes.value;
+ final int num = nTimes.value;
out.start = 0;
out.buffer = buffer = buffer.reallocIfNeeded( len * num );
for (int i =0; i < num; i++) {
@@ -1194,24 +1227,25 @@ public class StringFunctions{
*/
@FunctionTemplate(name = "toascii", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
public static class AsciiEndode implements DrillSimpleFunc {
-
@Param VarCharHolder in;
@Param VarCharHolder enc;
@Output VarCharHolder out;
@Workspace Charset inCharset;
@Inject DrillBuf buffer;
+ @Override
public void setup() {
inCharset = java.nio.charset.Charset.forName(org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(enc.start, enc.end, enc.buffer));
}
+ @Override
public void eval() {
- byte[] bytea = new byte[in.end - in.start];
- int index =0;
- for (int i = in.start; i<in.end; i++, index++) {
- bytea[index]=in.buffer.getByte(i);
+ final byte[] bytea = new byte[in.end - in.start];
+ int index = 0;
+ for (int i = in.start; i < in.end; i++, index++) {
+ bytea[index] = in.buffer.getByte(i);
}
- byte[] outBytea = new String(bytea, inCharset).getBytes(com.google.common.base.Charsets.UTF_8);
+ final byte[] outBytea = new String(bytea, inCharset).getBytes(com.google.common.base.Charsets.UTF_8);
out.buffer = buffer = buffer.reallocIfNeeded(outBytea.length);
out.buffer.setBytes(0, outBytea);
out.start = 0;
@@ -1224,14 +1258,15 @@ public class StringFunctions{
*/
@FunctionTemplate(name = "reverse", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL)
public static class ReverseString implements DrillSimpleFunc {
-
@Param VarCharHolder in;
@Output VarCharHolder out;
@Inject DrillBuf buffer;
+ @Override
public void setup() {
}
+ @Override
public void eval() {
final int len = in.end - in.start;
out.start = 0;
@@ -1242,7 +1277,7 @@ public class StringFunctions{
int index = in.end;
int innerindex = 0;
- for (int id = in.start; id < in.end; id+=charlen) {
+ for (int id = in.start; id < in.end; id += charlen) {
innerindex = charlen = org.apache.drill.exec.expr.fn.impl.StringFunctionUtil.utf8CharLen(in.buffer, id);
while (innerindex > 0) {
@@ -1254,5 +1289,4 @@ public class StringFunctions{
}
}
}
-
}
http://git-wip-us.apache.org/repos/asf/drill/blob/dca98ef6/exec/java-exec/src/main/java/org/apache/drill/exec/ops/BufferManager.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/BufferManager.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/BufferManager.java
index c953bb3..e0f1eab 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/BufferManager.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/BufferManager.java
@@ -21,8 +21,6 @@ import com.carrotsearch.hppc.LongObjectOpenHashMap;
import io.netty.buffer.DrillBuf;
import org.apache.drill.exec.memory.BufferAllocator;
-import java.io.Closeable;
-
/**
* Manages a list of {@link DrillBuf}s that can be reallocated as needed. Upon
* re-allocation the old buffer will be freed. Managing a list of these buffers
@@ -38,7 +36,6 @@ import java.io.Closeable;
* and {@link QueryContext}.
*/
public class BufferManager implements AutoCloseable {
-
private LongObjectOpenHashMap<DrillBuf> managedBuffers = new LongObjectOpenHashMap<>();
private final BufferAllocator allocator;
@@ -51,11 +48,12 @@ public class BufferManager implements AutoCloseable {
this.fragmentContext = fragmentContext;
}
+ @Override
public void close() throws Exception {
- Object[] mbuffers = ((LongObjectOpenHashMap<Object>)(Object)managedBuffers).values;
- for (int i =0; i < mbuffers.length; i++) {
+ final Object[] mbuffers = ((LongObjectOpenHashMap<Object>) (Object) managedBuffers).values;
+ for (int i = 0; i < mbuffers.length; i++) {
if (managedBuffers.allocated[i]) {
- ((DrillBuf)mbuffers[i]).release();
+ ((DrillBuf) mbuffers[i]).release(1);
}
}
managedBuffers.clear();
@@ -65,7 +63,7 @@ public class BufferManager implements AutoCloseable {
if (managedBuffers.remove(old.memoryAddress()) == null) {
throw new IllegalStateException("Tried to remove unmanaged buffer.");
}
- old.release();
+ old.release(1);
return getManagedBuffer(newSize);
}
@@ -80,5 +78,4 @@ public class BufferManager implements AutoCloseable {
newBuf.setBufferManager(this);
return newBuf;
}
-
}
http://git-wip-us.apache.org/repos/asf/drill/blob/dca98ef6/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ImplCreator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ImplCreator.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ImplCreator.java
index 66558be..98b2876 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ImplCreator.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ImplCreator.java
@@ -17,7 +17,6 @@
*/
package org.apache.drill.exec.physical.impl;
-import java.io.Closeable;
import java.io.IOException;
import java.security.PrivilegedExceptionAction;
import java.util.LinkedList;
@@ -44,10 +43,9 @@ import com.google.common.collect.Lists;
* Create RecordBatch tree (PhysicalOperator implementations) for a given PhysicalOperator tree.
*/
public class ImplCreator {
- static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ImplCreator.class);
+ private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ImplCreator.class);
- private RootExec root = null;
- private LinkedList<CloseableRecordBatch> operators = Lists.newLinkedList();
+ private final LinkedList<CloseableRecordBatch> operators = Lists.newLinkedList();
private ImplCreator() {}
@@ -109,6 +107,7 @@ public class ImplCreator {
final UserGroupInformation proxyUgi = ImpersonationUtil.createProxyUgi(root.getUserName(), context.getQueryUserName());
try {
return proxyUgi.doAs(new PrivilegedExceptionAction<RootExec>() {
+ @Override
public RootExec run() throws Exception {
return ((RootCreator<PhysicalOperator>) getOpCreator(root, context)).getRoot(context, root, childRecordBatches);
}
@@ -134,6 +133,7 @@ public class ImplCreator {
final UserGroupInformation proxyUgi = ImpersonationUtil.createProxyUgi(op.getUserName(), context.getQueryUserName());
try {
return proxyUgi.doAs(new PrivilegedExceptionAction<RecordBatch>() {
+ @Override
public RecordBatch run() throws Exception {
final CloseableRecordBatch batch = ((BatchCreator<PhysicalOperator>) getOpCreator(op, context)).getBatch(
context, op, childRecordBatches);
http://git-wip-us.apache.org/repos/asf/drill/blob/dca98ef6/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ScreenCreator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ScreenCreator.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ScreenCreator.java
index 363205c..97b8d97 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ScreenCreator.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/ScreenCreator.java
@@ -38,19 +38,20 @@ import com.google.common.base.Preconditions;
import org.apache.drill.exec.testing.ControlsInjector;
import org.apache.drill.exec.testing.ControlsInjectorFactory;
-public class ScreenCreator implements RootCreator<Screen>{
- private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ScreenCreator.class);
+public class ScreenCreator implements RootCreator<Screen> {
+ //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ScreenCreator.class);
private static final ControlsInjector injector = ControlsInjectorFactory.getInjector(ScreenCreator.class);
@Override
- public RootExec getRoot(FragmentContext context, Screen config, List<RecordBatch> children) throws ExecutionSetupException {
+ public RootExec getRoot(FragmentContext context, Screen config, List<RecordBatch> children)
+ throws ExecutionSetupException {
Preconditions.checkNotNull(children);
Preconditions.checkArgument(children.size() == 1);
return new ScreenRoot(context, children.iterator().next(), config);
}
-
static class ScreenRoot extends BaseRootExec {
+ private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ScreenRoot.class);
private final RecordBatch incoming;
private final FragmentContext context;
private final AccountingUserConnection userConnection;
@@ -71,7 +72,7 @@ public class ScreenCreator implements RootCreator<Screen>{
super(context, config);
this.context = context;
this.incoming = incoming;
- this.userConnection = context.getUserDataTunnel();
+ userConnection = context.getUserDataTunnel();
}
@Override
@@ -87,10 +88,10 @@ public class ScreenCreator implements RootCreator<Screen>{
if (firstBatch) {
// this is the only data message sent to the client and may contain the schema
QueryWritableBatch batch;
- QueryData header = QueryData.newBuilder() //
- .setQueryId(context.getHandle().getQueryId()) //
- .setRowCount(0) //
- .setDef(RecordBatchDef.getDefaultInstance()) //
+ QueryData header = QueryData.newBuilder()
+ .setQueryId(context.getHandle().getQueryId())
+ .setRowCount(0)
+ .setDef(RecordBatchDef.getDefaultInstance())
.build();
batch = new QueryWritableBatch(header);
@@ -109,7 +110,7 @@ public class ScreenCreator implements RootCreator<Screen>{
//$FALL-THROUGH$
case OK:
injector.injectPause(context.getExecutionControls(), "sending-data", logger);
- QueryWritableBatch batch = materializer.convertNext();
+ final QueryWritableBatch batch = materializer.convertNext();
updateStats(batch);
stats.startWait();
try {
@@ -133,13 +134,10 @@ public class ScreenCreator implements RootCreator<Screen>{
return incoming;
}
-
@Override
public void close() throws Exception {
injector.injectPause(context.getExecutionControls(), "send-complete", logger);
super.close();
}
}
-
-
}
http://git-wip-us.apache.org/repos/asf/drill/blob/dca98ef6/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/SingleSenderCreator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/SingleSenderCreator.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/SingleSenderCreator.java
index f382759..248c8da 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/SingleSenderCreator.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/SingleSenderCreator.java
@@ -52,7 +52,6 @@ public class SingleSenderCreator implements RootCreator<SingleSender>{
private RecordBatch incoming;
private AccountingDataTunnel tunnel;
private FragmentHandle handle;
- private SingleSender config;
private int recMajor;
private volatile boolean ok = true;
private volatile boolean done = false;
@@ -69,11 +68,10 @@ public class SingleSenderCreator implements RootCreator<SingleSender>{
public SingleSenderRootExec(FragmentContext context, RecordBatch batch, SingleSender config) throws OutOfMemoryException {
super(context, context.newOperatorContext(config, null, false), config);
this.incoming = batch;
- assert(incoming != null);
- this.handle = context.getHandle();
- this.config = config;
- this.recMajor = config.getOppositeMajorFragmentId();
- this.tunnel = context.getDataTunnel(config.getDestination());
+ assert incoming != null;
+ handle = context.getHandle();
+ recMajor = config.getOppositeMajorFragmentId();
+ tunnel = context.getDataTunnel(config.getDestination());
oppositeHandle = handle.toBuilder()
.setMajorFragmentId(config.getOppositeMajorFragmentId())
.setMinorFragmentId(config.getOppositeMinorFragmentId())
@@ -104,10 +102,10 @@ public class SingleSenderCreator implements RootCreator<SingleSender>{
case STOP:
case NONE:
// if we didn't do anything yet, send an empty schema.
- final BatchSchema sendSchema = incoming.getSchema() == null ? BatchSchema.newBuilder().build() : incoming
- .getSchema();
+ final BatchSchema sendSchema = incoming.getSchema() == null ?
+ BatchSchema.newBuilder().build() : incoming.getSchema();
- FragmentWritableBatch b2 = FragmentWritableBatch.getEmptyLastWithSchema(handle.getQueryId(),
+ final FragmentWritableBatch b2 = FragmentWritableBatch.getEmptyLastWithSchema(handle.getQueryId(),
handle.getMajorFragmentId(), handle.getMinorFragmentId(), recMajor, oppositeHandle.getMinorFragmentId(),
sendSchema);
stats.startWait();
@@ -120,8 +118,10 @@ public class SingleSenderCreator implements RootCreator<SingleSender>{
case OK_NEW_SCHEMA:
case OK:
- FragmentWritableBatch batch = new FragmentWritableBatch(false, handle.getQueryId(), handle.getMajorFragmentId(),
- handle.getMinorFragmentId(), recMajor, oppositeHandle.getMinorFragmentId(), incoming.getWritableBatch());
+ final FragmentWritableBatch batch = new FragmentWritableBatch(
+ false, handle.getQueryId(), handle.getMajorFragmentId(),
+ handle.getMinorFragmentId(), recMajor, oppositeHandle.getMinorFragmentId(),
+ incoming.getWritableBatch());
updateStats(batch);
stats.startWait();
try {
@@ -146,5 +146,4 @@ public class SingleSenderCreator implements RootCreator<SingleSender>{
done = true;
}
}
-
}
http://git-wip-us.apache.org/repos/asf/drill/blob/dca98ef6/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/TopN/PriorityQueueTemplate.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/TopN/PriorityQueueTemplate.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/TopN/PriorityQueueTemplate.java
index 7e22e65..5cdfc5d 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/TopN/PriorityQueueTemplate.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/TopN/PriorityQueueTemplate.java
@@ -38,10 +38,10 @@ import org.apache.drill.exec.record.selection.SelectionVector4;
import com.google.common.base.Stopwatch;
public abstract class PriorityQueueTemplate implements PriorityQueue {
- static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PriorityQueueTemplate.class);
+ private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PriorityQueueTemplate.class);
- private SelectionVector4 heapSv4;//This holds the heap
- private SelectionVector4 finalSv4;//This is for final sorted output
+ private SelectionVector4 heapSv4; //This holds the heap
+ private SelectionVector4 finalSv4; //This is for final sorted output
private ExpandableHyperContainer hyperBatch;
private FragmentContext context;
private BufferAllocator allocator;
@@ -60,6 +60,7 @@ public abstract class PriorityQueueTemplate implements PriorityQueue {
this.hasSv2 = hasSv2;
}
+ @Override
public void resetQueue(VectorContainer container, SelectionVector4 v4) throws SchemaChangeException {
assert container.getSchema().getSelectionVectorMode() == BatchSchema.SelectionVectorMode.FOUR_BYTE;
BatchSchema schema = container.getSchema();
@@ -69,10 +70,10 @@ public abstract class PriorityQueueTemplate implements PriorityQueue {
newContainer.add(container.getValueAccessorById(field.getValueClass(), ids).getValueVectors());
}
newContainer.buildSchema(BatchSchema.SelectionVectorMode.FOUR_BYTE);
- this.hyperBatch = new ExpandableHyperContainer(newContainer);
- this.batchCount = hyperBatch.iterator().next().getValueVectors().length;
+ hyperBatch = new ExpandableHyperContainer(newContainer);
+ batchCount = hyperBatch.iterator().next().getValueVectors().length;
final DrillBuf drillBuf = allocator.buffer(4 * (limit + 1));
- this.heapSv4 = new SelectionVector4(drillBuf, limit, Character.MAX_VALUE);
+ heapSv4 = new SelectionVector4(drillBuf, limit, Character.MAX_VALUE);
for (int i = 0; i < v4.getTotalCount(); i++) {
heapSv4.set(i, v4.get(i));
}
http://git-wip-us.apache.org/repos/asf/drill/blob/dca98ef6/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/WriterRecordBatch.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/WriterRecordBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/WriterRecordBatch.java
index 0a80b27..34c514e 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/WriterRecordBatch.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/WriterRecordBatch.java
@@ -48,14 +48,14 @@ public class WriterRecordBatch extends AbstractRecordBatch<Writer> {
private long counter = 0;
private final RecordBatch incoming;
private boolean processed = false;
- private String fragmentUniqueId;
+ private final String fragmentUniqueId;
private BatchSchema schema;
public WriterRecordBatch(Writer writer, RecordBatch incoming, FragmentContext context, RecordWriter recordWriter) throws OutOfMemoryException {
super(writer, context, false);
this.incoming = incoming;
- FragmentHandle handle = context.getHandle();
+ final FragmentHandle handle = context.getHandle();
fragmentUniqueId = String.format("%d_%d", handle.getMajorFragmentId(), handle.getMinorFragmentId());
this.recordWriter = recordWriter;
}
@@ -77,7 +77,7 @@ public class WriterRecordBatch extends AbstractRecordBatch<Writer> {
@Override
public IterOutcome innerNext() {
- if(processed) {
+ if (processed) {
// cleanup();
// if the upstream record batch is already processed and next() is called by
// downstream then return NONE to indicate completion
@@ -86,7 +86,7 @@ public class WriterRecordBatch extends AbstractRecordBatch<Writer> {
// process the complete upstream in one next() call
IterOutcome upstream;
- try{
+ try {
do {
upstream = next(incoming);
@@ -101,12 +101,12 @@ public class WriterRecordBatch extends AbstractRecordBatch<Writer> {
case OK_NEW_SCHEMA:
setupNewSchema();
- // fall through.
+ // $FALL-THROUGH$
case OK:
counter += eventBasedRecordWriter.write(incoming.getRecordCount());
logger.debug("Total records written so far: {}", counter);
- for(VectorWrapper<?> v : incoming) {
+ for(final VectorWrapper<?> v : incoming) {
v.getValueVector().clear();
}
break;
@@ -130,14 +130,15 @@ public class WriterRecordBatch extends AbstractRecordBatch<Writer> {
return IterOutcome.OK_NEW_SCHEMA;
}
- private void addOutputContainerData(){
- VarCharVector fragmentIdVector = (VarCharVector) container.getValueAccessorById( //
- VarCharVector.class, //
- container.getValueVectorId(SchemaPath.getSimplePath("Fragment")).getFieldIds() //
- ).getValueVector();
+ private void addOutputContainerData() {
+ final VarCharVector fragmentIdVector = (VarCharVector) container.getValueAccessorById(
+ VarCharVector.class,
+ container.getValueVectorId(SchemaPath.getSimplePath("Fragment")).getFieldIds())
+ .getValueVector();
AllocationHelper.allocate(fragmentIdVector, 1, 50);
- BigIntVector summaryVector = (BigIntVector) container.getValueAccessorById(BigIntVector.class,
- container.getValueVectorId(SchemaPath.getSimplePath("Number of records written")).getFieldIds()).getValueVector();
+ final BigIntVector summaryVector = (BigIntVector) container.getValueAccessorById(BigIntVector.class,
+ container.getValueVectorId(SchemaPath.getSimplePath("Number of records written")).getFieldIds())
+ .getValueVector();
AllocationHelper.allocate(summaryVector, 1, 8);
fragmentIdVector.getMutator().setSafe(0, fragmentUniqueId.getBytes());
fragmentIdVector.getMutator().setValueCount(1);
@@ -155,13 +156,16 @@ public class WriterRecordBatch extends AbstractRecordBatch<Writer> {
// Create two vectors for:
// 1. Fragment unique id.
// 2. Summary: currently contains number of records written.
- MaterializedField fragmentIdField = MaterializedField.create(SchemaPath.getSimplePath("Fragment"), Types.required(MinorType.VARCHAR));
- MaterializedField summaryField = MaterializedField.create(SchemaPath.getSimplePath("Number of records written"), Types.required(MinorType.BIGINT));
+ final MaterializedField fragmentIdField =
+ MaterializedField.create(SchemaPath.getSimplePath("Fragment"), Types.required(MinorType.VARCHAR));
+ final MaterializedField summaryField =
+ MaterializedField.create(SchemaPath.getSimplePath("Number of records written"),
+ Types.required(MinorType.BIGINT));
container.addOrGet(fragmentIdField);
container.addOrGet(summaryField);
container.buildSchema(BatchSchema.SelectionVectorMode.NONE);
- } finally{
+ } finally {
stats.stopSetup();
}
@@ -186,5 +190,4 @@ public class WriterRecordBatch extends AbstractRecordBatch<Writer> {
closeWriter();
super.close();
}
-
}
http://git-wip-us.apache.org/repos/asf/drill/blob/dca98ef6/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/StreamingAggBatch.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/StreamingAggBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/StreamingAggBatch.java
index 5a26134..2ab1e66 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/StreamingAggBatch.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/aggregate/StreamingAggBatch.java
@@ -113,7 +113,7 @@ public class StreamingAggBatch extends AbstractRecordBatch<StreamingAggregate> {
if (!createAggregator()) {
state = BatchState.DONE;
}
- for (VectorWrapper w : container) {
+ for (final VectorWrapper<?> w : container) {
w.getValueVector().allocateNew();
}
}
@@ -206,8 +206,8 @@ public class StreamingAggBatch extends AbstractRecordBatch<StreamingAggregate> {
*/
private void constructSpecialBatch() {
int exprIndex = 0;
- for (VectorWrapper vw: container) {
- ValueVector vv = vw.getValueVector();
+ for (final VectorWrapper<?> vw: container) {
+ final ValueVector vv = vw.getValueVector();
AllocationHelper.allocateNew(vv, SPECIAL_BATCH_COUNT);
vv.getMutator().setValueCount(SPECIAL_BATCH_COUNT);
if (vv.getField().getType().getMode() == TypeProtos.DataMode.REQUIRED) {
@@ -265,20 +265,20 @@ public class StreamingAggBatch extends AbstractRecordBatch<StreamingAggregate> {
ErrorCollector collector = new ErrorCollectorImpl();
- for (int i =0; i < keyExprs.length; i++) {
- NamedExpression ne = popConfig.getKeys()[i];
+ for (int i = 0; i < keyExprs.length; i++) {
+ final NamedExpression ne = popConfig.getKeys()[i];
final LogicalExpression expr = ExpressionTreeMaterializer.materialize(ne.getExpr(), incoming, collector,context.getFunctionRegistry() );
if (expr == null) {
continue;
}
keyExprs[i] = expr;
final MaterializedField outputField = MaterializedField.create(ne.getRef(), expr.getMajorType());
- ValueVector vector = TypeHelper.getNewVector(outputField, oContext.getAllocator());
+ final ValueVector vector = TypeHelper.getNewVector(outputField, oContext.getAllocator());
keyOutputIds[i] = container.add(vector);
}
- for (int i =0; i < valueExprs.length; i++) {
- NamedExpression ne = popConfig.getExprs()[i];
+ for (int i = 0; i < valueExprs.length; i++) {
+ final NamedExpression ne = popConfig.getExprs()[i];
final LogicalExpression expr = ExpressionTreeMaterializer.materialize(ne.getExpr(), incoming, collector, context.getFunctionRegistry());
if (expr == null) {
continue;
@@ -315,17 +315,17 @@ public class StreamingAggBatch extends AbstractRecordBatch<StreamingAggregate> {
private void setupIsSame(ClassGenerator<StreamingAggregator> cg, LogicalExpression[] keyExprs) {
cg.setMappingSet(IS_SAME_I1);
- for (LogicalExpression expr : keyExprs) {
+ for (final LogicalExpression expr : keyExprs) {
// first, we rewrite the evaluation stack for each side of the comparison.
cg.setMappingSet(IS_SAME_I1);
- HoldingContainer first = cg.addExpr(expr, false);
+ final HoldingContainer first = cg.addExpr(expr, false);
cg.setMappingSet(IS_SAME_I2);
- HoldingContainer second = cg.addExpr(expr, false);
+ final HoldingContainer second = cg.addExpr(expr, false);
- LogicalExpression fh =
+ final LogicalExpression fh =
FunctionGenerationHelper
.getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry());
- HoldingContainer out = cg.addExpr(fh, false);
+ final HoldingContainer out = cg.addExpr(fh, false);
cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
}
cg.getEvalBlock()._return(JExpr.TRUE);
@@ -338,17 +338,17 @@ public class StreamingAggBatch extends AbstractRecordBatch<StreamingAggregate> {
private void setupIsSameApart(ClassGenerator<StreamingAggregator> cg, LogicalExpression[] keyExprs) {
cg.setMappingSet(ISA_B1);
- for (LogicalExpression expr : keyExprs) {
+ for (final LogicalExpression expr : keyExprs) {
// first, we rewrite the evaluation stack for each side of the comparison.
cg.setMappingSet(ISA_B1);
- HoldingContainer first = cg.addExpr(expr, false);
+ final HoldingContainer first = cg.addExpr(expr, false);
cg.setMappingSet(ISA_B2);
- HoldingContainer second = cg.addExpr(expr, false);
+ final HoldingContainer second = cg.addExpr(expr, false);
- LogicalExpression fh =
+ final LogicalExpression fh =
FunctionGenerationHelper
.getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry());
- HoldingContainer out = cg.addExpr(fh, false);
+ final HoldingContainer out = cg.addExpr(fh, false);
cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
}
cg.getEvalBlock()._return(JExpr.TRUE);
@@ -360,8 +360,8 @@ public class StreamingAggBatch extends AbstractRecordBatch<StreamingAggregate> {
private void addRecordValues(ClassGenerator<StreamingAggregator> cg, LogicalExpression[] valueExprs) {
cg.setMappingSet(EVAL);
- for (LogicalExpression ex : valueExprs) {
- HoldingContainer hc = cg.addExpr(ex);
+ for (final LogicalExpression ex : valueExprs) {
+ final HoldingContainer hc = cg.addExpr(ex);
}
}
@@ -369,8 +369,8 @@ public class StreamingAggBatch extends AbstractRecordBatch<StreamingAggregate> {
private void outputRecordKeys(ClassGenerator<StreamingAggregator> cg, TypedFieldId[] keyOutputIds, LogicalExpression[] keyExprs) {
cg.setMappingSet(RECORD_KEYS);
- for (int i =0; i < keyExprs.length; i++) {
- HoldingContainer hc = cg.addExpr(new ValueVectorWriteExpression(keyOutputIds[i], keyExprs[i], true));
+ for (int i = 0; i < keyExprs.length; i++) {
+ final HoldingContainer hc = cg.addExpr(new ValueVectorWriteExpression(keyOutputIds[i], keyExprs[i], true));
}
}
@@ -383,15 +383,14 @@ public class StreamingAggBatch extends AbstractRecordBatch<StreamingAggregate> {
private void outputRecordKeysPrev(ClassGenerator<StreamingAggregator> cg, TypedFieldId[] keyOutputIds, LogicalExpression[] keyExprs) {
cg.setMappingSet(RECORD_KEYS_PREV);
- for (int i =0; i < keyExprs.length; i++) {
+ for (int i = 0; i < keyExprs.length; i++) {
// IMPORTANT: there is an implicit assertion here that the TypedFieldIds for the previous batch and the current batch are the same. This is possible because InternalBatch guarantees this.
logger.debug("Writing out expr {}", keyExprs[i]);
cg.rotateBlock();
cg.setMappingSet(RECORD_KEYS_PREV);
- HoldingContainer innerExpression = cg.addExpr(keyExprs[i], false);
+ final HoldingContainer innerExpression = cg.addExpr(keyExprs[i], false);
cg.setMappingSet(RECORD_KEYS_PREV_OUT);
- HoldingContainer outerExpression = cg.addExpr(new ValueVectorWriteExpression(keyOutputIds[i], new HoldingContainerExpression(innerExpression), true), false);
-
+ final HoldingContainer outerExpression = cg.addExpr(new ValueVectorWriteExpression(keyOutputIds[i], new HoldingContainerExpression(innerExpression), true), false);
}
}
@@ -428,5 +427,4 @@ public class StreamingAggBatch extends AbstractRecordBatch<StreamingAggregate> {
protected void killIncoming(boolean sendUpstream) {
incoming.kill(sendUpstream);
}
-
}
http://git-wip-us.apache.org/repos/asf/drill/blob/dca98ef6/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/broadcastsender/BroadcastSenderRootExec.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/broadcastsender/BroadcastSenderRootExec.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/broadcastsender/BroadcastSenderRootExec.java
index c6a07f8..98db0cd 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/broadcastsender/BroadcastSenderRootExec.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/broadcastsender/BroadcastSenderRootExec.java
@@ -41,8 +41,7 @@ import com.google.common.collect.ArrayListMultimap;
* to all nodes is cheaper than merging and computing all the joins in the same node.
*/
public class BroadcastSenderRootExec extends BaseRootExec {
- static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BroadcastSenderRootExec.class);
- private final FragmentContext context;
+ private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BroadcastSenderRootExec.class);
private final BroadcastSender config;
private final int[][] receivingMinorFragments;
private final AccountingDataTunnel[] tunnels;
@@ -64,7 +63,6 @@ public class BroadcastSenderRootExec extends BaseRootExec {
BroadcastSender config) throws OutOfMemoryException {
super(context, context.newOperatorContext(config, null, false), config);
this.ok = true;
- this.context = context;
this.incoming = incoming;
this.config = config;
this.handle = context.getHandle();
@@ -80,7 +78,7 @@ public class BroadcastSenderRootExec extends BaseRootExec {
this.tunnels = new AccountingDataTunnel[destCount];
this.receivingMinorFragments = new int[destCount][];
- for(DrillbitEndpoint ep : dests.keySet()){
+ for(final DrillbitEndpoint ep : dests.keySet()){
List<Integer> minorsList= dests.get(ep);
int[] minorsArray = new int[minorsList.size()];
int x = 0;
@@ -154,5 +152,4 @@ public class BroadcastSenderRootExec extends BaseRootExec {
stats.setLongStat(Metric.N_RECEIVERS, tunnels.length);
stats.addLongStat(Metric.BYTES_SENT, writableBatch.getByteCount());
}
-
}