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

Code before:
  ASSERT_RAISES(Invalid, Table::FromRecordBatches({batch1, batch2}));
}

TEST_F(TestTable, FromRecordBatchesZeroLength) {
  // ARROW-2307
  MakeExample1(10);

  ASSERT_OK_AND_ASSIGN(auto result, Table::FromRecordBatches(schema_, {}));

  ASSERT_EQ(0, result->num_rows());
  ASSERT_TRUE(result->schema()->Equals(*schema_));
}

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}));

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

Code after:
  ASSERT_TRUE(table->Equals(*table_renamed_field, options.use_schema(false)));

  // Different metadata
  ASSERT_TRUE(table->Equals(*table_with_metadata));
  ASSERT_TRUE(table->Equals(*table_with_metadata, options));
  ASSERT_FALSE(table->Equals(*table_with_metadata,
                             /*check_metadata=*/true));
  ASSERT_FALSE(table->Equals(*table_with_metadata,
                             /*check_metadata=*/true, options.use_schema(true)));
  ASSERT_TRUE(table->Equals(*table_with_metadata,
                            /*check_metadata=*/true, options.use_schema(false)));
  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));