arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-1504: [GLib] Add GArrowTimestampArray
Date Sat, 09 Sep 2017 17:47:49 GMT
Repository: arrow
Updated Branches:
  refs/heads/master 8b70ab07c -> 875be96da


ARROW-1504: [GLib] Add GArrowTimestampArray

Author: Kouhei Sutou <kou@clear-code.com>

Closes #1068 from kou/glib-add-timestamp-array and squashes the following commits:

27f0227f [Kouhei Sutou] [GLib] Add GArrowTimestampArray


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

Branch: refs/heads/master
Commit: 875be96da78d9503ce4aeb37fd7104e5662feab6
Parents: 8b70ab0
Author: Kouhei Sutou <kou@clear-code.com>
Authored: Sat Sep 9 13:47:44 2017 -0400
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Sat Sep 9 13:47:44 2017 -0400

----------------------------------------------------------------------
 c_glib/arrow-glib/array-builder.cpp     | 80 ++++++++++++++++++++++++
 c_glib/arrow-glib/array-builder.h       | 52 ++++++++++++++++
 c_glib/arrow-glib/array.cpp             | 92 ++++++++++++++++++++++++++++
 c_glib/arrow-glib/array.h               | 54 ++++++++++++++++
 c_glib/arrow-glib/data-type.cpp         | 44 +++++++++++++
 c_glib/arrow-glib/data-type.h           | 44 +++++++++++++
 c_glib/test/helper/buildable.rb         |  6 ++
 c_glib/test/test-timestamp-array.rb     | 57 +++++++++++++++++
 c_glib/test/test-timestamp-data-type.rb | 63 +++++++++++++++++++
 9 files changed, 492 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/875be96d/c_glib/arrow-glib/array-builder.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/array-builder.cpp b/c_glib/arrow-glib/array-builder.cpp
index 9919bff..f550eb5 100644
--- a/c_glib/arrow-glib/array-builder.cpp
+++ b/c_glib/arrow-glib/array-builder.cpp
@@ -113,6 +113,9 @@ G_BEGIN_DECLS
  * #GArrowDate64ArrayBuilder is the class to create a new
  * #GArrowDate64Array.
  *
+ * #GArrowTimestampArrayBuilder is the class to create a new
+ * #GArrowTimestampArray.
+ *
  * #GArrowTime32ArrayBuilder is the class to create a new
  * #GArrowTime32Array.
  *
@@ -1314,6 +1317,80 @@ garrow_date64_array_builder_append_null(GArrowDate64ArrayBuilder *builder,
 }
 
 
+G_DEFINE_TYPE(GArrowTimestampArrayBuilder,
+              garrow_timestamp_array_builder,
+              GARROW_TYPE_ARRAY_BUILDER)
+
+static void
+garrow_timestamp_array_builder_init(GArrowTimestampArrayBuilder *builder)
+{
+}
+
+static void
+garrow_timestamp_array_builder_class_init(GArrowTimestampArrayBuilderClass *klass)
+{
+}
+
+/**
+ * garrow_timestamp_array_builder_new:
+ * @data_type: A #GArrowTimestampDataType.
+ *
+ * Returns: A newly created #GArrowTimestampArrayBuilder.
+ *
+ * Since: 0.7.0
+ */
+GArrowTimestampArrayBuilder *
+garrow_timestamp_array_builder_new(GArrowTimestampDataType *data_type)
+{
+  auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type));
+  auto builder = garrow_array_builder_new(arrow_data_type,
+                                          NULL,
+                                          "[timestamp-array-builder][new]");
+  return GARROW_TIMESTAMP_ARRAY_BUILDER(builder);
+}
+
+/**
+ * garrow_timestamp_array_builder_append:
+ * @builder: A #GArrowTimestampArrayBuilder.
+ * @value: The number of milliseconds since UNIX epoch in signed 64bit integer.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: %TRUE on success, %FALSE if there was an error.
+ *
+ * Since: 0.7.0
+ */
+gboolean
+garrow_timestamp_array_builder_append(GArrowTimestampArrayBuilder *builder,
+                                      gint64 value,
+                                      GError **error)
+{
+  return garrow_array_builder_append<arrow::TimestampBuilder *>
+    (GARROW_ARRAY_BUILDER(builder),
+     value,
+     error,
+     "[timestamp-array-builder][append]");
+}
+
+/**
+ * garrow_timestamp_array_builder_append_null:
+ * @builder: A #GArrowTimestampArrayBuilder.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: %TRUE on success, %FALSE if there was an error.
+ *
+ * Since: 0.7.0
+ */
+gboolean
+garrow_timestamp_array_builder_append_null(GArrowTimestampArrayBuilder *builder,
+                                           GError **error)
+{
+  return garrow_array_builder_append_null<arrow::TimestampBuilder *>
+    (GARROW_ARRAY_BUILDER(builder),
+     error,
+     "[timestamp-array-builder][append-null]");
+}
+
+
 G_DEFINE_TYPE(GArrowTime32ArrayBuilder,
               garrow_time32_array_builder,
               GARROW_TYPE_ARRAY_BUILDER)
