@@ -206,6 +206,21 @@ TEST_F(TestPartitioning, DirectoryPartitioning) {
206206 equal (field_ref (" beta" ), literal (" foo" ))));
207207}
208208
209+ TEST_F (TestPartitioning, DirectoryPartitioningEquals) {
210+ auto part = std::make_shared<DirectoryPartitioning>(
211+ schema ({field (" alpha" , int32 ()), field (" beta" , utf8 ())}));
212+ auto other = std::make_shared<DirectoryPartitioning>(
213+ schema ({field (" alpha" , int32 ()), field (" gamma" , utf8 ())}));
214+ auto another = std::make_shared<DirectoryPartitioning>(
215+ schema ({field (" alpha" , int32 ()), field (" beta" , utf8 ())}));
216+ auto some_other = std::make_shared<DirectoryPartitioning>(
217+ schema ({field (" alpha" , int32 ()), field (" beta" , utf8 ())}));
218+ EXPECT_TRUE (part->Equals (*part));
219+ EXPECT_FALSE (part->Equals (*other));
220+ EXPECT_TRUE (part->Equals (*another));
221+ EXPECT_TRUE (another->Equals (*some_other));
222+ }
223+
209224TEST_F (TestPartitioning, FilenamePartitioning) {
210225 partitioning_ = std::make_shared<FilenamePartitioning>(
211226 schema ({field (" alpha" , int32 ()), field (" beta" , utf8 ())}));
@@ -222,6 +237,21 @@ TEST_F(TestPartitioning, FilenamePartitioning) {
222237 equal (field_ref (" beta" ), literal (" foo" ))));
223238}
224239
240+ TEST_F (TestPartitioning, FilenamePartitioningEquals) {
241+ auto part = std::make_shared<FilenamePartitioning>(
242+ schema ({field (" alpha" , int32 ()), field (" beta" , utf8 ())}));
243+ auto other_part = std::make_shared<FilenamePartitioning>(
244+ schema ({field (" sigma" , int32 ()), field (" beta" , utf8 ())}));
245+ auto another_part = std::make_shared<FilenamePartitioning>(
246+ schema ({field (" sigma" , int64 ()), field (" beta" , utf8 ())}));
247+ auto some_other_part = std::make_shared<FilenamePartitioning>(
248+ schema ({field (" sigma" , int64 ()), field (" beta" , utf8 ())}));
249+ EXPECT_TRUE (part->Equals (*part));
250+ EXPECT_FALSE (part->Equals (*other_part));
251+ EXPECT_FALSE (other_part->Equals (*another_part));
252+ EXPECT_TRUE (another_part->Equals (*some_other_part));
253+ }
254+
225255TEST_F (TestPartitioning, DirectoryPartitioningFormat) {
226256 partitioning_ = std::make_shared<DirectoryPartitioning>(
227257 schema ({field (" alpha" , int32 ()), field (" beta" , utf8 ())}));
@@ -426,6 +456,41 @@ TEST_F(TestPartitioning, HivePartitioning) {
426456 AssertParseError (" /alpha=0.0/beta=3.25/" ); // conversion of "0.0" to int32 fails
427457}
428458
459+ TEST_F (TestPartitioning, HivePartitioningEquals) {
460+ const auto & array_vector = ArrayVector ();
461+ ArrayVector other_vector (2 );
462+ other_vector[0 ] = ArrayFromJSON (utf8 (), R"( ["foo", "bar", "baz"])" );
463+ other_vector[1 ] = ArrayFromJSON (utf8 (), R"( ["bar", "foo", "baz"])" );
464+ auto part = std::make_shared<HivePartitioning>(
465+ schema ({field (" alpha" , int32 ()), field (" beta" , float32 ())}), array_vector, " xyz" );
466+ auto other_part = std::make_shared<HivePartitioning>(
467+ schema ({field (" sigma" , int32 ()), field (" beta" , float32 ())}), array_vector, " xyz" );
468+ auto another_part = std::make_shared<HivePartitioning>(
469+ schema ({field (" alpha" , int32 ()), field (" beta" , float32 ())}), other_vector, " xyz" );
470+ auto some_part = std::make_shared<HivePartitioning>(
471+ schema ({field (" alpha" , int32 ()), field (" beta" , float32 ())}), array_vector, " abc" );
472+ auto match_part = std::make_shared<HivePartitioning>(
473+ schema ({field (" alpha" , int32 ()), field (" beta" , float32 ())}), array_vector, " xyz" );
474+ EXPECT_TRUE (part->Equals (*part));
475+ EXPECT_FALSE (part->Equals (*other_part));
476+ EXPECT_FALSE (part->Equals (*another_part));
477+ EXPECT_FALSE (part->Equals (*some_part));
478+ EXPECT_TRUE (part->Equals (*match_part));
479+ }
480+
481+ TEST_F (TestPartitioning, CrossCheckPartitioningEquals) {
482+ auto file_part = std::make_shared<FilenamePartitioning>(
483+ schema ({field (" alpha" , int32 ()), field (" beta" , utf8 ())}));
484+ auto dir_part = std::make_shared<DirectoryPartitioning>(
485+ schema ({field (" alpha" , int32 ()), field (" beta" , utf8 ())}));
486+ auto hive_part = std::make_shared<HivePartitioning>(
487+ schema ({field (" alpha" , int32 ()), field (" beta" , float32 ())}), ArrayVector (), " xyz" );
488+ EXPECT_FALSE (file_part->Equals (*dir_part));
489+ EXPECT_FALSE (dir_part->Equals (*file_part));
490+ EXPECT_FALSE (dir_part->Equals (*hive_part));
491+ EXPECT_FALSE (hive_part->Equals (*dir_part));
492+ }
493+
429494TEST_F (TestPartitioning, HivePartitioningFormat) {
430495 partitioning_ = std::make_shared<HivePartitioning>(
431496 schema ({field (" alpha" , int32 ()), field (" beta" , float32 ())}), ArrayVector (), " xyz" );
@@ -891,6 +956,14 @@ class RangePartitioning : public Partitioning {
891956
892957 std::string type_name () const override { return " range" ; }
893958
959+ bool Equals (const Partitioning& other) const override {
960+ if (this == &other) {
961+ return true ;
962+ }
963+ return checked_cast<const RangePartitioning&>(other).type_name () == type_name () &&
964+ Partitioning::Equals (other);
965+ }
966+
894967 Result<compute::Expression> Parse (const std::string& path) const override {
895968 std::vector<compute::Expression> ranges;
896969
0 commit comments