EmmyMiao87 commented on a change in pull request #3739: URL: https://github.com/apache/incubator-doris/pull/3739#discussion_r436519696
########## File path: be/src/olap/schema_change.cpp ########## @@ -266,6 +260,92 @@ bool RowBlockChanger::change_row_block( int32_t ref_column = _schema_mapping[i].ref_column; if (_schema_mapping[i].ref_column >= 0) { + if (!_schema_mapping[i].materialized_function.empty()) { + VLOG(3) << "_schema_mapping[" << i << "].materialized_function : " << _schema_mapping[i].materialized_function; + // 效率低下,也可以直接计算变长域拷贝,但仍然会破坏封装 + for (size_t row_index = 0, new_row_index = 0; + row_index < ref_block->row_block_info().row_num; ++row_index) { + // 不需要的row,每次处理到这个row时就跳过 + if (need_filter_data && is_data_left_vec[row_index] == 0) { + continue; + } + + // 指定新的要写入的row index(不同于读的row_index) + mutable_block->get_row(new_row_index++, &write_helper); + ref_block->get_row(row_index, &read_helper); + + if (_schema_mapping[i].materialized_function == "to_bitmap") { Review comment: +1. Abstract the conversion of bitmap and hll into functions. ########## File path: be/src/olap/schema_change.cpp ########## @@ -266,6 +260,92 @@ bool RowBlockChanger::change_row_block( int32_t ref_column = _schema_mapping[i].ref_column; Review comment: Maybe you could refactor here. The main step is ``` for (columns) { for(row_index) { 1. bitmap 2. hll 3. convert type .... } } ``` ########## File path: be/src/olap/schema_change.cpp ########## @@ -266,6 +260,92 @@ bool RowBlockChanger::change_row_block( int32_t ref_column = _schema_mapping[i].ref_column; if (_schema_mapping[i].ref_column >= 0) { + if (!_schema_mapping[i].materialized_function.empty()) { + VLOG(3) << "_schema_mapping[" << i << "].materialized_function : " << _schema_mapping[i].materialized_function; + // 效率低下,也可以直接计算变长域拷贝,但仍然会破坏封装 + for (size_t row_index = 0, new_row_index = 0; + row_index < ref_block->row_block_info().row_num; ++row_index) { + // 不需要的row,每次处理到这个row时就跳过 + if (need_filter_data && is_data_left_vec[row_index] == 0) { + continue; + } + + // 指定新的要写入的row index(不同于读的row_index) + mutable_block->get_row(new_row_index++, &write_helper); + ref_block->get_row(row_index, &read_helper); + + if (_schema_mapping[i].materialized_function == "to_bitmap") { + write_helper.set_not_null(i); + BitmapValue bitmap; + if (!read_helper.is_null(ref_column)) { + uint64_t origin_value; + char *src = read_helper.cell_ptr(ref_column); + switch (ref_block->tablet_schema().column(ref_column).type()) { + case OLAP_FIELD_TYPE_TINYINT: + origin_value = *(int8_t *) src; + break; + case OLAP_FIELD_TYPE_UNSIGNED_TINYINT: + origin_value = *(uint8_t *) src; + break; + case OLAP_FIELD_TYPE_SMALLINT: + origin_value = *(int16_t *) src; + break; + case OLAP_FIELD_TYPE_UNSIGNED_SMALLINT: + origin_value = *(uint16_t *) src; + break; + case OLAP_FIELD_TYPE_INT: + origin_value = *(int32_t *) src; + break; + case OLAP_FIELD_TYPE_UNSIGNED_INT: + origin_value = *(uint32_t *) src; + break; + case OLAP_FIELD_TYPE_BIGINT: + origin_value = *(int64_t *) src; + break; + case OLAP_FIELD_TYPE_UNSIGNED_BIGINT: + origin_value = *(uint64_t *) src; + break; + default: + LOG(WARNING) << "the column type which was altered from was unsupported." + << " from_type=" + << ref_block->tablet_schema().column(ref_column).type(); + return false; + } + if (origin_value < 0) { + LOG(WARNING) << "The input: " << origin_value + << " is not valid, to_bitmap only support bigint value from 0 to 18446744073709551615 currently"; + return false; + } + bitmap.add(origin_value); + } + char *buf = reinterpret_cast<char *>(mem_pool->allocate(bitmap.getSizeInBytes())); + Slice dst(buf, bitmap.getSizeInBytes()); + bitmap.write(dst.data); + write_helper.set_field_content(i, reinterpret_cast<char *>(&dst), mem_pool); + } else if (_schema_mapping[i].materialized_function == "hll_hash") { + write_helper.set_not_null(i); Review comment: if (read_helper.is_null(ref_column)) write_helper.set_null(i) ########## File path: be/src/olap/schema_change.cpp ########## @@ -266,6 +260,92 @@ bool RowBlockChanger::change_row_block( int32_t ref_column = _schema_mapping[i].ref_column; if (_schema_mapping[i].ref_column >= 0) { + if (!_schema_mapping[i].materialized_function.empty()) { + VLOG(3) << "_schema_mapping[" << i << "].materialized_function : " << _schema_mapping[i].materialized_function; + // 效率低下,也可以直接计算变长域拷贝,但仍然会破坏封装 + for (size_t row_index = 0, new_row_index = 0; + row_index < ref_block->row_block_info().row_num; ++row_index) { + // 不需要的row,每次处理到这个row时就跳过 + if (need_filter_data && is_data_left_vec[row_index] == 0) { + continue; + } + + // 指定新的要写入的row index(不同于读的row_index) + mutable_block->get_row(new_row_index++, &write_helper); + ref_block->get_row(row_index, &read_helper); + + if (_schema_mapping[i].materialized_function == "to_bitmap") { + write_helper.set_not_null(i); + BitmapValue bitmap; + if (!read_helper.is_null(ref_column)) { Review comment: `if (read_helper.is_null(ref_column)) write_helper.set_null(i)` ########## File path: be/src/olap/schema_change.cpp ########## @@ -1810,10 +1902,26 @@ OLAPStatus SchemaChangeHandler::_parse_request(TabletSharedPtr base_tablet, continue; } + if (materialized_function_map.find(column_name) != materialized_function_map.end()) { Review comment: Maybe the column mapping should be init by the columnPB which comes from the thrift of defineExpr in column. The AlterReplicaTask does not need the TAlterMaterializedViewParam ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org