Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions be/src/olap/rowset/segment_v2/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,10 +1143,7 @@ Status Segment::seek_and_read_by_rowid(const TabletSchema& schema, SlotDescripto
}
RETURN_IF_ERROR(
iterator_hint->read_by_rowids(single_row_loc.data(), 1, file_storage_column));
// iterator_hint.reset(nullptr);
// Get it's inner field, for JSONB case
vectorized::Field field = remove_nullable(storage_type)->get_default();
file_storage_column->get(0, field);
vectorized::Field field = storage_type->get_type_field(*file_storage_column, 0);
result->insert(field);
} else {
int index = (slot->col_unique_id() >= 0) ? schema.field_index(slot->col_unique_id())
Expand Down
32 changes: 28 additions & 4 deletions be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "olap/rowset/segment_v2/vertical_segment_writer.h"

#include <gen_cpp/olap_file.pb.h>
#include <gen_cpp/segment_v2.pb.h>
#include <parallel_hashmap/phmap.h>

Expand All @@ -43,7 +44,8 @@
#include "olap/olap_common.h"
#include "olap/partial_update_info.h"
#include "olap/primary_key_index.h"
#include "olap/row_cursor.h" // RowCursor // IWYU pragma: keep
#include "olap/row_cursor.h" // RowCursor // IWYU pragma: keep
#include "olap/rowset/rowset_fwd.h"
#include "olap/rowset/rowset_writer_context.h" // RowsetWriterContext
#include "olap/rowset/segment_creator.h"
#include "olap/rowset/segment_v2/column_writer.h" // ColumnWriter
Expand All @@ -70,7 +72,10 @@
#include "vec/core/block.h"
#include "vec/core/column_with_type_and_name.h"
#include "vec/core/types.h"
#include "vec/data_types/data_type.h"
#include "vec/data_types/data_type_factory.hpp"
#include "vec/io/reader_buffer.h"
#include "vec/json/path_in_data.h"
#include "vec/jsonb/serialize.h"
#include "vec/olap/olap_data_convertor.h"

Expand Down Expand Up @@ -1040,6 +1045,10 @@ Status VerticalSegmentWriter::_append_block_with_variant_subcolumns(RowsInBlock&
remove_nullable(column_ref)->assume_mutable_ref());
const TabletColumnPtr& parent_column = _tablet_schema->columns()[i];

std::map<std::string, TabletColumnPtr> typed_columns;
for (const auto& col : parent_column->get_sub_columns()) {
typed_columns[col->name()] = col;
}
// generate column info by entry info
auto generate_column_info = [&](const auto& entry) {
const std::string& column_name =
Expand All @@ -1050,6 +1059,13 @@ Status VerticalSegmentWriter::_append_block_with_variant_subcolumns(RowsInBlock&
auto full_path = full_path_builder.append(parent_column->name_lower_case(), false)
.append(entry->path.get_parts(), false)
.build();
// typed column takes no effect no nested column
if (typed_columns.contains(entry->path.get_path()) && !entry->path.has_nested_part()) {
TabletColumn typed_column = *typed_columns[entry->path.get_path()];
typed_column.set_path_info(full_path);
typed_column.set_parent_unique_id(parent_column->unique_id());
return typed_column;
}
return vectorized::schema_util::get_column_by_type(
final_data_type_from_object, column_name,
vectorized::schema_util::ExtraInfo {
Expand All @@ -1069,14 +1085,22 @@ Status VerticalSegmentWriter::_append_block_with_variant_subcolumns(RowsInBlock&
CHECK(entry->data.is_finalized());
int current_column_id = column_id++;
TabletColumn tablet_column = generate_column_info(entry);
vectorized::DataTypePtr storage_type =
vectorized::DataTypeFactory::instance().create_data_type(tablet_column);
vectorized::DataTypePtr finalized_type = entry->data.get_least_common_type();
vectorized::ColumnPtr current_column =
entry->data.get_finalized_column_ptr()->get_ptr();
if (!storage_type->equals(*finalized_type)) {
RETURN_IF_ERROR(vectorized::schema_util::cast_column(
{current_column, finalized_type, ""}, storage_type, &current_column));
}
vectorized::schema_util::inherit_column_attributes(*parent_column, tablet_column,
_flush_schema);
RETURN_IF_ERROR(_create_column_writer(current_column_id /*unused*/, tablet_column,
_flush_schema));
RETURN_IF_ERROR(_olap_data_convertor->set_source_content_with_specifid_column(
{entry->data.get_finalized_column_ptr()->get_ptr(),
entry->data.get_least_common_type(), tablet_column.name()},
data.row_pos, data.num_rows, current_column_id));
{current_column->get_ptr(), storage_type, tablet_column.name()}, data.row_pos,
data.num_rows, current_column_id));
// convert column data from engine format to storage layer format
auto [status, column] = _olap_data_convertor->convert_column_data(current_column_id);
if (!status.ok()) {
Expand Down
2 changes: 2 additions & 0 deletions be/src/olap/tablet_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ TabletColumn TabletReader::materialize_column(const TabletColumn& orig) {
cast_type.type);
}
column_with_cast_type.set_type(filed_type);
column_with_cast_type.set_precision_frac(cast_type.precision, cast_type.scale);
column_with_cast_type.set_is_decimal(cast_type.precision > 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not rigorous to use cast_type.precision > 0 to judge is_decimal. You can use cast_type.is_decimal_v2_type() and cast_type.is_decimal_v3_type() or add a new is_decimal_type for cast_type.

return column_with_cast_type;
}

Expand Down
8 changes: 7 additions & 1 deletion be/src/olap/tablet_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ FieldType TabletColumn::get_field_type_by_type(PrimitiveType primitiveType) {
return FieldType::OLAP_FIELD_TYPE_JSONB;
case PrimitiveType::TYPE_VARIANT:
return FieldType::OLAP_FIELD_TYPE_VARIANT;
case PrimitiveType::TYPE_IPV4:
return FieldType::OLAP_FIELD_TYPE_IPV4;
case PrimitiveType::TYPE_IPV6:
return FieldType::OLAP_FIELD_TYPE_IPV6;
case PrimitiveType::TYPE_LAMBDA_FUNCTION:
return FieldType::OLAP_FIELD_TYPE_UNKNOWN; // Not implemented
case PrimitiveType::TYPE_AGG_STATE:
Expand Down Expand Up @@ -604,8 +608,10 @@ void TabletColumn::to_schema_pb(ColumnPB* column) const {
if (_has_default_value) {
column->set_default_value(_default_value);
}
if (_is_decimal) {
if (_precision >= 0) {
column->set_precision(_precision);
}
if (_frac >= 0) {
column->set_frac(_frac);
}
column->set_length(_length);
Expand Down
8 changes: 8 additions & 0 deletions be/src/olap/tablet_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <parallel_hashmap/phmap.h>

#include <algorithm>
#include <cstdint>
#include <map>
#include <memory>
#include <string>
Expand Down Expand Up @@ -182,6 +183,13 @@ class TabletColumn : public MetadataAdder<TabletColumn> {
const std::vector<TabletColumnPtr>& sparse_columns() const;
size_t num_sparse_columns() const { return _num_sparse_columns; }

void set_precision_frac(int32_t precision, int32_t frac) {
_precision = precision;
_frac = frac;
}

void set_is_decimal(bool is_decimal) { _is_decimal = is_decimal; }

Status check_valid() const {
if (type() != FieldType::OLAP_FIELD_TYPE_ARRAY &&
type() != FieldType::OLAP_FIELD_TYPE_STRUCT &&
Expand Down
16 changes: 16 additions & 0 deletions be/src/runtime/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <utility>

#include "olap/olap_define.h"
#include "runtime/define_primitive_type.h"
#include "runtime/primitive_type.h"

namespace doris {
Expand Down Expand Up @@ -113,6 +114,21 @@ TypeDescriptor::TypeDescriptor(const std::vector<TTypeNode>& types, int* idx)
contains_nulls.push_back(node.contains_nulls[1]);
break;
}
case TTypeNodeType::VARIANT: {
// complex variant type
DCHECK(!node.__isset.scalar_type);
DCHECK_LT(*idx, types.size() - 1);
DCHECK(!node.__isset.contains_nulls);
type = TYPE_VARIANT;
contains_nulls.reserve(node.struct_fields.size());
for (size_t i = 0; i < node.struct_fields.size(); i++) {
++(*idx);
children.push_back(TypeDescriptor(types, idx));
field_names.push_back(node.struct_fields[i].name);
contains_nulls.push_back(node.struct_fields[i].contains_null);
}
break;
}
default:
DCHECK(false) << node.type;
}
Expand Down
Loading