Skip to content

Commit a8bf0fb

Browse files
committed
ARROW-673: [Java] Support additional Time metadata
Author: Julien Le Dem <julien@dremio.com> Closes apache#407 from julienledem/time_md and squashes the following commits: 3f721e2 [Julien Le Dem] ARROW-673: [Java] Support additional Time metadata
1 parent 98a52b4 commit a8bf0fb

5 files changed

Lines changed: 10 additions & 42 deletions

File tree

‎java/vector/src/main/codegen/data/ArrowTypes.tdd‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
},
5959
{
6060
name: "Time",
61-
fields: []
61+
fields: [{name: "unit", type: short, valueType: TimeUnit}, {name: "bitWidth", type: int}]
6262
},
6363
{
6464
name: "Timestamp",

‎java/vector/src/main/codegen/templates/NullableValueVectors.java‎

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -84,43 +84,8 @@ public final class ${className} extends BaseDataValueVector implements <#if type
8484
values = new ${valuesName}(valuesField, allocator);
8585
mutator = new Mutator();
8686
accessor = new Accessor();
87-
<#if minor.class == "TinyInt" ||
88-
minor.class == "SmallInt" ||
89-
minor.class == "Int" ||
90-
minor.class == "BigInt">
91-
field = new Field(name, true, new Int(${type.width} * 8, true), dictionary, null);
92-
<#elseif minor.class == "UInt1" ||
93-
minor.class == "UInt2" ||
94-
minor.class == "UInt4" ||
95-
minor.class == "UInt8">
96-
field = new Field(name, true, new Int(${type.width} * 8, false), dictionary, null);
97-
<#elseif minor.class == "Date">
98-
field = new Field(name, true, new org.apache.arrow.vector.types.pojo.ArrowType.Date(), dictionary, null);
99-
<#elseif minor.class == "Time">
100-
field = new Field(name, true, new org.apache.arrow.vector.types.pojo.ArrowType.Time(), dictionary, null);
101-
<#elseif minor.class == "Float4">
102-
field = new Field(name, true, new FloatingPoint(org.apache.arrow.vector.types.FloatingPointPrecision.SINGLE), dictionary, null);
103-
<#elseif minor.class == "Float8">
104-
field = new Field(name, true, new FloatingPoint(org.apache.arrow.vector.types.FloatingPointPrecision.DOUBLE), dictionary, null);
105-
<#elseif minor.class == "TimeStampSec">
106-
field = new Field(name, true, new org.apache.arrow.vector.types.pojo.ArrowType.Timestamp(org.apache.arrow.vector.types.TimeUnit.SECOND), dictionary, null);
107-
<#elseif minor.class == "TimeStampMilli">
108-
field = new Field(name, true, new org.apache.arrow.vector.types.pojo.ArrowType.Timestamp(org.apache.arrow.vector.types.TimeUnit.MILLISECOND), dictionary, null);
109-
<#elseif minor.class == "TimeStampMicro">
110-
field = new Field(name, true, new org.apache.arrow.vector.types.pojo.ArrowType.Timestamp(org.apache.arrow.vector.types.TimeUnit.MICROSECOND), dictionary, null);
111-
<#elseif minor.class == "TimeStampNano">
112-
field = new Field(name, true, new org.apache.arrow.vector.types.pojo.ArrowType.Timestamp(org.apache.arrow.vector.types.TimeUnit.NANOSECOND), dictionary, null);
113-
<#elseif minor.class == "IntervalDay">
114-
field = new Field(name, true, new Interval(org.apache.arrow.vector.types.IntervalUnit.DAY_TIME), dictionary, null);
115-
<#elseif minor.class == "IntervalYear">
116-
field = new Field(name, true, new Interval(org.apache.arrow.vector.types.IntervalUnit.YEAR_MONTH), dictionary, null);
117-
<#elseif minor.class == "VarChar">
118-
field = new Field(name, true, new Utf8(), dictionary, null);
119-
<#elseif minor.class == "VarBinary">
120-
field = new Field(name, true, new Binary(), dictionary, null);
121-
<#elseif minor.class == "Bit">
122-
field = new Field(name, true, new Bool(), dictionary, null);
123-
</#if>
87+
ArrowType type = Types.MinorType.${minor.class?upper_case}.getType();
88+
field = new Field(name, true, type, dictionary, null);
12489
innerVectors = Collections.unmodifiableList(Arrays.<BufferBacked>asList(
12590
bits,
12691
<#if type.major = "VarLen">

‎java/vector/src/main/java/org/apache/arrow/vector/schema/TypeLayout.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public TypeLayout visit(Date type) {
164164

165165
@Override
166166
public TypeLayout visit(Time type) {
167-
return newFixedWidthTypeLayout(dataVector(64));
167+
return newFixedWidthTypeLayout(dataVector(type.getBitWidth()));
168168
}
169169

170170
@Override

‎java/vector/src/main/java/org/apache/arrow/vector/types/Types.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public class Types {
108108
private static final Field UINT4_FIELD = new Field("", true, new Int(32, false), null);
109109
private static final Field UINT8_FIELD = new Field("", true, new Int(64, false), null);
110110
private static final Field DATE_FIELD = new Field("", true, Date.INSTANCE, null);
111-
private static final Field TIME_FIELD = new Field("", true, Time.INSTANCE, null);
111+
private static final Field TIME_FIELD = new Field("", true, new Time(TimeUnit.MILLISECOND, 32), null);
112112
private static final Field TIMESTAMPSEC_FIELD = new Field("", true, new Timestamp(TimeUnit.SECOND), null);
113113
private static final Field TIMESTAMPMILLI_FIELD = new Field("", true, new Timestamp(TimeUnit.MILLISECOND), null);
114114
private static final Field TIMESTAMPMICRO_FIELD = new Field("", true, new Timestamp(TimeUnit.MICROSECOND), null);
@@ -235,7 +235,7 @@ public FieldWriter getNewFieldWriter(ValueVector vector) {
235235
return new DateWriterImpl((NullableDateVector) vector);
236236
}
237237
},
238-
TIME(Time.INSTANCE) {
238+
TIME(new Time(TimeUnit.MILLISECOND, 32)) {
239239
@Override
240240
public Field getField() {
241241
return TIME_FIELD;
@@ -639,6 +639,9 @@ public MinorType visit(FloatingPoint type) {
639639
}
640640

641641
@Override public MinorType visit(Time type) {
642+
if (type.getUnit() != TimeUnit.MILLISECOND || type.getBitWidth() != 32) {
643+
throw new IllegalArgumentException("Only milliseconds on 32 bits supported for now: " + type);
644+
}
642645
return MinorType.TIME;
643646
}
644647

‎java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void testAll() throws IOException {
7171
field("i", new ArrowType.Bool()),
7272
field("j", new ArrowType.Decimal(5, 5)),
7373
field("k", new ArrowType.Date()),
74-
field("l", new ArrowType.Time()),
74+
field("l", new ArrowType.Time(TimeUnit.MILLISECOND, 32)),
7575
field("m", new ArrowType.Timestamp(TimeUnit.MILLISECOND)),
7676
field("n", new ArrowType.Interval(IntervalUnit.DAY_TIME))
7777
));

0 commit comments

Comments
 (0)