@@ -1883,6 +1960,9 @@ garrow_array_builder_new_raw(arrow::ArrayBuilder *arrow_builder,
     case arrow::Type::type::DATE64:
       type = GARROW_TYPE_DATE64_ARRAY_BUILDER;
       break;
+    case arrow::Type::type::TIMESTAMP:
+      type = GARROW_TYPE_TIMESTAMP_ARRAY_BUILDER;
+      break;
     case arrow::Type::type::TIME32:
       type = GARROW_TYPE_TIME32_ARRAY_BUILDER;
       break;

http://git-wip-us.apache.org/repos/asf/arrow/blob/875be96d/c_glib/arrow-glib/array-builder.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/array-builder.h b/c_glib/arrow-glib/array-builder.h
index 981f0bc..4a19925 100644
--- a/c_glib/arrow-glib/array-builder.h
+++ b/c_glib/arrow-glib/array-builder.h
@@ -884,6 +884,58 @@ gboolean garrow_date64_array_builder_append_null(GArrowDate64ArrayBuilder
*build
                                                  GError **error);
 
 
+#define GARROW_TYPE_TIMESTAMP_ARRAY_BUILDER     \
+  (garrow_timestamp_array_builder_get_type())
+#define GARROW_TIMESTAMP_ARRAY_BUILDER(obj)                             \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),                                    \
+                              GARROW_TYPE_TIMESTAMP_ARRAY_BUILDER,      \
+                              GArrowTimestampArrayBuilder))
+#define GARROW_TIMESTAMP_ARRAY_BUILDER_CLASS(klass)             \
+  (G_TYPE_CHECK_CLASS_CAST((klass),                             \
+                           GARROW_TYPE_TIMESTAMP_ARRAY_BUILDER, \
+                           GArrowTimestampArrayBuilderClass))
+#define GARROW_IS_TIMESTAMP_ARRAY_BUILDER(obj)                          \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),                                    \
+                              GARROW_TYPE_TIMESTAMP_ARRAY_BUILDER))
+#define GARROW_IS_TIMESTAMP_ARRAY_BUILDER_CLASS(klass)                  \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),                                     \
+                           GARROW_TYPE_TIMESTAMP_ARRAY_BUILDER))
+#define GARROW_TIMESTAMP_ARRAY_BUILDER_GET_CLASS(obj)                   \
+  (G_TYPE_INSTANCE_GET_CLASS((obj),                                     \
+                             GARROW_TYPE_TIMESTAMP_ARRAY_BUILDER,       \
+                             GArrowTimestampArrayBuilderClass))
+
+typedef struct _GArrowTimestampArrayBuilder      GArrowTimestampArrayBuilder;
+typedef struct _GArrowTimestampArrayBuilderClass GArrowTimestampArrayBuilderClass;
+
+/**
+ * GArrowTimestampArrayBuilder:
+ *
+ * It wraps `arrow::TimestampBuilder`.
+ */
+struct _GArrowTimestampArrayBuilder
+{
+  /*< private >*/
+  GArrowArrayBuilder parent_instance;
+};
+
+struct _GArrowTimestampArrayBuilderClass
+{
+  GArrowArrayBuilderClass parent_class;
+};
+
+GType garrow_timestamp_array_builder_get_type(void) G_GNUC_CONST;
+
+GArrowTimestampArrayBuilder *
+garrow_timestamp_array_builder_new(GArrowTimestampDataType *data_type);
+
+gboolean garrow_timestamp_array_builder_append(GArrowTimestampArrayBuilder *builder,
+                                               gint64 value,
+                                               GError **error);
+gboolean garrow_timestamp_array_builder_append_null(GArrowTimestampArrayBuilder *builder,
+                                                    GError **error);
+
+
 #define GARROW_TYPE_TIME32_ARRAY_BUILDER        \
   (garrow_time32_array_builder_get_type())
 #define GARROW_TIME32_ARRAY_BUILDER(obj)                        \

