You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by sh...@apache.org on 2018/11/18 11:31:46 UTC
[arrow] branch master updated: ARROW-3830: [GLib] Add GArrowCodec
This is an automated email from the ASF dual-hosted git repository.
shiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new b315aa0 ARROW-3830: [GLib] Add GArrowCodec
b315aa0 is described below
commit b315aa01fa88c9f9b0a29472d3d3745fd65edb8a
Author: Kouhei Sutou <ko...@clear-code.com>
AuthorDate: Sun Nov 18 20:31:21 2018 +0900
ARROW-3830: [GLib] Add GArrowCodec
Author: Kouhei Sutou <ko...@clear-code.com>
Closes #2987 from kou/glib-codec and squashes the following commits:
445a95a9 <Kouhei Sutou> Add GArrowCodec
---
c_glib/arrow-glib/Makefile.am | 3 +
c_glib/arrow-glib/arrow-glib.h | 1 +
c_glib/arrow-glib/arrow-glib.hpp | 1 +
c_glib/arrow-glib/codec.cpp | 224 ++++++++++++++++++++++++++++++
c_glib/arrow-glib/codec.h | 67 +++++++++
c_glib/arrow-glib/codec.hpp | 34 +++++
c_glib/arrow-glib/meson.build | 3 +
c_glib/doc/arrow-glib/arrow-glib-docs.xml | 4 +
c_glib/test/test-codec.rb | 23 +++
9 files changed, 360 insertions(+)
diff --git a/c_glib/arrow-glib/Makefile.am b/c_glib/arrow-glib/Makefile.am
index bc9fcee..bf97168 100644
--- a/c_glib/arrow-glib/Makefile.am
+++ b/c_glib/arrow-glib/Makefile.am
@@ -54,6 +54,7 @@ libarrow_glib_la_headers = \
basic-data-type.h \
buffer.h \
chunked-array.h \
+ codec.h \
column.h \
composite-array.h \
composite-data-type.h \
@@ -105,6 +106,7 @@ libarrow_glib_la_sources = \
basic-data-type.cpp \
buffer.cpp \
chunked-array.cpp \
+ codec.cpp \
column.cpp \
composite-array.cpp \
composite-data-type.cpp \
@@ -150,6 +152,7 @@ libarrow_glib_la_cpp_headers = \
basic-data-type.hpp \
buffer.hpp \
chunked-array.hpp \
+ codec.hpp \
column.hpp \
data-type.hpp \
decimal.hpp \
diff --git a/c_glib/arrow-glib/arrow-glib.h b/c_glib/arrow-glib/arrow-glib.h
index 4921939..2a4de13 100644
--- a/c_glib/arrow-glib/arrow-glib.h
+++ b/c_glib/arrow-glib/arrow-glib.h
@@ -25,6 +25,7 @@
#include <arrow-glib/array.h>
#include <arrow-glib/array-builder.h>
#include <arrow-glib/chunked-array.h>
+#include <arrow-glib/codec.h>
#include <arrow-glib/column.h>
#include <arrow-glib/compute.h>
#include <arrow-glib/data-type.h>
diff --git a/c_glib/arrow-glib/arrow-glib.hpp b/c_glib/arrow-glib/arrow-glib.hpp
index 18e9925..ac8563c 100644
--- a/c_glib/arrow-glib/arrow-glib.hpp
+++ b/c_glib/arrow-glib/arrow-glib.hpp
@@ -25,6 +25,7 @@
#include <arrow-glib/array-builder.hpp>
#include <arrow-glib/buffer.hpp>
#include <arrow-glib/chunked-array.hpp>
+#include <arrow-glib/codec.hpp>
#include <arrow-glib/column.hpp>
#include <arrow-glib/data-type.hpp>
#include <arrow-glib/error.hpp>
diff --git a/c_glib/arrow-glib/codec.cpp b/c_glib/arrow-glib/codec.cpp
new file mode 100644
index 0000000..205ae89
--- /dev/null
+++ b/c_glib/arrow-glib/codec.cpp
@@ -0,0 +1,224 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <arrow-glib/codec.hpp>
+#include <arrow-glib/error.hpp>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION: codec
+ * @title: Codec related type and class
+ * @include: arrow-glib/arrow-glib.h
+ *
+ * #GArrowCompressionType provides compression types corresponding to
+ * `arrow::Compression::type`.
+ *
+ * #GArrowCocec is a class for compressing and decompressing data.
+ */
+
+typedef struct GArrowCodecPrivate_ {
+ arrow::util::Codec *codec;
+} GArrowCodecPrivate;
+
+enum {
+ PROP_CODEC = 1
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(GArrowCodec, garrow_codec, G_TYPE_OBJECT)
+
+#define GARROW_CODEC_GET_PRIVATE(object) \
+ static_cast<GArrowCodecPrivate *>( \
+ garrow_codec_get_instance_private( \
+ GARROW_CODEC(object)))
+
+static void
+garrow_codec_finalize(GObject *object)
+{
+ auto priv = GARROW_CODEC_GET_PRIVATE(object);
+
+ delete priv->codec;
+
+ G_OBJECT_CLASS(garrow_codec_parent_class)->finalize(object);
+}
+
+static void
+garrow_codec_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ auto priv = GARROW_CODEC_GET_PRIVATE(object);
+
+ switch (prop_id) {
+ case PROP_CODEC:
+ priv->codec = static_cast<arrow::util::Codec *>(g_value_get_pointer(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_codec_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_codec_init(GArrowCodec *object)
+{
+}
+
+static void
+garrow_codec_class_init(GArrowCodecClass *klass)
+{
+ GParamSpec *spec;
+
+ auto gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->finalize = garrow_codec_finalize;
+ gobject_class->set_property = garrow_codec_set_property;
+ gobject_class->get_property = garrow_codec_get_property;
+
+ spec = g_param_spec_pointer("codec",
+ "Codec",
+ "The raw arrow::util::Codec *",
+ static_cast<GParamFlags>(G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property(gobject_class, PROP_CODEC, spec);
+}
+
+/**
+ * garrow_codec_new:
+ * @type: A #GArrowCodompressionType.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: A newly created #GArrowCodec on success, %NULL on error.
+ *
+ * Since: 0.12.0
+ */
+GArrowCodec *
+garrow_codec_new(GArrowCompressionType type,
+ GError **error)
+{
+ auto arrow_type = garrow_compression_type_to_raw(type);
+ std::unique_ptr<arrow::util::Codec> arrow_codec;
+ auto status = arrow::util::Codec::Create(arrow_type, &arrow_codec);
+ if (garrow_error_check(error, status, "[codec][new]")) {
+ return garrow_codec_new_raw(arrow_codec.release());
+ } else {
+ return NULL;
+ }
+}
+
+/**
+ * garrow_codec_get_name:
+ * @codec: A #GArrowCodec.
+ *
+ * Returns: The name of the codec.
+ *
+ * Since: 0.12.0
+ */
+const gchar *
+garrow_codec_get_name(GArrowCodec *codec)
+{
+ auto arrow_codec = garrow_codec_get_raw(codec);
+ return arrow_codec->name();
+}
+
+G_END_DECLS
+
+GArrowCompressionType
+garrow_compression_type_from_raw(arrow::Compression::type arrow_type)
+{
+ switch (arrow_type) {
+ case arrow::Compression::type::UNCOMPRESSED:
+ return GARROW_COMPRESSION_TYPE_UNCOMPRESSED;
+ case arrow::Compression::type::SNAPPY:
+ return GARROW_COMPRESSION_TYPE_SNAPPY;
+ case arrow::Compression::type::GZIP:
+ return GARROW_COMPRESSION_TYPE_GZIP;
+ case arrow::Compression::type::BROTLI:
+ return GARROW_COMPRESSION_TYPE_BROTLI;
+ case arrow::Compression::type::ZSTD:
+ return GARROW_COMPRESSION_TYPE_ZSTD;
+ case arrow::Compression::type::LZ4:
+ return GARROW_COMPRESSION_TYPE_LZ4;
+ case arrow::Compression::type::LZO:
+ return GARROW_COMPRESSION_TYPE_LZO;
+ case arrow::Compression::type::BZ2:
+ return GARROW_COMPRESSION_TYPE_BZ2;
+ default:
+ return GARROW_COMPRESSION_TYPE_UNCOMPRESSED;
+ }
+}
+
+arrow::Compression::type
+garrow_compression_type_to_raw(GArrowCompressionType type)
+{
+ switch (type) {
+ case GARROW_COMPRESSION_TYPE_UNCOMPRESSED:
+ return arrow::Compression::type::UNCOMPRESSED;
+ case GARROW_COMPRESSION_TYPE_SNAPPY:
+ return arrow::Compression::type::SNAPPY;
+ case GARROW_COMPRESSION_TYPE_GZIP:
+ return arrow::Compression::type::GZIP;
+ case GARROW_COMPRESSION_TYPE_BROTLI:
+ return arrow::Compression::type::BROTLI;
+ case GARROW_COMPRESSION_TYPE_ZSTD:
+ return arrow::Compression::type::ZSTD;
+ case GARROW_COMPRESSION_TYPE_LZ4:
+ return arrow::Compression::type::LZ4;
+ case GARROW_COMPRESSION_TYPE_LZO:
+ return arrow::Compression::type::LZO;
+ case GARROW_COMPRESSION_TYPE_BZ2:
+ return arrow::Compression::type::BZ2;
+ default:
+ return arrow::Compression::type::UNCOMPRESSED;
+ }
+}
+
+GArrowCodec *
+garrow_codec_new_raw(arrow::util::Codec *arrow_codec)
+{
+ auto codec = GARROW_CODEC(g_object_new(GARROW_TYPE_CODEC,
+ "codec", arrow_codec,
+ NULL));
+ return codec;
+}
+
+arrow::util::Codec *
+garrow_codec_get_raw(GArrowCodec *codec)
+{
+ auto priv = GARROW_CODEC_GET_PRIVATE(codec);
+ return priv->codec;
+}
diff --git a/c_glib/arrow-glib/codec.h b/c_glib/arrow-glib/codec.h
new file mode 100644
index 0000000..5feab2b
--- /dev/null
+++ b/c_glib/arrow-glib/codec.h
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow-glib/gobject-type.h>
+
+G_BEGIN_DECLS
+
+/**
+ * GArrowCompressionType:
+ * @GARROW_COMPRESSION_TYPE_UNCOMPRESSED: Not compressed.
+ * @GARROW_COMPRESSION_TYPE_SNAPPY: Snappy compression.
+ * @GARROW_COMPRESSION_TYPE_GZIP: gzip compression.
+ * @GARROW_COMPRESSION_TYPE_BROTLI: Brotli compression.
+ * @GARROW_COMPRESSION_TYPE_ZSTD: Zstandard compression.
+ * @GARROW_COMPRESSION_TYPE_LZ4: LZ4 compression.
+ * @GARROW_COMPRESSION_TYPE_LZO: LZO compression.
+ * @GARROW_COMPRESSION_TYPE_BZ2: bzip2 compression.
+ *
+ * They are corresponding to `arrow::Compression::type` values.
+ */
+typedef enum {
+ GARROW_COMPRESSION_TYPE_UNCOMPRESSED,
+ GARROW_COMPRESSION_TYPE_SNAPPY,
+ GARROW_COMPRESSION_TYPE_GZIP,
+ GARROW_COMPRESSION_TYPE_BROTLI,
+ GARROW_COMPRESSION_TYPE_ZSTD,
+ GARROW_COMPRESSION_TYPE_LZ4,
+ GARROW_COMPRESSION_TYPE_LZO,
+ GARROW_COMPRESSION_TYPE_BZ2
+} GArrowCompressionType;
+
+
+#define GARROW_TYPE_CODEC (garrow_codec_get_type())
+G_DECLARE_DERIVABLE_TYPE(GArrowCodec,
+ garrow_codec,
+ GARROW,
+ CODEC,
+ GObject)
+struct _GArrowCodecClass
+{
+ GObjectClass parent_class;
+};
+
+GArrowCodec *garrow_codec_new(GArrowCompressionType type,
+ GError **error);
+
+const gchar *garrow_codec_get_name(GArrowCodec *codec);
+
+G_END_DECLS
diff --git a/c_glib/arrow-glib/codec.hpp b/c_glib/arrow-glib/codec.hpp
new file mode 100644
index 0000000..14c3ad7
--- /dev/null
+++ b/c_glib/arrow-glib/codec.hpp
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow/util/compression.h>
+
+#include <arrow-glib/codec.h>
+
+GArrowCompressionType
+garrow_compression_type_from_raw(arrow::Compression::type arrow_type);
+arrow::Compression::type
+garrow_compression_type_to_raw(GArrowCompressionType type);
+
+GArrowCodec *
+garrow_codec_new_raw(arrow::util::Codec *arrow_codec);
+arrow::util::Codec *
+garrow_codec_get_raw(GArrowCodec *codec);
diff --git a/c_glib/arrow-glib/meson.build b/c_glib/arrow-glib/meson.build
index b290039..d962ec1 100644
--- a/c_glib/arrow-glib/meson.build
+++ b/c_glib/arrow-glib/meson.build
@@ -23,6 +23,7 @@ sources = files(
'basic-data-type.cpp',
'buffer.cpp',
'chunked-array.cpp',
+ 'codec.cpp',
'column.cpp',
'composite-array.cpp',
'composite-data-type.cpp',
@@ -71,6 +72,7 @@ c_headers = files(
'basic-data-type.h',
'buffer.h',
'chunked-array.h',
+ 'codec.h',
'column.h',
'composite-array.h',
'composite-data-type.h',
@@ -123,6 +125,7 @@ cpp_headers = files(
'basic-data-type.hpp',
'buffer.hpp',
'chunked-array.hpp',
+ 'codec.hpp',
'column.hpp',
'data-type.hpp',
'decimal.hpp',
diff --git a/c_glib/doc/arrow-glib/arrow-glib-docs.xml b/c_glib/doc/arrow-glib/arrow-glib-docs.xml
index 948a321..17b7500 100644
--- a/c_glib/doc/arrow-glib/arrow-glib-docs.xml
+++ b/c_glib/doc/arrow-glib/arrow-glib-docs.xml
@@ -85,6 +85,10 @@
<title>Buffer</title>
<xi:include href="xml/buffer.xml"/>
</chapter>
+ <chapter id="codec">
+ <title>Codec</title>
+ <xi:include href="xml/codec.xml"/>
+ </chapter>
<chapter id="error">
<title>Error</title>
<xi:include href="xml/error.xml"/>
diff --git a/c_glib/test/test-codec.rb b/c_glib/test/test-codec.rb
new file mode 100644
index 0000000..6617815
--- /dev/null
+++ b/c_glib/test/test-codec.rb
@@ -0,0 +1,23 @@
+# 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 TestCodec < Test::Unit::TestCase
+ def test_name
+ codec = Arrow::Codec.new(:gzip)
+ assert_equal("gzip", codec.name)
+ end
+end