コード例 #1
0
      TEST_F(TestObSSTableSchema, test_compatible)
      {
        ObSSTableSchema schema;
        const ObSSTableSchemaColumnDef *column      = NULL;

        int64_t file_len = FileDirectoryUtils::get_size(schema_file_name);
        char * file_buf = reinterpret_cast<char*>(malloc(file_len));
        int64_t pos = 0;
        FileUtils filesys;
        filesys.open(schema_file_name, O_RDONLY);
        int64_t read_size = filesys.read(file_buf, file_len);
        EXPECT_EQ(read_size, file_len);
        schema.deserialize(file_buf, file_len, pos);
        EXPECT_EQ(schema.get_column_count(), 550);
        int64_t index_find = 0;
        int64_t index = 0;
        int64_t table_schema_size = 0;
        int64_t group_schema_size = 0;
          
        for (uint64_t table_id = 1000; table_id < 1010; ++table_id)
        {
          schema.get_table_schema(table_id, table_schema_size);
          EXPECT_EQ(55, table_schema_size);
          for(uint64_t group_id = 1; group_id < 11; ++group_id)
          {
            schema.get_group_schema(table_id, group_id, group_schema_size);
            EXPECT_EQ(group_schema_size, (int64_t)group_id);
            for(uint64_t column_id = 0; column_id < group_id; ++column_id)
            {
              index_find  = schema.find_column_id(table_id, group_id, column_id);
              column = schema.get_column_def(index_find);
              EXPECT_EQ(index, index_find);
              EXPECT_EQ(column_id, column->column_name_id_);
              EXPECT_EQ(group_id,  column->column_group_id_);
              EXPECT_EQ(table_id,  column->table_id_);
              EXPECT_EQ(ObIntType, column->column_value_type_);
              ++index;
            }
          }
        }
        }
コード例 #2
0
      TEST_F(TestObSSTableSchema, test_get_group_schema)
      {
        ObSSTableSchema schema;
        ObSSTableSchemaColumnDef column_def;
        const ObSSTableSchemaColumnDef* def_ptr;
        int ret = OB_SUCCESS;
        column_def.reserved_ = 0;

        for ( int table_id = 1000; table_id < 1010; ++table_id )
        {
          column_def.table_id_ = table_id;
          for ( int group_id = 1 ; group_id <= (table_id - 1000)%3 + 1; ++group_id )
          {
            column_def.column_group_id_ = static_cast<uint16_t>(group_id);
            for ( int column_id = 0; column_id < group_id; ++column_id )
            {
              column_def.column_name_id_ = column_id;
              column_def.column_value_type_ = ObIntType;
              ret = schema.add_column_def(column_def);
              EXPECT_TRUE(OB_SUCCESS == ret);
            }
          }
        }

        EXPECT_EQ(31, schema.get_column_count());
        int64_t size = 0;
        for ( int i = 1000; i < 1010; ++i)
        {
          for ( int gi = 1; gi <= (i - 1000)%3+1; ++gi)
          {
            def_ptr = schema.get_group_schema(i, gi, size);
            EXPECT_EQ(gi, size);
            for ( int j = 0; j < size; ++j )
            {
              EXPECT_EQ(i, (int32_t)def_ptr->table_id_);
              EXPECT_EQ(gi, def_ptr->column_group_id_);
              def_ptr++;
            }
          }
        }
      }