http://git-wip-us.apache.org/repos/asf/arrow/blob/875be96d/c_glib/arrow-glib/array.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/array.cpp b/c_glib/arrow-glib/array.cpp
index 17553ec..a52ea05 100644
--- a/c_glib/arrow-glib/array.cpp
+++ b/c_glib/arrow-glib/array.cpp
@@ -178,6 +178,12 @@ G_BEGIN_DECLS
  * more date data. If you don't have Arrow format data, you need to
  * use #GArrowDate64ArrayBuilder to create a new array.
  *
+ * #GArrowTimestampArray is a class for the number of
+ * seconds/milliseconds/microseconds/nanoseconds since UNIX epoch in
+ * 64-bit signed integer array. It can store zero or more timestamp
+ * data. If you don't have Arrow format data, you need to use
+ * #GArrowTimestampArrayBuilder to create a new array.
+ *
  * #GArrowTime32Array is a class for the number of seconds or
  * milliseconds since midnight in 32-bit signed integer array. It can
  * store zero or more time data. If you don't have Arrow format data,
@@ -1704,6 +1710,89 @@ garrow_date64_array_get_values(GArrowDate64Array *array,
 }
 
 
+G_DEFINE_TYPE(GArrowTimestampArray,             \
+              garrow_timestamp_array,           \
+              GARROW_TYPE_PRIMITIVE_ARRAY)
+
+static void
+garrow_timestamp_array_init(GArrowTimestampArray *object)
+{
+}
+
+static void
+garrow_timestamp_array_class_init(GArrowTimestampArrayClass *klass)
+{
+}
+
+/**
+ * garrow_timestamp_array_new:
+ * @data_type: The #GArrowTimestampDataType.
+ * @length: The number of elements.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowTimestampArray.
+ *
+ * Since: 0.7.0
+ */
+GArrowTimestampArray *
+garrow_timestamp_array_new(GArrowTimestampDataType *data_type,
+                           gint64 length,
+                           GArrowBuffer *data,
+                           GArrowBuffer *null_bitmap,
+                           gint64 n_nulls)
+{
+  auto array =
+    garrow_primitive_array_new<arrow::TimestampType>(GARROW_DATA_TYPE(data_type),
+                                                     length,
+                                                     data,
+                                                     null_bitmap,
+                                                     n_nulls);
+  return GARROW_TIMESTAMP_ARRAY(array);
+}
+
+/**
+ * garrow_timestamp_array_get_value:
+ * @array: A #GArrowTimestampArray.
+ * @i: The index of the target value.
+ *
+ * Returns: The i-th value.
+ *
+ * Since: 0.7.0
+ */
+gint64
+garrow_timestamp_array_get_value(GArrowTimestampArray *array,
+                                 gint64 i)
+{
+  auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+  return static_cast<arrow::TimestampArray *>(arrow_array.get())->Value(i);
+}
+
+/**
+ * garrow_timestamp_array_get_values:
+ * @array: A #GArrowTimestampArray.
+ * @length: (out): The number of values.
+ *
+ * Returns: (array length=length): The raw values.
+ *
+ * Since: 0.7.0
+ */
+const gint64 *
+garrow_timestamp_array_get_values(GArrowTimestampArray *array,
+                                  gint64 *length)
+{
+  auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+  auto values =
+    garrow_array_get_values_raw<arrow::TimestampType>(arrow_array, length);
+  return reinterpret_cast<const gint64 *>(values);
+}
+
+
 G_DEFINE_TYPE(GArrowTime32Array,               \
               garrow_time32_array,             \
               GARROW_TYPE_PRIMITIVE_ARRAY)
@@ -2135,6 +2224,9 @@ garrow_array_new_raw(std::shared_ptr<arrow::Array> *arrow_array)
   case arrow::Type::type::DATE64:
     type = GARROW_TYPE_DATE64_ARRAY;
     break;
+  case arrow::Type::type::TIMESTAMP:
+    type = GARROW_TYPE_TIMESTAMP_ARRAY;
+    break;
   case arrow::Type::type::TIME32:
     type = GARROW_TYPE_TIME32_ARRAY;
     break;

