Skip to content

Commit

Permalink
ARROW-13809: [C++][ABI] Add support for MonthDayNanoInterval to C ABI
Browse files Browse the repository at this point in the history
Closes apache#11177 from emkornfield/interval_abi

Lead-authored-by: Micah Kornfield <[email protected]>
Co-authored-by: Antoine Pitrou <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
  • Loading branch information
emkornfield and pitrou committed Sep 28, 2021
1 parent b0b475e commit 9a1f364
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cpp/src/arrow/c/bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ struct SchemaExporter {

Status Visit(const DayTimeIntervalType& type) { return SetFormat("tiD"); }

Status Visit(const MonthDayNanoIntervalType& type) { return SetFormat("tin"); }

Status Visit(const ListType& type) { return SetFormat("+l"); }

Status Visit(const LargeListType& type) { return SetFormat("+L"); }
Expand Down Expand Up @@ -1002,6 +1004,8 @@ struct SchemaImporter {
return ProcessPrimitive(day_time_interval());
case 'M':
return ProcessPrimitive(month_interval());
case 'n':
return ProcessPrimitive(month_day_nano_interval());
}
return f_parser_.Invalid();
}
Expand Down
11 changes: 10 additions & 1 deletion cpp/src/arrow/c/bridge_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ TEST_F(TestSchemaExport, Temporal) {
TestPrimitive(duration(TimeUnit::MICRO), "tDu");
TestPrimitive(duration(TimeUnit::NANO), "tDn");
TestPrimitive(month_interval(), "tiM");

TestPrimitive(month_day_nano_interval(), "tin");
TestPrimitive(day_time_interval(), "tiD");

TestPrimitive(timestamp(TimeUnit::SECOND), "tss:");
Expand Down Expand Up @@ -805,6 +805,8 @@ TEST_F(TestArrayExport, Primitive) {

TestPrimitive(decimal(16, 4), R"(["1234.5670", null])");
TestPrimitive(decimal256(16, 4), R"(["1234.5670", null])");

TestPrimitive(month_day_nano_interval(), R"([[-1, 5, 20], null])");
}

TEST_F(TestArrayExport, PrimitiveSliced) {
Expand Down Expand Up @@ -1303,6 +1305,8 @@ TEST_F(TestSchemaImport, Temporal) {
CheckImport(month_interval());
FillPrimitive("tiD");
CheckImport(day_time_interval());
FillPrimitive("tin");
CheckImport(month_day_nano_interval());

FillPrimitive("tss:");
CheckImport(timestamp(TimeUnit::SECOND));
Expand Down Expand Up @@ -2547,6 +2551,7 @@ TEST_F(TestSchemaRoundtrip, Temporal) {
TestWithTypeFactory(date32);
TestWithTypeFactory(day_time_interval);
TestWithTypeFactory(month_interval);
TestWithTypeFactory(month_day_nano_interval);
TestWithTypeFactory(std::bind(time64, TimeUnit::NANO));
TestWithTypeFactory(std::bind(duration, TimeUnit::MICRO));
TestWithTypeFactory([]() { return arrow::timestamp(TimeUnit::MICRO, "Europe/Paris"); });
Expand Down Expand Up @@ -2765,10 +2770,14 @@ TEST_F(TestArrayRoundtrip, Primitive) {
TestWithJSON(decimal128(16, 4), R"(["0.4759", "1234.5670", null])");
TestWithJSON(decimal256(16, 4), R"(["0.4759", "1234.5670", null])");

TestWithJSON(month_day_nano_interval(), R"([[1, -600, 5000], null])");

TestWithJSONSliced(int32(), "[4, 5]");
TestWithJSONSliced(int32(), "[4, 5, 6, null]");
TestWithJSONSliced(decimal128(16, 4), R"(["0.4759", "1234.5670", null])");
TestWithJSONSliced(decimal256(16, 4), R"(["0.4759", "1234.5670", null])");
TestWithJSONSliced(month_day_nano_interval(),
R"([[4, 5, 6], [1, -600, 5000], null, null])");
}

TEST_F(TestArrayRoundtrip, UnknownNullCount) {
Expand Down
3 changes: 3 additions & 0 deletions docs/source/format/CDataInterface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ Temporal types have multi-character format strings starting with ``t``:
+-----------------+---------------------------------------------------+------------+
| ``tiD`` | interval [days, time] | |
+-----------------+---------------------------------------------------+------------+
| ``tin`` | interval [month, day, nanoseconds] | |
+-----------------+---------------------------------------------------+------------+


Dictionary-encoded types do not have a specific format string. Instead, the
format string of the base array represents the dictionary index type, and the
Expand Down

0 comments on commit 9a1f364

Please sign in to comment.