| 628 | factory_ = HivePartitioning::MakeFactory(options); |
| 629 | |
| 630 | EXPECT_OK_AND_ASSIGN(auto schema, factory_->Inspect({"/alpha=a/beta=0"})); |
| 631 | EXPECT_OK_AND_ASSIGN(auto partitioning, factory_->Finish(schema)); |
| 632 | ASSERT_EQ("xyz", |
| 633 | std::static_pointer_cast<HivePartitioning>(partitioning)->null_fallback()); |
| 634 | } |
| 635 | |
| 636 | TEST_F(TestPartitioning, HiveDictionaryHasUniqueValues) { |
| 637 | HivePartitioningFactoryOptions options; |
| 638 | options.infer_dictionary = true; |
| 639 | factory_ = HivePartitioning::MakeFactory(options); |
| 640 | |
| 641 | auto alpha = DictStr("alpha"); |
| 642 | AssertInspect({"/alpha=a", "/alpha=b", "/alpha=a", "/alpha=b", "/alpha=c", "/alpha=a"}, |
| 643 | {alpha}); |
| 644 | ASSERT_OK_AND_ASSIGN(auto partitioning, factory_->Finish(schema({alpha}))); |
| 645 | |
| 646 | auto expected_dictionary = |
| 647 | checked_pointer_cast<StringArray>(ArrayFromJSON(utf8(), R"(["a", "b", "c"])")); |
| 648 | |
| 649 | for (int32_t i = 0; i < expected_dictionary->length(); ++i) { |
| 650 | DictionaryScalar::ValueType index_and_dictionary{std::make_shared<Int32Scalar>(i), |
| 651 | expected_dictionary}; |
| 652 | auto dictionary_scalar = |
| 653 | std::make_shared<DictionaryScalar>(index_and_dictionary, alpha->type()); |
| 654 | |
| 655 | auto path = "/alpha=" + expected_dictionary->GetString(i) + "/"; |
| 656 | AssertParse(path, equal(field_ref("alpha"), literal(dictionary_scalar))); |
| 657 | } |
| 658 | |
| 659 | AssertParseError("/alpha=yosemite/"); // not in inspected dictionary |
| 660 | } |
| 661 | |
| 662 | TEST_F(TestPartitioning, ExistingSchemaDirectory) { |
| 663 | // Infer dictionary values but with a given schema |
| 664 | auto dict_type = dictionary(int8(), utf8()); |
| 665 | PartitioningFactoryOptions options; |
| 666 | options.schema = schema({field("alpha", int64()), field("beta", dict_type)}); |
| 667 | factory_ = DirectoryPartitioning::MakeFactory({"alpha", "beta"}, options); |
| 668 | |
| 669 | AssertInspect({"/0/1"}, options.schema->fields()); |
| 670 | AssertInspect({"/0/1/what"}, options.schema->fields()); |
| 671 | |
| 672 | // fail if any segment is not parseable as schema type |
| 673 | EXPECT_RAISES_WITH_MESSAGE_THAT(Invalid, ::testing::HasSubstr("Failed to parse string"), |
| 674 | factory_->Inspect({"/0/1", "/hello/1"})); |
| 675 | factory_ = DirectoryPartitioning::MakeFactory({"alpha", "beta"}, options); |
| 676 | |
| 677 | // Now we don't fail since our type is large enough |
| 678 | AssertInspect({"/3760212050/1"}, options.schema->fields()); |
| 679 | // If there are still too many digits, fail |
| 680 | EXPECT_RAISES_WITH_MESSAGE_THAT(Invalid, ::testing::HasSubstr("Failed to parse string"), |
| 681 | factory_->Inspect({"/1038581385102940193760212050/1"})); |
| 682 | factory_ = DirectoryPartitioning::MakeFactory({"alpha", "beta"}, options); |
| 683 | |
| 684 | AssertInspect({"/0/1", "/2"}, options.schema->fields()); |
| 685 | } |
| 686 | |
| 687 | TEST_F(TestPartitioning, ExistingSchemaHive) { |
no test coverage detected