http://git-wip-us.apache.org/repos/asf/arrow/blob/875be96d/c_glib/arrow-glib/array.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/array.h b/c_glib/arrow-glib/array.h
index 9aaca47..da69207 100644
--- a/c_glib/arrow-glib/array.h
+++ b/c_glib/arrow-glib/array.h
@@ -966,6 +966,60 @@ const gint64 *garrow_date64_array_get_values(GArrowDate64Array *array,
                                              gint64 *length);
 
 
+#define GARROW_TYPE_TIMESTAMP_ARRAY             \
+  (garrow_timestamp_array_get_type())
+#define GARROW_TIMESTAMP_ARRAY(obj)                             \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),                            \
+                              GARROW_TYPE_TIMESTAMP_ARRAY,      \
+                              GArrowTimestampArray))
+#define GARROW_TIMESTAMP_ARRAY_CLASS(klass)             \
+  (G_TYPE_CHECK_CLASS_CAST((klass),                     \
+                           GARROW_TYPE_TIMESTAMP_ARRAY, \
+                           GArrowTimestampArrayClass))
+#define GARROW_IS_TIMESTAMP_ARRAY(obj)                          \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),                            \
+                              GARROW_TYPE_TIMESTAMP_ARRAY))
+#define GARROW_IS_TIMESTAMP_ARRAY_CLASS(klass)                  \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),                             \
+                           GARROW_TYPE_TIMESTAMP_ARRAY))
+#define GARROW_TIMESTAMP_ARRAY_GET_CLASS(obj)                   \
+  (G_TYPE_INSTANCE_GET_CLASS((obj),                             \
+                             GARROW_TYPE_TIMESTAMP_ARRAY,       \
+                             GArrowTimestampArrayClass))
+
+typedef struct _GArrowTimestampArray         GArrowTimestampArray;
+typedef struct _GArrowTimestampArrayClass    GArrowTimestampArrayClass;
+
+/**
+ * GArrowTimestampArray:
+ *
+ * It wraps `arrow::TimestampArray`.
+ */
+struct _GArrowTimestampArray
+{
+  /*< private >*/
+  GArrowPrimitiveArray parent_instance;
+};
+
+struct _GArrowTimestampArrayClass
+{
+  GArrowPrimitiveArrayClass parent_class;
+};
+
+GType garrow_timestamp_array_get_type(void) G_GNUC_CONST;
+
+GArrowTimestampArray *garrow_timestamp_array_new(GArrowTimestampDataType *data_type,
+                                                 gint64 length,
+                                                 GArrowBuffer *data,
+                                                 GArrowBuffer *null_bitmap,
+                                                 gint64 n_nulls);
+
+gint64 garrow_timestamp_array_get_value(GArrowTimestampArray *array,
+                                        gint64 i);
+const gint64 *garrow_timestamp_array_get_values(GArrowTimestampArray *array,
+                                                gint64 *length);
+
+
 #define GARROW_TYPE_TIME32_ARRAY                \
   (garrow_time32_array_get_type())
 #define GARROW_TIME32_ARRAY(obj)                        \

http://git-wip-us.apache.org/repos/asf/arrow/blob/875be96d/c_glib/arrow-glib/data-type.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/data-type.cpp b/c_glib/arrow-glib/data-type.cpp
index c2c7461..acb1484 100644
--- a/c_glib/arrow-glib/data-type.cpp
+++ b/c_glib/arrow-glib/data-type.cpp
@@ -75,6 +75,10 @@ G_BEGIN_DECLS
  * #GArrowDate64DataType is a class for the number of milliseconds
  * since UNIX epoch in 64-bit signed integer data type.
  *
+ * #GArrowTimestampDataType is a class for the number of
+ * seconds/milliseconds/microseconds/nanoseconds since UNIX epoch in
+ * 64-bit signed integer data type.
+ *
  * #GArrowTime32DataType is a class for the number of seconds or
  * milliseconds since midnight in 32-bit signed integer data type.
  *
@@ -738,6 +742,43 @@ garrow_date64_data_type_new(void)
 }
 
 
