diff --git a/java/vector/pom.xml b/java/vector/pom.xml index 46e06aa1e3f..b436f5f9cec 100644 --- a/java/vector/pom.xml +++ b/java/vector/pom.xml @@ -135,6 +135,13 @@ org.apache.drill.tools drill-fmpp-maven-plugin 1.5.0 + + + org.freemarker + freemarker + 2.3.23 + + generate-fmpp diff --git a/java/vector/src/main/codegen/data/ValueVectorTypes.tdd b/java/vector/src/main/codegen/data/ValueVectorTypes.tdd index 970d887c760..565174a4dd8 100644 --- a/java/vector/src/main/codegen/data/ValueVectorTypes.tdd +++ b/java/vector/src/main/codegen/data/ValueVectorTypes.tdd @@ -73,26 +73,10 @@ { class: "UInt8" }, { class: "Float8", javaType: "double", boxedType: "Double", fields: [{name: "value", type: "double"}] }, { class: "DateMilli", javaType: "long", friendlyType: "LocalDateTime" }, - { class: "TimeStampSec", javaType: "long", boxedType: "Long", friendlyType: "LocalDateTime" }, - { class: "TimeStampMilli", javaType: "long", boxedType: "Long", friendlyType: "LocalDateTime" }, - { class: "TimeStampMicro", javaType: "long", boxedType: "Long", friendlyType: "LocalDateTime" }, - { class: "TimeStampNano", javaType: "long", boxedType: "Long", friendlyType: "LocalDateTime" }, - { class: "TimeStampSecTZ", javaType: "long", boxedType: "Long", - typeParams: [ {name: "timezone", type: "String"} ], - arrowType: "org.apache.arrow.vector.types.pojo.ArrowType.Timestamp", - arrowTypeConstructorParams: ["org.apache.arrow.vector.types.TimeUnit.SECOND", "timezone"] }, - { class: "TimeStampMilliTZ", javaType: "long", boxedType: "Long", - typeParams: [ {name: "timezone", type: "String"} ], - arrowType: "org.apache.arrow.vector.types.pojo.ArrowType.Timestamp", - arrowTypeConstructorParams: ["org.apache.arrow.vector.types.TimeUnit.MILLISECOND", "timezone"] }, - { class: "TimeStampMicroTZ", javaType: "long", boxedType: "Long", - typeParams: [ {name: "timezone", type: "String"} ], - arrowType: "org.apache.arrow.vector.types.pojo.ArrowType.Timestamp", - arrowTypeConstructorParams: ["org.apache.arrow.vector.types.TimeUnit.MICROSECOND", "timezone"] }, - { class: "TimeStampNanoTZ", javaType: "long", boxedType: "Long", - typeParams: [ {name: "timezone", type: "String"} ], - arrowType: "org.apache.arrow.vector.types.pojo.ArrowType.Timestamp", - arrowTypeConstructorParams: ["org.apache.arrow.vector.types.TimeUnit.NANOSECOND", "timezone"] }, + { class: "Timestamp", javaType: "long", boxedType: "Long", friendlyType: "LocalDateTime" + typeParams: [ {name: "unit", type: "TimeUnit"}, { name: "timezone", type: "String"} ], + arrowType: "org.apache.arrow.vector.types.pojo.ArrowType.Timestamp", + }, { class: "TimeMicro" }, { class: "TimeNano" } ] @@ -116,7 +100,7 @@ { class: "Decimal", maxPrecisionDigits: 38, nDecimalDigits: 4, friendlyType: "BigDecimal", - typeParams: [ {name: "scale", type: "int"}, { name: "precision", type: "int"}], + typeParams: [ { name: "precision", type: "int"}, {name: "scale", type: "int"} ], arrowType: "org.apache.arrow.vector.types.pojo.ArrowType.Decimal", fields: [{name: "start", type: "int"}, {name: "buffer", type: "ArrowBuf"}] } diff --git a/java/vector/src/main/codegen/includes/vv_imports.ftl b/java/vector/src/main/codegen/includes/vv_imports.ftl index a55304d7335..28a8953e20b 100644 --- a/java/vector/src/main/codegen/includes/vv_imports.ftl +++ b/java/vector/src/main/codegen/includes/vv_imports.ftl @@ -55,6 +55,7 @@ import java.math.BigDecimal; import java.math.BigInteger; import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; import org.joda.time.LocalDateTime; import org.joda.time.Period; diff --git a/java/vector/src/main/codegen/templates/AbstractFieldWriter.java b/java/vector/src/main/codegen/templates/AbstractFieldWriter.java index 853f67fd0dd..5b0b0244fec 100644 --- a/java/vector/src/main/codegen/templates/AbstractFieldWriter.java +++ b/java/vector/src/main/codegen/templates/AbstractFieldWriter.java @@ -122,6 +122,13 @@ public ListWriter list(String name) { fail("${capName}(" + <#list minor.typeParams as typeParam>"${typeParam.name}: " + ${typeParam.name} + ", " + ")"); return null; } + + @Override + public ${capName}Writer ${lowerName}(<#list minor.typeParams as typeParam>${typeParam.type} ${typeParam.name}<#sep>, ) { + fail("${capName}(" + <#list minor.typeParams as typeParam>"${typeParam.name}: " + ${typeParam.name} + ", " + ")"); + return null; + } + @Override diff --git a/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java b/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java index 228c2c531f9..bd2248ba269 100644 --- a/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java +++ b/java/vector/src/main/codegen/templates/AbstractPromotableFieldWriter.java @@ -16,6 +16,7 @@ * limitations under the License. */ +import org.apache.arrow.vector.types.Types; import org.apache.drill.common.types.TypeProtos.MinorType; <@pp.dropOutputFile /> @@ -42,6 +43,8 @@ abstract class AbstractPromotableFieldWriter extends AbstractFieldWriter { * @param type the type of the values we want to write * @return the corresponding field writer */ + abstract protected FieldWriter getWriter(ArrowType type); + abstract protected FieldWriter getWriter(MinorType type); /** @@ -118,7 +121,12 @@ public ListWriter list(String name) { return getWriter(MinorType.MAP).${lowerName}(name<#list minor.typeParams as typeParam>, ${typeParam.name}); } - + @Override + public ${capName}Writer ${lowerName}(<#list minor.typeParams as typeParam>${typeParam.type} ${typeParam.name}<#sep>, ) { + return getWriter(MinorType.LIST).${lowerName}(<#list minor.typeParams as typeParam>${typeParam.name}<#sep>, ); + } + + <#else> @Override public ${capName}Writer ${lowerName}(String name) { return getWriter(MinorType.MAP).${lowerName}(name); @@ -128,7 +136,7 @@ public ListWriter list(String name) { public ${capName}Writer ${lowerName}() { return getWriter(MinorType.LIST).${lowerName}(); } - + public void copyReader(FieldReader reader) { diff --git a/java/vector/src/main/codegen/templates/ArrowType.java b/java/vector/src/main/codegen/templates/ArrowType.java index 93746303d93..9154416cb8a 100644 --- a/java/vector/src/main/codegen/templates/ArrowType.java +++ b/java/vector/src/main/codegen/templates/ArrowType.java @@ -159,7 +159,7 @@ public static class ${name} extends <#if type.complex>ComplexType<#else>Primitiv <#list fields as field> <#assign fieldType = field.valueType!field.type> - ${fieldType} ${field.name}; + public ${fieldType} ${field.name}; @JsonCreator diff --git a/java/vector/src/main/codegen/templates/BaseWriter.java b/java/vector/src/main/codegen/templates/BaseWriter.java index 405f466cbc7..aac9a4da013 100644 --- a/java/vector/src/main/codegen/templates/BaseWriter.java +++ b/java/vector/src/main/codegen/templates/BaseWriter.java @@ -78,6 +78,9 @@ public interface ListWriter extends BaseWriter { <#if lowerName == "int" ><#assign lowerName = "integer" /> <#assign upperName = minor.class?upper_case /> <#assign capName = minor.class?cap_first /> + <#if minor.typeParams?? > + ${capName}Writer ${lowerName}(<#list minor.typeParams as typeParam>${typeParam.type} ${typeParam.name}<#sep>, ); + ${capName}Writer ${lowerName}(); } diff --git a/java/vector/src/main/codegen/templates/ComplexReaders.java b/java/vector/src/main/codegen/templates/ComplexReaders.java index 4863ecdb632..a31090f52d8 100644 --- a/java/vector/src/main/codegen/templates/ComplexReaders.java +++ b/java/vector/src/main/codegen/templates/ComplexReaders.java @@ -96,10 +96,7 @@ public void read(Nullable${minor.class?cap_first}Holder h){ return vector.getObject(idx()); } - <#if minor.class == "TimeStampSec" || - minor.class == "TimeStampMilli" || - minor.class == "TimeStampMicro" || - minor.class == "TimeStampNano"> + <#if minor.class == "Timestamp"> @Override public ${minor.boxedType} read${minor.boxedType}(){ return vector.get(idx()); diff --git a/java/vector/src/main/codegen/templates/MapWriters.java b/java/vector/src/main/codegen/templates/MapWriters.java index a5ac1b71704..2858f74d060 100644 --- a/java/vector/src/main/codegen/templates/MapWriters.java +++ b/java/vector/src/main/codegen/templates/MapWriters.java @@ -231,25 +231,25 @@ public void end() { public ${minor.class}Writer ${lowerName}(String name) { FieldWriter writer = fields.get(handleCase(name)); + FieldType fieldType = FieldType.nullable( + <#if minor.typeParams??> + <#if minor.arrowTypeConstructorParams??> + <#assign constructorParams = minor.arrowTypeConstructorParams /> + <#else> + <#assign constructorParams = [] /> + <#list minor.typeParams as typeParam> + <#assign constructorParams = constructorParams + [ typeParam.name ] /> + + + new ${minor.arrowType}(${constructorParams?join(", ")}) + <#else> + MinorType.${upperName}.getType() + ); if(writer == null) { ValueVector vector; ValueVector currentVector = container.getChild(name); ${vectName}Vector v = container.addOrGet(name, - FieldType.nullable( - <#if minor.typeParams??> - <#if minor.arrowTypeConstructorParams??> - <#assign constructorParams = minor.arrowTypeConstructorParams /> - <#else> - <#assign constructorParams = [] /> - <#list minor.typeParams?reverse as typeParam> - <#assign constructorParams = constructorParams + [ typeParam.name ] /> - - - new ${minor.arrowType}(${constructorParams?join(", ")}) - <#else> - MinorType.${upperName}.getType() - - ), + fieldType, ${vectName}Vector.class); writer = new PromotableWriter(v, container, getNullableMapWriterFactory()); vector = v; @@ -264,7 +264,7 @@ public void end() { } else { if (writer instanceof PromotableWriter) { // ensure writers are initialized - ((PromotableWriter)writer).getWriter(MinorType.${upperName}); + ((PromotableWriter)writer).getWriter(fieldType.getType()); } } return writer; diff --git a/java/vector/src/main/codegen/templates/UnionListWriter.java b/java/vector/src/main/codegen/templates/UnionListWriter.java index 8ac23fe46f7..a0e906166b4 100644 --- a/java/vector/src/main/codegen/templates/UnionListWriter.java +++ b/java/vector/src/main/codegen/templates/UnionListWriter.java @@ -93,7 +93,6 @@ public void setPosition(int index) { <#assign uncappedName = name?uncap_first/> <#if uncappedName == "int" ><#assign uncappedName = "integer" /> <#if !minor.typeParams?? > - @Override public ${name}Writer ${uncappedName}() { return this; @@ -104,6 +103,24 @@ public void setPosition(int index) { mapName = name; return writer.${uncappedName}(name); } + + <#else> + @Override + public ${name}Writer ${uncappedName}() { + return this; + } + + public ${name}Writer ${uncappedName}(<#list minor.typeParams as typeParam>${typeParam.type} ${typeParam.name}<#sep>, ) { + ArrowType.${name} type = new ArrowType.${name}(<#list minor.typeParams as typeParam>${typeParam.name}<#sep>, ); + writer.getWriter(type); + return this; + } + + public ${name}Writer ${uncappedName}(String name, <#list minor.typeParams as typeParam>${typeParam.type} ${typeParam.name}<#sep>, ) { + mapName = name; + return writer.${uncappedName}(name, <#list minor.typeParams as typeParam>${typeParam.name}<#sep>, ); + } + @@ -158,7 +175,7 @@ public void end() { <#assign name = minor.class?cap_first /> <#assign fields = minor.fields!type.fields /> <#assign uncappedName = name?uncap_first/> - <#if !minor.typeParams?? > + @Override public void write${name}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, ) { writer.write${name}(<#list fields as field>${field.name}<#if field_has_next>, ); @@ -170,7 +187,6 @@ public void write(${name}Holder holder) { writer.setPosition(writer.idx()+1); } - } diff --git a/java/vector/src/main/codegen/templates/UnionReader.java b/java/vector/src/main/codegen/templates/UnionReader.java index 98bb7c1f53d..0255da60eb0 100644 --- a/java/vector/src/main/codegen/templates/UnionReader.java +++ b/java/vector/src/main/codegen/templates/UnionReader.java @@ -89,10 +89,8 @@ private FieldReader getReaderForIndex(int index) { <#list type.minor as minor> <#assign name = minor.class?cap_first /> <#assign uncappedName = name?uncap_first/> - <#if !minor.typeParams?? > case ${name?upper_case}: return (FieldReader) get${name}(); - default: @@ -158,7 +156,6 @@ public int size() { <#assign friendlyType = (minor.friendlyType!minor.boxedType!type.boxedType) /> <#assign safeType=friendlyType /> <#if safeType=="byte[]"><#assign safeType="ByteArray" /> - <#if !minor.typeParams?? > private ${name}ReaderImpl ${uncappedName}Reader; @@ -178,7 +175,6 @@ public void read(Nullable${name}Holder holder){ public void copyAsValue(${name}Writer writer){ getReaderForIndex(idx()).copyAsValue(writer); } - diff --git a/java/vector/src/main/codegen/templates/UnionVector.java b/java/vector/src/main/codegen/templates/UnionVector.java index 501933f8fbc..fd3e531b9bc 100644 --- a/java/vector/src/main/codegen/templates/UnionVector.java +++ b/java/vector/src/main/codegen/templates/UnionVector.java @@ -138,16 +138,12 @@ public List getFieldInnerVectors() { throw new UnsupportedOperationException("There are no inner vectors. Use geFieldBuffers"); } - private String fieldName(MinorType type) { - return type.name().toLowerCase(); + private String fieldName(ArrowType type) { + return Types.getMinorTypeForArrowType(type).name().toLowerCase(); } - private FieldType fieldType(MinorType type) { - return FieldType.nullable(type.getType()); - } - - private T addOrGet(MinorType minorType, Class c) { - return internalMap.addOrGet(fieldName(minorType), fieldType(minorType), c); + private T addOrGet(ArrowType type, Class c) { + return internalMap.addOrGet(fieldName(type), FieldType.nullable(type), c); } @Override @@ -177,7 +173,7 @@ public long getOffsetBufferAddress() { public MapVector getMap() { if (mapVector == null) { int vectorCount = internalMap.size(); - mapVector = addOrGet(MinorType.MAP, MapVector.class); + mapVector = addOrGet(MinorType.MAP.getType(), MapVector.class); if (internalMap.size() > vectorCount) { mapVector.allocateNew(); if (callBack != null) { @@ -200,7 +196,31 @@ public MapVector getMap() { public ${name}Vector get${name}Vector() { if (${uncappedName}Vector == null) { int vectorCount = internalMap.size(); - ${uncappedName}Vector = addOrGet(MinorType.${name?upper_case}, ${name}Vector.class); + ${uncappedName}Vector = addOrGet(MinorType.${name?upper_case}.getType(), ${name}Vector.class); + if (internalMap.size() > vectorCount) { + ${uncappedName}Vector.allocateNew(); + if (callBack != null) { + callBack.doWork(); + } + } + } + return ${uncappedName}Vector; + } + <#else> + + private ${name}Vector ${uncappedName}Vector; + + public ${name}Vector get${name}Vector() { + assert ${uncappedName}Vector != null; + return ${uncappedName}Vector; + } + + public ${name}Vector get${name}Vector(<#list minor.typeParams as typeParam>${typeParam.type} ${typeParam.name}<#sep>, ) { + ArrowType type = new ArrowType.${name}(<#list minor.typeParams as typeParam>${typeParam.name}<#sep>, ); + + if (${uncappedName}Vector == null) { + int vectorCount = internalMap.size(); + ${uncappedName}Vector = addOrGet(type, ${name}Vector.class); if (internalMap.size() > vectorCount) { ${uncappedName}Vector.allocateNew(); if (callBack != null) { @@ -210,6 +230,7 @@ public MapVector getMap() { } return ${uncappedName}Vector; } + @@ -217,7 +238,7 @@ public MapVector getMap() { public ListVector getList() { if (listVector == null) { int vectorCount = internalMap.size(); - listVector = addOrGet(MinorType.LIST, ListVector.class); + listVector = addOrGet(MinorType.LIST.getType(), ListVector.class); if (internalMap.size() > vectorCount) { listVector.allocateNew(); if (callBack != null) { @@ -499,10 +520,8 @@ public Object getObject(int index) { <#assign name = minor.class?cap_first /> <#assign fields = minor.fields!type.fields /> <#assign uncappedName = name?uncap_first/> - <#if !minor.typeParams?? > case ${name?upper_case}: return get${name}Vector().getObject(index); - case MAP: @@ -599,13 +618,17 @@ public void setSafe(int index, UnionHolder holder) { <#assign name = minor.class?cap_first /> <#assign fields = minor.fields!type.fields /> <#assign uncappedName = name?uncap_first/> - <#if !minor.typeParams?? > + <#if !minor.typeParams?? > public void setSafe(int index, Nullable${name}Holder holder) { setType(index, MinorType.${name?upper_case}); get${name}Vector().setSafe(index, holder); } - - + <#else> + public void setSafe(int index, Nullable${name}Holder holder) { + setType(index, MinorType.${name?upper_case}); + get${name}Vector(<#list minor.typeParams as typeParam>holder.${typeParam.name}<#sep>, ).setSafe(index, holder); + } + diff --git a/java/vector/src/main/codegen/templates/UnionWriter.java b/java/vector/src/main/codegen/templates/UnionWriter.java index 526708a4c32..af1b732c83f 100644 --- a/java/vector/src/main/codegen/templates/UnionWriter.java +++ b/java/vector/src/main/codegen/templates/UnionWriter.java @@ -17,6 +17,7 @@ */ import org.apache.arrow.vector.complex.impl.NullableMapWriterFactory; +import org.apache.arrow.vector.types.Types; <@pp.dropOutputFile /> <@pp.changeOutputFile name="/org/apache/arrow/vector/complex/impl/UnionWriter.java" /> @@ -30,8 +31,18 @@ import org.apache.arrow.vector.complex.writer.BaseWriter; import org.apache.arrow.vector.types.Types.MinorType; -/* +/** * This class is generated using freemarker and the ${.template_name} template. + * + * Example: + *
+ * {@code
+ * UnionWriter unionWriter = new UnionWriter(unionVector);
+ * unionWriter.asFloat4().writeFloat4(1.0);
+ * unionWriter.asTimestamp(TimeUnit.SECOND, "UTC").write(1000);
+ * }
+ * 
+ * */ @SuppressWarnings("unused") public class UnionWriter extends AbstractFieldWriter implements FieldWriter { @@ -110,7 +121,40 @@ public ListWriter asList() { return getListWriter(); } + /** + * Get writer from a MinorType. For complex minor type, the method will throw excepion + * because it cannot create writer from complex minor types. For simple MinorType, it will + * create the writer. + * @param minorType + * @return + */ BaseWriter getWriter(MinorType minorType) { + switch (minorType) { + case MAP: + return getMapWriter(); + case LIST: + return getListWriter(); + <#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/> + case ${name?upper_case}: + return get${name}Writer(); + + + default: + throw new UnsupportedOperationException("Unknown type: " + minorType); + } + } + + /** + * Get writer from a ArrowType. This will create the writer if it doesn't exist. + * @param minorType + * @return + */ + BaseWriter getWriter(ArrowType type) { + MinorType minorType = Types.getMinorTypeForArrowType(type); switch (minorType) { case MAP: return getMapWriter(); @@ -124,6 +168,10 @@ BaseWriter getWriter(MinorType minorType) { <#if !minor.typeParams??> case ${name?upper_case}: return get${name}Writer(); + <#else> + case ${name?upper_case}: + ArrowType.${name} ${uncappedName}Type = (ArrowType.${name}) type; + return get${name}Writer(<#list minor.typeParams as typeParam>${uncappedName}Type.${typeParam.name}<#sep>, ); @@ -136,10 +184,10 @@ BaseWriter getWriter(MinorType minorType) { <#assign name = minor.class?cap_first /> <#assign fields = minor.fields!type.fields /> <#assign uncappedName = name?uncap_first/> - <#if !minor.typeParams?? > - private ${name}Writer ${name?uncap_first}Writer; + private ${name}Writer ${uncappedName}Writer; + <#if !minor.typeParams??> private ${name}Writer get${name}Writer() { if (${uncappedName}Writer == null) { ${uncappedName}Writer = new ${name}WriterImpl(data.get${name}Vector()); @@ -161,12 +209,49 @@ public void write(${name}Holder holder) { get${name}Writer().write${name}(<#list fields as field>holder.${field.name}<#if field_has_next>, ); } + @Override + public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, ) { + data.setType(idx(), MinorType.${name?upper_case}); + get${name}Writer().setPosition(idx()); + get${name}Writer().write${name}(<#list fields as field>${field.name}<#if field_has_next>, ); + } + + <#else> + public ${name}Writer get${name}Writer() { + // returns existing writer + ${name}Writer writer = ${uncappedName}Writer; + assert writer != null; + return writer; + } + + public ${name}Writer get${name}Writer(<#list minor.typeParams as typeParam>${typeParam.type} ${typeParam.name}<#sep>, ) { + if (${uncappedName}Writer == null) { + ${uncappedName}Writer = new ${name}WriterImpl(data.get${name}Vector(<#list minor.typeParams as typeParam>${typeParam.name}<#sep>, )); + ${uncappedName}Writer.setPosition(idx()); + writers.add(${uncappedName}Writer); + } + return ${uncappedName}Writer; + } + + public ${name}Writer as${name}(<#list minor.typeParams as typeParam>${typeParam.type} ${typeParam.name}<#sep>, ) { + data.setType(idx(), MinorType.${name?upper_case}); + return get${name}Writer(<#list minor.typeParams as typeParam>${typeParam.name}<#sep>, ); + } + + @Override + public void write(${name}Holder holder) { + data.setType(idx(), MinorType.${name?upper_case}); + get${name}Writer().setPosition(idx()); + get${name}Writer(<#list minor.typeParams as typeParam>holder.${typeParam.name}<#sep>, ).write${name}(<#list fields as field>holder.${field.name}<#if field_has_next>, ); + } + + @Override public void write${minor.class}(<#list fields as field>${field.type} ${field.name}<#if field_has_next>, ) { data.setType(idx(), MinorType.${name?upper_case}); get${name}Writer().setPosition(idx()); get${name}Writer().write${name}(<#list fields as field>${field.name}<#if field_has_next>, ); } - + @@ -206,7 +291,7 @@ public MapWriter map(String name) { <#if lowerName == "int" ><#assign lowerName = "integer" /> <#assign upperName = minor.class?upper_case /> <#assign capName = minor.class?cap_first /> - <#if !minor.typeParams?? > + <#if !minor.typeParams?? > @Override public ${capName}Writer ${lowerName}(String name) { data.setType(idx(), MinorType.MAP); @@ -220,7 +305,21 @@ public MapWriter map(String name) { getListWriter().setPosition(idx()); return getListWriter().${lowerName}(); } - + <#else> + @Override + public ${capName}Writer ${lowerName}(String name, <#list minor.typeParams as typeParam>${typeParam.type} ${typeParam.name}<#sep>, ) { + data.setType(idx(), MinorType.MAP); + getMapWriter().setPosition(idx()); + return getMapWriter().${lowerName}(name, <#list minor.typeParams as typeParam>${typeParam.name}<#sep>, ); + } + + @Override + public ${capName}Writer ${lowerName}(<#list minor.typeParams as typeParam>${typeParam.type} ${typeParam.name}<#sep>, ) { + data.setType(idx(), MinorType.LIST); + getListWriter().setPosition(idx()); + return getListWriter().${lowerName}(<#list minor.typeParams as typeParam>${typeParam.name}<#sep>, ); + } + @Override diff --git a/java/vector/src/main/java/org/apache/arrow/vector/GenerateSampleData.java b/java/vector/src/main/java/org/apache/arrow/vector/GenerateSampleData.java index 89e2a02f6ac..17cfa2970da 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/GenerateSampleData.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/GenerateSampleData.java @@ -18,6 +18,7 @@ package org.apache.arrow.vector; +import javax.annotation.Nullable; import java.math.BigDecimal; import java.nio.charset.Charset; @@ -66,26 +67,12 @@ public static void generateTestData(final ValueVector vector, final int valueCou writeTimeNanoData((TimeNanoVector) vector, valueCount); } else if (vector instanceof TimeSecVector) { writeTimeSecData((TimeSecVector) vector, valueCount); - } else if (vector instanceof TimeStampSecVector) { - writeTimeStampData((TimeStampSecVector) vector, valueCount); - } else if (vector instanceof TimeStampMicroVector) { - writeTimeStampData((TimeStampMicroVector) vector, valueCount); - } else if (vector instanceof TimeStampMilliVector) { - writeTimeStampData((TimeStampMilliVector) vector, valueCount); - } else if (vector instanceof TimeStampNanoVector) { - writeTimeStampData((TimeStampNanoVector) vector, valueCount); - } else if (vector instanceof TimeStampSecTZVector) { - writeTimeStampData((TimeStampSecTZVector) vector, valueCount); - } else if (vector instanceof TimeStampMicroTZVector) { - writeTimeStampData((TimeStampMicroTZVector) vector, valueCount); - } else if (vector instanceof TimeStampMilliTZVector) { - writeTimeStampData((TimeStampMilliTZVector) vector, valueCount); - } else if (vector instanceof TimeStampNanoTZVector) { - writeTimeStampData((TimeStampNanoTZVector) vector, valueCount); + } else if (vector instanceof TimestampVector) { + writeTimeStampData((TimestampVector) vector, valueCount); } } - private static void writeTimeStampData(TimeStampVector vector, int valueCount) { + private static void writeTimeStampData(TimestampVector vector, int valueCount) { final long even = 100000; final long odd = 200000; for (int i = 0; i < valueCount; i++) { diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroTZVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroTZVector.java deleted file mode 100644 index bfe330a1e40..00000000000 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroTZVector.java +++ /dev/null @@ -1,217 +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. - */ - -package org.apache.arrow.vector; - -import org.apache.arrow.memory.BufferAllocator; -import org.apache.arrow.vector.complex.impl.TimeStampMicroTZReaderImpl; -import org.apache.arrow.vector.complex.reader.FieldReader; -import org.apache.arrow.vector.holders.TimeStampMicroTZHolder; -import org.apache.arrow.vector.holders.NullableTimeStampMicroTZHolder; -import org.apache.arrow.vector.types.TimeUnit; -import org.apache.arrow.vector.types.Types; -import org.apache.arrow.vector.types.pojo.FieldType; -import org.apache.arrow.vector.util.TransferPair; - -/** - * TimeStampMicroTZVector implements a fixed width vector (8 bytes) of - * timestamp (microsecond resolution) values which could be null. A validity buffer - * (bit vector) is maintained to track which elements in the vector are null. - */ -public class TimeStampMicroTZVector extends TimeStampVector { - private final FieldReader reader; - private final String timeZone; - - /** - * Instantiate a TimeStampMicroTZVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param allocator allocator for memory management. - */ - public TimeStampMicroTZVector(String name, BufferAllocator allocator, String timeZone) { - this(name, FieldType.nullable(new org.apache.arrow.vector.types.pojo.ArrowType.Timestamp(TimeUnit.MICROSECOND, timeZone)), - allocator); - } - - /** - * Instantiate a TimeStampMicroTZVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param fieldType type of Field materialized by this vector - * @param allocator allocator for memory management. - */ - public TimeStampMicroTZVector(String name, FieldType fieldType, BufferAllocator allocator) { - super(name, fieldType, allocator); - org.apache.arrow.vector.types.pojo.ArrowType.Timestamp arrowType = (org.apache.arrow.vector.types.pojo.ArrowType.Timestamp) fieldType.getType(); - timeZone = arrowType.getTimezone(); - reader = new TimeStampMicroTZReaderImpl(TimeStampMicroTZVector.this); - } - - /** - * Get a reader that supports reading values from this vector - * @return Field Reader for this vector - */ - @Override - public FieldReader getReader() { - return reader; - } - - /** - * Get minor type for this vector. The vector holds values belonging - * to a particular type. - * @return {@link org.apache.arrow.vector.types.Types.MinorType} - */ - @Override - public Types.MinorType getMinorType() { - return Types.MinorType.TIMESTAMPMICROTZ; - } - - - /****************************************************************** - * * - * vector value retrieval methods * - * * - ******************************************************************/ - - - /** - * Get the element at the given index from the vector and - * sets the state in holder. If element at given index - * is null, holder.isSet will be zero. - * - * @param index position of element - */ - public void get(int index, NullableTimeStampMicroTZHolder holder) { - if (isSet(index) == 0) { - holder.isSet = 0; - return; - } - holder.isSet = 1; - holder.value = valueBuffer.getLong(index * TYPE_WIDTH); - } - - /** - * Same as {@link #get(int)}. - * - * @param index position of element - * @return element at given index - */ - public Long getObject(int index) { - if (isSet(index) == 0) { - return null; - } else { - return valueBuffer.getLong(index * TYPE_WIDTH); - } - } - - - /****************************************************************** - * * - * vector value setter methods * - * * - ******************************************************************/ - - - /** - * Set the element at the given index to the value set in data holder. - * If the value in holder is not indicated as set, element in the - * at the given index will be null. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void set(int index, NullableTimeStampMicroTZHolder holder) throws IllegalArgumentException { - if (holder.isSet < 0) { - throw new IllegalArgumentException(); - } else if (holder.isSet > 0) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } else { - BitVectorHelper.setValidityBit(validityBuffer, index, 0); - } - } - - /** - * Set the element at the given index to the value set in data holder. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void set(int index, TimeStampMicroTZHolder holder) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } - - /** - * Same as {@link #set(int, NullableTimeStampMicroTZHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void setSafe(int index, NullableTimeStampMicroTZHolder holder) throws IllegalArgumentException { - handleSafe(index); - set(index, holder); - } - - /** - * Same as {@link #set(int, TimeStampMicroTZHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void setSafe(int index, TimeStampMicroTZHolder holder) { - handleSafe(index); - set(index, holder); - } - - - /****************************************************************** - * * - * vector transfer * - * * - ******************************************************************/ - - - /** - * Construct a TransferPair comprising of this and and a target vector of - * the same type. - * @param ref name of the target vector - * @param allocator allocator for the target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair getTransferPair(String ref, BufferAllocator allocator) { - TimeStampMicroTZVector to = new TimeStampMicroTZVector(ref, - field.getFieldType(), allocator); - return new TransferImpl(to); - } - - /** - * Construct a TransferPair with a desired target vector of the same type. - * @param to target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair makeTransferPair(ValueVector to) { - return new TransferImpl((TimeStampMicroTZVector) to); - } -} \ No newline at end of file diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroVector.java deleted file mode 100644 index 85b615d8f57..00000000000 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMicroVector.java +++ /dev/null @@ -1,219 +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. - */ - -package org.apache.arrow.vector; - -import org.apache.arrow.memory.BufferAllocator; -import org.apache.arrow.vector.complex.impl.TimeStampMicroReaderImpl; -import org.apache.arrow.vector.complex.reader.FieldReader; -import org.apache.arrow.vector.holders.TimeStampMicroHolder; -import org.apache.arrow.vector.holders.NullableTimeStampMicroHolder; -import org.apache.arrow.vector.types.Types; -import org.apache.arrow.vector.types.pojo.FieldType; -import org.apache.arrow.vector.util.TransferPair; -import org.joda.time.LocalDateTime; - -/** - * TimeStampMicroVector implements a fixed width vector (8 bytes) of - * timestamp (microsecond resolution) values which could be null. A validity buffer - * (bit vector) is maintained to track which elements in the vector are null. - */ -public class TimeStampMicroVector extends TimeStampVector { - private final FieldReader reader; - - /** - * Instantiate a TimeStampMicroVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param allocator allocator for memory management. - */ - public TimeStampMicroVector(String name, BufferAllocator allocator) { - this(name, FieldType.nullable(Types.MinorType.TIMESTAMPMICRO.getType()), - allocator); - } - - /** - * Instantiate a TimeStampMicroVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param fieldType type of Field materialized by this vector - * @param allocator allocator for memory management. - */ - public TimeStampMicroVector(String name, FieldType fieldType, BufferAllocator allocator) { - super(name, fieldType, allocator); - reader = new TimeStampMicroReaderImpl(TimeStampMicroVector.this); - } - - /** - * Get a reader that supports reading values from this vector - * @return Field Reader for this vector - */ - @Override - public FieldReader getReader() { - return reader; - } - - /** - * Get minor type for this vector. The vector holds values belonging - * to a particular type. - * @return {@link org.apache.arrow.vector.types.Types.MinorType} - */ - @Override - public Types.MinorType getMinorType() { - return Types.MinorType.TIMESTAMPMICRO; - } - - - /****************************************************************** - * * - * vector value retrieval methods * - * * - ******************************************************************/ - - - /** - * Get the element at the given index from the vector and - * sets the state in holder. If element at given index - * is null, holder.isSet will be zero. - * - * @param index position of element - */ - public void get(int index, NullableTimeStampMicroHolder holder) { - if (isSet(index) == 0) { - holder.isSet = 0; - return; - } - holder.isSet = 1; - holder.value = valueBuffer.getLong(index * TYPE_WIDTH); - } - - /** - * Same as {@link #get(int)}. - * - * @param index position of element - * @return element at given index - */ - public LocalDateTime getObject(int index) { - if (isSet(index) == 0) { - return null; - } else { - /* value is truncated when converting microseconds to milliseconds in order to use DateTime type */ - final long micros = valueBuffer.getLong(index * TYPE_WIDTH); - final long millis = java.util.concurrent.TimeUnit.MICROSECONDS.toMillis(micros); - final org.joda.time.LocalDateTime localDateTime = new org.joda.time.LocalDateTime(millis, - org.joda.time.DateTimeZone.UTC); - return localDateTime; - } - } - - - /****************************************************************** - * * - * vector value setter methods * - * * - ******************************************************************/ - - - /** - * Set the element at the given index to the value set in data holder. - * If the value in holder is not indicated as set, element in the - * at the given index will be null. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void set(int index, NullableTimeStampMicroHolder holder) throws IllegalArgumentException { - if (holder.isSet < 0) { - throw new IllegalArgumentException(); - } else if (holder.isSet > 0) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } else { - BitVectorHelper.setValidityBit(validityBuffer, index, 0); - } - } - - /** - * Set the element at the given index to the value set in data holder. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void set(int index, TimeStampMicroHolder holder) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } - - /** - * Same as {@link #set(int, NullableTimeStampMicroHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void setSafe(int index, NullableTimeStampMicroHolder holder) throws IllegalArgumentException { - handleSafe(index); - set(index, holder); - } - - /** - * Same as {@link #set(int, TimeStampMicroHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void setSafe(int index, TimeStampMicroHolder holder) { - handleSafe(index); - set(index, holder); - } - - - /****************************************************************** - * * - * vector transfer * - * * - ******************************************************************/ - - - /** - * Construct a TransferPair comprising of this and and a target vector of - * the same type. - * @param ref name of the target vector - * @param allocator allocator for the target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair getTransferPair(String ref, BufferAllocator allocator) { - TimeStampMicroVector to = new TimeStampMicroVector(ref, - field.getFieldType(), allocator); - return new TransferImpl(to); - } - - /** - * Construct a TransferPair with a desired target vector of the same type. - * @param to target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair makeTransferPair(ValueVector to) { - return new TransferImpl((TimeStampMicroVector) to); - } -} \ No newline at end of file diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliTZVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliTZVector.java deleted file mode 100644 index 9d68b564492..00000000000 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliTZVector.java +++ /dev/null @@ -1,216 +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. - */ - -package org.apache.arrow.vector; - -import org.apache.arrow.memory.BufferAllocator; -import org.apache.arrow.vector.complex.impl.TimeStampMilliTZReaderImpl; -import org.apache.arrow.vector.complex.reader.FieldReader; -import org.apache.arrow.vector.holders.TimeStampMilliTZHolder; -import org.apache.arrow.vector.holders.NullableTimeStampMilliTZHolder; -import org.apache.arrow.vector.types.TimeUnit; -import org.apache.arrow.vector.types.Types; -import org.apache.arrow.vector.types.pojo.FieldType; -import org.apache.arrow.vector.util.TransferPair; - -/** - * TimeStampMilliTZVector implements a fixed width vector (8 bytes) of - * timestamp (millisecond resolution) values which could be null. A validity buffer - * (bit vector) is maintained to track which elements in the vector are null. - */ -public class TimeStampMilliTZVector extends TimeStampVector { - private final FieldReader reader; - private final String timeZone; - - /** - * Instantiate a TimeStampMilliTZVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param allocator allocator for memory management. - */ - public TimeStampMilliTZVector(String name, BufferAllocator allocator, String timeZone) { - this(name, FieldType.nullable(new org.apache.arrow.vector.types.pojo.ArrowType.Timestamp(TimeUnit.MILLISECOND, timeZone)), - allocator); - } - - /** - * Instantiate a TimeStampMilliTZVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param fieldType type of Field materialized by this vector - * @param allocator allocator for memory management. - */ - public TimeStampMilliTZVector(String name, FieldType fieldType, BufferAllocator allocator) { - super(name, fieldType, allocator); - org.apache.arrow.vector.types.pojo.ArrowType.Timestamp arrowType = (org.apache.arrow.vector.types.pojo.ArrowType.Timestamp) fieldType.getType(); - timeZone = arrowType.getTimezone(); - reader = new TimeStampMilliTZReaderImpl(TimeStampMilliTZVector.this); - } - - /** - * Get a reader that supports reading values from this vector - * @return Field Reader for this vector - */ - @Override - public FieldReader getReader() { - return reader; - } - - /** - * Get minor type for this vector. The vector holds values belonging - * to a particular type. - * @return {@link org.apache.arrow.vector.types.Types.MinorType} - */ - @Override - public Types.MinorType getMinorType() { - return Types.MinorType.TIMESTAMPMILLITZ; - } - - - /****************************************************************** - * * - * vector value retrieval methods * - * * - ******************************************************************/ - - - /** - * Get the element at the given index from the vector and - * sets the state in holder. If element at given index - * is null, holder.isSet will be zero. - * - * @param index position of element - */ - public void get(int index, NullableTimeStampMilliTZHolder holder) { - if (isSet(index) == 0) { - holder.isSet = 0; - return; - } - holder.isSet = 1; - holder.value = valueBuffer.getLong(index * TYPE_WIDTH); - } - - /** - * Same as {@link #get(int)}. - * - * @param index position of element - * @return element at given index - */ - public Long getObject(int index) { - if (isSet(index) == 0) { - return null; - } else { - return valueBuffer.getLong(index * TYPE_WIDTH); - } - } - - - /****************************************************************** - * * - * vector value setter methods * - * * - ******************************************************************/ - - - /** - * Set the element at the given index to the value set in data holder. - * If the value in holder is not indicated as set, element in the - * at the given index will be null. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void set(int index, NullableTimeStampMilliTZHolder holder) throws IllegalArgumentException { - if (holder.isSet < 0) { - throw new IllegalArgumentException(); - } else if (holder.isSet > 0) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } else { - BitVectorHelper.setValidityBit(validityBuffer, index, 0); - } - } - - /** - * Set the element at the given index to the value set in data holder. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void set(int index, TimeStampMilliTZHolder holder) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } - - /** - * Same as {@link #set(int, NullableTimeStampMilliTZHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void setSafe(int index, NullableTimeStampMilliTZHolder holder) throws IllegalArgumentException { - handleSafe(index); - set(index, holder); - } - - /** - * Same as {@link #set(int, TimeStampMilliTZHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void setSafe(int index, TimeStampMilliTZHolder holder) { - handleSafe(index); - set(index, holder); - } - - - /****************************************************************** - * * - * vector transfer * - * * - ******************************************************************/ - - /** - * Construct a TransferPair comprising of this and and a target vector of - * the same type. - * @param ref name of the target vector - * @param allocator allocator for the target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair getTransferPair(String ref, BufferAllocator allocator) { - TimeStampMilliTZVector to = new TimeStampMilliTZVector(ref, - field.getFieldType(), allocator); - return new TransferImpl(to); - } - - /** - * Construct a TransferPair with a desired target vector of the same type. - * @param to target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair makeTransferPair(ValueVector to) { - return new TransferImpl((TimeStampMilliTZVector) to); - } -} \ No newline at end of file diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliVector.java deleted file mode 100644 index 7e8a1d0e2a8..00000000000 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampMilliVector.java +++ /dev/null @@ -1,217 +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. - */ - -package org.apache.arrow.vector; - -import org.apache.arrow.memory.BufferAllocator; -import org.apache.arrow.vector.complex.impl.TimeStampMilliReaderImpl; -import org.apache.arrow.vector.complex.reader.FieldReader; -import org.apache.arrow.vector.holders.TimeStampMilliHolder; -import org.apache.arrow.vector.holders.NullableTimeStampMilliHolder; -import org.apache.arrow.vector.types.Types; -import org.apache.arrow.vector.types.pojo.FieldType; -import org.apache.arrow.vector.util.TransferPair; -import org.joda.time.LocalDateTime; - -/** - * TimeStampMilliVector implements a fixed width vector (8 bytes) of - * timestamp (millisecond resolution) values which could be null. A validity buffer - * (bit vector) is maintained to track which elements in the vector are null. - */ -public class TimeStampMilliVector extends TimeStampVector { - private final FieldReader reader; - - /** - * Instantiate a TimeStampMilliVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param allocator allocator for memory management. - */ - public TimeStampMilliVector(String name, BufferAllocator allocator) { - this(name, FieldType.nullable(Types.MinorType.TIMESTAMPMILLI.getType()), - allocator); - } - - /** - * Instantiate a TimeStampMilliVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param fieldType type of Field materialized by this vector - * @param allocator allocator for memory management. - */ - public TimeStampMilliVector(String name, FieldType fieldType, BufferAllocator allocator) { - super(name, fieldType, allocator); - reader = new TimeStampMilliReaderImpl(TimeStampMilliVector.this); - } - - /** - * Get a reader that supports reading values from this vector - * @return Field Reader for this vector - */ - @Override - public FieldReader getReader() { - return reader; - } - - /** - * Get minor type for this vector. The vector holds values belonging - * to a particular type. - * @return {@link org.apache.arrow.vector.types.Types.MinorType} - */ - @Override - public Types.MinorType getMinorType() { - return Types.MinorType.TIMESTAMPMILLI; - } - - - /****************************************************************** - * * - * vector value retrieval methods * - * * - ******************************************************************/ - - - /** - * Get the element at the given index from the vector and - * sets the state in holder. If element at given index - * is null, holder.isSet will be zero. - * - * @param index position of element - */ - public void get(int index, NullableTimeStampMilliHolder holder) { - if (isSet(index) == 0) { - holder.isSet = 0; - return; - } - holder.isSet = 1; - holder.value = valueBuffer.getLong(index * TYPE_WIDTH); - } - - /** - * Same as {@link #get(int)}. - * - * @param index position of element - * @return element at given index - */ - public LocalDateTime getObject(int index) { - if (isSet(index) == 0) { - return null; - } else { - final long millis = valueBuffer.getLong(index * TYPE_WIDTH); - final org.joda.time.LocalDateTime localDateTime = new org.joda.time.LocalDateTime(millis, - org.joda.time.DateTimeZone.UTC); - return localDateTime; - } - } - - - /****************************************************************** - * * - * vector value setter methods * - * * - ******************************************************************/ - - - /** - * Set the element at the given index to the value set in data holder. - * If the value in holder is not indicated as set, element in the - * at the given index will be null. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void set(int index, NullableTimeStampMilliHolder holder) throws IllegalArgumentException { - if (holder.isSet < 0) { - throw new IllegalArgumentException(); - } else if (holder.isSet > 0) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } else { - BitVectorHelper.setValidityBit(validityBuffer, index, 0); - } - } - - /** - * Set the element at the given index to the value set in data holder. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void set(int index, TimeStampMilliHolder holder) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } - - /** - * Same as {@link #set(int, NullableTimeStampMilliHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void setSafe(int index, NullableTimeStampMilliHolder holder) throws IllegalArgumentException { - handleSafe(index); - set(index, holder); - } - - /** - * Same as {@link #set(int, TimeStampMilliHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void setSafe(int index, TimeStampMilliHolder holder) { - handleSafe(index); - set(index, holder); - } - - - /****************************************************************** - * * - * vector transfer * - * * - ******************************************************************/ - - - /** - * Construct a TransferPair comprising of this and and a target vector of - * the same type. - * @param ref name of the target vector - * @param allocator allocator for the target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair getTransferPair(String ref, BufferAllocator allocator) { - TimeStampMilliVector to = new TimeStampMilliVector(ref, - field.getFieldType(), allocator); - return new TransferImpl(to); - } - - /** - * Construct a TransferPair with a desired target vector of the same type. - * @param to target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair makeTransferPair(ValueVector to) { - return new TransferImpl((TimeStampMilliVector) to); - } -} \ No newline at end of file diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoTZVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoTZVector.java deleted file mode 100644 index e0361820137..00000000000 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoTZVector.java +++ /dev/null @@ -1,217 +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. - */ - -package org.apache.arrow.vector; - -import org.apache.arrow.memory.BufferAllocator; -import org.apache.arrow.vector.complex.impl.TimeStampNanoTZReaderImpl; -import org.apache.arrow.vector.complex.reader.FieldReader; -import org.apache.arrow.vector.holders.TimeStampNanoTZHolder; -import org.apache.arrow.vector.holders.NullableTimeStampNanoTZHolder; -import org.apache.arrow.vector.types.TimeUnit; -import org.apache.arrow.vector.types.Types; -import org.apache.arrow.vector.types.pojo.FieldType; -import org.apache.arrow.vector.util.TransferPair; - -/** - * TimeStampNanoTZVector implements a fixed width vector (8 bytes) of - * timestamp (nanosecond resolution) values which could be null. A validity buffer - * (bit vector) is maintained to track which elements in the vector are null. - */ -public class TimeStampNanoTZVector extends TimeStampVector { - private final FieldReader reader; - private final String timeZone; - - /** - * Instantiate a TimeStampNanoTZVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param allocator allocator for memory management. - */ - public TimeStampNanoTZVector(String name, BufferAllocator allocator, String timeZone) { - this(name, FieldType.nullable(new org.apache.arrow.vector.types.pojo.ArrowType.Timestamp(TimeUnit.NANOSECOND, timeZone)), - allocator); - } - - /** - * Instantiate a TimeStampNanoTZVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param fieldType type of Field materialized by this vector - * @param allocator allocator for memory management. - */ - public TimeStampNanoTZVector(String name, FieldType fieldType, BufferAllocator allocator) { - super(name, fieldType, allocator); - org.apache.arrow.vector.types.pojo.ArrowType.Timestamp arrowType = (org.apache.arrow.vector.types.pojo.ArrowType.Timestamp) fieldType.getType(); - timeZone = arrowType.getTimezone(); - reader = new TimeStampNanoTZReaderImpl(TimeStampNanoTZVector.this); - } - - /** - * Get a reader that supports reading values from this vector - * @return Field Reader for this vector - */ - @Override - public FieldReader getReader() { - return reader; - } - - /** - * Get minor type for this vector. The vector holds values belonging - * to a particular type. - * @return {@link org.apache.arrow.vector.types.Types.MinorType} - */ - @Override - public Types.MinorType getMinorType() { - return Types.MinorType.TIMESTAMPNANOTZ; - } - - - /****************************************************************** - * * - * vector value retrieval methods * - * * - ******************************************************************/ - - - /** - * Get the element at the given index from the vector and - * sets the state in holder. If element at given index - * is null, holder.isSet will be zero. - * - * @param index position of element - */ - public void get(int index, NullableTimeStampNanoTZHolder holder) { - if (isSet(index) == 0) { - holder.isSet = 0; - return; - } - holder.isSet = 1; - holder.value = valueBuffer.getLong(index * TYPE_WIDTH); - } - - /** - * Same as {@link #get(int)}. - * - * @param index position of element - * @return element at given index - */ - public Long getObject(int index) { - if (isSet(index) == 0) { - return null; - } else { - return valueBuffer.getLong(index * TYPE_WIDTH); - } - } - - - /****************************************************************** - * * - * vector value setter methods * - * * - ******************************************************************/ - - - /** - * Set the element at the given index to the value set in data holder. - * If the value in holder is not indicated as set, element in the - * at the given index will be null. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void set(int index, NullableTimeStampNanoTZHolder holder) throws IllegalArgumentException { - if (holder.isSet < 0) { - throw new IllegalArgumentException(); - } else if (holder.isSet > 0) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } else { - BitVectorHelper.setValidityBit(validityBuffer, index, 0); - } - } - - /** - * Set the element at the given index to the value set in data holder. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void set(int index, TimeStampNanoTZHolder holder) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } - - /** - * Same as {@link #set(int, NullableTimeStampNanoTZHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void setSafe(int index, NullableTimeStampNanoTZHolder holder) throws IllegalArgumentException { - handleSafe(index); - set(index, holder); - } - - /** - * Same as {@link #set(int, TimeStampNanoTZHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void setSafe(int index, TimeStampNanoTZHolder holder) { - handleSafe(index); - set(index, holder); - } - - - /****************************************************************** - * * - * vector transfer * - * * - ******************************************************************/ - - - /** - * Construct a TransferPair comprising of this and and a target vector of - * the same type. - * @param ref name of the target vector - * @param allocator allocator for the target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair getTransferPair(String ref, BufferAllocator allocator) { - TimeStampNanoTZVector to = new TimeStampNanoTZVector(ref, - field.getFieldType(), allocator); - return new TransferImpl(to); - } - - /** - * Construct a TransferPair with a desired target vector of the same type. - * @param to target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair makeTransferPair(ValueVector to) { - return new TransferImpl((TimeStampNanoTZVector) to); - } -} \ No newline at end of file diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoVector.java deleted file mode 100644 index fdf5d26945b..00000000000 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampNanoVector.java +++ /dev/null @@ -1,218 +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. - */ - -package org.apache.arrow.vector; - -import org.apache.arrow.memory.BufferAllocator; -import org.apache.arrow.vector.complex.impl.TimeStampNanoReaderImpl; -import org.apache.arrow.vector.complex.reader.FieldReader; -import org.apache.arrow.vector.holders.TimeStampNanoHolder; -import org.apache.arrow.vector.holders.NullableTimeStampNanoHolder; -import org.apache.arrow.vector.types.Types; -import org.apache.arrow.vector.types.pojo.FieldType; -import org.apache.arrow.vector.util.TransferPair; -import org.joda.time.LocalDateTime; - -/** - * TimeStampNanoVector implements a fixed width vector (8 bytes) of - * timestamp (nanosecond resolution) values which could be null. A validity buffer - * (bit vector) is maintained to track which elements in the vector are null. - */ -public class TimeStampNanoVector extends TimeStampVector { - private final FieldReader reader; - - /** - * Instantiate a TimeStampNanoVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param allocator allocator for memory management. - */ - public TimeStampNanoVector(String name, BufferAllocator allocator) { - this(name, FieldType.nullable(Types.MinorType.TIMESTAMPNANO.getType()), - allocator); - } - - /** - * Instantiate a TimeStampNanoVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param fieldType type of Field materialized by this vector - * @param allocator allocator for memory management. - */ - public TimeStampNanoVector(String name, FieldType fieldType, BufferAllocator allocator) { - super(name, fieldType, allocator); - reader = new TimeStampNanoReaderImpl(TimeStampNanoVector.this); - } - - /** - * Get a reader that supports reading values from this vector - * @return Field Reader for this vector - */ - @Override - public FieldReader getReader() { - return reader; - } - - /** - * Get minor type for this vector. The vector holds values belonging - * to a particular type. - * @return {@link org.apache.arrow.vector.types.Types.MinorType} - */ - @Override - public Types.MinorType getMinorType() { - return Types.MinorType.TIMESTAMPNANO; - } - - - /****************************************************************** - * * - * vector value retrieval methods * - * * - ******************************************************************/ - - - /** - * Get the element at the given index from the vector and - * sets the state in holder. If element at given index - * is null, holder.isSet will be zero. - * - * @param index position of element - */ - public void get(int index, NullableTimeStampNanoHolder holder) { - if (isSet(index) == 0) { - holder.isSet = 0; - return; - } - holder.isSet = 1; - holder.value = valueBuffer.getLong(index * TYPE_WIDTH); - } - - /** - * Same as {@link #get(int)}. - * - * @param index position of element - * @return element at given index - */ - public LocalDateTime getObject(int index) { - if (isSet(index) == 0) { - return null; - } else { - final long nanos = valueBuffer.getLong(index * TYPE_WIDTH); - final long millis = java.util.concurrent.TimeUnit.NANOSECONDS.toMillis(nanos); - final org.joda.time.LocalDateTime localDateTime = new org.joda.time.LocalDateTime(millis, - org.joda.time.DateTimeZone.UTC); - return localDateTime; - } - } - - - /****************************************************************** - * * - * vector value setter methods * - * * - ******************************************************************/ - - - /** - * Set the element at the given index to the value set in data holder. - * If the value in holder is not indicated as set, element in the - * at the given index will be null. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void set(int index, NullableTimeStampNanoHolder holder) throws IllegalArgumentException { - if (holder.isSet < 0) { - throw new IllegalArgumentException(); - } else if (holder.isSet > 0) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } else { - BitVectorHelper.setValidityBit(validityBuffer, index, 0); - } - } - - /** - * Set the element at the given index to the value set in data holder. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void set(int index, TimeStampNanoHolder holder) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } - - /** - * Same as {@link #set(int, NullableTimeStampNanoHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void setSafe(int index, NullableTimeStampNanoHolder holder) throws IllegalArgumentException { - handleSafe(index); - set(index, holder); - } - - /** - * Same as {@link #set(int, TimeStampNanoHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void setSafe(int index, TimeStampNanoHolder holder) { - handleSafe(index); - set(index, holder); - } - - - /****************************************************************** - * * - * vector transfer * - * * - ******************************************************************/ - - - /** - * Construct a TransferPair comprising of this and and a target vector of - * the same type. - * @param ref name of the target vector - * @param allocator allocator for the target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair getTransferPair(String ref, BufferAllocator allocator) { - TimeStampNanoVector to = new TimeStampNanoVector(ref, - field.getFieldType(), allocator); - return new TransferImpl(to); - } - - /** - * Construct a TransferPair with a desired target vector of the same type. - * @param to target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair makeTransferPair(ValueVector to) { - return new TransferImpl((TimeStampNanoVector) to); - } -} \ No newline at end of file diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecTZVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecTZVector.java deleted file mode 100644 index 201f1c317d0..00000000000 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecTZVector.java +++ /dev/null @@ -1,215 +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. - */ - -package org.apache.arrow.vector; - -import org.apache.arrow.memory.BufferAllocator; -import org.apache.arrow.vector.complex.impl.TimeStampSecTZReaderImpl; -import org.apache.arrow.vector.complex.reader.FieldReader; -import org.apache.arrow.vector.holders.TimeStampSecTZHolder; -import org.apache.arrow.vector.holders.NullableTimeStampSecTZHolder; -import org.apache.arrow.vector.types.Types; -import org.apache.arrow.vector.types.pojo.FieldType; -import org.apache.arrow.vector.util.TransferPair; - -/** - * TimeStampSecTZVector implements a fixed width vector (8 bytes) of - * timestamp (seconds resolution) values which could be null. A validity buffer - * (bit vector) is maintained to track which elements in the vector are null. - */ -public class TimeStampSecTZVector extends TimeStampVector { - private final FieldReader reader; - private final String timeZone; - - /** - * Instantiate a TimeStampSecTZVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param allocator allocator for memory management. - */ - public TimeStampSecTZVector(String name, BufferAllocator allocator, String timeZone) { - this(name, FieldType.nullable(new org.apache.arrow.vector.types.pojo.ArrowType.Timestamp(org.apache.arrow.vector.types.TimeUnit.SECOND, timeZone)), - allocator); - } - - /** - * Instantiate a TimeStampSecTZVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param fieldType type of Field materialized by this vector - * @param allocator allocator for memory management. - */ - public TimeStampSecTZVector(String name, FieldType fieldType, BufferAllocator allocator) { - super(name, fieldType, allocator); - org.apache.arrow.vector.types.pojo.ArrowType.Timestamp arrowType = (org.apache.arrow.vector.types.pojo.ArrowType.Timestamp) fieldType.getType(); - timeZone = arrowType.getTimezone(); - reader = new TimeStampSecTZReaderImpl(TimeStampSecTZVector.this); - } - - /** - * Get a reader that supports reading values from this vector - * @return Field Reader for this vector - */ - @Override - public FieldReader getReader() { - return reader; - } - - /** - * Get minor type for this vector. The vector holds values belonging - * to a particular type. - * @return {@link org.apache.arrow.vector.types.Types.MinorType} - */ - @Override - public Types.MinorType getMinorType() { - return Types.MinorType.TIMESTAMPSECTZ; - } - - - /****************************************************************** - * * - * vector value retrieval methods * - * * - ******************************************************************/ - - - /** - * Get the element at the given index from the vector and - * sets the state in holder. If element at given index - * is null, holder.isSet will be zero. - * - * @param index position of element - */ - public void get(int index, NullableTimeStampSecTZHolder holder) { - if (isSet(index) == 0) { - holder.isSet = 0; - return; - } - holder.isSet = 1; - holder.value = valueBuffer.getLong(index * TYPE_WIDTH); - } - - /** - * Same as {@link #get(int)}. - * - * @param index position of element - * @return element at given index - */ - public Long getObject(int index) { - if (isSet(index) == 0) { - return null; - } else { - return valueBuffer.getLong(index * TYPE_WIDTH); - } - } - - - /****************************************************************** - * * - * vector value setter methods * - * * - ******************************************************************/ - - - /** - * Set the element at the given index to the value set in data holder. - * If the value in holder is not indicated as set, element in the - * at the given index will be null. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void set(int index, NullableTimeStampSecTZHolder holder) throws IllegalArgumentException { - if (holder.isSet < 0) { - throw new IllegalArgumentException(); - } else if (holder.isSet > 0) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } else { - BitVectorHelper.setValidityBit(validityBuffer, index, 0); - } - } - - /** - * Set the element at the given index to the value set in data holder. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void set(int index, TimeStampSecTZHolder holder) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } - - /** - * Same as {@link #set(int, NullableTimeStampSecTZHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void setSafe(int index, NullableTimeStampSecTZHolder holder) throws IllegalArgumentException { - handleSafe(index); - set(index, holder); - } - - /** - * Same as {@link #set(int, TimeStampSecTZHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void setSafe(int index, TimeStampSecTZHolder holder) { - handleSafe(index); - set(index, holder); - } - - - /****************************************************************** - * * - * vector transfer * - * * - ******************************************************************/ - - /** - * Construct a TransferPair comprising of this and and a target vector of - * the same type. - * @param ref name of the target vector - * @param allocator allocator for the target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair getTransferPair(String ref, BufferAllocator allocator) { - TimeStampSecTZVector to = new TimeStampSecTZVector(ref, - field.getFieldType(), allocator); - return new TransferImpl(to); - } - - /** - * Construct a TransferPair with a desired target vector of the same type. - * @param to target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair makeTransferPair(ValueVector to) { - return new TransferImpl((TimeStampSecTZVector) to); - } -} \ No newline at end of file diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecVector.java deleted file mode 100644 index 4bcd4f7bf00..00000000000 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampSecVector.java +++ /dev/null @@ -1,218 +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. - */ - -package org.apache.arrow.vector; - -import org.apache.arrow.memory.BufferAllocator; -import org.apache.arrow.vector.complex.impl.TimeStampSecReaderImpl; -import org.apache.arrow.vector.complex.reader.FieldReader; -import org.apache.arrow.vector.holders.TimeStampSecHolder; -import org.apache.arrow.vector.holders.NullableTimeStampSecHolder; -import org.apache.arrow.vector.types.Types; -import org.apache.arrow.vector.types.pojo.FieldType; -import org.apache.arrow.vector.util.TransferPair; -import org.joda.time.LocalDateTime; - -/** - * TimeStampSecVector implements a fixed width vector (8 bytes) of - * timestamp (seconds resolution) values which could be null. A validity buffer (bit vector) is - * maintained to track which elements in the vector are null. - */ -public class TimeStampSecVector extends TimeStampVector { - private final FieldReader reader; - - /** - * Instantiate a TimeStampSecVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param allocator allocator for memory management. - */ - public TimeStampSecVector(String name, BufferAllocator allocator) { - this(name, FieldType.nullable(Types.MinorType.TIMESTAMPSEC.getType()), - allocator); - } - - /** - * Instantiate a TimeStampSecVector. This doesn't allocate any memory for - * the data in vector. - * @param name name of the vector - * @param fieldType type of Field materialized by this vector - * @param allocator allocator for memory management. - */ - public TimeStampSecVector(String name, FieldType fieldType, BufferAllocator allocator) { - super(name, fieldType, allocator); - reader = new TimeStampSecReaderImpl(TimeStampSecVector.this); - } - - /** - * Get a reader that supports reading values from this vector - * @return Field Reader for this vector - */ - @Override - public FieldReader getReader() { - return reader; - } - - /** - * Get minor type for this vector. The vector holds values belonging - * to a particular type. - * @return {@link org.apache.arrow.vector.types.Types.MinorType} - */ - @Override - public Types.MinorType getMinorType() { - return Types.MinorType.TIMESTAMPSEC; - } - - - /****************************************************************** - * * - * vector value retrieval methods * - * * - ******************************************************************/ - - - /** - * Get the element at the given index from the vector and - * sets the state in holder. If element at given index - * is null, holder.isSet will be zero. - * - * @param index position of element - */ - public void get(int index, NullableTimeStampSecHolder holder) { - if (isSet(index) == 0) { - holder.isSet = 0; - return; - } - holder.isSet = 1; - holder.value = valueBuffer.getLong(index * TYPE_WIDTH); - } - - /** - * Same as {@link #get(int)}. - * - * @param index position of element - * @return element at given index - */ - public LocalDateTime getObject(int index) { - if (isSet(index) == 0) { - return null; - } else { - final long secs = valueBuffer.getLong(index * TYPE_WIDTH); - final long millis = java.util.concurrent.TimeUnit.SECONDS.toMillis(secs); - final org.joda.time.LocalDateTime localDateTime = new org.joda.time.LocalDateTime(millis, - org.joda.time.DateTimeZone.UTC); - return localDateTime; - } - } - - - /****************************************************************** - * * - * vector value setter methods * - * * - ******************************************************************/ - - - /** - * Set the element at the given index to the value set in data holder. - * If the value in holder is not indicated as set, element in the - * at the given index will be null. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void set(int index, NullableTimeStampSecHolder holder) throws IllegalArgumentException { - if (holder.isSet < 0) { - throw new IllegalArgumentException(); - } else if (holder.isSet > 0) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } else { - BitVectorHelper.setValidityBit(validityBuffer, index, 0); - } - } - - /** - * Set the element at the given index to the value set in data holder. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void set(int index, TimeStampSecHolder holder) { - BitVectorHelper.setValidityBitToOne(validityBuffer, index); - setValue(index, holder.value); - } - - /** - * Same as {@link #set(int, NullableTimeStampSecHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder nullable data holder for value of element - */ - public void setSafe(int index, NullableTimeStampSecHolder holder) throws IllegalArgumentException { - handleSafe(index); - set(index, holder); - } - - /** - * Same as {@link #set(int, TimeStampSecHolder)} except that it handles the - * case when index is greater than or equal to existing - * value capacity {@link #getValueCapacity()}. - * - * @param index position of element - * @param holder data holder for value of element - */ - public void setSafe(int index, TimeStampSecHolder holder) { - handleSafe(index); - set(index, holder); - } - - - /****************************************************************** - * * - * vector transfer * - * * - ******************************************************************/ - - - /** - * Construct a TransferPair comprising of this and and a target vector of - * the same type. - * @param ref name of the target vector - * @param allocator allocator for the target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair getTransferPair(String ref, BufferAllocator allocator) { - TimeStampSecVector to = new TimeStampSecVector(ref, - field.getFieldType(), allocator); - return new TransferImpl(to); - } - - /** - * Construct a TransferPair with a desired target vector of the same type. - * @param to target vector - * @return {@link TransferPair} - */ - @Override - public TransferPair makeTransferPair(ValueVector to) { - return new TransferImpl((TimeStampSecVector) to); - } -} \ No newline at end of file diff --git a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampVector.java b/java/vector/src/main/java/org/apache/arrow/vector/TimestampVector.java similarity index 61% rename from java/vector/src/main/java/org/apache/arrow/vector/TimeStampVector.java rename to java/vector/src/main/java/org/apache/arrow/vector/TimestampVector.java index 4c70b819cbf..13d72c488cb 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/TimeStampVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/TimestampVector.java @@ -18,30 +18,83 @@ package org.apache.arrow.vector; +import com.google.common.base.Preconditions; +import org.apache.arrow.vector.types.TimeUnit; +import org.joda.time.DateTimeZone; + import io.netty.buffer.ArrowBuf; import org.apache.arrow.memory.BufferAllocator; +import org.apache.arrow.vector.complex.impl.TimestampReaderImpl; +import org.apache.arrow.vector.complex.reader.FieldReader; +import org.apache.arrow.vector.holders.NullableTimestampHolder; +import org.apache.arrow.vector.holders.TimestampHolder; +import org.apache.arrow.vector.types.Types; +import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.FieldType; import org.apache.arrow.vector.util.TransferPair; +import org.joda.time.LocalDateTime; + /** - * TimeStampVector is an abstract interface for fixed width vector (8 bytes) + * TimestampVector is an abstract interface for fixed width vector (8 bytes) * of timestamp values which could be null. A validity buffer (bit vector) is * maintained to track which elements in the vector are null. */ -public abstract class TimeStampVector extends BaseFixedWidthVector { +public class TimestampVector extends BaseFixedWidthVector { protected static final byte TYPE_WIDTH = 8; + private final FieldReader reader; + private final TimeUnit unit; + private final DateTimeZone timezone; + + /** + * Instantiate a TimestampVector. This doesn't allocate any memory for + * the data in vector. + * @param name name of the vector + * @param allocator allocator for memory management. + * @param unit time unit + * @param timezone time zone + */ + public TimestampVector(String name, BufferAllocator allocator, TimeUnit unit, String timezone) { + this(name, FieldType.nullable(new ArrowType.Timestamp(unit, timezone)), allocator); + } /** - * Instantiate a TimeStampVector. This doesn't allocate any memory for + * Instantiate a TimestampVector. This doesn't allocate any memory for * the data in vector. * @param name name of the vector * @param fieldType type of Field materialized by this vector * @param allocator allocator for memory management. */ - public TimeStampVector(String name, FieldType fieldType, BufferAllocator allocator) { + public TimestampVector(String name, FieldType fieldType, BufferAllocator allocator) { super(name, allocator, fieldType, TYPE_WIDTH); + + ArrowType.Timestamp arrowType = (ArrowType.Timestamp) fieldType.getType(); + + this.reader = new TimestampReaderImpl(this); + this.unit = arrowType.getUnit(); + // TODO: Decide if this is right - This matches the current behavior + this.timezone = arrowType.getTimezone() == null ? + DateTimeZone.UTC : DateTimeZone.forID(arrowType.getTimezone()); } + /** + * Get a reader that supports reading values from this vector + * @return Field Reader for this vector + */ + @Override + public FieldReader getReader() { + return reader; + } + + /** + * Get minor type for this vector. The vector holds values belonging + * to a particular type. + * @return {@link org.apache.arrow.vector.types.Types.MinorType} + */ + @Override + public Types.MinorType getMinorType() { + return Types.MinorType.TIMESTAMP; + } /****************************************************************** * * @@ -69,21 +122,21 @@ public long get(int index) throws IllegalStateException { * @param thisIndex position to copy to in this vector * @param from source vector */ - public void copyFrom(int fromIndex, int thisIndex, TimeStampVector from) { + public void copyFrom(int fromIndex, int thisIndex, TimestampVector from) { BitVectorHelper.setValidityBit(validityBuffer, thisIndex, from.isSet(fromIndex)); final long value = from.valueBuffer.getLong(fromIndex * TYPE_WIDTH); valueBuffer.setLong(thisIndex * TYPE_WIDTH, value); } /** - * Same as {@link #copyFromSafe(int, int, TimeStampVector)} except that + * Same as {@link #copyFromSafe(int, int, TimestampVector)} except that * it handles the case when the capacity of the vector needs to be expanded * before copy. * @param fromIndex position to copy from in source vector * @param thisIndex position to copy to in this vector * @param from source vector */ - public void copyFromSafe(int fromIndex, int thisIndex, TimeStampVector from) { + public void copyFromSafe(int fromIndex, int thisIndex, TimestampVector from) { handleSafe(thisIndex); copyFrom(fromIndex, thisIndex, from); } @@ -111,6 +164,22 @@ public void set(int index, long value) { setValue(index, value); } + public void set(int index, NullableTimestampHolder holder) { + if (holder.isSet < 0) { + throw new IllegalArgumentException(); + } else if (holder.isSet > 0) { + BitVectorHelper.setValidityBitToOne(validityBuffer, index); + setValue(index, holder.value); + } else { + BitVectorHelper.setValidityBit(validityBuffer, index, 0); + } + } + + public void set(int index, TimestampHolder holder) { + BitVectorHelper.setValidityBitToOne(validityBuffer, index); + setValue(index, holder.value); + } + /** * Same as {@link #set(int, long)} except that it handles the * case when index is greater than or equal to existing @@ -124,6 +193,16 @@ public void setSafe(int index, long value) { set(index, value); } + public void setSafe(int index, NullableTimestampHolder holder) { + handleSafe(index); + set(index, holder); + } + + public void setSafe(int index, TimestampHolder holder) { + handleSafe(index); + set(index, holder); + } + /** * Set the element at the given index to null. * @@ -179,6 +258,37 @@ public static long get(final ArrowBuf buffer, final int index) { return buffer.getLong(index * TYPE_WIDTH); } + public void get(int index, NullableTimestampHolder holder) { + if (isSet(index) == 0) { + holder.isSet = 0; + return; + } + holder.isSet = 1; + holder.value = valueBuffer.getLong(index * TYPE_WIDTH); + } + + @Override + public LocalDateTime getObject(int index) { + if (isSet(index) == 0) { + return null; + } else { + long millis = unit.toMillis(get(index)); + LocalDateTime date = new LocalDateTime(millis, timezone); + return date; + } + } + + @Override + public TransferPair getTransferPair(String ref, BufferAllocator allocator) { + TimestampVector to = new TimestampVector(ref, field.getFieldType(), allocator); + return new TransferImpl(to); + } + + @Override + public TransferPair makeTransferPair(ValueVector to) { + return new TransferImpl((TimestampVector) to); + } + /****************************************************************** * * @@ -188,14 +298,15 @@ public static long get(final ArrowBuf buffer, final int index) { public class TransferImpl implements TransferPair { - TimeStampVector to; + TimestampVector to; - public TransferImpl(TimeStampVector to) { + public TransferImpl(TimestampVector to) { + Preconditions.checkArgument(unit == to.unit); this.to = to; } @Override - public TimeStampVector getTo() { + public TimestampVector getTo() { return to; } @@ -211,7 +322,7 @@ public void splitAndTransfer(int startIndex, int length) { @Override public void copyValueSafe(int fromIndex, int toIndex) { - to.copyFromSafe(fromIndex, toIndex, TimeStampVector.this); + to.copyFromSafe(fromIndex, toIndex, TimestampVector.this); } } } \ No newline at end of file diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/PromotableWriter.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/PromotableWriter.java index 9abd38d20ac..504a204938c 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/PromotableWriter.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/impl/PromotableWriter.java @@ -26,7 +26,9 @@ import org.apache.arrow.vector.complex.MapVector; import org.apache.arrow.vector.complex.UnionVector; import org.apache.arrow.vector.complex.writer.FieldWriter; +import org.apache.arrow.vector.types.Types; import org.apache.arrow.vector.types.Types.MinorType; +import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.types.pojo.FieldType; import org.apache.arrow.vector.util.TransferPair; @@ -119,7 +121,27 @@ public void setPosition(int index) { } } - protected FieldWriter getWriter(MinorType type) { + protected FieldWriter getWriter(MinorType minorType) { + + if (state == State.UNION) { + ((UnionWriter) writer).getWriter(type); + } else if (state == State.UNTYPED) { + if (minorType == null) { + // ??? + return null; + } + ValueVector v = listVector.addOrGetVector(FieldType.nullable(minorType.getType())).getVector(); + v.allocateNew(); + setWriter(v); + writer.setPosition(position); + } else if (minorType != this.type) { + promoteToUnion(); + ((UnionWriter) writer).getWriter(minorType); + } + return writer; + } + + protected FieldWriter getWriter(ArrowType type) { if (state == State.UNION) { ((UnionWriter) writer).getWriter(type); } else if (state == State.UNTYPED) { @@ -127,11 +149,11 @@ protected FieldWriter getWriter(MinorType type) { // ??? return null; } - ValueVector v = listVector.addOrGetVector(FieldType.nullable(type.getType())).getVector(); + ValueVector v = listVector.addOrGetVector(FieldType.nullable(type)).getVector(); v.allocateNew(); setWriter(v); writer.setPosition(position); - } else if (type != this.type) { + } else if (Types.getMinorTypeForArrowType(type) != this.type) { promoteToUnion(); ((UnionWriter) writer).getWriter(type); } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/ipc/JsonFileReader.java b/java/vector/src/main/java/org/apache/arrow/vector/ipc/JsonFileReader.java index 04d50331b76..8e03a1e13fd 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/ipc/JsonFileReader.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/ipc/JsonFileReader.java @@ -445,14 +445,7 @@ private ArrowBuf readIntoBuffer(BufferAllocator allocator, ArrowVectorType buffe case TIMENANO: reader = helper.INT8; break; - case TIMESTAMPNANO: - case TIMESTAMPMICRO: - case TIMESTAMPMILLI: - case TIMESTAMPSEC: - case TIMESTAMPNANOTZ: - case TIMESTAMPMICROTZ: - case TIMESTAMPMILLITZ: - case TIMESTAMPSECTZ: + case TIMESTAMP: reader = helper.INT8; break; default: diff --git a/java/vector/src/main/java/org/apache/arrow/vector/ipc/JsonFileWriter.java b/java/vector/src/main/java/org/apache/arrow/vector/ipc/JsonFileWriter.java index 067fb25b8d8..8f58077ecae 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/ipc/JsonFileWriter.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/ipc/JsonFileWriter.java @@ -242,29 +242,8 @@ private void writeValueToGenerator(ArrowVectorType bufferType, ArrowBuf buffer, case TIMENANO: generator.writeNumber(TimeNanoVector.get(buffer, index)); break; - case TIMESTAMPSEC: - generator.writeNumber(TimeStampSecVector.get(buffer, index)); - break; - case TIMESTAMPMILLI: - generator.writeNumber(TimeStampMilliVector.get(buffer, index)); - break; - case TIMESTAMPMICRO: - generator.writeNumber(TimeStampMicroVector.get(buffer, index)); - break; - case TIMESTAMPNANO: - generator.writeNumber(TimeStampNanoVector.get(buffer, index)); - break; - case TIMESTAMPSECTZ: - generator.writeNumber(TimeStampSecTZVector.get(buffer, index)); - break; - case TIMESTAMPMILLITZ: - generator.writeNumber(TimeStampMilliTZVector.get(buffer, index)); - break; - case TIMESTAMPMICROTZ: - generator.writeNumber(TimeStampMicroTZVector.get(buffer, index)); - break; - case TIMESTAMPNANOTZ: - generator.writeNumber(TimeStampNanoTZVector.get(buffer, index)); + case TIMESTAMP: + generator.writeNumber(TimestampVector.get(buffer, index)); break; case BIT: generator.writeNumber(BitVectorHelper.get(buffer, index)); diff --git a/java/vector/src/main/java/org/apache/arrow/vector/types/TimeUnit.java b/java/vector/src/main/java/org/apache/arrow/vector/types/TimeUnit.java index 1da9321fcc4..c4a5812ea51 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/types/TimeUnit.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/types/TimeUnit.java @@ -19,10 +19,10 @@ package org.apache.arrow.vector.types; public enum TimeUnit { - SECOND(org.apache.arrow.flatbuf.TimeUnit.SECOND), - MILLISECOND(org.apache.arrow.flatbuf.TimeUnit.MILLISECOND), - MICROSECOND(org.apache.arrow.flatbuf.TimeUnit.MICROSECOND), - NANOSECOND(org.apache.arrow.flatbuf.TimeUnit.NANOSECOND); + SECOND(org.apache.arrow.flatbuf.TimeUnit.SECOND, java.util.concurrent.TimeUnit.SECONDS), + MILLISECOND(org.apache.arrow.flatbuf.TimeUnit.MILLISECOND, java.util.concurrent.TimeUnit.MILLISECONDS), + MICROSECOND(org.apache.arrow.flatbuf.TimeUnit.MICROSECOND, java.util.concurrent.TimeUnit.MICROSECONDS), + NANOSECOND(org.apache.arrow.flatbuf.TimeUnit.NANOSECOND, java.util.concurrent.TimeUnit.NANOSECONDS); private static final TimeUnit[] valuesByFlatbufId = new TimeUnit[TimeUnit.values().length]; @@ -33,9 +33,11 @@ public enum TimeUnit { } private final short flatbufID; + private final java.util.concurrent.TimeUnit timeUnit; - TimeUnit(short flatbufID) { + TimeUnit(short flatbufID, java.util.concurrent.TimeUnit timeUnit) { this.flatbufID = flatbufID; + this.timeUnit = timeUnit; } public short getFlatbufID() { @@ -45,4 +47,20 @@ public short getFlatbufID() { public static TimeUnit fromFlatbufID(short id) { return valuesByFlatbufId[id]; } + + public final long toNanos(long duration) { + return timeUnit.toNanos(duration); + } + + public final long toMicros(long duration) { + return timeUnit.toMicros(duration); + } + + public final long toMillis(long duration) { + return timeUnit.toMillis(duration); + } + + public final long toSeconds(long duration) { + return timeUnit.toSeconds(duration); + } } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/types/Types.java b/java/vector/src/main/java/org/apache/arrow/vector/types/Types.java index 7834845aad8..3d5142c40f7 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/types/Types.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/types/Types.java @@ -35,18 +35,11 @@ import org.apache.arrow.vector.IntervalDayVector; import org.apache.arrow.vector.IntervalYearVector; import org.apache.arrow.vector.SmallIntVector; +import org.apache.arrow.vector.TimestampVector; import org.apache.arrow.vector.TimeMicroVector; import org.apache.arrow.vector.TimeMilliVector; import org.apache.arrow.vector.TimeNanoVector; import org.apache.arrow.vector.TimeSecVector; -import org.apache.arrow.vector.TimeStampMicroTZVector; -import org.apache.arrow.vector.TimeStampMicroVector; -import org.apache.arrow.vector.TimeStampMilliTZVector; -import org.apache.arrow.vector.TimeStampMilliVector; -import org.apache.arrow.vector.TimeStampNanoTZVector; -import org.apache.arrow.vector.TimeStampNanoVector; -import org.apache.arrow.vector.TimeStampSecTZVector; -import org.apache.arrow.vector.TimeStampSecVector; import org.apache.arrow.vector.TinyIntVector; import org.apache.arrow.vector.UInt1Vector; import org.apache.arrow.vector.UInt2Vector; @@ -76,14 +69,7 @@ import org.apache.arrow.vector.complex.impl.TimeMilliWriterImpl; import org.apache.arrow.vector.complex.impl.TimeNanoWriterImpl; import org.apache.arrow.vector.complex.impl.TimeSecWriterImpl; -import org.apache.arrow.vector.complex.impl.TimeStampMicroTZWriterImpl; -import org.apache.arrow.vector.complex.impl.TimeStampMicroWriterImpl; -import org.apache.arrow.vector.complex.impl.TimeStampMilliTZWriterImpl; -import org.apache.arrow.vector.complex.impl.TimeStampMilliWriterImpl; -import org.apache.arrow.vector.complex.impl.TimeStampNanoTZWriterImpl; -import org.apache.arrow.vector.complex.impl.TimeStampNanoWriterImpl; -import org.apache.arrow.vector.complex.impl.TimeStampSecTZWriterImpl; -import org.apache.arrow.vector.complex.impl.TimeStampSecWriterImpl; +import org.apache.arrow.vector.complex.impl.TimestampWriterImpl; import org.apache.arrow.vector.complex.impl.TinyIntWriterImpl; import org.apache.arrow.vector.complex.impl.UInt1WriterImpl; import org.apache.arrow.vector.complex.impl.UInt2WriterImpl; @@ -249,52 +235,15 @@ public FieldWriter getNewFieldWriter(ValueVector vector) { return new TimeNanoWriterImpl((TimeNanoVector) vector); } }, - // time in second from the Unix epoch, 00:00:00.000000 on 1 January 1970, UTC. - TIMESTAMPSEC(new Timestamp(org.apache.arrow.vector.types.TimeUnit.SECOND, null)) { + TIMESTAMP(null) { @Override public FieldVector getNewVector(String name, FieldType fieldType, BufferAllocator allocator, CallBack schemaChangeCallback) { - return new TimeStampSecVector(name, fieldType, allocator); + return new TimestampVector(name, fieldType, allocator); } @Override public FieldWriter getNewFieldWriter(ValueVector vector) { - return new TimeStampSecWriterImpl((TimeStampSecVector) vector); - } - }, - // time in millis from the Unix epoch, 00:00:00.000 on 1 January 1970, UTC. - TIMESTAMPMILLI(new Timestamp(org.apache.arrow.vector.types.TimeUnit.MILLISECOND, null)) { - @Override - public FieldVector getNewVector(String name, FieldType fieldType, BufferAllocator allocator, CallBack schemaChangeCallback) { - return new TimeStampMilliVector(name, fieldType, allocator); - } - - @Override - public FieldWriter getNewFieldWriter(ValueVector vector) { - return new TimeStampMilliWriterImpl((TimeStampMilliVector) vector); - } - }, - // time in microsecond from the Unix epoch, 00:00:00.000000 on 1 January 1970, UTC. - TIMESTAMPMICRO(new Timestamp(org.apache.arrow.vector.types.TimeUnit.MICROSECOND, null)) { - @Override - public FieldVector getNewVector(String name, FieldType fieldType, BufferAllocator allocator, CallBack schemaChangeCallback) { - return new TimeStampMicroVector(name, fieldType, allocator); - } - - @Override - public FieldWriter getNewFieldWriter(ValueVector vector) { - return new TimeStampMicroWriterImpl((TimeStampMicroVector) vector); - } - }, - // time in nanosecond from the Unix epoch, 00:00:00.000000000 on 1 January 1970, UTC. - TIMESTAMPNANO(new Timestamp(org.apache.arrow.vector.types.TimeUnit.NANOSECOND, null)) { - @Override - public FieldVector getNewVector(String name, FieldType fieldType, BufferAllocator allocator, CallBack schemaChangeCallback) { - return new TimeStampNanoVector(name, fieldType, allocator); - } - - @Override - public FieldWriter getNewFieldWriter(ValueVector vector) { - return new TimeStampNanoWriterImpl((TimeStampNanoVector) vector); + return new TimestampWriterImpl((TimestampVector) vector); } }, INTERVALDAY(new Interval(IntervalUnit.DAY_TIME)) { @@ -466,52 +415,9 @@ public FieldVector getNewVector(String name, FieldType fieldType, BufferAllocato public FieldWriter getNewFieldWriter(ValueVector vector) { return new UnionWriter((UnionVector) vector); } - }, - TIMESTAMPSECTZ(null) { - @Override - public FieldVector getNewVector(String name, FieldType fieldType, BufferAllocator allocator, CallBack schemaChangeCallback) { - return new TimeStampSecTZVector(name, fieldType, allocator); - } - - @Override - public FieldWriter getNewFieldWriter(ValueVector vector) { - return new TimeStampSecTZWriterImpl((TimeStampSecTZVector) vector); - } - }, - TIMESTAMPMILLITZ(null) { - @Override - public FieldVector getNewVector(String name, FieldType fieldType, BufferAllocator allocator, CallBack schemaChangeCallback) { - return new TimeStampMilliTZVector(name, fieldType, allocator); - } - - @Override - public FieldWriter getNewFieldWriter(ValueVector vector) { - return new TimeStampMilliTZWriterImpl((TimeStampMilliTZVector) vector); - } - }, - TIMESTAMPMICROTZ(null) { - @Override - public FieldVector getNewVector(String name, FieldType fieldType, BufferAllocator allocator, CallBack schemaChangeCallback) { - return new TimeStampMicroTZVector(name, fieldType, allocator); - } - - @Override - public FieldWriter getNewFieldWriter(ValueVector vector) { - return new TimeStampMicroTZWriterImpl((TimeStampMicroTZVector) vector); - } - }, - TIMESTAMPNANOTZ(null) { - @Override - public FieldVector getNewVector(String name, FieldType fieldType, BufferAllocator allocator, CallBack schemaChangeCallback) { - return new TimeStampNanoTZVector(name, fieldType, allocator); - } - - @Override - public FieldWriter getNewFieldWriter(ValueVector vector) { - return new TimeStampNanoTZWriterImpl((TimeStampNanoTZVector) vector); - } }; + private final ArrowType type; MinorType(ArrowType type) { @@ -637,19 +543,7 @@ public MinorType visit(Time type) { @Override public MinorType visit(Timestamp type) { - String tz = type.getTimezone(); - switch (type.getUnit()) { - case SECOND: - return tz == null ? MinorType.TIMESTAMPSEC : MinorType.TIMESTAMPSECTZ; - case MILLISECOND: - return tz == null ? MinorType.TIMESTAMPMILLI : MinorType.TIMESTAMPMILLITZ; - case MICROSECOND: - return tz == null ? MinorType.TIMESTAMPMICRO : MinorType.TIMESTAMPMICROTZ; - case NANOSECOND: - return tz == null ? MinorType.TIMESTAMPNANO : MinorType.TIMESTAMPNANOTZ; - default: - throw new IllegalArgumentException("unknown unit: " + type); - } + return MinorType.TIMESTAMP; } @Override diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java b/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java index 87ffcafecd1..a2aa4c87cdd 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestCopyFrom.java @@ -20,6 +20,7 @@ import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; +import org.apache.arrow.vector.types.TimeUnit; import org.apache.arrow.vector.types.Types; import org.joda.time.Period; import org.junit.After; @@ -49,7 +50,7 @@ * NullableVarChar * NullableTimeMicro * NullableTimeMilli - * NullableTimeStamp* + * NullableTimestamp */ public class TestCopyFrom { @@ -974,8 +975,10 @@ public void testCopyFromWithNulls13() { @Test /* TimeStampVector */ public void testCopyFromWithNulls14() { - try (final TimeStampVector vector1 = new TimeStampMicroVector(EMPTY_SCHEMA_PATH, allocator); - final TimeStampVector vector2 = new TimeStampMicroVector(EMPTY_SCHEMA_PATH, allocator)) { + try (final TimestampVector vector1 = new TimestampVector( + EMPTY_SCHEMA_PATH, allocator, TimeUnit.MILLISECOND, null); + final TimestampVector vector2 = new TimestampVector( + EMPTY_SCHEMA_PATH, allocator, TimeUnit.MILLISECOND, null)) { vector1.allocateNew(); assertEquals(4096, vector1.getValueCapacity()); diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java index aec7d0f3273..640d3a807e7 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java @@ -26,13 +26,15 @@ import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.complex.UnionVector; -import org.apache.arrow.vector.holders.NullableBitHolder; -import org.apache.arrow.vector.holders.NullableIntHolder; -import org.apache.arrow.vector.holders.NullableUInt4Holder; -import org.apache.arrow.vector.holders.NullableFloat4Holder; +import org.apache.arrow.vector.complex.impl.UnionReader; +import org.apache.arrow.vector.complex.impl.UnionWriter; +import org.apache.arrow.vector.holders.*; +import org.apache.arrow.vector.types.TimeUnit; import org.apache.arrow.vector.types.Types; import org.apache.arrow.vector.types.Types.MinorType; import org.apache.arrow.vector.util.TransferPair; +import org.joda.time.DateTimeZone; +import org.joda.time.LocalDateTime; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -86,6 +88,45 @@ public void testUnionVector() throws Exception { } } + @Test + public void testNonSimpleType() throws Exception { + final NullableFloat4Holder float4Holder = new NullableFloat4Holder(); + final NullableTimestampHolder timestampHolder = new NullableTimestampHolder(); + timestampHolder.unit = TimeUnit.SECOND; + timestampHolder.timezone = "America/New_York"; + + try (UnionVector unionVector = new UnionVector(EMPTY_SCHEMA_PATH, allocator, null)) { + unionVector.allocateNew(); + + int count = 100; + + for (int i = 0; i < count; i++) { + if (i % 3 == 0) { + float4Holder.isSet = 1; + float4Holder.value = i; + unionVector.setSafe(i, float4Holder); + } else if (i % 3 == 1) { + timestampHolder.isSet = 1; + timestampHolder.value = i * 60 * 60; + unionVector.setSafe(i, timestampHolder); + } + } + unionVector.setValueCount(count); + + for (int i = 0; i < count; i++) { + if (i % 3 == 0) { + assertEquals(Float.valueOf(i), unionVector.getObject(i)); + } else if (i % 3 == 1) { + LocalDateTime actual = (LocalDateTime) unionVector.getObject(i); + LocalDateTime expected = new LocalDateTime(i * 60 * 60 * 1000, DateTimeZone.forID("America/New_York")); + assertTrue(actual.equals(expected)); + } else { + assert(unionVector.isNull(i)); + } + } + } + } + @Test public void testTransfer() throws Exception { try (UnionVector srcVector = new UnionVector(EMPTY_SCHEMA_PATH, allocator, null)) { diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java index 336ae1c7a01..4d587718f45 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java @@ -17,7 +17,7 @@ */ package org.apache.arrow.vector; -import org.apache.arrow.vector.util.OversizedAllocationException; + import static org.apache.arrow.vector.TestUtils.newVarBinaryVector; import static org.apache.arrow.vector.TestUtils.newVarCharVector; @@ -39,11 +39,15 @@ import org.apache.arrow.vector.ipc.message.ArrowRecordBatch; import org.apache.arrow.vector.ipc.message.TypeLayout; +import org.apache.arrow.vector.types.TimeUnit; import org.apache.arrow.vector.types.Types.MinorType; import org.apache.arrow.vector.types.pojo.Schema; import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.util.TransferPair; +import org.apache.arrow.vector.util.OversizedAllocationException; +import org.joda.time.DateTimeZone; +import org.joda.time.LocalDateTime; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -473,6 +477,39 @@ public void testFixedType4() { } } + @Test + public void testTimestampVector() { + try (final TimestampVector vector = newVector( + TimestampVector.class, + EMPTY_SCHEMA_PATH, + new ArrowType.Timestamp(TimeUnit.SECOND, null), allocator);) { + int initialCapacity = 16; + vector.allocateNew(initialCapacity); + + vector.set(0, 1000); + vector.set(1, 2000); + + assertEquals(new LocalDateTime(1000 * 1000, DateTimeZone.UTC), vector.getObject(0)); + assertEquals(new LocalDateTime(2000 * 1000, DateTimeZone.UTC), vector.getObject(1)); + } + + try (final TimestampVector vector = newVector( + TimestampVector.class, + EMPTY_SCHEMA_PATH, + new ArrowType.Timestamp(TimeUnit.SECOND, "America/New_York"), allocator);) { + int initialCapacity = 16; + vector.allocateNew(initialCapacity); + + vector.set(0, 1000); + vector.set(1, 2000); + + assertEquals(new LocalDateTime(1000 * 1000, DateTimeZone.forID("America/New_York")), + vector.getObject(0)); + assertEquals(new LocalDateTime(2000 * 1000, DateTimeZone.forID("America/New_York")), + vector.getObject(1)); + } + } + @Test /* UInt4Vector */ public void testNullableFixedType1() { diff --git a/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java b/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java index bd8489eb20f..47c20266562 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java @@ -53,7 +53,8 @@ import org.apache.arrow.vector.complex.writer.BaseWriter.ListWriter; import org.apache.arrow.vector.complex.writer.BaseWriter.MapWriter; import org.apache.arrow.vector.holders.IntHolder; -import org.apache.arrow.vector.holders.NullableTimeStampNanoTZHolder; +import org.apache.arrow.vector.holders.NullableTimestampHolder; +import org.apache.arrow.vector.types.TimeUnit; import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.ArrowType.ArrowTypeID; import org.apache.arrow.vector.types.pojo.ArrowType.Int; @@ -69,6 +70,7 @@ import org.apache.arrow.vector.util.JsonStringHashMap; import org.apache.arrow.vector.util.Text; import org.apache.arrow.vector.util.TransferPair; +import org.joda.time.DateTimeZone; import org.joda.time.LocalDateTime; import org.junit.Assert; import org.junit.Test; @@ -379,10 +381,12 @@ public void unionListListType() { ListWriter innerListWriter = listWriter.list(); innerListWriter.startList(); for (int k = 0; k < i % 13; k++) { - if (k % 2 == 0) { + if (k % 3 == 0) { innerListWriter.integer().writeInt(k); - } else { + } else if (k % 3 == 1){ innerListWriter.bigInt().writeBigInt(k); + } else { + innerListWriter.timestamp(TimeUnit.SECOND, "America/New_York").writeTimestamp(k * 60 * 60); } } innerListWriter.endList(); @@ -409,10 +413,12 @@ public void unionListListType2() { for (int j = 0; j < i % 7; j++) { innerListWriter.startList(); for (int k = 0; k < i % 13; k++) { - if (k % 2 == 0) { + if (k % 3 == 0) { innerListWriter.integer().writeInt(k); - } else { + } else if (k % 3 == 1){ innerListWriter.bigInt().writeBigInt(k); + } else { + innerListWriter.timestamp(TimeUnit.SECOND, "America/New_York").writeTimestamp(k * 60 * 60); } } innerListWriter.endList(); @@ -433,10 +439,14 @@ private void checkUnionList(ListVector listVector) { FieldReader innerListReader = listReader.reader(); for (int k = 0; k < i % 13; k++) { innerListReader.next(); - if (k % 2 == 0) { + if (k % 3 == 0) { Assert.assertEquals("record: " + i, k, innerListReader.reader().readInteger().intValue()); - } else { + } else if (k % 3 == 1) { Assert.assertEquals("record: " + i, k, innerListReader.reader().readLong().longValue()); + } else { + Assert.assertEquals("record:" + i, + new LocalDateTime(k * 60 * 60 * 1000, DateTimeZone.forID("America/New_York")), + innerListReader.reader().readLocalDateTime()); } } } @@ -450,20 +460,26 @@ public void simpleUnion() { unionWriter.allocate(); for (int i = 0; i < COUNT; i++) { unionWriter.setPosition(i); - if (i % 2 == 0) { + if (i % 3 == 0 ) { unionWriter.writeInt(i); - } else { + } else if (i % 3 == 1) { unionWriter.writeFloat4((float) i); + } else { + unionWriter.asTimestamp(TimeUnit.SECOND, "America/New_York").writeTimestamp(i * 60 * 60); } } vector.setValueCount(COUNT); UnionReader unionReader = new UnionReader(vector); for (int i = 0; i < COUNT; i++) { unionReader.setPosition(i); - if (i % 2 == 0) { + if (i % 3 == 0) { Assert.assertEquals(i, i, unionReader.readInteger()); - } else { + } else if (i % 3 == 1) { Assert.assertEquals((float) i, unionReader.readFloat(), 1e-12); + } else { + Assert.assertEquals( + new LocalDateTime(i * 60 * 60 * 1000, DateTimeZone.forID("America/New_York")), + unionReader.readLocalDateTime()); } } vector.close(); @@ -474,6 +490,7 @@ public void promotableWriter() { MapVector parent = MapVector.empty("parent", allocator); ComplexWriter writer = new ComplexWriterImpl("root", parent); MapWriter rootWriter = writer.rootAsMap(); + for (int i = 0; i < 100; i++) { BigIntWriter bigIntWriter = rootWriter.bigInt("a"); bigIntWriter.setPosition(i); @@ -494,11 +511,18 @@ public void promotableWriter() { tempBuf.setBytes(0, bytes); varCharWriter.writeVarChar(0, bytes.length, tempBuf); } + for (int i = 200; i < 300 ; i++) { + TimestampWriter timestampWriter = rootWriter.timestamp("a", TimeUnit.SECOND, "America/New_York"); + timestampWriter.setPosition(i); + timestampWriter.writeTimestamp(i * 60 * 60); + } + field = parent.getField().getChildren().get(0).getChildren().get(0); Assert.assertEquals("a", field.getName()); Assert.assertEquals(Union.TYPE_TYPE, field.getType().getTypeID()); Assert.assertEquals(Int.TYPE_TYPE, field.getChildren().get(0).getType().getTypeID()); Assert.assertEquals(Utf8.TYPE_TYPE, field.getChildren().get(1).getType().getTypeID()); + Assert.assertEquals(new ArrowType.Timestamp(TimeUnit.SECOND, "America/New_York"), field.getChildren().get(2).getType()); MapReader rootReader = new SingleMapReaderImpl(parent).reader("root"); for (int i = 0; i < 100; i++) { rootReader.setPosition(i); @@ -513,6 +537,12 @@ public void promotableWriter() { Text value = reader.readText(); Assert.assertEquals(Integer.toString(i), value.toString()); } + for (int i = 200; i < 300; i++) { + rootReader.setPosition(i); + FieldReader reader = rootReader.reader("a"); + LocalDateTime value = reader.readLocalDateTime(); + Assert.assertEquals(new LocalDateTime(i * 60 * 60 * 1000, DateTimeZone.forID("America/New_York")), value); + } } /** @@ -525,6 +555,7 @@ public void promotableWriterSchema() { MapWriter rootWriter = writer.rootAsMap(); rootWriter.bigInt("a"); rootWriter.varChar("a"); + rootWriter.timestamp("a", TimeUnit.SECOND, "America/New_York"); Field field = parent.getField().getChildren().get(0).getChildren().get(0); Assert.assertEquals("a", field.getName()); @@ -535,6 +566,8 @@ public void promotableWriterSchema() { Assert.assertEquals(64, intType.getBitWidth()); Assert.assertTrue(intType.getIsSigned()); Assert.assertEquals(ArrowTypeID.Utf8, field.getChildren().get(1).getType().getTypeID()); + Assert.assertEquals(new ArrowType.Timestamp(TimeUnit.SECOND, "America/New_York"), + field.getChildren().get(2).getType()); } private Set getFieldNames(List fields) { @@ -623,14 +656,14 @@ public void timeStampSecWriter() throws Exception { MapWriter rootWriter = writer.rootAsMap(); { - TimeStampSecWriter timeStampSecWriter = rootWriter.timeStampSec("sec"); + TimestampWriter timeStampSecWriter = rootWriter.timestamp("sec", TimeUnit.SECOND, null); timeStampSecWriter.setPosition(0); - timeStampSecWriter.writeTimeStampSec(expectedSecs); + timeStampSecWriter.writeTimestamp(expectedSecs); } { - TimeStampSecTZWriter timeStampSecTZWriter = rootWriter.timeStampSecTZ("secTZ", "UTC"); + TimestampWriter timeStampSecTZWriter = rootWriter.timestamp("secTZ", TimeUnit.SECOND, "UTC"); timeStampSecTZWriter.setPosition(1); - timeStampSecTZWriter.writeTimeStampSecTZ(expectedSecs); + timeStampSecTZWriter.writeTimestamp(expectedSecs); } // schema List children = parent.getField().getChildren().get(0).getChildren(); @@ -666,15 +699,15 @@ public void timeStampMilliWriters() throws Exception { ComplexWriter writer = new ComplexWriterImpl("root", parent); MapWriter rootWriter = writer.rootAsMap(); { - TimeStampMilliWriter timeStampWriter = rootWriter.timeStampMilli("milli"); + TimestampWriter timeStampWriter = rootWriter.timestamp("milli",TimeUnit.MILLISECOND, null); timeStampWriter.setPosition(0); - timeStampWriter.writeTimeStampMilli(expectedMillis); + timeStampWriter.writeTimestamp(expectedMillis); } String tz = DateUtility.getTimeZone(10); { - TimeStampMilliTZWriter timeStampTZWriter = rootWriter.timeStampMilliTZ("milliTZ", tz); + TimestampWriter timeStampTZWriter = rootWriter.timestamp("milliTZ", TimeUnit.MILLISECOND, tz); timeStampTZWriter.setPosition(0); - timeStampTZWriter.writeTimeStampMilliTZ(expectedMillis); + timeStampTZWriter.writeTimestamp(expectedMillis); } // schema List children = parent.getField().getChildren().get(0).getChildren(); @@ -723,15 +756,15 @@ public void timeStampMicroWriters() throws Exception { MapWriter rootWriter = writer.rootAsMap(); { - TimeStampMicroWriter timeStampMicroWriter = rootWriter.timeStampMicro("micro"); + TimestampWriter timeStampMicroWriter = rootWriter.timestamp("micro", TimeUnit.MICROSECOND, null); timeStampMicroWriter.setPosition(0); - timeStampMicroWriter.writeTimeStampMicro(expectedMicros); + timeStampMicroWriter.writeTimestamp(expectedMicros); } String tz = DateUtility.getTimeZone(5); { - TimeStampMicroTZWriter timeStampMicroWriter = rootWriter.timeStampMicroTZ("microTZ", tz); + TimestampWriter timeStampMicroWriter = rootWriter.timestamp("microTZ", TimeUnit.MICROSECOND, tz); timeStampMicroWriter.setPosition(1); - timeStampMicroWriter.writeTimeStampMicroTZ(expectedMicros); + timeStampMicroWriter.writeTimestamp(expectedMicros); } // schema @@ -770,15 +803,15 @@ public void timeStampNanoWriters() throws Exception { MapWriter rootWriter = writer.rootAsMap(); { - TimeStampNanoWriter timeStampNanoWriter = rootWriter.timeStampNano("nano"); + TimestampWriter timeStampNanoWriter = rootWriter.timestamp("nano", TimeUnit.NANOSECOND, null); timeStampNanoWriter.setPosition(0); - timeStampNanoWriter.writeTimeStampNano(expectedNanos); + timeStampNanoWriter.writeTimestamp(expectedNanos); } String tz = DateUtility.getTimeZone(3); { - TimeStampNanoTZWriter timeStampNanoWriter = rootWriter.timeStampNanoTZ("nanoTZ", tz); + TimestampWriter timeStampNanoWriter = rootWriter.timestamp("nanoTZ", TimeUnit.NANOSECOND, tz); timeStampNanoWriter.setPosition(0); - timeStampNanoWriter.writeTimeStampNanoTZ(expectedNanos); + timeStampNanoWriter.writeTimestamp(expectedNanos); } // schema List children = parent.getField().getChildren().get(0).getChildren(); @@ -800,7 +833,7 @@ public void timeStampNanoWriters() throws Exception { nanoReader.setPosition(0); long nanoLong = nanoReader.readLong(); Assert.assertEquals(expectedNanos, nanoLong); - NullableTimeStampNanoTZHolder h = new NullableTimeStampNanoTZHolder(); + NullableTimestampHolder h = new NullableTimestampHolder(); nanoReader.read(h); Assert.assertEquals(expectedNanos, h.value); } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/ipc/BaseFileTest.java b/java/vector/src/test/java/org/apache/arrow/vector/ipc/BaseFileTest.java index 3514acaa242..10fbe88eabd 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/ipc/BaseFileTest.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/ipc/BaseFileTest.java @@ -42,25 +42,23 @@ import org.apache.arrow.vector.complex.impl.ComplexWriterImpl; import org.apache.arrow.vector.complex.impl.UnionListWriter; import org.apache.arrow.vector.complex.reader.FieldReader; +import org.apache.arrow.vector.complex.writer.*; import org.apache.arrow.vector.complex.writer.BaseWriter.ComplexWriter; import org.apache.arrow.vector.complex.writer.BaseWriter.ListWriter; import org.apache.arrow.vector.complex.writer.BaseWriter.MapWriter; -import org.apache.arrow.vector.complex.writer.BigIntWriter; -import org.apache.arrow.vector.complex.writer.DateMilliWriter; -import org.apache.arrow.vector.complex.writer.IntWriter; -import org.apache.arrow.vector.complex.writer.TimeMilliWriter; -import org.apache.arrow.vector.complex.writer.TimeStampMilliTZWriter; -import org.apache.arrow.vector.complex.writer.TimeStampMilliWriter; import org.apache.arrow.vector.dictionary.Dictionary; import org.apache.arrow.vector.dictionary.DictionaryEncoder; import org.apache.arrow.vector.dictionary.DictionaryProvider; -import org.apache.arrow.vector.holders.NullableTimeStampMilliHolder; +import org.apache.arrow.vector.holders.NullableTimestampHolder; +import org.apache.arrow.vector.types.TimeUnit; import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.DictionaryEncoding; import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.types.pojo.FieldType; import org.apache.arrow.vector.util.DateUtility; import org.apache.arrow.vector.util.Text; +import org.joda.time.Chronology; +import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.LocalDateTime; import org.junit.After; @@ -130,7 +128,7 @@ protected void writeComplexData(int count, MapVector parent) { listWriter.endList(); mapWriter.setPosition(i); mapWriter.start(); - mapWriter.timeStampMilli("timestamp").writeTimeStampMilli(i); + mapWriter.timestamp("timestamp", TimeUnit.MILLISECOND, null).writeTimestamp(i); mapWriter.end(); } writer.setValueCount(count); @@ -160,7 +158,7 @@ protected void validateComplexContent(int count, VectorSchemaRoot root) { } Assert.assertEquals(Long.valueOf(i), root.getVector("bigInt").getObject(i)); Assert.assertEquals(i % 3, ((List) root.getVector("list").getObject(i)).size()); - NullableTimeStampMilliHolder h = new NullableTimeStampMilliHolder(); + NullableTimestampHolder h = new NullableTimestampHolder(); FieldReader mapReader = root.getVector("map").getReader(); mapReader.setPosition(i); mapReader.reader("timestamp").read(h); @@ -172,16 +170,21 @@ private LocalDateTime makeDateTimeFromCount(int i) { return new LocalDateTime(2000 + i, 1 + i, 1 + i, i, i, i, i); } + private DateTime makeDateTimeFromCount(int i, String tz) { + return new DateTime(2000 + i, 1 + i, 1 + i, i, i, i, i, DateTimeZone.forID(tz)); + } + protected void writeDateTimeData(int count, MapVector parent) { Assert.assertTrue(count < 100); ComplexWriter writer = new ComplexWriterImpl("root", parent); MapWriter rootWriter = writer.rootAsMap(); DateMilliWriter dateWriter = rootWriter.dateMilli("date"); TimeMilliWriter timeWriter = rootWriter.timeMilli("time"); - TimeStampMilliWriter timeStampMilliWriter = rootWriter.timeStampMilli("timestamp-milli"); - TimeStampMilliTZWriter timeStampMilliTZWriter = rootWriter.timeStampMilliTZ("timestamp-milliTZ", "Europe/Paris"); + TimestampWriter timeStampMilliWriter = rootWriter.timestamp("timestamp-milli", TimeUnit.MILLISECOND, null); + TimestampWriter timeStampMilliTZWriter = rootWriter.timestamp("timestamp-milliTZ",TimeUnit.MILLISECOND, "Europe/Paris"); for (int i = 0; i < count; i++) { LocalDateTime dt = makeDateTimeFromCount(i); + DateTime dt2 = makeDateTimeFromCount(i, "Europe/Paris"); // Number of days in milliseconds since epoch, stored as 64-bit integer, only date part is used dateWriter.setPosition(i); long dateLong = DateUtility.toMillis(dt.minusMillis(dt.getMillisOfDay())); @@ -191,9 +194,9 @@ protected void writeDateTimeData(int count, MapVector parent) { timeWriter.writeTimeMilli(dt.getMillisOfDay()); // Timestamp is milliseconds since the epoch, stored as 64-bit integer timeStampMilliWriter.setPosition(i); - timeStampMilliWriter.writeTimeStampMilli(DateUtility.toMillis(dt)); + timeStampMilliWriter.writeTimestamp(DateUtility.toMillis(dt)); timeStampMilliTZWriter.setPosition(i); - timeStampMilliTZWriter.writeTimeStampMilliTZ(DateUtility.toMillis(dt)); + timeStampMilliTZWriter.writeTimestamp(dt2.getMillis()); } writer.setValueCount(count); } @@ -204,6 +207,7 @@ protected void validateDateTimeContent(int count, VectorSchemaRoot root) { for (int i = 0; i < count; i++) { long dateVal = ((DateMilliVector) root.getVector("date")).get(i); LocalDateTime dt = makeDateTimeFromCount(i); + LocalDateTime dt2 = makeDateTimeFromCount(i, "Europe/Paris").toLocalDateTime(); LocalDateTime dateExpected = dt.minusMillis(dt.getMillisOfDay()); Assert.assertEquals(DateUtility.toMillis(dateExpected), dateVal); long timeVal = ((TimeMilliVector) root.getVector("time")).get(i); @@ -211,7 +215,7 @@ protected void validateDateTimeContent(int count, VectorSchemaRoot root) { Object timestampMilliVal = root.getVector("timestamp-milli").getObject(i); Assert.assertEquals(dt, timestampMilliVal); Object timestampMilliTZVal = root.getVector("timestamp-milliTZ").getObject(i); - Assert.assertEquals(DateUtility.toMillis(dt), timestampMilliTZVal); + Assert.assertEquals(dt2, timestampMilliTZVal); } } @@ -483,7 +487,7 @@ public void validateUnionData(int count, VectorSchemaRoot root) { Assert.assertEquals(i % 3, unionReader.size()); break; case 3: - NullableTimeStampMilliHolder h = new NullableTimeStampMilliHolder(); + NullableTimestampHolder h = new NullableTimestampHolder(); unionReader.reader("timestamp").read(h); Assert.assertEquals(i, h.value); break; @@ -525,7 +529,7 @@ public void writeUnionData(int count, MapVector parent) { case 3: mapWriter.setPosition(i); mapWriter.start(); - mapWriter.timeStampMilli("timestamp").writeTimeStampMilli(i); + mapWriter.timestamp("timestamp", TimeUnit.MILLISECOND, null).writeTimestamp(i); mapWriter.end(); break; } diff --git a/java/vector/src/test/java/org/apache/arrow/vector/pojo/TestConvert.java b/java/vector/src/test/java/org/apache/arrow/vector/pojo/TestConvert.java index f6f1ad221f3..a9aa4baaf42 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/pojo/TestConvert.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/pojo/TestConvert.java @@ -137,7 +137,7 @@ public void nestedSchema() { childrenBuilder.add(new Field("child4", FieldType.nullable(new List()), ImmutableList.of( new Field("child4.1", FieldType.nullable(Utf8.INSTANCE), null) ))); - childrenBuilder.add(new Field("child5", FieldType.nullable(new Union(UnionMode.Sparse, new int[] {MinorType.TIMESTAMPMILLI.ordinal(), MinorType.FLOAT8.ordinal()})), ImmutableList.of( + childrenBuilder.add(new Field("child5", FieldType.nullable(new Union(UnionMode.Sparse, new int[] {MinorType.TIMESTAMP.ordinal(), MinorType.FLOAT8.ordinal()})), ImmutableList.of( new Field("child5.1", FieldType.nullable(new Timestamp(TimeUnit.MILLISECOND, null)), null), new Field("child5.2", FieldType.nullable(new FloatingPoint(DOUBLE)), ImmutableList.of()), new Field("child5.3", true, new Timestamp(TimeUnit.MILLISECOND, "UTC"), null)