src/yb/common/schema-test.cc
TEST(TestSchema, TestProjectMissingColumn) {
  Schema schema1({ ColumnSchema("key", STRING), ColumnSchema("val", UINT32) }, 1);
  Schema schema2({ ColumnSchema("val", UINT32), ColumnSchema("non_present", STRING) }, 0);
  Schema schema3({ ColumnSchema("val", UINT32), ColumnSchema("non_present", UINT32, true) }, 0);

  RowProjector row_projector(&schema1, &schema2);
  Status s = row_projector.Init();
  ASSERT_TRUE(s.IsInvalidArgument());
  ASSERT_STR_CONTAINS(s.message().ToString(),
    "does not exist in the projection, and it does not have a nullable type");

  // Verify Default nullable column with no default value
  ASSERT_OK(row_projector.Reset(&schema1, &schema3));

  ASSERT_EQ(1, row_projector.base_cols_mapping().size());
  ASSERT_EQ(0, row_projector.adapter_cols_mapping().size());

  ASSERT_EQ(row_projector.base_cols_mapping()[0].first, 0);  // val schema2
  ASSERT_EQ(row_projector.base_cols_mapping()[0].second, 1); // val schema1
}
// Test projection when the some columns in the projection
// are not present in the base schema
Test projection when the some columns in the projection
are not present in the base schema
Test projection when the some columns in the projection are not present in the base schema
TEST(TestSchema, TestProjectMissingColumn) {
  Schema schema1({ ColumnSchema("key", STRING), ColumnSchema("val", UINT32) }, 1);
  Schema schema2({ ColumnSchema("val", UINT32), ColumnSchema("non_present", STRING) }, 0);
  Schema schema3({ ColumnSchema("val", UINT32), ColumnSchema("non_present", UINT32, true) }, 0);
  RowProjector row_projector(&schema1, &schema2);
  Status s = row_projector.Init();
  ASSERT_TRUE(s.IsInvalidArgument());
  ASSERT_STR_CONTAINS(s.message().ToString(),
    "does not exist in the projection, and it does not have a nullable type");
  ASSERT_OK(row_projector.Reset(&schema1, &schema3));
  ASSERT_EQ(1, row_projector.base_cols_mapping().size());
  ASSERT_EQ(0, row_projector.adapter_cols_mapping().size());
  ASSERT_EQ(row_projector.base_cols_mapping()[0].first, 0);  
  ASSERT_EQ(row_projector.base_cols_mapping()[0].second, 1); 
}
TEST ( TestSchema , TestProjectMissingColumn ) { Schema schema1 ( { ColumnSchema ( " " , STRING ) , ColumnSchema ( " " , UINT32 ) } , 1 ) ; Schema schema2 ( { ColumnSchema ( " " , UINT32 ) , ColumnSchema ( " " , STRING ) } , 0 ) ; Schema schema3 ( { ColumnSchema ( " " , UINT32 ) , ColumnSchema ( " " , UINT32 , true ) } , 0 ) ; RowProjector row_projector ( & schema1 , & schema2 ) ; Status s = row_projector . Init ( ) ; ASSERT_TRUE ( s . IsInvalidArgument ( ) ) ; ASSERT_STR_CONTAINS ( s . message ( ) . ToString ( ) , " " ) ; ASSERT_OK ( row_projector . Reset ( & schema1 , & schema3 ) ) ; ASSERT_EQ ( 1 , row_projector . base_cols_mapping ( ) . size ( ) ) ; ASSERT_EQ ( 0 , row_projector . adapter_cols_mapping ( ) . size ( ) ) ; ASSERT_EQ ( row_projector . base_cols_mapping ( ) [ 0 ] . first , 0 ) ; ASSERT_EQ ( row_projector . base_cols_mapping ( ) [ 0 ] . second , 1 ) ; }
Test projection when the some columns in the projection
are not present in the base schema
Test projection when the some columns in the projection are not present in the base schema
// Verify Default nullable column with no default value // val schema2 // val schema1