+G_DEFINE_TYPE(GArrowTimestampDataType,                \
+              garrow_timestamp_data_type,             \
+              GARROW_TYPE_DATA_TYPE)
+
+static void
+garrow_timestamp_data_type_init(GArrowTimestampDataType *object)
+{
+}
+
+static void
+garrow_timestamp_data_type_class_init(GArrowTimestampDataTypeClass *klass)
+{
+}
+
+/**
+ * garrow_timestamp_data_type_new:
+ * @unit: The unit of the timestamp data.
+ *
+ * Returns: A newly created the number of
+ *   seconds/milliseconds/microseconds/nanoseconds since UNIX epoch in
+ *   64-bit signed integer data type.
+ *
+ * Since: 0.7.0
+ */
+GArrowTimestampDataType *
+garrow_timestamp_data_type_new(GArrowTimeUnit unit)
+{
+  auto arrow_unit = garrow_time_unit_to_raw(unit);
+  auto arrow_data_type = arrow::timestamp(arrow_unit);
+  auto data_type =
+    GARROW_TIMESTAMP_DATA_TYPE(g_object_new(GARROW_TYPE_TIMESTAMP_DATA_TYPE,
+                                            "data-type", &arrow_data_type,
+                                            NULL));
+  return data_type;
+}
+
+
 G_DEFINE_TYPE(GArrowTimeDataType,               \
               garrow_time_data_type,            \
               GARROW_TYPE_DATA_TYPE)
@@ -1057,6 +1098,9 @@ garrow_data_type_new_raw(std::shared_ptr<arrow::DataType> *arrow_data_type)
   case arrow::Type::type::DATE64:
     type = GARROW_TYPE_DATE64_DATA_TYPE;
     break;
+  case arrow::Type::type::TIMESTAMP:
+    type = GARROW_TYPE_TIMESTAMP_DATA_TYPE;
+    break;
   case arrow::Type::type::TIME32:
     type = GARROW_TYPE_TIME32_DATA_TYPE;
     break;

http://git-wip-us.apache.org/repos/asf/arrow/blob/875be96d/c_glib/arrow-glib/data-type.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/data-type.h b/c_glib/arrow-glib/data-type.h
index c01201d..a450ab3 100644
--- a/c_glib/arrow-glib/data-type.h
+++ b/c_glib/arrow-glib/data-type.h
@@ -780,6 +780,50 @@ GType                 garrow_date64_data_type_get_type (void) G_GNUC_CONST;
 GArrowDate64DataType *garrow_date64_data_type_new      (void);
 
 
+#define GARROW_TYPE_TIMESTAMP_DATA_TYPE         \
+  (garrow_timestamp_data_type_get_type())
+#define GARROW_TIMESTAMP_DATA_TYPE(obj)                         \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),                            \
+                              GARROW_TYPE_TIMESTAMP_DATA_TYPE,  \
+                              GArrowTimestampDataType))
+#define GARROW_TIMESTAMP_DATA_TYPE_CLASS(klass)                 \
+  (G_TYPE_CHECK_CLASS_CAST((klass),                             \
+                           GARROW_TYPE_TIMESTAMP_DATA_TYPE,     \
+                           GArrowTimestampDataTypeClass))
+#define GARROW_IS_TIMESTAMP_DATA_TYPE(obj)                      \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),                            \
+                              GARROW_TYPE_TIMESTAMP_DATA_TYPE))
+#define GARROW_IS_TIMESTAMP_DATA_TYPE_CLASS(klass)              \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),                             \
+                           GARROW_TYPE_TIMESTAMP_DATA_TYPE))
+#define GARROW_TIMESTAMP_DATA_TYPE_GET_CLASS(obj)               \
+  (G_TYPE_INSTANCE_GET_CLASS((obj),                             \
+                             GARROW_TYPE_TIMESTAMP_DATA_TYPE,   \
+                             GArrowTimestampDataTypeClass))
+
+typedef struct _GArrowTimestampDataType         GArrowTimestampDataType;
+typedef struct _GArrowTimestampDataTypeClass    GArrowTimestampDataTypeClass;
+
+/**
+ * GArrowTimestampDataType:
+ *
+ * It wraps `arrow::TimestampType`.
+ */
+struct _GArrowTimestampDataType
+{
+  /*< private >*/
+  GArrowDataType parent_instance;
+};
+
+struct _GArrowTimestampDataTypeClass
+{
+  GArrowDataTypeClass parent_class;
+};
+
+GType                 garrow_timestamp_data_type_get_type (void) G_GNUC_CONST;
+GArrowTimestampDataType *garrow_timestamp_data_type_new   (GArrowTimeUnit unit);
+
+
 #define GARROW_TYPE_TIME_DATA_TYPE              \
   (garrow_time_data_type_get_type())
 #define GARROW_TIME_DATA_TYPE(obj)                              \