コード例 #3
0
      TEST_F(TestObSSTableSchema, test_serialize_and_deserialize)
      {
        ObSSTableSchema schema;
        ObSSTableSchema deserialized_schema;
        ObSSTableSchemaColumnDef column_def;
        memset(&column_def, 0, sizeof(column_def));
        const ObSSTableSchemaColumnDef *column = NULL;
        const ObSSTableSchemaColumnDef *deserialized_column = NULL;
        int64_t buf_size = (DEFAULT_COLUMN_DEF_SIZE + 1)  * sizeof(ObSSTableSchemaColumnDef)
                            + sizeof(ObSSTableSchemaHeader);
        char serialize_buf[buf_size];
        int64_t pos = 0;
        int ret = OB_SUCCESS;

        for (int i = 0; i < DEFAULT_COLUMN_DEF_SIZE; ++i)
        {
          column_def.column_group_id_ = static_cast<uint16_t>((i % 128) / 8);
          column_def.column_name_id_ = (i % 8) + 2;
          column_def.column_value_type_ = ObNullType;
          column_def.table_id_ = i / 128 + 1000;
          ret = schema.add_column_def(column_def);
          EXPECT_EQ(OB_SUCCESS, ret);
        }

        EXPECT_EQ(DEFAULT_COLUMN_DEF_SIZE, schema.get_column_count());

        for (int i = 0; i < DEFAULT_COLUMN_DEF_SIZE; ++i)
        {
          column = schema.get_column_def(i);
          EXPECT_EQ((i % 128) / 8, (int32_t)column->column_group_id_);
          EXPECT_EQ((i % 8) + 2, (int32_t)column->column_name_id_);
          EXPECT_EQ(ObNullType, column->column_value_type_);
          EXPECT_EQ(i / 128 + 1000, (int32_t)column->table_id_);
        }

        uint64_t find_id[OB_MAX_COLUMN_GROUP_NUMBER];
        uint64_t group_id_out  = OB_INVALID_ID;

        int64_t size = OB_MAX_COLUMN_GROUP_NUMBER;
        
        //TEST get table column group ids
        for(uint64_t table_id = 1000; table_id < 1100; ++table_id)
        {
          size = OB_MAX_COLUMN_GROUP_NUMBER;
          ret  = schema.get_table_column_groups_id(table_id, find_id, size);
          EXPECT_EQ(16, size);
          for(int64_t index = 0; index < size; ++index)
          {
            EXPECT_EQ(index, (int64_t)find_id[index]);
          }
        }
        
        //TEST get offset first column group schema
        int64_t offset = -1;
        for(uint64_t table_id = 1000; table_id < 1100; ++table_id)
        {
          for(uint64_t column_id = 2; column_id < 10; ++column_id)
          {
            size = OB_MAX_COLUMN_GROUP_NUMBER;
            offset  = schema.find_offset_first_column_group_schema(table_id, column_id, group_id_out);
            EXPECT_EQ(offset, (int64_t)(column_id - 2));
            EXPECT_EQ(group_id_out, (uint64_t)0);
          }
        }
        
        //TEST get column group schema
        int64_t group_size = 0;
        const ObSSTableSchemaColumnDef* def = NULL;
        for(uint64_t table_id = 1000; table_id < 1100; ++table_id)
        {
          for(uint64_t group_id = 0; group_id < 16; ++group_id)
          {
            def = schema.get_group_schema(table_id, group_id, group_size);
            EXPECT_EQ(group_size, 8);
            EXPECT_EQ(def, schema.get_column_def(static_cast<int32_t>(group_id * 8 + (table_id - 1000) * 128)));
          }
        }
        
        //TEST get column group ids 
        for(uint64_t table_id = 1000; table_id < 1100; ++table_id)
        {
          for(uint64_t column_id = 2; column_id < 10; ++column_id)
          {
            size = OB_MAX_COLUMN_GROUP_NUMBER;
            ret  = schema.get_column_groups_id(table_id, column_id, find_id, size);
            EXPECT_EQ((int)size, 16);
            for(int i = 0; i < size; ++i)
            {
              EXPECT_EQ((int)find_id[i], i);
            }
          }
        }

        schema.serialize(serialize_buf, buf_size, pos);
        pos = 0;

        deserialized_schema.deserialize(serialize_buf, buf_size, pos);

        EXPECT_EQ(schema.get_column_count(), deserialized_schema.get_column_count());
        for (int i = 0; i < DEFAULT_COLUMN_DEF_SIZE; ++i)
        {
          column = schema.get_column_def(i);
          deserialized_column = deserialized_schema.get_column_def(i);
          EXPECT_EQ((i % 128) / 8, (int32_t)column->column_group_id_);
          EXPECT_EQ((i % 8) + 2, (int32_t)column->column_name_id_);
          EXPECT_EQ(column->column_name_id_, deserialized_column->column_name_id_);
          EXPECT_EQ(ObNullType, column->column_value_type_);
          EXPECT_EQ(i / 128 + 1000, (int32_t)column->table_id_);
          EXPECT_EQ(column->column_value_type_, deserialized_column->column_value_type_);
        }
        for(uint64_t table_id = 1000; table_id < 1100; ++table_id)
        {
          size = OB_MAX_COLUMN_GROUP_NUMBER;
          ret  = deserialized_schema.get_table_column_groups_id(table_id, find_id, size);
          EXPECT_EQ(16, size);
          for(int64_t index = 0; index < size; ++index)
          {
            EXPECT_EQ(index, (int64_t)find_id[index]);
          }
        }

        offset = -1;
        group_id_out = OB_INVALID_ID;
        for(uint64_t table_id = 1000; table_id < 1100; ++table_id)
        {
          for(uint64_t column_id = 2; column_id < 10; ++column_id)
          {
            size = OB_MAX_COLUMN_GROUP_NUMBER;
            offset = deserialized_schema.find_offset_first_column_group_schema(table_id, column_id, group_id_out);
            EXPECT_EQ(offset, (int64_t)(column_id - 2));
            EXPECT_EQ(group_id_out, (uint64_t)0);
          }
        }
                 
        //TEST get column group schema
        group_size = 0;
        for(uint64_t table_id = 1000; table_id < 1100; ++table_id)
        {
          for(uint64_t group_id = 0; group_id < 16; ++group_id)
          {
            def = deserialized_schema.get_group_schema(table_id, group_id, group_size);
            EXPECT_EQ(group_size, 8);
            EXPECT_EQ(def, deserialized_schema.get_column_def(static_cast<int32_t>(group_id * 8 + (table_id - 1000) * 128)));
          }
        }
        
        //TEST get column group ids 
        for(uint64_t table_id = 1000; table_id < 1100; ++table_id)
        {
          for(uint64_t column_id = 2; column_id < 10; ++column_id)
          {
            size = OB_MAX_COLUMN_GROUP_NUMBER;
            ret  = deserialized_schema.get_column_groups_id(table_id, column_id, find_id, size);
            EXPECT_EQ((int)size, 16);
            for(int i = 0; i < size; ++i)
            {
              EXPECT_EQ((int)find_id[i], i);
            }
          }
        }
      }