You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ja...@apache.org on 2016/02/17 13:39:43 UTC
[08/17] arrow git commit: ARROW-1: Initial Arrow Code Commit
http://git-wip-us.apache.org/repos/asf/arrow/blob/fa5f0299/java/vector/src/main/codegen/templates/AbstractFieldWriter.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/AbstractFieldWriter.java b/java/vector/src/main/codegen/templates/AbstractFieldWriter.java
new file mode 100644
index 0000000..6ee9dad
--- /dev/null
+++ b/java/vector/src/main/codegen/templates/AbstractFieldWriter.java
@@ -0,0 +1,147 @@
+/**
+ * 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.
+ */
+
+<@pp.dropOutputFile />
+<@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/AbstractFieldWriter.java" />
+
+
+<#include "/@includes/license.ftl" />
+
+package org.apache.arrow.vector.complex.impl;
+
+<#include "/@includes/vv_imports.ftl" />
+
+/*
+ * This class is generated using freemarker and the ${.template_name} template.
+ */
+@SuppressWarnings("unused")
+abstract class AbstractFieldWriter extends AbstractBaseWriter implements FieldWriter {
+ AbstractFieldWriter(FieldWriter parent) {
+ super(parent);
+ }
+
+ @Override
+ public void start() {
+ throw new IllegalStateException(String.format("You tried to start when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
+ }
+
+ @Override
+ public void end() {
+ throw new IllegalStateException(String.format("You tried to end when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
+ }
+
+ @Override
+ public void startList() {
+ throw new IllegalStateException(String.format("You tried to start when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
+ }
+
+ @Override
+ public void endList() {
+ throw new IllegalStateException(String.format("You tried to end when you are using a ValueWriter of type %s.", this.getClass().getSimpleName()));
+ }
+
+ <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
+ <#assign fields = minor.fields!type.fields />
+ @Override
+ public void write(${name}Holder holder) {
+ fail("${name}");
+ }
+
+ public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) {
+ fail("${name}");
+ }
+
+ </#list></#list>
+
+ public void writeNull() {
+ fail("${name}");
+ }
+
+ /**
+ * This implementation returns {@code false}.
+ * <p>
+ * Must be overridden by map writers.
+ * </p>
+ */
+ @Override
+ public boolean isEmptyMap() {
+ return false;
+ }
+
+ @Override
+ public MapWriter map() {
+ fail("Map");
+ return null;
+ }
+
+ @Override
+ public ListWriter list() {
+ fail("List");
+ return null;
+ }
+
+ @Override
+ public MapWriter map(String name) {
+ fail("Map");
+ return null;
+ }
+
+ @Override
+ public ListWriter list(String name) {
+ fail("List");
+ return null;
+ }
+
+ <#list vv.types as type><#list type.minor as minor>
+ <#assign lowerName = minor.class?uncap_first />
+ <#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
+ <#assign upperName = minor.class?upper_case />
+ <#assign capName = minor.class?cap_first />
+ <#if minor.class?starts_with("Decimal") >
+ public ${capName}Writer ${lowerName}(String name, int scale, int precision) {
+ fail("${capName}");
+ return null;
+ }
+ </#if>
+
+ @Override
+ public ${capName}Writer ${lowerName}(String name) {
+ fail("${capName}");
+ return null;
+ }
+
+ @Override
+ public ${capName}Writer ${lowerName}() {
+ fail("${capName}");
+ return null;
+ }
+
+ </#list></#list>
+
+ public void copyReader(FieldReader reader) {
+ fail("Copy FieldReader");
+ }
+
+ public void copyReaderToField(String name, FieldReader reader) {
+ fail("Copy FieldReader to STring");
+ }
+
+ private void fail(String name) {
+ throw new IllegalArgumentException(String.format("You tried to write a %s type when you are using a ValueWriter of type %s.", name, this.getClass().getSimpleName()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/arrow/blob/fa5f0299/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java b/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java
new file mode 100644
index 0000000..549dbf1
--- /dev/null
+++ b/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java
@@ -0,0 +1,142 @@
+/**
+ * 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.common.types.TypeProtos.MinorType;
+
+<@pp.dropOutputFile />
+<@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/AbstractPromotableFieldWriter.java" />
+
+
+<#include "/@includes/license.ftl" />
+
+package org.apache.arrow.vector.complex.impl;
+
+<#include "/@includes/vv_imports.ftl" />
+
+/*
+ * A FieldWriter which delegates calls to another FieldWriter. The delegate FieldWriter can be promoted to a new type
+ * when necessary. Classes that extend this class are responsible for handling promotion.
+ *
+ * This class is generated using freemarker and the ${.template_name} template.
+ *
+ */
+@SuppressWarnings("unused")
+abstract class AbstractPromotableFieldWriter extends AbstractFieldWriter {
+ AbstractPromotableFieldWriter(FieldWriter parent) {
+ super(parent);
+ }
+
+ /**
+ * Retrieve the FieldWriter, promoting if it is not a FieldWriter of the specified type
+ * @param type
+ * @return
+ */
+ abstract protected FieldWriter getWriter(MinorType type);
+
+ /**
+ * Return the current FieldWriter
+ * @return
+ */
+ abstract protected FieldWriter getWriter();
+
+ @Override
+ public void start() {
+ getWriter(MinorType.MAP).start();
+ }
+
+ @Override
+ public void end() {
+ getWriter(MinorType.MAP).end();
+ }
+
+ @Override
+ public void startList() {
+ getWriter(MinorType.LIST).startList();
+ }
+
+ @Override
+ public void endList() {
+ getWriter(MinorType.LIST).endList();
+ }
+
+ <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
+ <#assign fields = minor.fields!type.fields />
+ <#if !minor.class?starts_with("Decimal") >
+ @Override
+ public void write(${name}Holder holder) {
+ getWriter(MinorType.${name?upper_case}).write(holder);
+ }
+
+ public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) {
+ getWriter(MinorType.${name?upper_case}).write${minor.class}(<#list fields as field>${field.name}<#if field_has_next>, </#if></#list>);
+ }
+
+ </#if>
+ </#list></#list>
+
+ public void writeNull() {
+ }
+
+ @Override
+ public MapWriter map() {
+ return getWriter(MinorType.LIST).map();
+ }
+
+ @Override
+ public ListWriter list() {
+ return getWriter(MinorType.LIST).list();
+ }
+
+ @Override
+ public MapWriter map(String name) {
+ return getWriter(MinorType.MAP).map(name);
+ }
+
+ @Override
+ public ListWriter list(String name) {
+ return getWriter(MinorType.MAP).list(name);
+ }
+
+ <#list vv.types as type><#list type.minor as minor>
+ <#assign lowerName = minor.class?uncap_first />
+ <#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
+ <#assign upperName = minor.class?upper_case />
+ <#assign capName = minor.class?cap_first />
+ <#if !minor.class?starts_with("Decimal") >
+
+ @Override
+ public ${capName}Writer ${lowerName}(String name) {
+ return getWriter(MinorType.MAP).${lowerName}(name);
+ }
+
+ @Override
+ public ${capName}Writer ${lowerName}() {
+ return getWriter(MinorType.LIST).${lowerName}();
+ }
+
+ </#if>
+ </#list></#list>
+
+ public void copyReader(FieldReader reader) {
+ getWriter().copyReader(reader);
+ }
+
+ public void copyReaderToField(String name, FieldReader reader) {
+ getWriter().copyReaderToField(name, reader);
+ }
+}
http://git-wip-us.apache.org/repos/asf/arrow/blob/fa5f0299/java/vector/src/main/codegen/templates/BaseReader.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/BaseReader.java b/java/vector/src/main/codegen/templates/BaseReader.java
new file mode 100644
index 0000000..8f12b1d
--- /dev/null
+++ b/java/vector/src/main/codegen/templates/BaseReader.java
@@ -0,0 +1,73 @@
+/**
+ * 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.
+ */
+
+<@pp.dropOutputFile />
+<@pp.changeOutputFile name="/org/apache/arrow/vector/complex/reader/BaseReader.java" />
+
+
+<#include "/@includes/license.ftl" />
+
+package org.apache.arrow.vector.complex.reader;
+
+<#include "/@includes/vv_imports.ftl" />
+
+
+
+@SuppressWarnings("unused")
+public interface BaseReader extends Positionable{
+ MajorType getType();
+ MaterializedField getField();
+ void reset();
+ void read(UnionHolder holder);
+ void read(int index, UnionHolder holder);
+ void copyAsValue(UnionWriter writer);
+ boolean isSet();
+
+ public interface MapReader extends BaseReader, Iterable<String>{
+ FieldReader reader(String name);
+ }
+
+ public interface RepeatedMapReader extends MapReader{
+ boolean next();
+ int size();
+ void copyAsValue(MapWriter writer);
+ }
+
+ public interface ListReader extends BaseReader{
+ FieldReader reader();
+ }
+
+ public interface RepeatedListReader extends ListReader{
+ boolean next();
+ int size();
+ void copyAsValue(ListWriter writer);
+ }
+
+ public interface ScalarReader extends
+ <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first /> ${name}Reader, </#list></#list>
+ <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first /> Repeated${name}Reader, </#list></#list>
+ BaseReader {}
+
+ interface ComplexReader{
+ MapReader rootAsMap();
+ ListReader rootAsList();
+ boolean rootIsMap();
+ boolean ok();
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/arrow/blob/fa5f0299/java/vector/src/main/codegen/templates/BaseWriter.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/BaseWriter.java b/java/vector/src/main/codegen/templates/BaseWriter.java
new file mode 100644
index 0000000..299b238
--- /dev/null
+++ b/java/vector/src/main/codegen/templates/BaseWriter.java
@@ -0,0 +1,117 @@
+/**
+ * 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.
+ */
+
+<@pp.dropOutputFile />
+<@pp.changeOutputFile name="/org/apache/arrow/vector/complex/writer/BaseWriter.java" />
+
+
+<#include "/@includes/license.ftl" />
+
+package org.apache.arrow.vector.complex.writer;
+
+<#include "/@includes/vv_imports.ftl" />
+
+/*
+ * File generated from ${.template_name} using FreeMarker.
+ */
+@SuppressWarnings("unused")
+ public interface BaseWriter extends AutoCloseable, Positionable {
+ FieldWriter getParent();
+ int getValueCapacity();
+
+ public interface MapWriter extends BaseWriter {
+
+ MaterializedField getField();
+
+ /**
+ * Whether this writer is a map writer and is empty (has no children).
+ *
+ * <p>
+ * Intended only for use in determining whether to add dummy vector to
+ * avoid empty (zero-column) schema, as in JsonReader.
+ * </p>
+ *
+ */
+ boolean isEmptyMap();
+
+ <#list vv.types as type><#list type.minor as minor>
+ <#assign lowerName = minor.class?uncap_first />
+ <#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
+ <#assign upperName = minor.class?upper_case />
+ <#assign capName = minor.class?cap_first />
+ <#if minor.class?starts_with("Decimal") >
+ ${capName}Writer ${lowerName}(String name, int scale, int precision);
+ </#if>
+ ${capName}Writer ${lowerName}(String name);
+ </#list></#list>
+
+ void copyReaderToField(String name, FieldReader reader);
+ MapWriter map(String name);
+ ListWriter list(String name);
+ void start();
+ void end();
+ }
+
+ public interface ListWriter extends BaseWriter {
+ void startList();
+ void endList();
+ MapWriter map();
+ ListWriter list();
+ void copyReader(FieldReader reader);
+
+ <#list vv.types as type><#list type.minor as minor>
+ <#assign lowerName = minor.class?uncap_first />
+ <#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
+ <#assign upperName = minor.class?upper_case />
+ <#assign capName = minor.class?cap_first />
+ ${capName}Writer ${lowerName}();
+ </#list></#list>
+ }
+
+ public interface ScalarWriter extends
+ <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first /> ${name}Writer, </#list></#list> BaseWriter {}
+
+ public interface ComplexWriter {
+ void allocate();
+ void clear();
+ void copyReader(FieldReader reader);
+ MapWriter rootAsMap();
+ ListWriter rootAsList();
+
+ void setPosition(int index);
+ void setValueCount(int count);
+ void reset();
+ }
+
+ public interface MapOrListWriter {
+ void start();
+ void end();
+ MapOrListWriter map(String name);
+ MapOrListWriter listoftmap(String name);
+ MapOrListWriter list(String name);
+ boolean isMapWriter();
+ boolean isListWriter();
+ VarCharWriter varChar(String name);
+ IntWriter integer(String name);
+ BigIntWriter bigInt(String name);
+ Float4Writer float4(String name);
+ Float8Writer float8(String name);
+ BitWriter bit(String name);
+ VarBinaryWriter binary(String name);
+ }
+}
http://git-wip-us.apache.org/repos/asf/arrow/blob/fa5f0299/java/vector/src/main/codegen/templates/BasicTypeHelper.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/BasicTypeHelper.java b/java/vector/src/main/codegen/templates/BasicTypeHelper.java
new file mode 100644
index 0000000..bb6446e
--- /dev/null
+++ b/java/vector/src/main/codegen/templates/BasicTypeHelper.java
@@ -0,0 +1,538 @@
+/**
+ * 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.
+ */
+
+<@pp.dropOutputFile />
+<@pp.changeOutputFile name="/org/apache/arrow/vector/util/BasicTypeHelper.java" />
+
+<#include "/@includes/license.ftl" />
+
+package org.apache.arrow.vector.util;
+
+<#include "/@includes/vv_imports.ftl" />
+import org.apache.arrow.vector.complex.UnionVector;
+import org.apache.arrow.vector.complex.RepeatedMapVector;
+import org.apache.arrow.vector.util.CallBack;
+
+public class BasicTypeHelper {
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BasicTypeHelper.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;
+
+ protected 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);
+ }
+
+ protected 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 ValueVector getNewVector(String name, BufferAllocator allocator, MajorType type, CallBack callback){
+ MaterializedField field = MaterializedField.create(name, 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 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 = 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 = 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 = 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/arrow/blob/fa5f0299/java/vector/src/main/codegen/templates/ComplexCopier.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/ComplexCopier.java b/java/vector/src/main/codegen/templates/ComplexCopier.java
new file mode 100644
index 0000000..3614231
--- /dev/null
+++ b/java/vector/src/main/codegen/templates/ComplexCopier.java
@@ -0,0 +1,133 @@
+/**
+ * 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.
+ */
+
+<@pp.dropOutputFile />
+<@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/ComplexCopier.java" />
+
+
+<#include "/@includes/license.ftl" />
+
+package org.apache.arrow.vector.complex.impl;
+
+<#include "/@includes/vv_imports.ftl" />
+
+/*
+ * This class is generated using freemarker and the ${.template_name} template.
+ */
+@SuppressWarnings("unused")
+public class ComplexCopier {
+
+ /**
+ * Do a deep copy of the value in input into output
+ * @param in
+ * @param out
+ */
+ public static void copy(FieldReader input, FieldWriter output) {
+ writeValue(input, output);
+ }
+
+ private static void writeValue(FieldReader reader, FieldWriter writer) {
+ final DataMode m = reader.getType().getMode();
+ final MinorType mt = reader.getType().getMinorType();
+
+ switch(m){
+ case OPTIONAL:
+ case REQUIRED:
+
+
+ switch (mt) {
+
+ case LIST:
+ writer.startList();
+ while (reader.next()) {
+ writeValue(reader.reader(), getListWriterForReader(reader.reader(), writer));
+ }
+ writer.endList();
+ break;
+ case MAP:
+ writer.start();
+ if (reader.isSet()) {
+ for(String name : reader){
+ FieldReader childReader = reader.reader(name);
+ if(childReader.isSet()){
+ writeValue(childReader, getMapWriterForReader(childReader, writer, name));
+ }
+ }
+ }
+ writer.end();
+ break;
+ <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
+ <#assign fields = minor.fields!type.fields />
+ <#assign uncappedName = name?uncap_first/>
+ <#if !minor.class?starts_with("Decimal")>
+
+ case ${name?upper_case}:
+ if (reader.isSet()) {
+ Nullable${name}Holder ${uncappedName}Holder = new Nullable${name}Holder();
+ reader.read(${uncappedName}Holder);
+ if (${uncappedName}Holder.isSet == 1) {
+ writer.write${name}(<#list fields as field>${uncappedName}Holder.${field.name}<#if field_has_next>, </#if></#list>);
+ }
+ }
+ break;
+
+ </#if>
+ </#list></#list>
+ }
+ break;
+ }
+ }
+
+ private static FieldWriter getMapWriterForReader(FieldReader reader, MapWriter writer, String name) {
+ switch (reader.getType().getMinorType()) {
+ <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
+ <#assign fields = minor.fields!type.fields />
+ <#assign uncappedName = name?uncap_first/>
+ <#if !minor.class?starts_with("Decimal")>
+ case ${name?upper_case}:
+ return (FieldWriter) writer.<#if name == "Int">integer<#else>${uncappedName}</#if>(name);
+ </#if>
+ </#list></#list>
+ case MAP:
+ return (FieldWriter) writer.map(name);
+ case LIST:
+ return (FieldWriter) writer.list(name);
+ default:
+ throw new UnsupportedOperationException(reader.getType().toString());
+ }
+ }
+
+ private static FieldWriter getListWriterForReader(FieldReader reader, ListWriter writer) {
+ switch (reader.getType().getMinorType()) {
+ <#list vv.types as type><#list type.minor as minor><#assign name = minor.class?cap_first />
+ <#assign fields = minor.fields!type.fields />
+ <#assign uncappedName = name?uncap_first/>
+ <#if !minor.class?starts_with("Decimal")>
+ case ${name?upper_case}:
+ return (FieldWriter) writer.<#if name == "Int">integer<#else>${uncappedName}</#if>();
+ </#if>
+ </#list></#list>
+ case MAP:
+ return (FieldWriter) writer.map();
+ case LIST:
+ return (FieldWriter) writer.list();
+ default:
+ throw new UnsupportedOperationException(reader.getType().toString());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/arrow/blob/fa5f0299/java/vector/src/main/codegen/templates/ComplexReaders.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/ComplexReaders.java b/java/vector/src/main/codegen/templates/ComplexReaders.java
new file mode 100644
index 0000000..34c6571
--- /dev/null
+++ b/java/vector/src/main/codegen/templates/ComplexReaders.java
@@ -0,0 +1,183 @@
+/**
+ * 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 java.lang.Override;
+import java.util.List;
+
+import org.apache.arrow.record.TransferPair;
+import org.apache.arrow.vector.complex.IndexHolder;
+import org.apache.arrow.vector.complex.writer.IntervalWriter;
+import org.apache.arrow.vector.complex.writer.BaseWriter.MapWriter;
+
+<@pp.dropOutputFile />
+<#list vv.types as type>
+<#list type.minor as minor>
+<#list ["", "Repeated"] as mode>
+<#assign lowerName = minor.class?uncap_first />
+<#if lowerName == "int" ><#assign lowerName = "integer" /></#if>
+<#assign name = mode + minor.class?cap_first />
+<#assign javaType = (minor.javaType!type.javaType) />
+<#assign friendlyType = (minor.friendlyType!minor.boxedType!type.boxedType) />
+<#assign safeType=friendlyType />
+<#if safeType=="byte[]"><#assign safeType="ByteArray" /></#if>
+
+<#assign hasFriendly = minor.friendlyType!"no" == "no" />
+
+<#list ["", "Nullable"] as nullMode>
+<#if (mode == "Repeated" && nullMode == "") || mode == "" >
+<@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/${nullMode}${name}ReaderImpl.java" />
+<#include "/@includes/license.ftl" />
+
+package org.apache.arrow.vector.complex.impl;
+
+<#include "/@includes/vv_imports.ftl" />
+
+@SuppressWarnings("unused")
+public class ${nullMode}${name}ReaderImpl extends AbstractFieldReader {
+
+ private final ${nullMode}${name}Vector vector;
+
+ public ${nullMode}${name}ReaderImpl(${nullMode}${name}Vector vector){
+ super();
+ this.vector = vector;
+ }
+
+ public MajorType getType(){
+ return vector.getField().getType();
+ }
+
+ public MaterializedField getField(){
+ return vector.getField();
+ }
+
+ public boolean isSet(){
+ <#if nullMode == "Nullable">
+ return !vector.getAccessor().isNull(idx());
+ <#else>
+ return true;
+ </#if>
+ }
+
+
+
+
+ <#if mode == "Repeated">
+
+ public void copyAsValue(${minor.class?cap_first}Writer writer){
+ Repeated${minor.class?cap_first}WriterImpl impl = (Repeated${minor.class?cap_first}WriterImpl) writer;
+ impl.vector.copyFromSafe(idx(), impl.idx(), vector);
+ }
+
+ public void copyAsField(String name, MapWriter writer){
+ Repeated${minor.class?cap_first}WriterImpl impl = (Repeated${minor.class?cap_first}WriterImpl) writer.list(name).${lowerName}();
+ impl.vector.copyFromSafe(idx(), impl.idx(), vector);
+ }
+
+ public int size(){
+ return vector.getAccessor().getInnerValueCountAt(idx());
+ }
+
+ public void read(int arrayIndex, ${minor.class?cap_first}Holder h){
+ vector.getAccessor().get(idx(), arrayIndex, h);
+ }
+ public void read(int arrayIndex, Nullable${minor.class?cap_first}Holder h){
+ vector.getAccessor().get(idx(), arrayIndex, h);
+ }
+
+ public ${friendlyType} read${safeType}(int arrayIndex){
+ return vector.getAccessor().getSingleObject(idx(), arrayIndex);
+ }
+
+
+ public List<Object> readObject(){
+ return (List<Object>) (Object) vector.getAccessor().getObject(idx());
+ }
+
+ <#else>
+
+ public void copyAsValue(${minor.class?cap_first}Writer writer){
+ ${nullMode}${minor.class?cap_first}WriterImpl impl = (${nullMode}${minor.class?cap_first}WriterImpl) writer;
+ impl.vector.copyFromSafe(idx(), impl.idx(), vector);
+ }
+
+ public void copyAsField(String name, MapWriter writer){
+ ${nullMode}${minor.class?cap_first}WriterImpl impl = (${nullMode}${minor.class?cap_first}WriterImpl) writer.${lowerName}(name);
+ impl.vector.copyFromSafe(idx(), impl.idx(), vector);
+ }
+
+ <#if nullMode != "Nullable">
+ public void read(${minor.class?cap_first}Holder h){
+ vector.getAccessor().get(idx(), h);
+ }
+ </#if>
+
+ public void read(Nullable${minor.class?cap_first}Holder h){
+ vector.getAccessor().get(idx(), h);
+ }
+
+ public ${friendlyType} read${safeType}(){
+ return vector.getAccessor().getObject(idx());
+ }
+
+ public void copyValue(FieldWriter w){
+
+ }
+
+ public Object readObject(){
+ return vector.getAccessor().getObject(idx());
+ }
+
+
+ </#if>
+}
+</#if>
+</#list>
+<@pp.changeOutputFile name="/org/apache/arrow/vector/complex/reader/${name}Reader.java" />
+<#include "/@includes/license.ftl" />
+
+package org.apache.arrow.vector.complex.reader;
+
+<#include "/@includes/vv_imports.ftl" />
+@SuppressWarnings("unused")
+public interface ${name}Reader extends BaseReader{
+
+ <#if mode == "Repeated">
+ public int size();
+ public void read(int arrayIndex, ${minor.class?cap_first}Holder h);
+ public void read(int arrayIndex, Nullable${minor.class?cap_first}Holder h);
+ public Object readObject(int arrayIndex);
+ public ${friendlyType} read${safeType}(int arrayIndex);
+ <#else>
+ public void read(${minor.class?cap_first}Holder h);
+ public void read(Nullable${minor.class?cap_first}Holder h);
+ public Object readObject();
+ public ${friendlyType} read${safeType}();
+ </#if>
+ public boolean isSet();
+ public void copyAsValue(${minor.class}Writer writer);
+ public void copyAsField(String name, ${minor.class}Writer writer);
+
+}
+
+
+
+</#list>
+</#list>
+</#list>
+
+
http://git-wip-us.apache.org/repos/asf/arrow/blob/fa5f0299/java/vector/src/main/codegen/templates/ComplexWriters.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/ComplexWriters.java b/java/vector/src/main/codegen/templates/ComplexWriters.java
new file mode 100644
index 0000000..8f9a6e7
--- /dev/null
+++ b/java/vector/src/main/codegen/templates/ComplexWriters.java
@@ -0,0 +1,151 @@
+/**
+ * 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.
+ */
+
+<@pp.dropOutputFile />
+<#list vv.types as type>
+<#list type.minor as minor>
+<#list ["", "Nullable", "Repeated"] as mode>
+<#assign name = mode + minor.class?cap_first />
+<#assign eName = name />
+<#assign javaType = (minor.javaType!type.javaType) />
+<#assign fields = minor.fields!type.fields />
+
+<@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/${eName}WriterImpl.java" />
+<#include "/@includes/license.ftl" />
+
+package org.apache.arrow.vector.complex.impl;
+
+<#include "/@includes/vv_imports.ftl" />
+
+/*
+ * This class is generated using FreeMarker on the ${.template_name} template.
+ */
+@SuppressWarnings("unused")
+public class ${eName}WriterImpl extends AbstractFieldWriter {
+
+ private final ${name}Vector.Mutator mutator;
+ final ${name}Vector vector;
+
+ public ${eName}WriterImpl(${name}Vector vector, AbstractFieldWriter parent) {
+ super(parent);
+ this.mutator = vector.getMutator();
+ this.vector = vector;
+ }
+
+ @Override
+ public MaterializedField getField() {
+ return vector.getField();
+ }
+
+ @Override
+ public int getValueCapacity() {
+ return vector.getValueCapacity();
+ }
+
+ @Override
+ public void allocate() {
+ vector.allocateNew();
+ }
+
+ @Override
+ public void close() {
+ vector.close();
+ }
+
+ @Override
+ public void clear() {
+ vector.clear();
+ }
+
+ @Override
+ protected int idx() {
+ return super.idx();
+ }
+
+ <#if mode == "Repeated">
+
+ public void write(${minor.class?cap_first}Holder h) {
+ mutator.addSafe(idx(), h);
+ vector.getMutator().setValueCount(idx()+1);
+ }
+
+ public void write(Nullable${minor.class?cap_first}Holder h) {
+ mutator.addSafe(idx(), h);
+ vector.getMutator().setValueCount(idx()+1);
+ }
+
+ <#if !(minor.class == "Decimal9" || minor.class == "Decimal18" || minor.class == "Decimal28Sparse" || minor.class == "Decimal38Sparse" || minor.class == "Decimal28Dense" || minor.class == "Decimal38Dense")>
+ public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) {
+ mutator.addSafe(idx(), <#list fields as field>${field.name}<#if field_has_next>, </#if></#list>);
+ vector.getMutator().setValueCount(idx()+1);
+ }
+ </#if>
+
+ public void setPosition(int idx) {
+ super.setPosition(idx);
+ mutator.startNewValue(idx);
+ }
+
+
+ <#else>
+
+ public void write(${minor.class}Holder h) {
+ mutator.setSafe(idx(), h);
+ vector.getMutator().setValueCount(idx()+1);
+ }
+
+ public void write(Nullable${minor.class}Holder h) {
+ mutator.setSafe(idx(), h);
+ vector.getMutator().setValueCount(idx()+1);
+ }
+
+ <#if !(minor.class == "Decimal9" || minor.class == "Decimal18" || minor.class == "Decimal28Sparse" || minor.class == "Decimal38Sparse" || minor.class == "Decimal28Dense" || minor.class == "Decimal38Dense")>
+ public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>) {
+ mutator.setSafe(idx(), <#if mode == "Nullable">1, </#if><#list fields as field>${field.name}<#if field_has_next>, </#if></#list>);
+ vector.getMutator().setValueCount(idx()+1);
+ }
+
+ <#if mode == "Nullable">
+
+ public void writeNull() {
+ mutator.setNull(idx());
+ vector.getMutator().setValueCount(idx()+1);
+ }
+ </#if>
+ </#if>
+ </#if>
+}
+
+<@pp.changeOutputFile name="/org/apache/arrow/vector/complex/writer/${eName}Writer.java" />
+<#include "/@includes/license.ftl" />
+
+package org.apache.arrow.vector.complex.writer;
+
+<#include "/@includes/vv_imports.ftl" />
+@SuppressWarnings("unused")
+public interface ${eName}Writer extends BaseWriter {
+ public void write(${minor.class}Holder h);
+
+ <#if !(minor.class == "Decimal9" || minor.class == "Decimal18" || minor.class == "Decimal28Sparse" || minor.class == "Decimal38Sparse" || minor.class == "Decimal28Dense" || minor.class == "Decimal38Dense")>
+ public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, </#if></#list>);
+ </#if>
+}
+
+</#list>
+</#list>
+</#list>
http://git-wip-us.apache.org/repos/asf/arrow/blob/fa5f0299/java/vector/src/main/codegen/templates/FixedValueVectors.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/FixedValueVectors.java b/java/vector/src/main/codegen/templates/FixedValueVectors.java
new file mode 100644
index 0000000..18fcac9
--- /dev/null
+++ b/java/vector/src/main/codegen/templates/FixedValueVectors.java
@@ -0,0 +1,813 @@
+/**
+ * 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 java.lang.Override;
+
+<@pp.dropOutputFile />
+<#list vv.types as type>
+<#list type.minor as minor>
+<#assign friendlyType = (minor.friendlyType!minor.boxedType!type.boxedType) />
+
+<#if type.major == "Fixed">
+<@pp.changeOutputFile name="/org/apache/arrow/vector/${minor.class}Vector.java" />
+<#include "/@includes/license.ftl" />
+
+package org.apache.arrow.vector;
+
+<#include "/@includes/vv_imports.ftl" />
+
+/**
+ * ${minor.class} implements a vector of fixed width values. Elements in the vector are accessed
+ * by position, starting from the logical start of the vector. Values should be pushed onto the
+ * vector sequentially, but may be randomly accessed.
+ * The width of each element is ${type.width} byte(s)
+ * The equivalent Java primitive is '${minor.javaType!type.javaType}'
+ *
+ * NB: this class is automatically generated from ${.template_name} and ValueVectorTypes.tdd using FreeMarker.
+ */
+public final class ${minor.class}Vector extends BaseDataValueVector implements FixedWidthVector{
+ private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(${minor.class}Vector.class);
+
+ private final FieldReader reader = new ${minor.class}ReaderImpl(${minor.class}Vector.this);
+ private final Accessor accessor = new Accessor();
+ private final Mutator mutator = new Mutator();
+
+ private int allocationSizeInBytes = INITIAL_VALUE_ALLOCATION * ${type.width};
+ private int allocationMonitor = 0;
+
+ public ${minor.class}Vector(MaterializedField field, BufferAllocator allocator) {
+ super(field, allocator);
+ }
+
+ @Override
+ public FieldReader getReader(){
+ return reader;
+ }
+
+ @Override
+ public int getBufferSizeFor(final int valueCount) {
+ if (valueCount == 0) {
+ return 0;
+ }
+ return valueCount * ${type.width};
+ }
+
+ @Override
+ public int getValueCapacity(){
+ return (int) (data.capacity() *1.0 / ${type.width});
+ }
+
+ @Override
+ public Accessor getAccessor(){
+ return accessor;
+ }
+
+ @Override
+ public Mutator getMutator(){
+ return mutator;
+ }
+
+ @Override
+ public void setInitialCapacity(final int valueCount) {
+ final long size = 1L * valueCount * ${type.width};
+ if (size > MAX_ALLOCATION_SIZE) {
+ throw new OversizedAllocationException("Requested amount of memory is more than max allowed allocation size");
+ }
+ allocationSizeInBytes = (int)size;
+ }
+
+ @Override
+ public void allocateNew() {
+ if(!allocateNewSafe()){
+ throw new OutOfMemoryException("Failure while allocating buffer.");
+ }
+ }
+
+ @Override
+ public boolean allocateNewSafe() {
+ long curAllocationSize = allocationSizeInBytes;
+ if (allocationMonitor > 10) {
+ curAllocationSize = Math.max(8, curAllocationSize / 2);
+ allocationMonitor = 0;
+ } else if (allocationMonitor < -2) {
+ curAllocationSize = allocationSizeInBytes * 2L;
+ allocationMonitor = 0;
+ }
+
+ try{
+ allocateBytes(curAllocationSize);
+ } catch (RuntimeException ex) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Allocate a new buffer that supports setting at least the provided number of values. May actually be sized bigger
+ * depending on underlying buffer rounding size. Must be called prior to using the ValueVector.
+ *
+ * Note that the maximum number of values a vector can allocate is Integer.MAX_VALUE / value width.
+ *
+ * @param valueCount
+ * @throws org.apache.arrow.memory.OutOfMemoryException if it can't allocate the new buffer
+ */
+ @Override
+ public void allocateNew(final int valueCount) {
+ allocateBytes(valueCount * ${type.width});
+ }
+
+ @Override
+ public void reset() {
+ allocationSizeInBytes = INITIAL_VALUE_ALLOCATION;
+ allocationMonitor = 0;
+ zeroVector();
+ super.reset();
+ }
+
+ private void allocateBytes(final long size) {
+ if (size > MAX_ALLOCATION_SIZE) {
+ throw new OversizedAllocationException("Requested amount of memory is more than max allowed allocation size");
+ }
+
+ final int curSize = (int)size;
+ clear();
+ data = allocator.buffer(curSize);
+ data.readerIndex(0);
+ allocationSizeInBytes = curSize;
+ }
+
+/**
+ * Allocate new buffer with double capacity, and copy data into the new buffer. Replace vector's buffer with new buffer, and release old one
+ *
+ * @throws org.apache.arrow.memory.OutOfMemoryException if it can't allocate the new buffer
+ */
+ public void reAlloc() {
+ final long newAllocationSize = allocationSizeInBytes * 2L;
+ if (newAllocationSize > MAX_ALLOCATION_SIZE) {
+ throw new OversizedAllocationException("Unable to expand the buffer. Max allowed buffer size is reached.");
+ }
+
+ logger.debug("Reallocating vector [{}]. # of bytes: [{}] -> [{}]", field, allocationSizeInBytes, newAllocationSize);
+ final ArrowBuf newBuf = allocator.buffer((int)newAllocationSize);
+ newBuf.setBytes(0, data, 0, data.capacity());
+ final int halfNewCapacity = newBuf.capacity() / 2;
+ newBuf.setZero(halfNewCapacity, halfNewCapacity);
+ newBuf.writerIndex(data.writerIndex());
+ data.release(1);
+ data = newBuf;
+ allocationSizeInBytes = (int)newAllocationSize;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void zeroVector() {
+ data.setZero(0, data.capacity());
+ }
+
+// @Override
+// public void load(SerializedField metadata, ArrowBuf buffer) {
+// Preconditions.checkArgument(this.field.getPath().equals(metadata.getNamePart().getName()), "The field %s doesn't match the provided metadata %s.", this.field, metadata);
+// final int actualLength = metadata.getBufferLength();
+// final int valueCount = metadata.getValueCount();
+// final int expectedLength = valueCount * ${type.width};
+// assert actualLength == expectedLength : String.format("Expected to load %d bytes but actually loaded %d bytes", expectedLength, actualLength);
+//
+// clear();
+// if (data != null) {
+// data.release(1);
+// }
+// data = buffer.slice(0, actualLength);
+// data.retain(1);
+// data.writerIndex(actualLength);
+// }
+
+ public TransferPair getTransferPair(BufferAllocator allocator){
+ return new TransferImpl(getField(), allocator);
+ }
+
+ @Override
+ public TransferPair getTransferPair(String ref, BufferAllocator allocator){
+ return new TransferImpl(getField().withPath(ref), allocator);
+ }
+
+ @Override
+ public TransferPair makeTransferPair(ValueVector to) {
+ return new TransferImpl((${minor.class}Vector) to);
+ }
+
+ public void transferTo(${minor.class}Vector target){
+ target.clear();
+ target.data = data.transferOwnership(target.allocator).buffer;
+ target.data.writerIndex(data.writerIndex());
+ clear();
+ }
+
+ public void splitAndTransferTo(int startIndex, int length, ${minor.class}Vector target) {
+ final int startPoint = startIndex * ${type.width};
+ final int sliceLength = length * ${type.width};
+ target.clear();
+ target.data = data.slice(startPoint, sliceLength).transferOwnership(target.allocator).buffer;
+ target.data.writerIndex(sliceLength);
+ }
+
+ private class TransferImpl implements TransferPair{
+ private ${minor.class}Vector to;
+
+ public TransferImpl(MaterializedField field, BufferAllocator allocator){
+ to = new ${minor.class}Vector(field, allocator);
+ }
+
+ public TransferImpl(${minor.class}Vector to) {
+ this.to = to;
+ }
+
+ @Override
+ public ${minor.class}Vector getTo(){
+ return to;
+ }
+
+ @Override
+ public void transfer(){
+ transferTo(to);
+ }
+
+ @Override
+ public void splitAndTransfer(int startIndex, int length) {
+ splitAndTransferTo(startIndex, length, to);
+ }
+
+ @Override
+ public void copyValueSafe(int fromIndex, int toIndex) {
+ to.copyFromSafe(fromIndex, toIndex, ${minor.class}Vector.this);
+ }
+ }
+
+ public void copyFrom(int fromIndex, int thisIndex, ${minor.class}Vector from){
+ <#if (type.width > 8)>
+ from.data.getBytes(fromIndex * ${type.width}, data, thisIndex * ${type.width}, ${type.width});
+ <#else> <#-- type.width <= 8 -->
+ data.set${(minor.javaType!type.javaType)?cap_first}(thisIndex * ${type.width},
+ from.data.get${(minor.javaType!type.javaType)?cap_first}(fromIndex * ${type.width})
+ );
+ </#if> <#-- type.width -->
+ }
+
+ public void copyFromSafe(int fromIndex, int thisIndex, ${minor.class}Vector from){
+ while(thisIndex >= getValueCapacity()) {
+ reAlloc();
+ }
+ copyFrom(fromIndex, thisIndex, from);
+ }
+
+ public void decrementAllocationMonitor() {
+ if (allocationMonitor > 0) {
+ allocationMonitor = 0;
+ }
+ --allocationMonitor;
+ }
+
+ private void incrementAllocationMonitor() {
+ ++allocationMonitor;
+ }
+
+ public final class Accessor extends BaseDataValueVector.BaseAccessor {
+ @Override
+ public int getValueCount() {
+ return data.writerIndex() / ${type.width};
+ }
+
+ @Override
+ public boolean isNull(int index){
+ return false;
+ }
+
+ <#if (type.width > 8)>
+
+ public ${minor.javaType!type.javaType} get(int index) {
+ return data.slice(index * ${type.width}, ${type.width});
+ }
+
+ <#if (minor.class == "Interval")>
+ public void get(int index, ${minor.class}Holder holder){
+
+ final int offsetIndex = index * ${type.width};
+ holder.months = data.getInt(offsetIndex);
+ holder.days = data.getInt(offsetIndex + ${minor.daysOffset});
+ holder.milliseconds = data.getInt(offsetIndex + ${minor.millisecondsOffset});
+ }
+
+ public void get(int index, Nullable${minor.class}Holder holder){
+ final int offsetIndex = index * ${type.width};
+ holder.isSet = 1;
+ holder.months = data.getInt(offsetIndex);
+ holder.days = data.getInt(offsetIndex + ${minor.daysOffset});
+ holder.milliseconds = data.getInt(offsetIndex + ${minor.millisecondsOffset});
+ }
+
+ @Override
+ public ${friendlyType} getObject(int index) {
+ final int offsetIndex = index * ${type.width};
+ final int months = data.getInt(offsetIndex);
+ final int days = data.getInt(offsetIndex + ${minor.daysOffset});
+ final int millis = data.getInt(offsetIndex + ${minor.millisecondsOffset});
+ final Period p = new Period();
+ return p.plusMonths(months).plusDays(days).plusMillis(millis);
+ }
+
+ public StringBuilder getAsStringBuilder(int index) {
+
+ final int offsetIndex = index * ${type.width};
+
+ int months = data.getInt(offsetIndex);
+ final int days = data.getInt(offsetIndex + ${minor.daysOffset});
+ int millis = data.getInt(offsetIndex + ${minor.millisecondsOffset});
+
+ final int years = (months / org.apache.arrow.vector.util.DateUtility.yearsToMonths);
+ months = (months % org.apache.arrow.vector.util.DateUtility.yearsToMonths);
+
+ final int hours = millis / (org.apache.arrow.vector.util.DateUtility.hoursToMillis);
+ millis = millis % (org.apache.arrow.vector.util.DateUtility.hoursToMillis);
+
+ final int minutes = millis / (org.apache.arrow.vector.util.DateUtility.minutesToMillis);
+ millis = millis % (org.apache.arrow.vector.util.DateUtility.minutesToMillis);
+
+ final long seconds = millis / (org.apache.arrow.vector.util.DateUtility.secondsToMillis);
+ millis = millis % (org.apache.arrow.vector.util.DateUtility.secondsToMillis);
+
+ final String yearString = (Math.abs(years) == 1) ? " year " : " years ";
+ final String monthString = (Math.abs(months) == 1) ? " month " : " months ";
+ final String dayString = (Math.abs(days) == 1) ? " day " : " days ";
+
+
+ return(new StringBuilder().
+ append(years).append(yearString).
+ append(months).append(monthString).
+ append(days).append(dayString).
+ append(hours).append(":").
+ append(minutes).append(":").
+ append(seconds).append(".").
+ append(millis));
+ }
+
+ <#elseif (minor.class == "IntervalDay")>
+ public void get(int index, ${minor.class}Holder holder){
+
+ final int offsetIndex = index * ${type.width};
+ holder.days = data.getInt(offsetIndex);
+ holder.milliseconds = data.getInt(offsetIndex + ${minor.millisecondsOffset});
+ }
+
+ public void get(int index, Nullable${minor.class}Holder holder){
+ final int offsetIndex = index * ${type.width};
+ holder.isSet = 1;
+ holder.days = data.getInt(offsetIndex);
+ holder.milliseconds = data.getInt(offsetIndex + ${minor.millisecondsOffset});
+ }
+
+ @Override
+ public ${friendlyType} getObject(int index) {
+ final int offsetIndex = index * ${type.width};
+ final int millis = data.getInt(offsetIndex + ${minor.millisecondsOffset});
+ final int days = data.getInt(offsetIndex);
+ final Period p = new Period();
+ return p.plusDays(days).plusMillis(millis);
+ }
+
+
+ public StringBuilder getAsStringBuilder(int index) {
+ final int offsetIndex = index * ${type.width};
+
+ int millis = data.getInt(offsetIndex + ${minor.millisecondsOffset});
+ final int days = data.getInt(offsetIndex);
+
+ final int hours = millis / (org.apache.arrow.vector.util.DateUtility.hoursToMillis);
+ millis = millis % (org.apache.arrow.vector.util.DateUtility.hoursToMillis);
+
+ final int minutes = millis / (org.apache.arrow.vector.util.DateUtility.minutesToMillis);
+ millis = millis % (org.apache.arrow.vector.util.DateUtility.minutesToMillis);
+
+ final int seconds = millis / (org.apache.arrow.vector.util.DateUtility.secondsToMillis);
+ millis = millis % (org.apache.arrow.vector.util.DateUtility.secondsToMillis);
+
+ final String dayString = (Math.abs(days) == 1) ? " day " : " days ";
+
+ return(new StringBuilder().
+ append(days).append(dayString).
+ append(hours).append(":").
+ append(minutes).append(":").
+ append(seconds).append(".").
+ append(millis));
+ }
+
+ <#elseif (minor.class == "Decimal28Sparse") || (minor.class == "Decimal38Sparse") || (minor.class == "Decimal28Dense") || (minor.class == "Decimal38Dense")>
+
+ public void get(int index, ${minor.class}Holder holder) {
+ holder.start = index * ${type.width};
+ holder.buffer = data;
+ holder.scale = getField().getScale();
+ holder.precision = getField().getPrecision();
+ }
+
+ public void get(int index, Nullable${minor.class}Holder holder) {
+ holder.isSet = 1;
+ holder.start = index * ${type.width};
+ holder.buffer = data;
+ holder.scale = getField().getScale();
+ holder.precision = getField().getPrecision();
+ }
+
+ @Override
+ public ${friendlyType} getObject(int index) {
+ <#if (minor.class == "Decimal28Sparse") || (minor.class == "Decimal38Sparse")>
+ // Get the BigDecimal object
+ return org.apache.arrow.vector.util.DecimalUtility.getBigDecimalFromSparse(data, index * ${type.width}, ${minor.nDecimalDigits}, getField().getScale());
+ <#else>
+ return org.apache.arrow.vector.util.DecimalUtility.getBigDecimalFromDense(data, index * ${type.width}, ${minor.nDecimalDigits}, getField().getScale(), ${minor.maxPrecisionDigits}, ${type.width});
+ </#if>
+ }
+
+ <#else>
+ public void get(int index, ${minor.class}Holder holder){
+ holder.buffer = data;
+ holder.start = index * ${type.width};
+ }
+
+ public void get(int index, Nullable${minor.class}Holder holder){
+ holder.isSet = 1;
+ holder.buffer = data;
+ holder.start = index * ${type.width};
+ }
+
+ @Override
+ public ${friendlyType} getObject(int index) {
+ return data.slice(index * ${type.width}, ${type.width})
+ }
+
+ </#if>
+ <#else> <#-- type.width <= 8 -->
+
+ public ${minor.javaType!type.javaType} get(int index) {
+ return data.get${(minor.javaType!type.javaType)?cap_first}(index * ${type.width});
+ }
+
+ <#if type.width == 4>
+ public long getTwoAsLong(int index) {
+ return data.getLong(index * ${type.width});
+ }
+
+ </#if>
+
+ <#if minor.class == "Date">
+ @Override
+ public ${friendlyType} getObject(int index) {
+ org.joda.time.DateTime date = new org.joda.time.DateTime(get(index), org.joda.time.DateTimeZone.UTC);
+ date = date.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault());
+ return date;
+ }
+
+ <#elseif minor.class == "TimeStamp">
+ @Override
+ public ${friendlyType} getObject(int index) {
+ org.joda.time.DateTime date = new org.joda.time.DateTime(get(index), org.joda.time.DateTimeZone.UTC);
+ date = date.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault());
+ return date;
+ }
+
+ <#elseif minor.class == "IntervalYear">
+ @Override
+ public ${friendlyType} getObject(int index) {
+
+ final int value = get(index);
+
+ final int years = (value / org.apache.arrow.vector.util.DateUtility.yearsToMonths);
+ final int months = (value % org.apache.arrow.vector.util.DateUtility.yearsToMonths);
+ final Period p = new Period();
+ return p.plusYears(years).plusMonths(months);
+ }
+
+ public StringBuilder getAsStringBuilder(int index) {
+
+ int months = data.getInt(index);
+
+ final int years = (months / org.apache.arrow.vector.util.DateUtility.yearsToMonths);
+ months = (months % org.apache.arrow.vector.util.DateUtility.yearsToMonths);
+
+ final String yearString = (Math.abs(years) == 1) ? " year " : " years ";
+ final String monthString = (Math.abs(months) == 1) ? " month " : " months ";
+
+ return(new StringBuilder().
+ append(years).append(yearString).
+ append(months).append(monthString));
+ }
+
+ <#elseif minor.class == "Time">
+ @Override
+ public DateTime getObject(int index) {
+
+ org.joda.time.DateTime time = new org.joda.time.DateTime(get(index), org.joda.time.DateTimeZone.UTC);
+ time = time.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault());
+ return time;
+ }
+
+ <#elseif minor.class == "Decimal9" || minor.class == "Decimal18">
+ @Override
+ public ${friendlyType} getObject(int index) {
+
+ final BigInteger value = BigInteger.valueOf(((${type.boxedType})get(index)).${type.javaType}Value());
+ return new BigDecimal(value, getField().getScale());
+ }
+
+ <#else>
+ @Override
+ public ${friendlyType} getObject(int index) {
+ return get(index);
+ }
+ public ${minor.javaType!type.javaType} getPrimitiveObject(int index) {
+ return get(index);
+ }
+ </#if>
+
+ public void get(int index, ${minor.class}Holder holder){
+ <#if minor.class.startsWith("Decimal")>
+ holder.scale = getField().getScale();
+ holder.precision = getField().getPrecision();
+ </#if>
+
+ holder.value = data.get${(minor.javaType!type.javaType)?cap_first}(index * ${type.width});
+ }
+
+ public void get(int index, Nullable${minor.class}Holder holder){
+ holder.isSet = 1;
+ holder.value = data.get${(minor.javaType!type.javaType)?cap_first}(index * ${type.width});
+ }
+
+
+ </#if> <#-- type.width -->
+ }
+
+ /**
+ * ${minor.class}.Mutator implements a mutable vector of fixed width values. Elements in the
+ * vector are accessed by position from the logical start of the vector. Values should be pushed
+ * onto the vector sequentially, but may be randomly accessed.
+ * The width of each element is ${type.width} byte(s)
+ * The equivalent Java primitive is '${minor.javaType!type.javaType}'
+ *
+ * NB: this class is automatically generated from ValueVectorTypes.tdd using FreeMarker.
+ */
+ public final class Mutator extends BaseDataValueVector.BaseMutator {
+
+ private Mutator(){};
+ /**
+ * Set the element at the given index to the given value. Note that widths smaller than
+ * 32 bits are handled by the ArrowBuf interface.
+ *
+ * @param index position of the bit to set
+ * @param value value to set
+ */
+ <#if (type.width > 8)>
+ public void set(int index, <#if (type.width > 4)>${minor.javaType!type.javaType}<#else>int</#if> value) {
+ data.setBytes(index * ${type.width}, value, 0, ${type.width});
+ }
+
+ public void setSafe(int index, <#if (type.width > 4)>${minor.javaType!type.javaType}<#else>int</#if> value) {
+ while(index >= getValueCapacity()) {
+ reAlloc();
+ }
+ data.setBytes(index * ${type.width}, value, 0, ${type.width});
+ }
+
+ <#if (minor.class == "Interval")>
+ public void set(int index, int months, int days, int milliseconds){
+ final int offsetIndex = index * ${type.width};
+ data.setInt(offsetIndex, months);
+ data.setInt((offsetIndex + ${minor.daysOffset}), days);
+ data.setInt((offsetIndex + ${minor.millisecondsOffset}), milliseconds);
+ }
+
+ protected void set(int index, ${minor.class}Holder holder){
+ set(index, holder.months, holder.days, holder.milliseconds);
+ }
+
+ protected void set(int index, Nullable${minor.class}Holder holder){
+ set(index, holder.months, holder.days, holder.milliseconds);
+ }
+
+ public void setSafe(int index, int months, int days, int milliseconds){
+ while(index >= getValueCapacity()) {
+ reAlloc();
+ }
+ set(index, months, days, milliseconds);
+ }
+
+ public void setSafe(int index, Nullable${minor.class}Holder holder){
+ setSafe(index, holder.months, holder.days, holder.milliseconds);
+ }
+
+ public void setSafe(int index, ${minor.class}Holder holder){
+ setSafe(index, holder.months, holder.days, holder.milliseconds);
+ }
+
+ <#elseif (minor.class == "IntervalDay")>
+ public void set(int index, int days, int milliseconds){
+ final int offsetIndex = index * ${type.width};
+ data.setInt(offsetIndex, days);
+ data.setInt((offsetIndex + ${minor.millisecondsOffset}), milliseconds);
+ }
+
+ protected void set(int index, ${minor.class}Holder holder){
+ set(index, holder.days, holder.milliseconds);
+ }
+ protected void set(int index, Nullable${minor.class}Holder holder){
+ set(index, holder.days, holder.milliseconds);
+ }
+
+ public void setSafe(int index, int days, int milliseconds){
+ while(index >= getValueCapacity()) {
+ reAlloc();
+ }
+ set(index, days, milliseconds);
+ }
+
+ public void setSafe(int index, ${minor.class}Holder holder){
+ setSafe(index, holder.days, holder.milliseconds);
+ }
+
+ public void setSafe(int index, Nullable${minor.class}Holder holder){
+ setSafe(index, holder.days, holder.milliseconds);
+ }
+
+ <#elseif (minor.class == "Decimal28Sparse" || minor.class == "Decimal38Sparse") || (minor.class == "Decimal28Dense") || (minor.class == "Decimal38Dense")>
+
+ public void set(int index, ${minor.class}Holder holder){
+ set(index, holder.start, holder.buffer);
+ }
+
+ void set(int index, Nullable${minor.class}Holder holder){
+ set(index, holder.start, holder.buffer);
+ }
+
+ public void setSafe(int index, Nullable${minor.class}Holder holder){
+ setSafe(index, holder.start, holder.buffer);
+ }
+ public void setSafe(int index, ${minor.class}Holder holder){
+ setSafe(index, holder.start, holder.buffer);
+ }
+
+ public void setSafe(int index, int start, ArrowBuf buffer){
+ while(index >= getValueCapacity()) {
+ reAlloc();
+ }
+ set(index, start, buffer);
+ }
+
+ public void set(int index, int start, ArrowBuf buffer){
+ data.setBytes(index * ${type.width}, buffer, start, ${type.width});
+ }
+
+ <#else>
+
+ protected void set(int index, ${minor.class}Holder holder){
+ set(index, holder.start, holder.buffer);
+ }
+
+ public void set(int index, Nullable${minor.class}Holder holder){
+ set(index, holder.start, holder.buffer);
+ }
+
+ public void set(int index, int start, ArrowBuf buffer){
+ data.setBytes(index * ${type.width}, buffer, start, ${type.width});
+ }
+
+ public void setSafe(int index, ${minor.class}Holder holder){
+ setSafe(index, holder.start, holder.buffer);
+ }
+ public void setSafe(int index, Nullable${minor.class}Holder holder){
+ setSafe(index, holder.start, holder.buffer);
+ }
+
+ public void setSafe(int index, int start, ArrowBuf buffer){
+ while(index >= getValueCapacity()) {
+ reAlloc();
+ }
+ set(index, holder);
+ }
+
+ public void set(int index, Nullable${minor.class}Holder holder){
+ data.setBytes(index * ${type.width}, holder.buffer, holder.start, ${type.width});
+ }
+ </#if>
+
+ @Override
+ public void generateTestData(int count) {
+ setValueCount(count);
+ boolean even = true;
+ final int valueCount = getAccessor().getValueCount();
+ for(int i = 0; i < valueCount; i++, even = !even) {
+ final byte b = even ? Byte.MIN_VALUE : Byte.MAX_VALUE;
+ for(int w = 0; w < ${type.width}; w++){
+ data.setByte(i + w, b);
+ }
+ }
+ }
+
+ <#else> <#-- type.width <= 8 -->
+ public void set(int index, <#if (type.width >= 4)>${minor.javaType!type.javaType}<#else>int</#if> value) {
+ data.set${(minor.javaType!type.javaType)?cap_first}(index * ${type.width}, value);
+ }
+
+ public void setSafe(int index, <#if (type.width >= 4)>${minor.javaType!type.javaType}<#else>int</#if> value) {
+ while(index >= getValueCapacity()) {
+ reAlloc();
+ }
+ set(index, value);
+ }
+
+ protected void set(int index, ${minor.class}Holder holder){
+ data.set${(minor.javaType!type.javaType)?cap_first}(index * ${type.width}, holder.value);
+ }
+
+ public void setSafe(int index, ${minor.class}Holder holder){
+ while(index >= getValueCapacity()) {
+ reAlloc();
+ }
+ set(index, holder);
+ }
+
+ protected void set(int index, Nullable${minor.class}Holder holder){
+ data.set${(minor.javaType!type.javaType)?cap_first}(index * ${type.width}, holder.value);
+ }
+
+ public void setSafe(int index, Nullable${minor.class}Holder holder){
+ while(index >= getValueCapacity()) {
+ reAlloc();
+ }
+ set(index, holder);
+ }
+
+ @Override
+ public void generateTestData(int size) {
+ setValueCount(size);
+ boolean even = true;
+ final int valueCount = getAccessor().getValueCount();
+ for(int i = 0; i < valueCount; i++, even = !even) {
+ if(even){
+ set(i, ${minor.boxedType!type.boxedType}.MIN_VALUE);
+ }else{
+ set(i, ${minor.boxedType!type.boxedType}.MAX_VALUE);
+ }
+ }
+ }
+
+ public void generateTestDataAlt(int size) {
+ setValueCount(size);
+ boolean even = true;
+ final int valueCount = getAccessor().getValueCount();
+ for(int i = 0; i < valueCount; i++, even = !even) {
+ if(even){
+ set(i, (${(minor.javaType!type.javaType)}) 1);
+ }else{
+ set(i, (${(minor.javaType!type.javaType)}) 0);
+ }
+ }
+ }
+
+ </#if> <#-- type.width -->
+
+ @Override
+ public void setValueCount(int valueCount) {
+ final int currentValueCapacity = getValueCapacity();
+ final int idx = (${type.width} * valueCount);
+ while(valueCount > getValueCapacity()) {
+ reAlloc();
+ }
+ if (valueCount > 0 && currentValueCapacity > valueCount * 2) {
+ incrementAllocationMonitor();
+ } else if (allocationMonitor > 0) {
+ allocationMonitor = 0;
+ }
+ VectorTrimmer.trim(data, idx);
+ data.writerIndex(valueCount * ${type.width});
+ }
+ }
+}
+
+</#if> <#-- type.major -->
+</#list>
+</#list>