kou commented on code in PR #48681:
URL: https://github.com/apache/arrow/pull/48681#discussion_r2655944096
##########
c_glib/arrow-glib/writer.cpp:
##########
@@ -300,6 +301,320 @@ garrow_record_batch_file_writer_new(GArrowOutputStream
*sink,
}
}
+struct GArrowCSVWriteOptionsPrivate
+{
+ arrow::csv::WriteOptions write_options;
+};
+
+enum {
+ PROP_CSV_WRITE_OPTIONS_INCLUDE_HEADER = 1,
+ PROP_CSV_WRITE_OPTIONS_BATCH_SIZE,
+ PROP_CSV_WRITE_OPTIONS_DELIMITER,
+ PROP_CSV_WRITE_OPTIONS_NULL_STRING,
+ PROP_CSV_WRITE_OPTIONS_EOL,
+ PROP_CSV_WRITE_OPTIONS_QUOTING_STYLE,
+ PROP_CSV_WRITE_OPTIONS_QUOTING_HEADER,
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(GArrowCSVWriteOptions, garrow_csv_write_options,
G_TYPE_OBJECT)
+
+#define GARROW_CSV_WRITE_OPTIONS_GET_PRIVATE(object)
\
+ static_cast<GArrowCSVWriteOptionsPrivate *>(
\
+
garrow_csv_write_options_get_instance_private(GARROW_CSV_WRITE_OPTIONS(object)))
+
+static void
+garrow_csv_write_options_finalize(GObject *object)
+{
+ auto priv = GARROW_CSV_WRITE_OPTIONS_GET_PRIVATE(object);
+
+ priv->write_options.~WriteOptions();
+
+ G_OBJECT_CLASS(garrow_csv_write_options_parent_class)->finalize(object);
+}
+
+static void
+garrow_csv_write_options_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ auto priv = GARROW_CSV_WRITE_OPTIONS_GET_PRIVATE(object);
+
+ switch (prop_id) {
+ case PROP_CSV_WRITE_OPTIONS_INCLUDE_HEADER:
+ priv->write_options.include_header = g_value_get_boolean(value);
+ break;
+ case PROP_CSV_WRITE_OPTIONS_BATCH_SIZE:
+ priv->write_options.batch_size = g_value_get_int(value);
+ break;
+ case PROP_CSV_WRITE_OPTIONS_DELIMITER:
+ priv->write_options.delimiter = g_value_get_schar(value);
+ break;
+ case PROP_CSV_WRITE_OPTIONS_NULL_STRING:
+ priv->write_options.null_string = g_value_get_string(value);
+ break;
+ case PROP_CSV_WRITE_OPTIONS_EOL:
+ priv->write_options.eol = g_value_get_string(value);
+ break;
+ case PROP_CSV_WRITE_OPTIONS_QUOTING_STYLE:
+ priv->write_options.quoting_style =
+ static_cast<arrow::csv::QuotingStyle>(g_value_get_enum(value));
+ break;
+ case PROP_CSV_WRITE_OPTIONS_QUOTING_HEADER:
+ priv->write_options.quoting_header =
+ static_cast<arrow::csv::QuotingStyle>(g_value_get_enum(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_csv_write_options_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ auto priv = GARROW_CSV_WRITE_OPTIONS_GET_PRIVATE(object);
+
+ switch (prop_id) {
+ case PROP_CSV_WRITE_OPTIONS_INCLUDE_HEADER:
+ g_value_set_boolean(value, priv->write_options.include_header);
+ break;
+ case PROP_CSV_WRITE_OPTIONS_BATCH_SIZE:
+ g_value_set_int(value, priv->write_options.batch_size);
+ break;
+ case PROP_CSV_WRITE_OPTIONS_DELIMITER:
+ g_value_set_schar(value, priv->write_options.delimiter);
+ break;
+ case PROP_CSV_WRITE_OPTIONS_NULL_STRING:
+ g_value_set_string(value, priv->write_options.null_string.c_str());
+ break;
+ case PROP_CSV_WRITE_OPTIONS_EOL:
+ g_value_set_string(value, priv->write_options.eol.c_str());
+ break;
+ case PROP_CSV_WRITE_OPTIONS_QUOTING_STYLE:
+ g_value_set_enum(
+ value,
+ static_cast<GArrowCSVQuotingStyle>(priv->write_options.quoting_style));
+ break;
+ case PROP_CSV_WRITE_OPTIONS_QUOTING_HEADER:
+ g_value_set_enum(
+ value,
+ static_cast<GArrowCSVQuotingStyle>(priv->write_options.quoting_header));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_csv_write_options_init(GArrowCSVWriteOptions *object)
+{
+ auto priv = GARROW_CSV_WRITE_OPTIONS_GET_PRIVATE(object);
+ new (&priv->write_options) arrow::csv::WriteOptions;
+ priv->write_options = arrow::csv::WriteOptions::Defaults();
+}
+
+static void
+garrow_csv_write_options_class_init(GArrowCSVWriteOptionsClass *klass)
+{
+ GParamSpec *spec;
+
+ auto gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->finalize = garrow_csv_write_options_finalize;
+ gobject_class->set_property = garrow_csv_write_options_set_property;
+ gobject_class->get_property = garrow_csv_write_options_get_property;
+
+ auto write_options = arrow::csv::WriteOptions::Defaults();
+
+ /**
+ * GArrowCSVWriteOptions:include-header:
+ *
+ * Whether to write an initial header line with column names.
+ *
+ * Since: 23.0.0
+ */
+ spec = g_param_spec_boolean("include-header",
+ "Include header",
+ "Whether to write an initial header line with
column names",
+ write_options.include_header,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
+ PROP_CSV_WRITE_OPTIONS_INCLUDE_HEADER,
+ spec);
+
+ /**
+ * GArrowCSVWriteOptions:batch-size:
+ *
+ * Maximum number of rows processed at a time.
+ *
+ * The CSV writer converts and writes data in batches of N rows. This number
can impact
+ * performance.
+ *
+ * Since: 23.0.0
+ */
+ spec = g_param_spec_int("batch-size",
+ "Batch size",
+ "Maximum number of rows processed at a time",
+ 1,
+ G_MAXINT32,
+ write_options.batch_size,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
PROP_CSV_WRITE_OPTIONS_BATCH_SIZE, spec);
+
+ /**
+ * GArrowCSVWriteOptions:delimiter:
+ *
+ * Field delimiter.
+ *
+ * Since: 23.0.0
+ */
+ spec = g_param_spec_char("delimiter",
+ "Delimiter",
+ "Field delimiter",
+ 0,
+ G_MAXINT8,
+ write_options.delimiter,
+ static_cast<GParamFlags>(G_PARAM_READWRITE));
+ g_object_class_install_property(gobject_class,
PROP_CSV_WRITE_OPTIONS_DELIMITER, spec);
+
+ /**
+ * GArrowCSVWriteOptions:null-string:
+ *
+ * The string to write for null values. Quotes are not allowed in this
string.
+ *
+ * Since: 23.0.0
+ */
+ spec = g_param_spec_string("null-string",
+ "Null string",
+ "The string to write for null values",
+ "",
Review Comment:
Ah. `g_param_spec_string()`'s documentation
https://docs.gtk.org/gobject/func.param_spec_string.html#parameters says "The
data is owned by the caller of the function." but it's copied in the function:
https://gitlab.gnome.org/GNOME/glib/-/blob/main/gobject/gparamspecs.c?ref_type=heads#L2438
So, we can use `c_str()` here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]