You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ja...@apache.org on 2015/11/13 03:37:47 UTC
[17/45] drill git commit: DRILL-3987: (REFACTOR) Common and Vector
modules building.
http://git-wip-us.apache.org/repos/asf/drill/blob/4524fdbe/exec/vector/src/main/codegen/templates/TypeHelper.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/templates/TypeHelper.java b/exec/vector/src/main/codegen/templates/TypeHelper.java
deleted file mode 100644
index b8178cb..0000000
--- a/exec/vector/src/main/codegen/templates/TypeHelper.java
+++ /dev/null
@@ -1,600 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.drill.exec.vector.complex.UnionVector;
-
-<@pp.dropOutputFile />
-<@pp.changeOutputFile name="/org/apache/drill/exec/expr/TypeHelper.java" />
-
-<#include "/@includes/license.ftl" />
-
-package org.apache.drill.exec.expr;
-
-<#include "/@includes/vv_imports.ftl" />
-import org.apache.drill.common.expression.SchemaPath;
-import org.apache.drill.common.types.TypeProtos.DataMode;
-import org.apache.drill.common.types.TypeProtos.MinorType;
-import org.apache.drill.common.types.TypeProtos.MajorType;
-import org.apache.drill.exec.record.MaterializedField;
-import org.apache.drill.exec.vector.accessor.*;
-import org.apache.drill.exec.vector.complex.RepeatedMapVector;
-import org.apache.drill.exec.util.CallBack;
-
-public class TypeHelper {
- static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TypeHelper.class);
-
- private static final int WIDTH_ESTIMATE = 50;
-
- // Default length when casting to varchar : 65536 = 2^16
- // This only defines an absolute maximum for values, setting
- // a high value like this will not inflate the size for small values
- public static final int VARCHAR_DEFAULT_CAST_LEN = 65536;
-
- private static String buildErrorMessage(final String operation, final MinorType type, final DataMode mode) {
- return String.format("Unable to %s for minor type [%s] and mode [%s]", operation, type, mode);
- }
-
- private static String buildErrorMessage(final String operation, final MajorType type) {
- return buildErrorMessage(operation, type.getMinorType(), type.getMode());
- }
-
- public static int getSize(MajorType major) {
- switch (major.getMinorType()) {
-<#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case}:
- return ${type.width}<#if minor.class?substring(0, 3) == "Var" ||
- minor.class?substring(0, 3) == "PRO" ||
- minor.class?substring(0, 3) == "MSG"> + WIDTH_ESTIMATE</#if>;
- </#list>
-</#list>
- case FIXEDCHAR: return major.getWidth();
- case FIXED16CHAR: return major.getWidth();
- case FIXEDBINARY: return major.getWidth();
- }
- throw new UnsupportedOperationException(buildErrorMessage("get size", major));
- }
-
- public static SqlAccessor getSqlAccessor(ValueVector vector){
- final MajorType type = vector.getField().getType();
- switch(type.getMinorType()){
- case UNION:
- return new UnionSqlAccessor((UnionVector) vector);
- <#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case}:
- switch (type.getMode()) {
- case REQUIRED:
- return new ${minor.class}Accessor((${minor.class}Vector) vector);
- case OPTIONAL:
- return new Nullable${minor.class}Accessor((Nullable${minor.class}Vector) vector);
- case REPEATED:
- return new GenericAccessor(vector);
- }
- </#list>
- </#list>
- case MAP:
- case LIST:
- return new GenericAccessor(vector);
- }
- throw new UnsupportedOperationException(buildErrorMessage("find sql accessor", type));
- }
-
- public static ValueVector getNewVector(SchemaPath parentPath, String name, BufferAllocator allocator, MajorType type, CallBack callback){
- SchemaPath child = parentPath.getChild(name);
- MaterializedField field = MaterializedField.create(child, type);
- return getNewVector(field, allocator, callback);
- }
-
-
- public static Class<?> getValueVectorClass(MinorType type, DataMode mode){
- switch (type) {
- case UNION:
- return UnionVector.class;
- case MAP:
- switch (mode) {
- case OPTIONAL:
- case REQUIRED:
- return MapVector.class;
- case REPEATED:
- return RepeatedMapVector.class;
- }
-
- case LIST:
- switch (mode) {
- case REPEATED:
- return RepeatedListVector.class;
- case REQUIRED:
- case OPTIONAL:
- return ListVector.class;
- }
-
-<#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case}:
- switch (mode) {
- case REQUIRED:
- return ${minor.class}Vector.class;
- case OPTIONAL:
- return Nullable${minor.class}Vector.class;
- case REPEATED:
- return Repeated${minor.class}Vector.class;
- }
- </#list>
-</#list>
- case GENERIC_OBJECT :
- return ObjectVector.class ;
- default:
- break;
- }
- throw new UnsupportedOperationException(buildErrorMessage("get value vector class", type, mode));
- }
- public static Class<?> getReaderClassName( MinorType type, DataMode mode, boolean isSingularRepeated){
- switch (type) {
- case MAP:
- switch (mode) {
- case REQUIRED:
- if (!isSingularRepeated)
- return SingleMapReaderImpl.class;
- else
- return SingleLikeRepeatedMapReaderImpl.class;
- case REPEATED:
- return RepeatedMapReaderImpl.class;
- }
- case LIST:
- switch (mode) {
- case REQUIRED:
- return SingleListReaderImpl.class;
- case REPEATED:
- return RepeatedListReaderImpl.class;
- }
-
-<#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case}:
- switch (mode) {
- case REQUIRED:
- return ${minor.class}ReaderImpl.class;
- case OPTIONAL:
- return Nullable${minor.class}ReaderImpl.class;
- case REPEATED:
- return Repeated${minor.class}ReaderImpl.class;
- }
- </#list>
-</#list>
- default:
- break;
- }
- throw new UnsupportedOperationException(buildErrorMessage("get reader class name", type, mode));
- }
-
- public static Class<?> getWriterInterface( MinorType type, DataMode mode){
- switch (type) {
- case UNION: return UnionWriter.class;
- case MAP: return MapWriter.class;
- case LIST: return ListWriter.class;
-<#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case}: return ${minor.class}Writer.class;
- </#list>
-</#list>
- default:
- break;
- }
- throw new UnsupportedOperationException(buildErrorMessage("get writer interface", type, mode));
- }
-
- public static Class<?> getWriterImpl( MinorType type, DataMode mode){
- switch (type) {
- case UNION:
- return UnionWriter.class;
- case MAP:
- switch (mode) {
- case REQUIRED:
- case OPTIONAL:
- return SingleMapWriter.class;
- case REPEATED:
- return RepeatedMapWriter.class;
- }
- case LIST:
- switch (mode) {
- case REQUIRED:
- case OPTIONAL:
- return UnionListWriter.class;
- case REPEATED:
- return RepeatedListWriter.class;
- }
-
-<#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case}:
- switch (mode) {
- case REQUIRED:
- return ${minor.class}WriterImpl.class;
- case OPTIONAL:
- return Nullable${minor.class}WriterImpl.class;
- case REPEATED:
- return Repeated${minor.class}WriterImpl.class;
- }
- </#list>
-</#list>
- default:
- break;
- }
- throw new UnsupportedOperationException(buildErrorMessage("get writer implementation", type, mode));
- }
-
- public static Class<?> getHolderReaderImpl( MinorType type, DataMode mode){
- switch (type) {
-<#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case}:
- switch (mode) {
- case REQUIRED:
- return ${minor.class}HolderReaderImpl.class;
- case OPTIONAL:
- return Nullable${minor.class}HolderReaderImpl.class;
- case REPEATED:
- return Repeated${minor.class}HolderReaderImpl.class;
- }
- </#list>
-</#list>
- default:
- break;
- }
- throw new UnsupportedOperationException(buildErrorMessage("get holder reader implementation", type, mode));
- }
-
- public static JType getHolderType(JCodeModel model, MinorType type, DataMode mode){
- switch (type) {
- case UNION:
- return model._ref(UnionHolder.class);
- case MAP:
- case LIST:
- return model._ref(ComplexHolder.class);
-
-<#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case}:
- switch (mode) {
- case REQUIRED:
- return model._ref(${minor.class}Holder.class);
- case OPTIONAL:
- return model._ref(Nullable${minor.class}Holder.class);
- case REPEATED:
- return model._ref(Repeated${minor.class}Holder.class);
- }
- </#list>
-</#list>
- case GENERIC_OBJECT:
- return model._ref(ObjectHolder.class);
- default:
- break;
- }
- throw new UnsupportedOperationException(buildErrorMessage("get holder type", type, mode));
- }
-
- public static ValueVector getNewVector(MaterializedField field, BufferAllocator allocator){
- return getNewVector(field, allocator, null);
- }
- public static ValueVector getNewVector(MaterializedField field, BufferAllocator allocator, CallBack callBack){
- MajorType type = field.getType();
-
- switch (type.getMinorType()) {
-
- case UNION:
- return new UnionVector(field, allocator, callBack);
-
- case MAP:
- switch (type.getMode()) {
- case REQUIRED:
- case OPTIONAL:
- return new MapVector(field, allocator, callBack);
- case REPEATED:
- return new RepeatedMapVector(field, allocator, callBack);
- }
- case LIST:
- switch (type.getMode()) {
- case REPEATED:
- return new RepeatedListVector(field, allocator, callBack);
- case OPTIONAL:
- case REQUIRED:
- return new ListVector(field, allocator, callBack);
- }
-<#list vv. types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case}:
- switch (type.getMode()) {
- case REQUIRED:
- return new ${minor.class}Vector(field, allocator);
- case OPTIONAL:
- return new Nullable${minor.class}Vector(field, allocator);
- case REPEATED:
- return new Repeated${minor.class}Vector(field, allocator);
- }
- </#list>
-</#list>
- case GENERIC_OBJECT:
- return new ObjectVector(field, allocator) ;
- default:
- break;
- }
- // All ValueVector types have been handled.
- throw new UnsupportedOperationException(buildErrorMessage("get new vector", type));
- }
-
- public static ValueHolder getValue(ValueVector vector, int index) {
- MajorType type = vector.getField().getType();
- ValueHolder holder;
- switch(type.getMinorType()) {
-<#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case} :
- <#if minor.class?starts_with("Var") || minor.class == "IntervalDay" || minor.class == "Interval" ||
- minor.class?starts_with("Decimal28") || minor.class?starts_with("Decimal38")>
- switch (type.getMode()) {
- case REQUIRED:
- holder = new ${minor.class}Holder();
- ((${minor.class}Vector) vector).getAccessor().get(index, (${minor.class}Holder)holder);
- return holder;
- case OPTIONAL:
- holder = new Nullable${minor.class}Holder();
- ((Nullable${minor.class}Holder)holder).isSet = ((Nullable${minor.class}Vector) vector).getAccessor().isSet(index);
- if (((Nullable${minor.class}Holder)holder).isSet == 1) {
- ((Nullable${minor.class}Vector) vector).getAccessor().get(index, (Nullable${minor.class}Holder)holder);
- }
- return holder;
- }
- <#else>
- switch (type.getMode()) {
- case REQUIRED:
- holder = new ${minor.class}Holder();
- ((${minor.class}Holder)holder).value = ((${minor.class}Vector) vector).getAccessor().get(index);
- return holder;
- case OPTIONAL:
- holder = new Nullable${minor.class}Holder();
- ((Nullable${minor.class}Holder)holder).isSet = ((Nullable${minor.class}Vector) vector).getAccessor().isSet(index);
- if (((Nullable${minor.class}Holder)holder).isSet == 1) {
- ((Nullable${minor.class}Holder)holder).value = ((Nullable${minor.class}Vector) vector).getAccessor().get(index);
- }
- return holder;
- }
- </#if>
- </#list>
-</#list>
- case GENERIC_OBJECT:
- holder = new ObjectHolder();
- ((ObjectHolder)holder).obj = ((ObjectVector) vector).getAccessor().getObject(index) ;
- break;
- }
-
- throw new UnsupportedOperationException(buildErrorMessage("get value", type));
- }
-
- public static void setValue(ValueVector vector, int index, ValueHolder holder) {
- MajorType type = vector.getField().getType();
-
- switch(type.getMinorType()) {
-<#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case} :
- switch (type.getMode()) {
- case REQUIRED:
- ((${minor.class}Vector) vector).getMutator().setSafe(index, (${minor.class}Holder) holder);
- return;
- case OPTIONAL:
- if (((Nullable${minor.class}Holder) holder).isSet == 1) {
- ((Nullable${minor.class}Vector) vector).getMutator().setSafe(index, (Nullable${minor.class}Holder) holder);
- }
- return;
- }
- </#list>
-</#list>
- case GENERIC_OBJECT:
- ((ObjectVector) vector).getMutator().setSafe(index, (ObjectHolder) holder);
- return;
- default:
- throw new UnsupportedOperationException(buildErrorMessage("set value", type));
- }
- }
-
- public static void setValueSafe(ValueVector vector, int index, ValueHolder holder) {
- MajorType type = vector.getField().getType();
-
- switch(type.getMinorType()) {
- <#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case} :
- switch (type.getMode()) {
- case REQUIRED:
- ((${minor.class}Vector) vector).getMutator().setSafe(index, (${minor.class}Holder) holder);
- return;
- case OPTIONAL:
- if (((Nullable${minor.class}Holder) holder).isSet == 1) {
- ((Nullable${minor.class}Vector) vector).getMutator().setSafe(index, (Nullable${minor.class}Holder) holder);
- } else {
- ((Nullable${minor.class}Vector) vector).getMutator().isSafe(index);
- }
- return;
- }
- </#list>
- </#list>
- case GENERIC_OBJECT:
- ((ObjectVector) vector).getMutator().setSafe(index, (ObjectHolder) holder);
- default:
- throw new UnsupportedOperationException(buildErrorMessage("set value safe", type));
- }
- }
-
- public static boolean compareValues(ValueVector v1, int v1index, ValueVector v2, int v2index) {
- MajorType type1 = v1.getField().getType();
- MajorType type2 = v2.getField().getType();
-
- if (type1.getMinorType() != type2.getMinorType()) {
- return false;
- }
-
- switch(type1.getMinorType()) {
-<#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case} :
- if ( ((${minor.class}Vector) v1).getAccessor().get(v1index) ==
- ((${minor.class}Vector) v2).getAccessor().get(v2index) )
- return true;
- break;
- </#list>
-</#list>
- default:
- break;
- }
- return false;
- }
-
- /**
- * Create a ValueHolder of MajorType.
- * @param type
- * @return
- */
- public static ValueHolder createValueHolder(MajorType type) {
- switch(type.getMinorType()) {
- <#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case} :
-
- switch (type.getMode()) {
- case REQUIRED:
- return new ${minor.class}Holder();
- case OPTIONAL:
- return new Nullable${minor.class}Holder();
- case REPEATED:
- return new Repeated${minor.class}Holder();
- }
- </#list>
- </#list>
- case GENERIC_OBJECT:
- return new ObjectHolder();
- default:
- throw new UnsupportedOperationException(buildErrorMessage("create value holder", type));
- }
- }
-
- public static boolean isNull(ValueHolder holder) {
- MajorType type = TypeHelper.getValueHolderType(holder);
-
- switch(type.getMinorType()) {
- <#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case} :
-
- switch (type.getMode()) {
- case REQUIRED:
- return true;
- case OPTIONAL:
- return ((Nullable${minor.class}Holder) holder).isSet == 0;
- case REPEATED:
- return true;
- }
- </#list>
- </#list>
- default:
- throw new UnsupportedOperationException(buildErrorMessage("check is null", type));
- }
- }
-
- public static ValueHolder deNullify(ValueHolder holder) {
- MajorType type = TypeHelper.getValueHolderType(holder);
-
- switch(type.getMinorType()) {
- <#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case} :
-
- switch (type.getMode()) {
- case REQUIRED:
- return holder;
- case OPTIONAL:
- if( ((Nullable${minor.class}Holder) holder).isSet == 1) {
- ${minor.class}Holder newHolder = new ${minor.class}Holder();
-
- <#assign fields = minor.fields!type.fields />
- <#list fields as field>
- newHolder.${field.name} = ((Nullable${minor.class}Holder) holder).${field.name};
- </#list>
-
- return newHolder;
- } else {
- throw new UnsupportedOperationException("You can not convert a null value into a non-null value!");
- }
- case REPEATED:
- return holder;
- }
- </#list>
- </#list>
- default:
- throw new UnsupportedOperationException(buildErrorMessage("deNullify", type));
- }
- }
-
- public static ValueHolder nullify(ValueHolder holder) {
- MajorType type = TypeHelper.getValueHolderType(holder);
-
- switch(type.getMinorType()) {
- <#list vv.types as type>
- <#list type.minor as minor>
- case ${minor.class?upper_case} :
- switch (type.getMode()) {
- case REQUIRED:
- Nullable${minor.class}Holder newHolder = new Nullable${minor.class}Holder();
- newHolder.isSet = 1;
- <#assign fields = minor.fields!type.fields />
- <#list fields as field>
- newHolder.${field.name} = ((${minor.class}Holder) holder).${field.name};
- </#list>
- return newHolder;
- case OPTIONAL:
- return holder;
- case REPEATED:
- throw new UnsupportedOperationException("You can not convert repeated type " + type + " to nullable type!");
- }
- </#list>
- </#list>
- default:
- throw new UnsupportedOperationException(buildErrorMessage("nullify", type));
- }
- }
-
- public static MajorType getValueHolderType(ValueHolder holder) {
-
- if (0 == 1) {
- return null;
- }
- <#list vv.types as type>
- <#list type.minor as minor>
- else if (holder instanceof ${minor.class}Holder) {
- return ((${minor.class}Holder) holder).TYPE;
- } else if (holder instanceof Nullable${minor.class}Holder) {
- return ((Nullable${minor.class}Holder) holder).TYPE;
- }
- </#list>
- </#list>
-
- throw new UnsupportedOperationException("ValueHolder is not supported for 'getValueHolderType' method.");
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/drill/blob/4524fdbe/exec/vector/src/main/codegen/templates/UnionVector.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/templates/UnionVector.java b/exec/vector/src/main/codegen/templates/UnionVector.java
index dfcccb2..2ac4e96 100644
--- a/exec/vector/src/main/codegen/templates/UnionVector.java
+++ b/exec/vector/src/main/codegen/templates/UnionVector.java
@@ -151,7 +151,7 @@ public class UnionVector implements ValueVector {
}
@Override
- public void allocateNew() throws OutOfMemoryRuntimeException {
+ public void allocateNew() throws OutOfMemoryException {
internalMap.allocateNew();
if (typeVector != null) {
typeVector.zeroVector();
http://git-wip-us.apache.org/repos/asf/drill/blob/4524fdbe/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/codegen/templates/VariableLengthVectors.java b/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
index bba39fe..f734734 100644
--- a/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
+++ b/exec/vector/src/main/codegen/templates/VariableLengthVectors.java
@@ -18,7 +18,7 @@
import java.lang.Override;
-import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
+import org.apache.drill.exec.exception.OutOfMemoryException;
import org.apache.drill.exec.vector.BaseDataValueVector;
import org.apache.drill.exec.vector.BaseValueVector;
import org.apache.drill.exec.vector.VariableWidthVector;
@@ -284,7 +284,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
@Override
public void allocateNew() {
if(!allocateNewSafe()){
- throw new OutOfMemoryRuntimeException("Failure while allocating buffer.");
+ throw new OutOfMemoryException("Failure while allocating buffer.");
}
}
@@ -314,7 +314,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
data = allocator.buffer(requestedSize);
allocationSizeInBytes = requestedSize;
offsetVector.allocateNew();
- } catch (OutOfMemoryRuntimeException e) {
+ } catch (OutOfMemoryException e) {
clear();
return false;
}
http://git-wip-us.apache.org/repos/asf/drill/blob/4524fdbe/exec/vector/src/main/java/io/netty/buffer/DrillBuf.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/io/netty/buffer/DrillBuf.java b/exec/vector/src/main/java/io/netty/buffer/DrillBuf.java
index 5e437b2..38eb622 100644
--- a/exec/vector/src/main/java/io/netty/buffer/DrillBuf.java
+++ b/exec/vector/src/main/java/io/netty/buffer/DrillBuf.java
@@ -32,8 +32,6 @@ import java.util.concurrent.atomic.AtomicLong;
import org.apache.drill.exec.memory.Accountor;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.ops.BufferManager;
-import org.apache.drill.exec.ops.FragmentContext;
-import org.apache.drill.exec.ops.OperatorContext;
import org.apache.drill.exec.util.AssertionUtil;
import com.google.common.base.Preconditions;
@@ -58,8 +56,6 @@ public final class DrillBuf extends AbstractByteBuf implements AutoCloseable {
// to share code and to remove the hacky code here to use only
// one of these types at a time and use null checks to find out
// which.
- private OperatorContext context;
- private FragmentContext fContext;
private BufferManager bufManager;
public DrillBuf(BufferAllocator allocator, Accountor a, UnsafeDirectLittleEndian b) {
@@ -127,13 +123,6 @@ public final class DrillBuf extends AbstractByteBuf implements AutoCloseable {
this.allocator = allocator;
}
- public void setOperatorContext(OperatorContext c) {
- this.context = c;
- }
- public void setFragmentContext(FragmentContext c) {
- this.fContext = c;
- }
-
public void setBufferManager(BufferManager bufManager) {
this.bufManager = bufManager;
}
@@ -146,11 +135,8 @@ public final class DrillBuf extends AbstractByteBuf implements AutoCloseable {
if (this.capacity() >= size) {
return this;
}
- if (context != null) {
- return context.replace(this, size);
- } else if(fContext != null) {
- return fContext.replace(this, size);
- } else if (bufManager != null) {
+
+ if (bufManager != null) {
return bufManager.replace(this, size);
} else {
throw new UnsupportedOperationException("Realloc is only available in the context of an operator's UDFs");
http://git-wip-us.apache.org/repos/asf/drill/blob/4524fdbe/exec/vector/src/main/java/io/netty/buffer/FakeAllocator.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/io/netty/buffer/FakeAllocator.java b/exec/vector/src/main/java/io/netty/buffer/FakeAllocator.java
index 721aff9..53ca91c 100644
--- a/exec/vector/src/main/java/io/netty/buffer/FakeAllocator.java
+++ b/exec/vector/src/main/java/io/netty/buffer/FakeAllocator.java
@@ -17,11 +17,10 @@
*/
package io.netty.buffer;
+import org.apache.drill.exec.exception.OutOfMemoryException;
import org.apache.drill.exec.memory.Accountor;
import org.apache.drill.exec.memory.BufferAllocator;
-import org.apache.drill.exec.memory.OutOfMemoryException;
-import org.apache.drill.exec.ops.FragmentContext;
-import org.apache.drill.exec.proto.ExecProtos.FragmentHandle;
+import org.apache.drill.exec.memory.LimitConsumer;
import org.apache.drill.exec.util.Pointer;
class FakeAllocator implements BufferAllocator {
@@ -47,7 +46,7 @@ class FakeAllocator implements BufferAllocator {
}
@Override
- public BufferAllocator getChildAllocator(FragmentContext context, long initialReservation, long maximumReservation,
+ public BufferAllocator getChildAllocator(LimitConsumer consumer, long initialReservation, long maximumReservation,
boolean applyFragmentLimit)
throws OutOfMemoryException {
throw new UnsupportedOperationException();
@@ -69,17 +68,17 @@ class FakeAllocator implements BufferAllocator {
}
@Override
- public void resetFragmentLimits() {
+ public void resetLimits() {
throw new UnsupportedOperationException();
}
@Override
- public void setFragmentLimit(long l) {
+ public void setLimit(long l) {
throw new UnsupportedOperationException();
}
@Override
- public long getFragmentLimit(){
+ public long getLimit(){
throw new UnsupportedOperationException();
}
@@ -97,10 +96,9 @@ class FakeAllocator implements BufferAllocator {
return 0;
}
- static class FakeAccountor extends Accountor {
+ static class FakeAccountor implements Accountor {
public FakeAccountor() {
- super(null, false, null, null, 0, 0, true);
}
@Override
@@ -140,17 +138,42 @@ class FakeAllocator implements BufferAllocator {
@Override
public void releasePartial(DrillBuf buf, long size) {
-
+ throw new UnsupportedOperationException();
}
@Override
public void release(DrillBuf buf, long size) {
-
+ throw new UnsupportedOperationException();
}
@Override
public void close() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean transferIn(DrillBuf buf, long size) {
+ return false;
+ }
+
+ @Override
+ public long getPeakMemoryAllocation() {
+ return 0;
+ }
+
+ @Override
+ public long resetFragmentLimits() {
+ return 0;
+ }
+ @Override
+ public void setFragmentLimit(long add) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getFragmentLimit() {
+ return 0;
}
http://git-wip-us.apache.org/repos/asf/drill/blob/4524fdbe/exec/vector/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java b/exec/vector/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java
index 2ca79f0..5809df5 100644
--- a/exec/vector/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java
+++ b/exec/vector/src/main/java/io/netty/buffer/PooledByteBufAllocatorL.java
@@ -24,7 +24,6 @@ import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.drill.common.exceptions.DrillRuntimeException;
-import org.apache.drill.exec.metrics.DrillMetrics;
import org.apache.drill.exec.util.AssertionUtil;
import com.codahale.metrics.Gauge;
@@ -40,9 +39,7 @@ public class PooledByteBufAllocatorL extends PooledByteBufAllocator{
private static final int MEMORY_LOGGER_FREQUENCY_SECONDS = 60;
private static final String METRIC_PREFIX = "drill.allocator.";
- public static final PooledByteBufAllocatorL DEFAULT = new PooledByteBufAllocatorL();
-
- private final MetricRegistry registry = DrillMetrics.getInstance();
+ private final MetricRegistry registry;
private final AtomicLong hugeBufferSize = new AtomicLong(0);
private final AtomicLong hugeBufferCount = new AtomicLong(0);
private final AtomicLong normalBufferSize = new AtomicLong(0);
@@ -53,8 +50,9 @@ public class PooledByteBufAllocatorL extends PooledByteBufAllocator{
private final Histogram largeBuffersHist;
private final Histogram normalBuffersHist;
- private PooledByteBufAllocatorL() {
+ public PooledByteBufAllocatorL(MetricRegistry registry) {
super(true);
+ this.registry = registry;
try {
Field f = PooledByteBufAllocator.class.getDeclaredField("directArenas");
f.setAccessible(true);
@@ -110,6 +108,7 @@ public class PooledByteBufAllocatorL extends PooledByteBufAllocator{
public boolean matches(String name, Metric metric) {
return name.startsWith("drill.allocator.");
}
+
});
}
http://git-wip-us.apache.org/repos/asf/drill/blob/4524fdbe/exec/vector/src/main/java/org/apache/drill/exec/exception/OutOfMemoryException.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/exception/OutOfMemoryException.java b/exec/vector/src/main/java/org/apache/drill/exec/exception/OutOfMemoryException.java
new file mode 100644
index 0000000..17d099d
--- /dev/null
+++ b/exec/vector/src/main/java/org/apache/drill/exec/exception/OutOfMemoryException.java
@@ -0,0 +1,51 @@
+/**
+ * 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.exception;
+
+import org.apache.drill.common.exceptions.DrillRuntimeException;
+
+public class OutOfMemoryException extends DrillRuntimeException {
+ private static final long serialVersionUID = -6858052345185793382L;
+
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(OutOfMemoryException.class);
+
+ public OutOfMemoryException() {
+ super();
+ }
+
+ public OutOfMemoryException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+
+ public OutOfMemoryException(String message, Throwable cause) {
+ super(message, cause);
+
+ }
+
+ public OutOfMemoryException(String message) {
+ super(message);
+
+ }
+
+ public OutOfMemoryException(Throwable cause) {
+ super(cause);
+
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/drill/blob/4524fdbe/exec/vector/src/main/java/org/apache/drill/exec/exception/OversizedAllocationException.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/exception/OversizedAllocationException.java b/exec/vector/src/main/java/org/apache/drill/exec/exception/OversizedAllocationException.java
index f5ae70c..c192359 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/exception/OversizedAllocationException.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/exception/OversizedAllocationException.java
@@ -18,7 +18,6 @@
package org.apache.drill.exec.exception;
import org.apache.drill.common.exceptions.DrillRuntimeException;
-import org.apache.drill.exec.record.RecordBatch;
/**
* An exception that is used to signal that allocation request in bytes is greater than the maximum allowed by
http://git-wip-us.apache.org/repos/asf/drill/blob/4524fdbe/exec/vector/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java b/exec/vector/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java
new file mode 100644
index 0000000..006a084
--- /dev/null
+++ b/exec/vector/src/main/java/org/apache/drill/exec/expr/fn/impl/ByteFunctionHelpers.java
@@ -0,0 +1,236 @@
+/*******************************************************************************
+
+ * 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.expr.fn.impl;
+
+import io.netty.buffer.DrillBuf;
+import io.netty.util.internal.PlatformDependent;
+
+import org.apache.drill.exec.util.AssertionUtil;
+import org.apache.drill.exec.util.DecimalUtility;
+
+import com.google.common.primitives.UnsignedLongs;
+
+public class ByteFunctionHelpers {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ByteFunctionHelpers.class);
+
+ private static final boolean BOUNDS_CHECKING_ENABLED = AssertionUtil.BOUNDS_CHECKING_ENABLED;
+
+ /**
+ * Helper function to check for equality of bytes in two DrillBuffers
+ *
+ * @param left Left DrillBuf for comparison
+ * @param lStart start offset in the buffer
+ * @param lEnd end offset in the buffer
+ * @param right Right DrillBuf for comparison
+ * @param rStart start offset in the buffer
+ * @param rEnd end offset in the buffer
+ * @return 1 if left input is greater, -1 if left input is smaller, 0 otherwise
+ */
+ public static final int equal(final DrillBuf left, int lStart, int lEnd, final DrillBuf right, int rStart, int rEnd){
+ if(BOUNDS_CHECKING_ENABLED){
+ left.checkBytes(lStart, lEnd);
+ right.checkBytes(rStart, rEnd);
+ }
+ return memEqual(left.memoryAddress(), lStart, lEnd, right.memoryAddress(), rStart, rEnd);
+ }
+
+ private static final int memEqual(final long laddr, int lStart, int lEnd, final long raddr, int rStart,
+ final int rEnd) {
+
+ int n = lEnd - lStart;
+ if (n == rEnd - rStart) {
+ long lPos = laddr + lStart;
+ long rPos = raddr + rStart;
+
+ while (n > 7) {
+ long leftLong = PlatformDependent.getLong(lPos);
+ long rightLong = PlatformDependent.getLong(rPos);
+ if (leftLong != rightLong) {
+ return 0;
+ }
+ lPos += 8;
+ rPos += 8;
+ n -= 8;
+ }
+ while (n-- != 0) {
+ byte leftByte = PlatformDependent.getByte(lPos);
+ byte rightByte = PlatformDependent.getByte(rPos);
+ if (leftByte != rightByte) {
+ return 0;
+ }
+ lPos++;
+ rPos++;
+ }
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * Helper function to compare a set of bytes in two DrillBuffers.
+ *
+ * Function will check data before completing in the case that
+ *
+ * @param left Left DrillBuf to compare
+ * @param lStart start offset in the buffer
+ * @param lEnd end offset in the buffer
+ * @param right Right DrillBuf to compare
+ * @param rStart start offset in the buffer
+ * @param rEnd end offset in the buffer
+ * @return 1 if left input is greater, -1 if left input is smaller, 0 otherwise
+ */
+ public static final int compare(final DrillBuf left, int lStart, int lEnd, final DrillBuf right, int rStart, int rEnd){
+ if(BOUNDS_CHECKING_ENABLED){
+ left.checkBytes(lStart, lEnd);
+ right.checkBytes(rStart, rEnd);
+ }
+ return memcmp(left.memoryAddress(), lStart, lEnd, right.memoryAddress(), rStart, rEnd);
+ }
+
+ private static final int memcmp(final long laddr, int lStart, int lEnd, final long raddr, int rStart, final int rEnd) {
+ int lLen = lEnd - lStart;
+ int rLen = rEnd - rStart;
+ int n = Math.min(rLen, lLen);
+ long lPos = laddr + lStart;
+ long rPos = raddr + rStart;
+
+ while (n > 7) {
+ long leftLong = PlatformDependent.getLong(lPos);
+ long rightLong = PlatformDependent.getLong(rPos);
+ if (leftLong != rightLong) {
+ return UnsignedLongs.compare(Long.reverseBytes(leftLong), Long.reverseBytes(rightLong));
+ }
+ lPos += 8;
+ rPos += 8;
+ n -= 8;
+ }
+
+ while (n-- != 0) {
+ byte leftByte = PlatformDependent.getByte(lPos);
+ byte rightByte = PlatformDependent.getByte(rPos);
+ if (leftByte != rightByte) {
+ return ((leftByte & 0xFF) - (rightByte & 0xFF)) > 0 ? 1 : -1;
+ }
+ lPos++;
+ rPos++;
+ }
+
+ if (lLen == rLen) {
+ return 0;
+ }
+
+ return lLen > rLen ? 1 : -1;
+
+ }
+
+ /**
+ * Helper function to compare a set of bytes in DrillBuf to a ByteArray.
+ *
+ * @param left Left DrillBuf for comparison purposes
+ * @param lStart start offset in the buffer
+ * @param lEnd end offset in the buffer
+ * @param right second input to be compared
+ * @param rStart start offset in the byte array
+ * @param rEnd end offset in the byte array
+ * @return 1 if left input is greater, -1 if left input is smaller, 0 otherwise
+ */
+ public static final int compare(final DrillBuf left, int lStart, int lEnd, final byte[] right, int rStart, final int rEnd) {
+ if(BOUNDS_CHECKING_ENABLED){
+ left.checkBytes(lStart, lEnd);
+ }
+ return memcmp(left.memoryAddress(), lStart, lEnd, right, rStart, rEnd);
+ }
+
+
+ private static final int memcmp(final long laddr, int lStart, int lEnd, final byte[] right, int rStart, final int rEnd) {
+ int lLen = lEnd - lStart;
+ int rLen = rEnd - rStart;
+ int n = Math.min(rLen, lLen);
+ long lPos = laddr + lStart;
+ int rPos = rStart;
+
+ while (n-- != 0) {
+ byte leftByte = PlatformDependent.getByte(lPos);
+ byte rightByte = right[rPos];
+ if (leftByte != rightByte) {
+ return ((leftByte & 0xFF) - (rightByte & 0xFF)) > 0 ? 1 : -1;
+ }
+ lPos++;
+ rPos++;
+ }
+
+ if (lLen == rLen) {
+ return 0;
+ }
+
+ return lLen > rLen ? 1 : -1;
+ }
+
+ /*
+ * Following are helper functions to interact with sparse decimal represented in a byte array.
+ */
+
+ // Get the integer ignore the sign
+ public static int getInteger(byte[] b, int index) {
+ return getInteger(b, index, true);
+ }
+ // Get the integer, ignore the sign
+ public static int getInteger(byte[] b, int index, boolean ignoreSign) {
+ int startIndex = index * DecimalUtility.INTEGER_SIZE;
+
+ if (index == 0 && ignoreSign == true) {
+ return (b[startIndex + 3] & 0xFF) |
+ (b[startIndex + 2] & 0xFF) << 8 |
+ (b[startIndex + 1] & 0xFF) << 16 |
+ (b[startIndex] & 0x7F) << 24;
+ }
+
+ return ((b[startIndex + 3] & 0xFF) |
+ (b[startIndex + 2] & 0xFF) << 8 |
+ (b[startIndex + 1] & 0xFF) << 16 |
+ (b[startIndex] & 0xFF) << 24);
+
+ }
+
+ // Set integer in the byte array
+ public static void setInteger(byte[] b, int index, int value) {
+ int startIndex = index * DecimalUtility.INTEGER_SIZE;
+ b[startIndex] = (byte) ((value >> 24) & 0xFF);
+ b[startIndex + 1] = (byte) ((value >> 16) & 0xFF);
+ b[startIndex + 2] = (byte) ((value >> 8) & 0xFF);
+ b[startIndex + 3] = (byte) ((value) & 0xFF);
+ }
+
+ // Set the sign in a sparse decimal representation
+ public static void setSign(byte[] b, boolean sign) {
+ int value = getInteger(b, 0);
+ if (sign == true) {
+ setInteger(b, 0, value | 0x80000000);
+ } else {
+ setInteger(b, 0, value & 0x7FFFFFFF);
+ }
+ }
+
+ // Get the sign
+ public static boolean getSign(byte[] b) {
+ return ((getInteger(b, 0, false) & 0x80000000) != 0);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/drill/blob/4524fdbe/exec/vector/src/main/java/org/apache/drill/exec/expr/fn/impl/DateUtility.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/expr/fn/impl/DateUtility.java b/exec/vector/src/main/java/org/apache/drill/exec/expr/fn/impl/DateUtility.java
new file mode 100644
index 0000000..98a0b61
--- /dev/null
+++ b/exec/vector/src/main/java/org/apache/drill/exec/expr/fn/impl/DateUtility.java
@@ -0,0 +1,682 @@
+/**
+ * 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.expr.fn.impl;
+
+import org.joda.time.Period;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.DateTimeFormatterBuilder;
+import org.joda.time.format.DateTimeParser;
+
+import com.carrotsearch.hppc.ObjectIntOpenHashMap;
+
+// Utility class for Date, DateTime, TimeStamp, Interval data types
+public class DateUtility {
+
+
+ /* We have a hashmap that stores the timezone as the key and an index as the value
+ * While storing the timezone in value vectors, holders we only use this index. As we
+ * reconstruct the timestamp, we use this index to index through the array timezoneList
+ * and get the corresponding timezone and pass it to joda-time
+ */
+ public static ObjectIntOpenHashMap<String> timezoneMap = new ObjectIntOpenHashMap<String>();
+
+ public static String[] timezoneList = {"Africa/Abidjan",
+ "Africa/Accra",
+ "Africa/Addis_Ababa",
+ "Africa/Algiers",
+ "Africa/Asmara",
+ "Africa/Asmera",
+ "Africa/Bamako",
+ "Africa/Bangui",
+ "Africa/Banjul",
+ "Africa/Bissau",
+ "Africa/Blantyre",
+ "Africa/Brazzaville",
+ "Africa/Bujumbura",
+ "Africa/Cairo",
+ "Africa/Casablanca",
+ "Africa/Ceuta",
+ "Africa/Conakry",
+ "Africa/Dakar",
+ "Africa/Dar_es_Salaam",
+ "Africa/Djibouti",
+ "Africa/Douala",
+ "Africa/El_Aaiun",
+ "Africa/Freetown",
+ "Africa/Gaborone",
+ "Africa/Harare",
+ "Africa/Johannesburg",
+ "Africa/Juba",
+ "Africa/Kampala",
+ "Africa/Khartoum",
+ "Africa/Kigali",
+ "Africa/Kinshasa",
+ "Africa/Lagos",
+ "Africa/Libreville",
+ "Africa/Lome",
+ "Africa/Luanda",
+ "Africa/Lubumbashi",
+ "Africa/Lusaka",
+ "Africa/Malabo",
+ "Africa/Maputo",
+ "Africa/Maseru",
+ "Africa/Mbabane",
+ "Africa/Mogadishu",
+ "Africa/Monrovia",
+ "Africa/Nairobi",
+ "Africa/Ndjamena",
+ "Africa/Niamey",
+ "Africa/Nouakchott",
+ "Africa/Ouagadougou",
+ "Africa/Porto-Novo",
+ "Africa/Sao_Tome",
+ "Africa/Timbuktu",
+ "Africa/Tripoli",
+ "Africa/Tunis",
+ "Africa/Windhoek",
+ "America/Adak",
+ "America/Anchorage",
+ "America/Anguilla",
+ "America/Antigua",
+ "America/Araguaina",
+ "America/Argentina/Buenos_Aires",
+ "America/Argentina/Catamarca",
+ "America/Argentina/ComodRivadavia",
+ "America/Argentina/Cordoba",
+ "America/Argentina/Jujuy",
+ "America/Argentina/La_Rioja",
+ "America/Argentina/Mendoza",
+ "America/Argentina/Rio_Gallegos",
+ "America/Argentina/Salta",
+ "America/Argentina/San_Juan",
+ "America/Argentina/San_Luis",
+ "America/Argentina/Tucuman",
+ "America/Argentina/Ushuaia",
+ "America/Aruba",
+ "America/Asuncion",
+ "America/Atikokan",
+ "America/Atka",
+ "America/Bahia",
+ "America/Bahia_Banderas",
+ "America/Barbados",
+ "America/Belem",
+ "America/Belize",
+ "America/Blanc-Sablon",
+ "America/Boa_Vista",
+ "America/Bogota",
+ "America/Boise",
+ "America/Buenos_Aires",
+ "America/Cambridge_Bay",
+ "America/Campo_Grande",
+ "America/Cancun",
+ "America/Caracas",
+ "America/Catamarca",
+ "America/Cayenne",
+ "America/Cayman",
+ "America/Chicago",
+ "America/Chihuahua",
+ "America/Coral_Harbour",
+ "America/Cordoba",
+ "America/Costa_Rica",
+ "America/Cuiaba",
+ "America/Curacao",
+ "America/Danmarkshavn",
+ "America/Dawson",
+ "America/Dawson_Creek",
+ "America/Denver",
+ "America/Detroit",
+ "America/Dominica",
+ "America/Edmonton",
+ "America/Eirunepe",
+ "America/El_Salvador",
+ "America/Ensenada",
+ "America/Fort_Wayne",
+ "America/Fortaleza",
+ "America/Glace_Bay",
+ "America/Godthab",
+ "America/Goose_Bay",
+ "America/Grand_Turk",
+ "America/Grenada",
+ "America/Guadeloupe",
+ "America/Guatemala",
+ "America/Guayaquil",
+ "America/Guyana",
+ "America/Halifax",
+ "America/Havana",
+ "America/Hermosillo",
+ "America/Indiana/Indianapolis",
+ "America/Indiana/Knox",
+ "America/Indiana/Marengo",
+ "America/Indiana/Petersburg",
+ "America/Indiana/Tell_City",
+ "America/Indiana/Vevay",
+ "America/Indiana/Vincennes",
+ "America/Indiana/Winamac",
+ "America/Indianapolis",
+ "America/Inuvik",
+ "America/Iqaluit",
+ "America/Jamaica",
+ "America/Jujuy",
+ "America/Juneau",
+ "America/Kentucky/Louisville",
+ "America/Kentucky/Monticello",
+ "America/Knox_IN",
+ "America/Kralendijk",
+ "America/La_Paz",
+ "America/Lima",
+ "America/Los_Angeles",
+ "America/Louisville",
+ "America/Lower_Princes",
+ "America/Maceio",
+ "America/Managua",
+ "America/Manaus",
+ "America/Marigot",
+ "America/Martinique",
+ "America/Matamoros",
+ "America/Mazatlan",
+ "America/Mendoza",
+ "America/Menominee",
+ "America/Merida",
+ "America/Metlakatla",
+ "America/Mexico_City",
+ "America/Miquelon",
+ "America/Moncton",
+ "America/Monterrey",
+ "America/Montevideo",
+ "America/Montreal",
+ "America/Montserrat",
+ "America/Nassau",
+ "America/New_York",
+ "America/Nipigon",
+ "America/Nome",
+ "America/Noronha",
+ "America/North_Dakota/Beulah",
+ "America/North_Dakota/Center",
+ "America/North_Dakota/New_Salem",
+ "America/Ojinaga",
+ "America/Panama",
+ "America/Pangnirtung",
+ "America/Paramaribo",
+ "America/Phoenix",
+ "America/Port-au-Prince",
+ "America/Port_of_Spain",
+ "America/Porto_Acre",
+ "America/Porto_Velho",
+ "America/Puerto_Rico",
+ "America/Rainy_River",
+ "America/Rankin_Inlet",
+ "America/Recife",
+ "America/Regina",
+ "America/Resolute",
+ "America/Rio_Branco",
+ "America/Rosario",
+ "America/Santa_Isabel",
+ "America/Santarem",
+ "America/Santiago",
+ "America/Santo_Domingo",
+ "America/Sao_Paulo",
+ "America/Scoresbysund",
+ "America/Shiprock",
+ "America/Sitka",
+ "America/St_Barthelemy",
+ "America/St_Johns",
+ "America/St_Kitts",
+ "America/St_Lucia",
+ "America/St_Thomas",
+ "America/St_Vincent",
+ "America/Swift_Current",
+ "America/Tegucigalpa",
+ "America/Thule",
+ "America/Thunder_Bay",
+ "America/Tijuana",
+ "America/Toronto",
+ "America/Tortola",
+ "America/Vancouver",
+ "America/Virgin",
+ "America/Whitehorse",
+ "America/Winnipeg",
+ "America/Yakutat",
+ "America/Yellowknife",
+ "Antarctica/Casey",
+ "Antarctica/Davis",
+ "Antarctica/DumontDUrville",
+ "Antarctica/Macquarie",
+ "Antarctica/Mawson",
+ "Antarctica/McMurdo",
+ "Antarctica/Palmer",
+ "Antarctica/Rothera",
+ "Antarctica/South_Pole",
+ "Antarctica/Syowa",
+ "Antarctica/Vostok",
+ "Arctic/Longyearbyen",
+ "Asia/Aden",
+ "Asia/Almaty",
+ "Asia/Amman",
+ "Asia/Anadyr",
+ "Asia/Aqtau",
+ "Asia/Aqtobe",
+ "Asia/Ashgabat",
+ "Asia/Ashkhabad",
+ "Asia/Baghdad",
+ "Asia/Bahrain",
+ "Asia/Baku",
+ "Asia/Bangkok",
+ "Asia/Beirut",
+ "Asia/Bishkek",
+ "Asia/Brunei",
+ "Asia/Calcutta",
+ "Asia/Choibalsan",
+ "Asia/Chongqing",
+ "Asia/Chungking",
+ "Asia/Colombo",
+ "Asia/Dacca",
+ "Asia/Damascus",
+ "Asia/Dhaka",
+ "Asia/Dili",
+ "Asia/Dubai",
+ "Asia/Dushanbe",
+ "Asia/Gaza",
+ "Asia/Harbin",
+ "Asia/Hebron",
+ "Asia/Ho_Chi_Minh",
+ "Asia/Hong_Kong",
+ "Asia/Hovd",
+ "Asia/Irkutsk",
+ "Asia/Istanbul",
+ "Asia/Jakarta",
+ "Asia/Jayapura",
+ "Asia/Jerusalem",
+ "Asia/Kabul",
+ "Asia/Kamchatka",
+ "Asia/Karachi",
+ "Asia/Kashgar",
+ "Asia/Kathmandu",
+ "Asia/Katmandu",
+ "Asia/Kolkata",
+ "Asia/Krasnoyarsk",
+ "Asia/Kuala_Lumpur",
+ "Asia/Kuching",
+ "Asia/Kuwait",
+ "Asia/Macao",
+ "Asia/Macau",
+ "Asia/Magadan",
+ "Asia/Makassar",
+ "Asia/Manila",
+ "Asia/Muscat",
+ "Asia/Nicosia",
+ "Asia/Novokuznetsk",
+ "Asia/Novosibirsk",
+ "Asia/Omsk",
+ "Asia/Oral",
+ "Asia/Phnom_Penh",
+ "Asia/Pontianak",
+ "Asia/Pyongyang",
+ "Asia/Qatar",
+ "Asia/Qyzylorda",
+ "Asia/Rangoon",
+ "Asia/Riyadh",
+ "Asia/Saigon",
+ "Asia/Sakhalin",
+ "Asia/Samarkand",
+ "Asia/Seoul",
+ "Asia/Shanghai",
+ "Asia/Singapore",
+ "Asia/Taipei",
+ "Asia/Tashkent",
+ "Asia/Tbilisi",
+ "Asia/Tehran",
+ "Asia/Tel_Aviv",
+ "Asia/Thimbu",
+ "Asia/Thimphu",
+ "Asia/Tokyo",
+ "Asia/Ujung_Pandang",
+ "Asia/Ulaanbaatar",
+ "Asia/Ulan_Bator",
+ "Asia/Urumqi",
+ "Asia/Vientiane",
+ "Asia/Vladivostok",
+ "Asia/Yakutsk",
+ "Asia/Yekaterinburg",
+ "Asia/Yerevan",
+ "Atlantic/Azores",
+ "Atlantic/Bermuda",
+ "Atlantic/Canary",
+ "Atlantic/Cape_Verde",
+ "Atlantic/Faeroe",
+ "Atlantic/Faroe",
+ "Atlantic/Jan_Mayen",
+ "Atlantic/Madeira",
+ "Atlantic/Reykjavik",
+ "Atlantic/South_Georgia",
+ "Atlantic/St_Helena",
+ "Atlantic/Stanley",
+ "Australia/ACT",
+ "Australia/Adelaide",
+ "Australia/Brisbane",
+ "Australia/Broken_Hill",
+ "Australia/Canberra",
+ "Australia/Currie",
+ "Australia/Darwin",
+ "Australia/Eucla",
+ "Australia/Hobart",
+ "Australia/LHI",
+ "Australia/Lindeman",
+ "Australia/Lord_Howe",
+ "Australia/Melbourne",
+ "Australia/NSW",
+ "Australia/North",
+ "Australia/Perth",
+ "Australia/Queensland",
+ "Australia/South",
+ "Australia/Sydney",
+ "Australia/Tasmania",
+ "Australia/Victoria",
+ "Australia/West",
+ "Australia/Yancowinna",
+ "Brazil/Acre",
+ "Brazil/DeNoronha",
+ "Brazil/East",
+ "Brazil/West",
+ "CET",
+ "CST6CDT",
+ "Canada/Atlantic",
+ "Canada/Central",
+ "Canada/East-Saskatchewan",
+ "Canada/Eastern",
+ "Canada/Mountain",
+ "Canada/Newfoundland",
+ "Canada/Pacific",
+ "Canada/Saskatchewan",
+ "Canada/Yukon",
+ "Chile/Continental",
+ "Chile/EasterIsland",
+ "Cuba",
+ "EET",
+ "EST",
+ "EST5EDT",
+ "Egypt",
+ "Eire",
+ "Etc/GMT",
+ "Etc/GMT+0",
+ "Etc/GMT+1",
+ "Etc/GMT+10",
+ "Etc/GMT+11",
+ "Etc/GMT+12",
+ "Etc/GMT+2",
+ "Etc/GMT+3",
+ "Etc/GMT+4",
+ "Etc/GMT+5",
+ "Etc/GMT+6",
+ "Etc/GMT+7",
+ "Etc/GMT+8",
+ "Etc/GMT+9",
+ "Etc/GMT-0",
+ "Etc/GMT-1",
+ "Etc/GMT-10",
+ "Etc/GMT-11",
+ "Etc/GMT-12",
+ "Etc/GMT-13",
+ "Etc/GMT-14",
+ "Etc/GMT-2",
+ "Etc/GMT-3",
+ "Etc/GMT-4",
+ "Etc/GMT-5",
+ "Etc/GMT-6",
+ "Etc/GMT-7",
+ "Etc/GMT-8",
+ "Etc/GMT-9",
+ "Etc/GMT0",
+ "Etc/Greenwich",
+ "Etc/UCT",
+ "Etc/UTC",
+ "Etc/Universal",
+ "Etc/Zulu",
+ "Europe/Amsterdam",
+ "Europe/Andorra",
+ "Europe/Athens",
+ "Europe/Belfast",
+ "Europe/Belgrade",
+ "Europe/Berlin",
+ "Europe/Bratislava",
+ "Europe/Brussels",
+ "Europe/Bucharest",
+ "Europe/Budapest",
+ "Europe/Chisinau",
+ "Europe/Copenhagen",
+ "Europe/Dublin",
+ "Europe/Gibraltar",
+ "Europe/Guernsey",
+ "Europe/Helsinki",
+ "Europe/Isle_of_Man",
+ "Europe/Istanbul",
+ "Europe/Jersey",
+ "Europe/Kaliningrad",
+ "Europe/Kiev",
+ "Europe/Lisbon",
+ "Europe/Ljubljana",
+ "Europe/London",
+ "Europe/Luxembourg",
+ "Europe/Madrid",
+ "Europe/Malta",
+ "Europe/Mariehamn",
+ "Europe/Minsk",
+ "Europe/Monaco",
+ "Europe/Moscow",
+ "Europe/Nicosia",
+ "Europe/Oslo",
+ "Europe/Paris",
+ "Europe/Podgorica",
+ "Europe/Prague",
+ "Europe/Riga",
+ "Europe/Rome",
+ "Europe/Samara",
+ "Europe/San_Marino",
+ "Europe/Sarajevo",
+ "Europe/Simferopol",
+ "Europe/Skopje",
+ "Europe/Sofia",
+ "Europe/Stockholm",
+ "Europe/Tallinn",
+ "Europe/Tirane",
+ "Europe/Tiraspol",
+ "Europe/Uzhgorod",
+ "Europe/Vaduz",
+ "Europe/Vatican",
+ "Europe/Vienna",
+ "Europe/Vilnius",
+ "Europe/Volgograd",
+ "Europe/Warsaw",
+ "Europe/Zagreb",
+ "Europe/Zaporozhye",
+ "Europe/Zurich",
+ "GB",
+ "GB-Eire",
+ "GMT",
+ "GMT+0",
+ "GMT-0",
+ "GMT0",
+ "Greenwich",
+ "HST",
+ "Hongkong",
+ "Iceland",
+ "Indian/Antananarivo",
+ "Indian/Chagos",
+ "Indian/Christmas",
+ "Indian/Cocos",
+ "Indian/Comoro",
+ "Indian/Kerguelen",
+ "Indian/Mahe",
+ "Indian/Maldives",
+ "Indian/Mauritius",
+ "Indian/Mayotte",
+ "Indian/Reunion",
+ "Iran",
+ "Israel",
+ "Jamaica",
+ "Japan",
+ "Kwajalein",
+ "Libya",
+ "MET",
+ "MST",
+ "MST7MDT",
+ "Mexico/BajaNorte",
+ "Mexico/BajaSur",
+ "Mexico/General",
+ "NZ",
+ "NZ-CHAT",
+ "Navajo",
+ "PRC",
+ "PST8PDT",
+ "Pacific/Apia",
+ "Pacific/Auckland",
+ "Pacific/Chatham",
+ "Pacific/Chuuk",
+ "Pacific/Easter",
+ "Pacific/Efate",
+ "Pacific/Enderbury",
+ "Pacific/Fakaofo",
+ "Pacific/Fiji",
+ "Pacific/Funafuti",
+ "Pacific/Galapagos",
+ "Pacific/Gambier",
+ "Pacific/Guadalcanal",
+ "Pacific/Guam",
+ "Pacific/Honolulu",
+ "Pacific/Johnston",
+ "Pacific/Kiritimati",
+ "Pacific/Kosrae",
+ "Pacific/Kwajalein",
+ "Pacific/Majuro",
+ "Pacific/Marquesas",
+ "Pacific/Midway",
+ "Pacific/Nauru",
+ "Pacific/Niue",
+ "Pacific/Norfolk",
+ "Pacific/Noumea",
+ "Pacific/Pago_Pago",
+ "Pacific/Palau",
+ "Pacific/Pitcairn",
+ "Pacific/Pohnpei",
+ "Pacific/Ponape",
+ "Pacific/Port_Moresby",
+ "Pacific/Rarotonga",
+ "Pacific/Saipan",
+ "Pacific/Samoa",
+ "Pacific/Tahiti",
+ "Pacific/Tarawa",
+ "Pacific/Tongatapu",
+ "Pacific/Truk",
+ "Pacific/Wake",
+ "Pacific/Wallis",
+ "Pacific/Yap",
+ "Poland",
+ "Portugal",
+ "ROC",
+ "ROK",
+ "Singapore",
+ "Turkey",
+ "UCT",
+ "US/Alaska",
+ "US/Aleutian",
+ "US/Arizona",
+ "US/Central",
+ "US/East-Indiana",
+ "US/Eastern",
+ "US/Hawaii",
+ "US/Indiana-Starke",
+ "US/Michigan",
+ "US/Mountain",
+ "US/Pacific",
+ "US/Pacific-New",
+ "US/Samoa",
+ "UTC",
+ "Universal",
+ "W-SU",
+ "WET",
+ "Zulu"};
+
+ static {
+ for (int i = 0; i < timezoneList.length; i++) {
+ timezoneMap.put(timezoneList[i], i);
+ }
+ }
+
+ public static final DateTimeFormatter formatDate = DateTimeFormat.forPattern("yyyy-MM-dd");
+ public static final DateTimeFormatter formatTimeStamp = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS");
+ public static final DateTimeFormatter formatTimeStampTZ = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS ZZZ");
+ public static final DateTimeFormatter formatTime = DateTimeFormat.forPattern("HH:mm:ss.SSS");
+
+ public static DateTimeFormatter dateTimeTZFormat = null;
+ public static DateTimeFormatter timeFormat = null;
+
+ public static final int yearsToMonths = 12;
+ public static final int hoursToMillis = 60 * 60 * 1000;
+ public static final int minutesToMillis = 60 * 1000;
+ public static final int secondsToMillis = 1000;
+ public static final int monthToStandardDays = 30;
+ public static final long monthsToMillis = 2592000000L; // 30 * 24 * 60 * 60 * 1000
+ public static final int daysToStandardMillis = 24 * 60 * 60 * 1000;
+
+
+ public static int getIndex(String timezone) {
+ return timezoneMap.get(timezone);
+ }
+
+ public static String getTimeZone(int index) {
+ return timezoneList[index];
+ }
+
+ // Function returns the date time formatter used to parse date strings
+ public static DateTimeFormatter getDateTimeFormatter() {
+
+ if (dateTimeTZFormat == null) {
+ DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
+ DateTimeParser optionalTime = DateTimeFormat.forPattern(" HH:mm:ss").getParser();
+ DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser();
+ DateTimeParser optionalZone = DateTimeFormat.forPattern(" ZZZ").getParser();
+
+ dateTimeTZFormat = new DateTimeFormatterBuilder().append(dateFormatter).appendOptional(optionalTime).appendOptional(optionalSec).appendOptional(optionalZone).toFormatter();
+ }
+
+ return dateTimeTZFormat;
+ }
+
+ // Function returns time formatter used to parse time strings
+ public static DateTimeFormatter getTimeFormatter() {
+ if (timeFormat == null) {
+ DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("HH:mm:ss");
+ DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser();
+ timeFormat = new DateTimeFormatterBuilder().append(timeFormatter).appendOptional(optionalSec).toFormatter();
+ }
+ return timeFormat;
+ }
+
+ public static int monthsFromPeriod(Period period){
+ return (period.getYears() * yearsToMonths) + period.getMonths();
+ }
+
+ public static int millisFromPeriod(final Period period){
+ return (period.getHours() * hoursToMillis) +
+ (period.getMinutes() * minutesToMillis) +
+ (period.getSeconds() * secondsToMillis) +
+ (period.getMillis());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/drill/blob/4524fdbe/exec/vector/src/main/java/org/apache/drill/exec/memory/Accountor.java
----------------------------------------------------------------------
diff --git a/exec/vector/src/main/java/org/apache/drill/exec/memory/Accountor.java b/exec/vector/src/main/java/org/apache/drill/exec/memory/Accountor.java
new file mode 100644
index 0000000..7014a0b
--- /dev/null
+++ b/exec/vector/src/main/java/org/apache/drill/exec/memory/Accountor.java
@@ -0,0 +1,43 @@
+/**
+ * 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 io.netty.buffer.DrillBuf;
+
+public interface Accountor extends AutoCloseable{
+
+ public boolean transferTo(Accountor target, DrillBuf buf, long size);
+ public boolean transferIn(DrillBuf buf, long size);
+ public long getAvailable();
+ public long getCapacity();
+ public long getAllocation();
+ public long getPeakMemoryAllocation();
+
+ public boolean reserve(long size);
+ public boolean forceAdditionalReservation(long size);
+
+ public void reserved(long expected, DrillBuf buf);
+
+ public void release(DrillBuf buf, long size);
+ public void releasePartial(DrillBuf buf, long size);
+ public long resetFragmentLimits();
+ public void close();
+
+ public void setFragmentLimit(long add);
+ public long getFragmentLimit();
+}