From 6a0513b7273dbcb8416bd6f50de666b01430ac75 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Sat, 25 Sep 2021 05:04:13 +0900 Subject: [PATCH] ARROW-14072: [GLib][Parquet] Add gparquet_arrow_file_reader_get_n_rows() Version macros are removed. We reuse Apache Arrow GLib's version macros for Apache Parquet GLib. Closes #11215 from kou/glib-parquet-reader-n-rows Authored-by: Sutou Kouhei Signed-off-by: Sutou Kouhei --- c_glib/doc/parquet-glib/meson.build | 2 +- c_glib/doc/parquet-glib/parquet-glib-docs.xml | 16 +- c_glib/parquet-glib/arrow-file-reader.cpp | 15 ++ c_glib/parquet-glib/arrow-file-reader.h | 8 +- c_glib/parquet-glib/arrow-file-writer.h | 30 ++- c_glib/parquet-glib/meson.build | 10 - c_glib/parquet-glib/parquet-glib.h | 2 - c_glib/parquet-glib/version.h.in | 218 ------------------ c_glib/test/parquet/test-arrow-file-reader.rb | 4 + 9 files changed, 43 insertions(+), 262 deletions(-) delete mode 100644 c_glib/parquet-glib/version.h.in diff --git a/c_glib/doc/parquet-glib/meson.build b/c_glib/doc/parquet-glib/meson.build index 5c717b14a1ba6..f4ee794d05a1a 100644 --- a/c_glib/doc/parquet-glib/meson.build +++ b/c_glib/doc/parquet-glib/meson.build @@ -66,7 +66,7 @@ gnome.gtkdoc(package_id, gobject_typesfile: package_id + '.types', scan_args: [ '--rebuild-types', - '--deprecated-guards=GPARQUET_DISABLE_DEPRECATED', + '--deprecated-guards=GARROW_DISABLE_DEPRECATED', ], mkdb_args: [ '--output-format=xml', diff --git a/c_glib/doc/parquet-glib/parquet-glib-docs.xml b/c_glib/doc/parquet-glib/parquet-glib-docs.xml index 77812e012d706..0d42a7d5b7419 100644 --- a/c_glib/doc/parquet-glib/parquet-glib-docs.xml +++ b/c_glib/doc/parquet-glib/parquet-glib-docs.xml @@ -45,14 +45,6 @@ - - Misc - - Version - - - - Object Hierarchy @@ -65,6 +57,10 @@ Index of deprecated API + + Index of new symbols in 6.0.0 + + Index of new symbols in 1.0.0 @@ -73,10 +69,6 @@ Index of new symbols in 0.17.0 - - Index of new symbols in 0.16.0 - - Index of new symbols in 0.15.0 diff --git a/c_glib/parquet-glib/arrow-file-reader.cpp b/c_glib/parquet-glib/arrow-file-reader.cpp index d6c20cf42f0f2..2532db2020de2 100644 --- a/c_glib/parquet-glib/arrow-file-reader.cpp +++ b/c_glib/parquet-glib/arrow-file-reader.cpp @@ -351,6 +351,21 @@ gparquet_arrow_file_reader_get_n_row_groups(GParquetArrowFileReader *reader) return parquet_arrow_file_reader->num_row_groups(); } +/** + * gparquet_arrow_file_reader_get_n_rows: + * @reader: A #GParquetArrowFileReader. + * + * Returns: The number of rows. + * + * Since: 6.0.0 + */ +gint64 +gparquet_arrow_file_reader_get_n_rows(GParquetArrowFileReader *reader) +{ + auto parquet_arrow_file_reader = gparquet_arrow_file_reader_get_raw(reader); + return parquet_arrow_file_reader->parquet_reader()->metadata()->num_rows(); +} + /** * gparquet_arrow_file_reader_use_threads: * @reader: A #GParquetArrowFileReader. diff --git a/c_glib/parquet-glib/arrow-file-reader.h b/c_glib/parquet-glib/arrow-file-reader.h index 6832f3a2d3d55..abea06c57f263 100644 --- a/c_glib/parquet-glib/arrow-file-reader.h +++ b/c_glib/parquet-glib/arrow-file-reader.h @@ -21,8 +21,6 @@ #include -#include - G_BEGIN_DECLS #define GPARQUET_TYPE_ARROW_FILE_READER (gparquet_arrow_file_reader_get_type()) @@ -47,7 +45,7 @@ GArrowTable * gparquet_arrow_file_reader_read_table(GParquetArrowFileReader *reader, GError **error); -GPARQUET_AVAILABLE_IN_1_0 +GARROW_AVAILABLE_IN_1_0 GArrowTable * gparquet_arrow_file_reader_read_row_group(GParquetArrowFileReader *reader, gint row_group_index, @@ -67,6 +65,10 @@ gparquet_arrow_file_reader_read_column_data(GParquetArrowFileReader *reader, gint gparquet_arrow_file_reader_get_n_row_groups(GParquetArrowFileReader *reader); +GARROW_AVAILABLE_IN_6_0 +gint64 +gparquet_arrow_file_reader_get_n_rows(GParquetArrowFileReader *reader); + void gparquet_arrow_file_reader_set_use_threads(GParquetArrowFileReader *reader, gboolean use_threads); diff --git a/c_glib/parquet-glib/arrow-file-writer.h b/c_glib/parquet-glib/arrow-file-writer.h index 14242138e799b..67083a0743e1f 100644 --- a/c_glib/parquet-glib/arrow-file-writer.h +++ b/c_glib/parquet-glib/arrow-file-writer.h @@ -21,8 +21,6 @@ #include -#include - G_BEGIN_DECLS #define GPARQUET_TYPE_WRITER_PROPERTIES \ @@ -37,55 +35,55 @@ struct _GParquetWriterPropertiesClass GObjectClass parent_class; }; -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 GParquetWriterProperties *gparquet_writer_properties_new(void); -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 void gparquet_writer_properties_set_compression(GParquetWriterProperties *properties, GArrowCompressionType compression_type, const gchar *path); -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 GArrowCompressionType gparquet_writer_properties_get_compression_path(GParquetWriterProperties *properties, const gchar *path); -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 void gparquet_writer_properties_enable_dictionary(GParquetWriterProperties *properties, const gchar *path); -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 void gparquet_writer_properties_disable_dictionary(GParquetWriterProperties *properties, const gchar *path); -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 gboolean gparquet_writer_properties_is_dictionary_enabled(GParquetWriterProperties *properties, const gchar *path); -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 void gparquet_writer_properties_set_dictionary_page_size_limit(GParquetWriterProperties *properties, gint64 limit); -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 gint64 gparquet_writer_properties_get_dictionary_page_size_limit(GParquetWriterProperties *properties); -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 void gparquet_writer_properties_set_batch_size(GParquetWriterProperties *properties, gint64 batch_size); -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 gint64 gparquet_writer_properties_get_batch_size(GParquetWriterProperties *properties); -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 void gparquet_writer_properties_set_max_row_group_length(GParquetWriterProperties *properties, gint64 length); -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 gint64 gparquet_writer_properties_get_max_row_group_length(GParquetWriterProperties *properties); -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 void gparquet_writer_properties_set_data_page_size(GParquetWriterProperties *properties, gint64 data_page_size); -GPARQUET_AVAILABLE_IN_0_17 +GARROW_AVAILABLE_IN_0_17 gint64 gparquet_writer_properties_get_data_page_size(GParquetWriterProperties *properties); diff --git a/c_glib/parquet-glib/meson.build b/c_glib/parquet-glib/meson.build index 316482dea3089..73cd9e45c95a3 100644 --- a/c_glib/parquet-glib/meson.build +++ b/c_glib/parquet-glib/meson.build @@ -36,16 +36,6 @@ cpp_headers = files( 'parquet-glib.hpp', ) -version_h_conf = configuration_data() -version_h_conf.set('GPARQUET_VERSION_MAJOR', version_major) -version_h_conf.set('GPARQUET_VERSION_MINOR', version_minor) -version_h_conf.set('GPARQUET_VERSION_MICRO', version_micro) -version_h_conf.set('GPARQUET_VERSION_TAG', version_tag) -version_h = configure_file(input: 'version.h.in', - output: 'version.h', - configuration: version_h_conf) -c_headers += version_h - headers = c_headers + cpp_headers install_headers(headers, subdir: project_name) diff --git a/c_glib/parquet-glib/parquet-glib.h b/c_glib/parquet-glib/parquet-glib.h index b5cdce7d649b9..6ae0f7e8fec90 100644 --- a/c_glib/parquet-glib/parquet-glib.h +++ b/c_glib/parquet-glib/parquet-glib.h @@ -19,7 +19,5 @@ #pragma once -#include - #include #include diff --git a/c_glib/parquet-glib/version.h.in b/c_glib/parquet-glib/version.h.in deleted file mode 100644 index 34edd9f13412c..0000000000000 --- a/c_glib/parquet-glib/version.h.in +++ /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. - */ - -#pragma once - -#include - -/** - * SECTION: version - * @section_id: version-macros - * @title: Version related macros - * @include: parquet-glib/parquet-glib.h - * - * Apache Parquet GLib provides macros that can be used by C pre-processor. - * They are useful to check version related things at compile time. - */ - -/** - * GPARQUET_VERSION_MAJOR: - * - * The major version. - * - * Since: 0.16.0 - */ -#define GPARQUET_VERSION_MAJOR (@GPARQUET_VERSION_MAJOR@) - -/** - * GPARQUET_VERSION_MINOR: - * - * The minor version. - * - * Since: 0.16.0 - */ -#define GPARQUET_VERSION_MINOR (@GPARQUET_VERSION_MINOR@) - -/** - * GPARQUET_VERSION_MICRO: - * - * The micro version. - * - * Since: 0.16.0 - */ -#define GPARQUET_VERSION_MICRO (@GPARQUET_VERSION_MICRO@) - -/** - * GPARQUET_VERSION_TAG: - * - * The version tag. Normally, it's an empty string. It's "SNAPSHOT" - * for snapshot version. - * - * Since: 0.16.0 - */ -#define GPARQUET_VERSION_TAG "@GPARQUET_VERSION_TAG@" - -/** - * GPARQUET_VERSION_CHECK: - * @major: A major version to check for. - * @minor: A minor version to check for. - * @micro: A micro version to check for. - * - * You can use this macro in C pre-processor. - * - * Returns: %TRUE if the compile time Apache Parquet GLib version is the - * same as or newer than the passed version, %FALSE otherwise. - * - * Since: 0.16.0 - */ -#define GPARQUET_VERSION_CHECK(major, minor, micro) \ - (GPARQUET_MAJOR_VERSION > (major) || \ - (GPARQUET_MAJOR_VERSION == (major) && \ - GPARQUET_MINOR_VERSION > (minor)) || \ - (GPARQUET_MAJOR_VERSION == (major) && \ - GPARQUET_MINOR_VERSION == (minor) && \ - GPARQUET_MICRO_VERSION >= (micro))) - -/** - * GPARQUET_DISABLE_DEPRECATION_WARNINGS: - * - * If this macro is defined, no deprecated warnings are produced. - * - * You must define this macro before including the - * parquet-glib/parquet-glib.h header. - * - * Since: 0.16.0 - */ - -#ifdef GPARQUET_DISABLE_DEPRECATION_WARNINGS -# define GPARQUET_DEPRECATED -# define GPARQUET_DEPRECATED_FOR(function) -# define GPARQUET_UNAVAILABLE(major, minor) -#else -# define GPARQUET_DEPRECATED G_DEPRECATED -# define GPARQUET_DEPRECATED_FOR(function) G_DEPRECATED_FOR(function) -# define GPARQUET_UNAVAILABLE(major, minor) G_UNAVAILABLE(major, minor) -#endif - -/** - * GPARQUET_VERSION_1_0: - * - * You can use this macro value for compile time API version check. - * - * Since: 1.0.0 - */ -#define GPARQUET_VERSION_1_0 G_ENCODE_VERSION(1, 0) - -/** - * GPARQUET_VERSION_0_16: - * - * You can use this macro value for compile time API version check. - * - * Since: 0.16.0 - */ -#define GPARQUET_VERSION_0_16 G_ENCODE_VERSION(0, 16) - -/** - * GPARQUET_VERSION_MIN_REQUIRED: - * - * You can use this macro for compile time API version check. - * - * This macro value must be one of the predefined version macros such - * as %GPARQUET_VERSION_0_16. - * - * If you use any functions that is defined by newer version than - * %GPARQUET_VERSION_MIN_REQUIRED, deprecated warnings are produced at - * compile time. - * - * You must define this macro before including the - * parquet-glib/parquet-glib.h header. - * - * Since: 0.16.0 - */ -#ifndef GPARQUET_VERSION_MIN_REQUIRED -# define GPARQUET_VERSION_MIN_REQUIRED \ - G_ENCODE_VERSION(GPARQUET_VERSION_MAJOR, GPARQUET_VERSION_MINOR) -#endif - -/** - * GPARQUET_VERSION_MAX_ALLOWED: - * - * You can use this macro for compile time API version check. - * - * This macro value must be one of the predefined version macros such - * as %GPARQUET_VERSION_0_16. - * - * If you use any functions that is defined by newer version than - * %GPARQUET_VERSION_MAX_ALLOWED, deprecated warnings are produced at - * compile time. - * - * You must define this macro before including the - * parquet-glib/parquet-glib.h header. - * - * Since: 0.16.0 - */ -#ifndef GPARQUET_VERSION_MAX_ALLOWED -# define GPARQUET_VERSION_MAX_ALLOWED \ - G_ENCODE_VERSION(GPARQUET_VERSION_MAJOR, GPARQUET_VERSION_MINOR) -#endif - - -#define GPARQUET_AVAILABLE_IN_ALL - -#if GPARQUET_VERSION_MIN_REQUIRED >= GPARQUET_VERSION_1_0 -# define GPARQUET_DEPRECATED_IN_1_0 GPARQUET_DEPRECATED -# define GPARQUET_DEPRECATED_IN_1_0_FOR(function) GPARQUET_DEPRECATED_FOR(function) -#else -# define GPARQUET_DEPRECATED_IN_1_0 -# define GPARQUET_DEPRECATED_IN_1_0_FOR(function) -#endif - -#if GPARQUET_VERSION_MAX_ALLOWED < GPARQUET_VERSION_1_0 -# define GPARQUET_AVAILABLE_IN_1_0 GPARQUET_UNAVAILABLE(1, 0) -#else -# define GPARQUET_AVAILABLE_IN_1_0 -#endif - -#if GPARQUET_VERSION_MIN_REQUIRED >= GPARQUET_VERSION_0_17 -# define GPARQUET_DEPRECATED_IN_0_17 GPARQUET_DEPRECATED -# define GPARQUET_DEPRECATED_IN_0_17_FOR(function) GPARQUET_DEPRECATED_FOR(function) -#else -# define GPARQUET_DEPRECATED_IN_0_17 -# define GPARQUET_DEPRECATED_IN_0_17_FOR(function) -#endif - -#if GPARQUET_VERSION_MAX_ALLOWED < GPARQUET_VERSION_0_17 -# define GPARQUET_AVAILABLE_IN_0_17 GPARQUET_UNAVAILABLE(0, 17) -#else -# define GPARQUET_AVAILABLE_IN_0_17 -#endif - -#if GPARQUET_VERSION_MIN_REQUIRED >= GPARQUET_VERSION_0_16 -# define GPARQUET_DEPRECATED_IN_0_16 GPARQUET_DEPRECATED -# define GPARQUET_DEPRECATED_IN_0_16_FOR(function) GPARQUET_DEPRECATED_FOR(function) -#else -# define GPARQUET_DEPRECATED_IN_0_16 -# define GPARQUET_DEPRECATED_IN_0_16_FOR(function) -#endif - -#if GPARQUET_VERSION_MAX_ALLOWED < GPARQUET_VERSION_0_16 -# define GPARQUET_AVAILABLE_IN_0_16 GPARQUET_UNAVAILABLE(0, 16) -#else -# define GPARQUET_AVAILABLE_IN_0_16 -#endif diff --git a/c_glib/test/parquet/test-arrow-file-reader.rb b/c_glib/test/parquet/test-arrow-file-reader.rb index 4aac394976208..45eb335965434 100644 --- a/c_glib/test/parquet/test-arrow-file-reader.rb +++ b/c_glib/test/parquet/test-arrow-file-reader.rb @@ -62,4 +62,8 @@ def test_read_column @reader.read_column_data(-1), ]) end + + def test_n_rows + assert_equal(2, @reader.n_rows) + end end