Repository: arrow
Updated Branches:
  refs/heads/master 98a52b482 -> a8bf0fbc8


ARROW-673: [Java] Support additional Time metadata

Author: Julien Le Dem <jul...@dremio.com>

Closes #407 from julienledem/time_md and squashes the following commits:

3f721e2 [Julien Le Dem] ARROW-673: [Java] Support additional Time metadata


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/a8bf0fbc
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/a8bf0fbc
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/a8bf0fbc

Branch: refs/heads/master
Commit: a8bf0fbc832fef3e2a6a9ec075db03007a26442a
Parents: 98a52b4
Author: Julien Le Dem <jul...@dremio.com>
Authored: Tue Mar 21 15:21:44 2017 -0700
Committer: Julien Le Dem <jul...@dremio.com>
Committed: Tue Mar 21 15:21:44 2017 -0700

----------------------------------------------------------------------
 .../vector/src/main/codegen/data/ArrowTypes.tdd |  2 +-
 .../codegen/templates/NullableValueVectors.java | 39 +-------------------
 .../apache/arrow/vector/schema/TypeLayout.java  |  2 +-
 .../org/apache/arrow/vector/types/Types.java    |  7 +++-
 .../arrow/vector/types/pojo/TestSchema.java     |  2 +-
 5 files changed, 10 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/a8bf0fbc/java/vector/src/main/codegen/data/ArrowTypes.tdd
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/data/ArrowTypes.tdd 
b/java/vector/src/main/codegen/data/ArrowTypes.tdd
index 01465e5..8f99752 100644
--- a/java/vector/src/main/codegen/data/ArrowTypes.tdd
+++ b/java/vector/src/main/codegen/data/ArrowTypes.tdd
@@ -58,7 +58,7 @@
     },
     {
       name: "Time",
-      fields: []
+      fields: [{name: "unit", type: short, valueType: TimeUnit}, {name: 
"bitWidth", type: int}]
     },
     {
       name: "Timestamp",

http://git-wip-us.apache.org/repos/asf/arrow/blob/a8bf0fbc/java/vector/src/main/codegen/templates/NullableValueVectors.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/NullableValueVectors.java 
b/java/vector/src/main/codegen/templates/NullableValueVectors.java
index b3e10e3..ec2ce79 100644
--- a/java/vector/src/main/codegen/templates/NullableValueVectors.java
+++ b/java/vector/src/main/codegen/templates/NullableValueVectors.java
@@ -84,43 +84,8 @@ public final class ${className} extends BaseDataValueVector 
implements <#if type
     values = new ${valuesName}(valuesField, allocator);
     mutator = new Mutator();
     accessor = new Accessor();
-  <#if minor.class == "TinyInt" ||
-        minor.class == "SmallInt" ||
-        minor.class == "Int" ||
-        minor.class == "BigInt">
-    field = new Field(name, true, new Int(${type.width} * 8, true), 
dictionary, null);
-  <#elseif minor.class == "UInt1" ||
-        minor.class == "UInt2" ||
-        minor.class == "UInt4" ||
-        minor.class == "UInt8">
-    field = new Field(name, true, new Int(${type.width} * 8, false), 
dictionary, null);
-  <#elseif minor.class == "Date">
-    field = new Field(name, true, new 
org.apache.arrow.vector.types.pojo.ArrowType.Date(), dictionary, null);
-  <#elseif minor.class == "Time">
-    field = new Field(name, true, new 
org.apache.arrow.vector.types.pojo.ArrowType.Time(), dictionary, null);
-  <#elseif minor.class == "Float4">
-    field = new Field(name, true, new 
FloatingPoint(org.apache.arrow.vector.types.FloatingPointPrecision.SINGLE), 
dictionary, null);
-  <#elseif minor.class == "Float8">
-    field = new Field(name, true, new 
FloatingPoint(org.apache.arrow.vector.types.FloatingPointPrecision.DOUBLE), 
dictionary, null);
-  <#elseif minor.class == "TimeStampSec">
-    field = new Field(name, true, new 
org.apache.arrow.vector.types.pojo.ArrowType.Timestamp(org.apache.arrow.vector.types.TimeUnit.SECOND),
 dictionary, null);
-  <#elseif minor.class == "TimeStampMilli">
-    field = new Field(name, true, new 
org.apache.arrow.vector.types.pojo.ArrowType.Timestamp(org.apache.arrow.vector.types.TimeUnit.MILLISECOND),
 dictionary, null);
-  <#elseif minor.class == "TimeStampMicro">
-    field = new Field(name, true, new 
org.apache.arrow.vector.types.pojo.ArrowType.Timestamp(org.apache.arrow.vector.types.TimeUnit.MICROSECOND),
 dictionary, null);
-  <#elseif minor.class == "TimeStampNano">
-    field = new Field(name, true, new 
org.apache.arrow.vector.types.pojo.ArrowType.Timestamp(org.apache.arrow.vector.types.TimeUnit.NANOSECOND),
 dictionary, null);
-  <#elseif minor.class == "IntervalDay">
-    field = new Field(name, true, new 
Interval(org.apache.arrow.vector.types.IntervalUnit.DAY_TIME), dictionary, 
null);
-  <#elseif minor.class == "IntervalYear">
-    field = new Field(name, true, new 
Interval(org.apache.arrow.vector.types.IntervalUnit.YEAR_MONTH), dictionary, 
null);
-  <#elseif minor.class == "VarChar">
-    field = new Field(name, true, new Utf8(), dictionary, null);
-  <#elseif minor.class == "VarBinary">
-    field = new Field(name, true, new Binary(), dictionary, null);
-  <#elseif minor.class == "Bit">
-    field = new Field(name, true, new Bool(), dictionary, null);
-  </#if>
+    ArrowType type = Types.MinorType.${minor.class?upper_case}.getType();
+    field = new Field(name, true, type, dictionary, null);
     innerVectors = Collections.unmodifiableList(Arrays.<BufferBacked>asList(
         bits,
         <#if type.major = "VarLen">

http://git-wip-us.apache.org/repos/asf/arrow/blob/a8bf0fbc/java/vector/src/main/java/org/apache/arrow/vector/schema/TypeLayout.java
----------------------------------------------------------------------
diff --git 
a/java/vector/src/main/java/org/apache/arrow/vector/schema/TypeLayout.java 
b/java/vector/src/main/java/org/apache/arrow/vector/schema/TypeLayout.java
index 0b58691..69d550f 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/schema/TypeLayout.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/schema/TypeLayout.java
@@ -164,7 +164,7 @@ public class TypeLayout {
 
       @Override
       public TypeLayout visit(Time type) {
-        return newFixedWidthTypeLayout(dataVector(64));
+        return newFixedWidthTypeLayout(dataVector(type.getBitWidth()));
       }
 
       @Override

http://git-wip-us.apache.org/repos/asf/arrow/blob/a8bf0fbc/java/vector/src/main/java/org/apache/arrow/vector/types/Types.java
----------------------------------------------------------------------
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 8f2d042..7cbf3c5 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
@@ -108,7 +108,7 @@ public class Types {
   private static final Field UINT4_FIELD = new Field("", true, new Int(32, 
false), null);
   private static final Field UINT8_FIELD = new Field("", true, new Int(64, 
false), null);
   private static final Field DATE_FIELD = new Field("", true, Date.INSTANCE, 
null);
-  private static final Field TIME_FIELD = new Field("", true, Time.INSTANCE, 
null);
+  private static final Field TIME_FIELD = new Field("", true, new 
Time(TimeUnit.MILLISECOND, 32), null);
   private static final Field TIMESTAMPSEC_FIELD = new Field("", true, new 
Timestamp(TimeUnit.SECOND), null);
   private static final Field TIMESTAMPMILLI_FIELD = new Field("", true, new 
Timestamp(TimeUnit.MILLISECOND), null);
   private static final Field TIMESTAMPMICRO_FIELD = new Field("", true, new 
Timestamp(TimeUnit.MICROSECOND), null);
@@ -235,7 +235,7 @@ public class Types {
         return new DateWriterImpl((NullableDateVector) vector);
       }
     },
-    TIME(Time.INSTANCE) {
+    TIME(new Time(TimeUnit.MILLISECOND, 32)) {
       @Override
       public Field getField() {
         return TIME_FIELD;
@@ -639,6 +639,9 @@ public class Types {
       }
 
       @Override public MinorType visit(Time type) {
+        if (type.getUnit() != TimeUnit.MILLISECOND || type.getBitWidth() != 
32) {
+          throw new IllegalArgumentException("Only milliseconds on 32 bits 
supported for now: " + type);
+        }
         return MinorType.TIME;
       }
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/a8bf0fbc/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java
----------------------------------------------------------------------
diff --git 
a/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java 
b/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java
index f04c78e..5b74c54 100644
--- 
a/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java
+++ 
b/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java
@@ -71,7 +71,7 @@ public class TestSchema {
         field("i", new ArrowType.Bool()),
         field("j", new ArrowType.Decimal(5, 5)),
         field("k", new ArrowType.Date()),
-        field("l", new ArrowType.Time()),
+        field("l", new ArrowType.Time(TimeUnit.MILLISECOND, 32)),
         field("m", new ArrowType.Timestamp(TimeUnit.MILLISECOND)),
         field("n", new ArrowType.Interval(IntervalUnit.DAY_TIME))
         ));

Reply via email to