Repository: apache/arrow
File: cpp/src/arrow/table_test.cc (C++)

Code before:
}

TEST_F(TestTable, CombineChunksZeroColumn) {
  // ARROW-11232
  auto record_batch = RecordBatch::Make(schema({}), /*num_rows=*/10,
                                        std::vector<std::shared_ptr<Array>>{});

  ASSERT_OK_AND_ASSIGN(
      auto table,
      Table::FromRecordBatches(record_batch->schema(), {record_batch, record_batch}));
  ASSERT_EQ(20, table->num_rows());

  ASSERT_OK_AND_ASSIGN(auto combined, table->CombineChunks());

  EXPECT_EQ(20, combined->num_rows());
  EXPECT_TRUE(combined->Equals(*table));
}

TEST_F(TestTable, CombineChunksZeroRow) {
  MakeExample1(10);

  ASSERT_OK_AND_ASSIGN(auto table, Table::FromRecordBatches(schema_, {}));
  ASSERT_EQ(0, table->num_rows());

  ASSERT_OK_AND_ASSIGN(auto compacted, table->CombineChunks());
  ASSERT_TRUE(compacted->Equals(*table));

  ASSERT_OK_AND_ASSIGN(auto batch, table->CombineChunksToBatch());
  ASSERT_OK_AND_ASSIGN(auto expected, RecordBatch::MakeEmpty(schema_));
  ASSERT_NO_FATAL_FAILURE(AssertBatchesEqual(*expected, *batch, /*verbose=*/true));
}

TEST_F(TestTable, CombineChunks) {
  MakeExample1(10);
  auto batch1 = RecordBatch::Make(schema_, 10, arrays_);

  MakeExample1(15);
  auto batch2 = RecordBatch::Make(schema_, 15, arrays_);

  ASSERT_OK_AND_ASSIGN(auto table, Table::FromRecordBatches({batch1, batch2}));
  for (int i = 0; i < table->num_columns(); ++i) {
    ASSERT_EQ(2, table->column(i)->num_chunks());
  }

  ASSERT_OK_AND_ASSIGN(auto compacted, table->CombineChunks());

  EXPECT_TRUE(compacted->Equals(*table));
  for (int i = 0; i < compacted->num_columns(); ++i) {
    EXPECT_EQ(1, compacted->column(i)->num_chunks());
  }
}

Review comment (suggestion):
```suggestion
  auto other_table = TableFromJSON(
```

Code after:
  ASSERT_TRUE(
      table->Equals(*table_with_metadata, options.use_schema(true).use_metadata(false)));
  ASSERT_FALSE(
      table->Equals(*table_with_metadata, options.use_schema(true).use_metadata(true)));
  ASSERT_TRUE(
      table->Equals(*table_with_metadata, options.use_schema(false).use_metadata(true)));
}

TEST(TestTableEqualityFloatType, SameValue) {
  auto schema = ::arrow::schema({field("f0", int32()), field("f1", float64())});
  auto table = TableFromJSON(
      schema, {R"([{"f0": 1, "f1": 4.0}, {"f0": 2, "f1": 5.0}, {"f0": 3, "f1": 6.0}])"});
  auto other_table = TableFromJSON(
      schema, {R"([{"f0": 1, "f1": 4.0}, {"f0": 2, "f1": 5.0}, {"f0": 3, "f1": 6.0}])"});

  ASSERT_TRUE(table->Equals(*other_table));
}

TEST(TestTableEqualityFloatType, SingedZero) {
  auto schema = ::arrow::schema({field("f0", int32()), field("f1", float64())});
  auto table = TableFromJSON(
      schema, {R"([{"f0": 1, "f1": 4.0}, {"f0": 2, "f1": -0.0}, {"f0": 3, "f1": 0.0}])"});
  auto other_table = TableFromJSON(
      schema, {R"([{"f0": 1, "f1": 4.0}, {"f0": 2, "f1": 0.0}, {"f0": 3, "f1": -0.0}])"});
  auto options = EqualOptions::Defaults();

  ASSERT_TRUE(table->Equals(*other_table, options));
  ASSERT_FALSE(table->Equals(*other_table, options.signed_zeros_equal(false)));
}

TEST(TestTableEqualityFloatType, Infinity) {
  auto schema = ::arrow::schema({field("f0", int32()), field("f1", float64())});
  auto table = TableFromJSON(
      schema, {R"([{"f0": 1, "f1": 4.0}, {"f0": 2, "f1": 5.0}, {"f0": 3, "f1": Inf}])"});
  auto table_different_inf = TableFromJSON(
      schema, {R"([{"f0": 1, "f1": 4.0}, {"f0": 2, "f1": 5.0}, {"f0": 3, "f1": -Inf}])"});
  auto table_same_inf = TableFromJSON(
      schema, {R"([{"f0": 1, "f1": 4.0}, {"f0": 2, "f1": 5.0}, {"f0": 3, "f1": Inf}])"});

  ASSERT_FALSE(table->Equals(*table_different_inf));
  ASSERT_TRUE(table->Equals(*table_same_inf));
}

TEST(TestTableEqualityFloatType, NaN) {
  auto schema = ::arrow::schema({field("f0", int32()), field("f1", float64())});
  auto table = TableFromJSON(
      schema, {R"([{"f0": 1, "f1": 4.0}, {"f0": 2, "f1": NaN}, {"f0": 3, "f1": 6.0}])"});
  auto other_table = TableFromJSON(
      schema, {R"([{"f0": 1, "f1": 4.0}, {"f0": 2, "f1": NaN}, {"f0": 3, "f1": 6.0}])"});
  auto options = EqualOptions::Defaults();