| 233 | } |
| 234 | |
| 235 | TEST(Substrait, SupportedTypes) { |
| 236 | auto ExpectEq = [](std::string_view json, std::shared_ptr<DataType> expected_type) { |
| 237 | ARROW_SCOPED_TRACE(json); |
| 238 | |
| 239 | ExtensionSet empty; |
| 240 | ASSERT_OK_AND_ASSIGN(auto buf, internal::SubstraitFromJSON( |
| 241 | "Type", json, /*ignore_unknown_fields=*/false)); |
| 242 | ASSERT_OK_AND_ASSIGN(auto type, DeserializeType(*buf, empty)); |
| 243 | |
| 244 | EXPECT_EQ(*type, *expected_type); |
| 245 | |
| 246 | ASSERT_OK_AND_ASSIGN(auto serialized, SerializeType(*type, &empty)); |
| 247 | EXPECT_EQ(empty.num_types(), 0); |
| 248 | |
| 249 | // FIXME chokes on NULLABILITY_UNSPECIFIED |
| 250 | // EXPECT_THAT(internal::CheckMessagesEquivalent("Type", *buf, *serialized), Ok()); |
| 251 | |
| 252 | ASSERT_OK_AND_ASSIGN(auto roundtripped, DeserializeType(*serialized, empty)); |
| 253 | |
| 254 | EXPECT_EQ(*roundtripped, *expected_type); |
| 255 | }; |
| 256 | |
| 257 | ExpectEq(R"({"bool": {}})", boolean()); |
| 258 | |
| 259 | ExpectEq(R"({"i8": {}})", int8()); |
| 260 | ExpectEq(R"({"i16": {}})", int16()); |
| 261 | ExpectEq(R"({"i32": {}})", int32()); |
| 262 | ExpectEq(R"({"i64": {}})", int64()); |
| 263 | |
| 264 | ExpectEq(R"({"fp32": {}})", float32()); |
| 265 | ExpectEq(R"({"fp64": {}})", float64()); |
| 266 | |
| 267 | ExpectEq(R"({"string": {}})", utf8()); |
| 268 | ExpectEq(R"({"binary": {}})", binary()); |
| 269 | |
| 270 | ExpectEq(R"({"timestamp": {}})", timestamp(TimeUnit::MICRO)); |
| 271 | ExpectEq(R"({"date": {}})", date32()); |
| 272 | ExpectEq(R"({"time": {}})", time64(TimeUnit::MICRO)); |
| 273 | ExpectEq(R"({"timestamp_tz": {}})", timestamp(TimeUnit::MICRO, "UTC")); |
| 274 | ExpectEq(R"({"interval_year": {}})", interval_year()); |
| 275 | ExpectEq(R"({"interval_day": {}})", interval_day()); |
| 276 | |
| 277 | ExpectEq(R"({"uuid": {}})", uuid()); |
| 278 | |
| 279 | ExpectEq(R"({"fixed_char": {"length": 32}})", fixed_char(32)); |
| 280 | ExpectEq(R"({"varchar": {"length": 1024}})", varchar(1024)); |
| 281 | ExpectEq(R"({"fixed_binary": {"length": 32}})", fixed_size_binary(32)); |
| 282 | |
| 283 | ExpectEq(R"({"decimal": {"precision": 27, "scale": 5}})", decimal128(27, 5)); |
| 284 | |
| 285 | ExpectEq(R"({"struct": { |
| 286 | "types": [ |
| 287 | {"i64": {}}, |
| 288 | {"list": {"type": {"string":{}} }} |
| 289 | ] |
| 290 | }})", |
| 291 | struct_({ |
| 292 | field("", int64()), |
no test coverage detected