http://git-wip-us.apache.org/repos/asf/arrow/blob/875be96d/c_glib/test/helper/buildable.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/helper/buildable.rb b/c_glib/test/helper/buildable.rb
index cb427d7..0ed5759 100644
--- a/c_glib/test/helper/buildable.rb
+++ b/c_glib/test/helper/buildable.rb
@@ -73,6 +73,12 @@ module Helper
       build_array(Arrow::Date64ArrayBuilder.new, values)
     end
 
+    def build_timestamp_array(unit, values)
+      data_type = Arrow::TimestampDataType.new(unit)
+      build_array(Arrow::TimestampArrayBuilder.new(data_type),
+                  values)
+    end
+
     def build_time32_array(unit, values)
       build_array(Arrow::Time32ArrayBuilder.new(Arrow::Time32DataType.new(unit)),
                   values)

http://git-wip-us.apache.org/repos/asf/arrow/blob/875be96d/c_glib/test/test-timestamp-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-timestamp-array.rb b/c_glib/test/test-timestamp-array.rb
new file mode 100644
index 0000000..7934023
--- /dev/null
+++ b/c_glib/test/test-timestamp-array.rb
@@ -0,0 +1,57 @@
+# 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.
+
+class TestTimestampArray < Test::Unit::TestCase
+  include Helper::Buildable
+  include Helper::Omittable
+
+  def test_new
+    epoch = 0
+    after_epoch = 1504953190854 # 2017-09-09T10:33:10.854Z
+    raw_data = [epoch, after_epoch]
+    data_type = Arrow::TimestampDataType.new(:milli)
+    assert_equal(build_timestamp_array(:milli, [*raw_data, nil]),
+                 Arrow::TimestampArray.new(data_type,
+                                           3,
+                                           Arrow::Buffer.new(raw_data.pack("q*")),
+                                           Arrow::Buffer.new([0b011].pack("C*")),
+                                           -1))
+  end
+
+  def test_buffer
+    epoch = 0
+    after_epoch = 1504953190854 # 2017-09-09T10:33:10.854Z
+    raw_data = [epoch, after_epoch]
+    array = build_timestamp_array(:milli, raw_data)
+    assert_equal(raw_data.pack("q*"),
+                 array.buffer.data.to_s)
+  end
+
+  def test_value
+    after_epoch = 1504953190854 # 2017-09-09T10:33:10.854Z
+    array = build_timestamp_array(:milli, [after_epoch])
+    assert_equal(after_epoch, array.get_value(0))
+  end
+
+  def test_values
+    epoch = 0
+    after_epoch = 1504953190854 # 2017-09-09T10:33:10.854Z
+    raw_data = [epoch, after_epoch]
+    array = build_timestamp_array(:milli, raw_data)
+    assert_equal(raw_data, array.values)
+  end
+end

http://git-wip-us.apache.org/repos/asf/arrow/blob/875be96d/c_glib/test/test-timestamp-data-type.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-timestamp-data-type.rb b/c_glib/test/test-timestamp-data-type.rb
new file mode 100644
index 0000000..8303887
--- /dev/null
+++ b/c_glib/test/test-timestamp-data-type.rb
@@ -0,0 +1,63 @@
+# 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.
+
+class TestTimestampDataType < Test::Unit::TestCase
+  def test_type
+    data_type = Arrow::TimestampDataType.new(:micro)
+    assert_equal(Arrow::Type::TIMESTAMP, data_type.id)
+  end
+
+  sub_test_case("second") do
+    def setup
+      @data_type = Arrow::TimestampDataType.new(:second)
+    end
+
+    def test_to_s
+      assert_equal("timestamp[s]", @data_type.to_s)
+    end
+  end
+
+  sub_test_case("millisecond") do
+    def setup
+      @data_type = Arrow::TimestampDataType.new(:milli)
+    end
+
+    def test_to_s
+      assert_equal("timestamp[ms]", @data_type.to_s)
+    end
+  end
+
+  sub_test_case("micro") do
+    def setup
+      @data_type = Arrow::TimestampDataType.new(:micro)
+    end
+
+    def test_to_s
+      assert_equal("timestamp[us]", @data_type.to_s)
+    end
+  end
+
+  sub_test_case("nano") do
+    def setup
+      @data_type = Arrow::TimestampDataType.new(:nano)
+    end
+
+    def test_to_s
+      assert_equal("timestamp[ns]", @data_type.to_s)
+    end
+  end
+end


Mime
View raw message