Skip to content

Conversation

@stenlarsson
Copy link
Contributor

@stenlarsson stenlarsson commented Dec 29, 2025

Rationale for this change

Using Arrow for writing CSVs could potentially give a lot better performance than using Ruby, but the CSV writer is not available.

What changes are included in this PR?

This adds a CSVWriter and options class to the GLib wrapper.

Are these changes tested?

Yes, with Ruby unit tests.

Are there any user-facing changes?

Yes, new classes.

@stenlarsson stenlarsson requested a review from kou as a code owner December 29, 2025 19:14
@github-actions
Copy link

⚠️ GitHub issue #48680 has been automatically assigned in GitHub to PR creator.

spec = g_param_spec_string("null-string",
"Null string",
"The string to write for null values",
"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"",
write_options.null_string.c_str(),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always find this difficult in C++, so I wonder, is that safe? The data for the string will be owned by the write_options variable, right? And when that goes out of scope, the string could potentially be gone? I guess it works because it is a constant somewhere.

spec = g_param_spec_string("eol",
"EOL",
"The end of line character to use for ending rows",
"\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"\n",
write_options.eol.c_str(),


def test_delimiter
assert_equal(44, @options.delimiter) # 44 is the ASCII code for comma
@options.delimiter = ";".ord
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use String, right?

Suggested change
@options.delimiter = ";".ord
@options.delimiter = ";"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is implemented in the Ruby wrapper. It can't be used in the tests for the GLib wrapper, right?

Comment on lines +156 to +160
options = Arrow::CSVWriteOptions.new
options.include_header = false
options.delimiter = ";".ord
options.quoting_style = Arrow::CSVQuotingStyle::NONE
options.null_string = "NULL"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use

options = {
  include_header: false,
  delimiter: ";",
  quoting_style: :none,
  null_string: "NULL,
}

by defining Arrow::CSVWriteOptions.try_convert:

module Arrow
  class CSVWriteOptions
    class << self
      def try_convert(value)
        case value
        when Hash
          options = new
          value.each do |k, v|
            options.public_send("#{k}=", value)
          end
          options
        else
          nil
        end
      end
    end
  end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good idea! I assume you meant to comment on the test for the Ruby wrapper, not GLib though.

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Dec 31, 2025
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants