src/yb/common/schema-test.cc
TEST(TestSchema, TestProjectRename) {
  SchemaBuilder builder;
  ASSERT_OK(builder.AddKeyColumn("key", STRING));
  ASSERT_OK(builder.AddColumn("val", UINT32));
  Schema schema1 = builder.Build();

  builder.Reset(schema1);
  ASSERT_OK(builder.AddNullableColumn("non_present", UINT32));
  ASSERT_OK(builder.RenameColumn("val", "val_renamed"));
  Schema schema2 = builder.Build();

  RowProjector row_projector(&schema1, &schema2);
  ASSERT_OK(row_projector.Init());

  ASSERT_EQ(2, 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);  // key schema2
  ASSERT_EQ(row_projector.base_cols_mapping()[0].second, 0); // key schema1

  ASSERT_EQ(row_projector.base_cols_mapping()[1].first, 1);  // val_renamed schema2
  ASSERT_EQ(row_projector.base_cols_mapping()[1].second, 1); // val schema1
}
// Test projection mapping using IDs.
// This simulate a column rename ('val' -> 'val_renamed')
// and a new column added ('non_present')
Test projection mapping using IDs.
Test projection mapping using IDs .
TEST(TestSchema, TestProjectRename) {
  SchemaBuilder builder;
  ASSERT_OK(builder.AddKeyColumn("key", STRING));
  ASSERT_OK(builder.AddColumn("val", UINT32));
  Schema schema1 = builder.Build();
  builder.Reset(schema1);
  ASSERT_OK(builder.AddNullableColumn("non_present", UINT32));
  ASSERT_OK(builder.RenameColumn("val", "val_renamed"));
  Schema schema2 = builder.Build();
  RowProjector row_projector(&schema1, &schema2);
  ASSERT_OK(row_projector.Init());
  ASSERT_EQ(2, 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, 0); 
  ASSERT_EQ(row_projector.base_cols_mapping()[1].first, 1);  
  ASSERT_EQ(row_projector.base_cols_mapping()[1].second, 1); 
}
TEST ( TestSchema , TestProjectRename ) { SchemaBuilder builder ; ASSERT_OK ( builder . AddKeyColumn ( " " , STRING ) ) ; ASSERT_OK ( builder . AddColumn ( " " , UINT32 ) ) ; Schema schema1 = builder . Build ( ) ; builder . Reset ( schema1 ) ; ASSERT_OK ( builder . AddNullableColumn ( " " , UINT32 ) ) ; ASSERT_OK ( builder . RenameColumn ( " " , " " ) ) ; Schema schema2 = builder . Build ( ) ; RowProjector row_projector ( & schema1 , & schema2 ) ; ASSERT_OK ( row_projector . Init ( ) ) ; ASSERT_EQ ( 2 , 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 , 0 ) ; ASSERT_EQ ( row_projector . base_cols_mapping ( ) [ 1 ] . first , 1 ) ; ASSERT_EQ ( row_projector . base_cols_mapping ( ) [ 1 ] . second , 1 ) ; }
Test projection mapping using IDs.
Test projection mapping using IDs .
// key schema2 // key schema1 // val_renamed schema2 // val schema1