test/test-csv-loader.rb in red-arrow-15.0.2 vs test/test-csv-loader.rb in red-arrow-16.0.0

- old
+ new

@@ -15,10 +15,11 @@ # specific language governing permissions and limitations # under the License. class CSVLoaderTest < Test::Unit::TestCase include Helper::Fixture + include Helper::Omittable def load_csv(input) Arrow::CSVLoader.load(input, skip_lines: /^#/) end @@ -243,8 +244,46 @@ assert_equal(table, load_csv(Zlib::Deflate.deflate(csv), schema: table.schema, encoding: encoding, compression: :gzip)) + end + + sub_test_case(":timestamp_parsers") do + test(":iso8601") do + require_glib(2, 58, 0) + data_type = Arrow::TimestampDataType.new(:second, + GLib::TimeZone.new("UTC")) + timestamps = [ + Time.iso8601("2024-03-16T23:54:12Z"), + Time.iso8601("2024-03-16T23:54:13Z"), + Time.iso8601("2024-03-16T23:54:14Z"), + ] + values = Arrow::TimestampArray.new(data_type, timestamps) + assert_equal(Arrow::Table.new(value: values), + load_csv(<<-CSV, headers: true, timestamp_parsers: [:iso8601])) +value +#{timestamps[0].iso8601} +#{timestamps[1].iso8601} +#{timestamps[2].iso8601} + CSV + end + + test("String") do + timestamps = [ + Time.iso8601("2024-03-16T23:54:12Z"), + Time.iso8601("2024-03-16T23:54:13Z"), + Time.iso8601("2024-03-16T23:54:14Z"), + ] + values = Arrow::TimestampArray.new(:second, timestamps) + format = "%Y-%m-%dT%H:%M:%S" + assert_equal(Arrow::Table.new(value: values).schema, + load_csv(<<-CSV, headers: true, timestamp_parsers: [format]).schema) +value +#{timestamps[0].iso8601.chomp("Z")} +#{timestamps[1].iso8601.chomp("Z")} +#{timestamps[2].iso8601.chomp("Z")} + CSV + end end end end