Skip to content
Merged
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
61 changes: 57 additions & 4 deletions be/src/exec/tablet_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,22 @@ std::string OlapTableSchemaParam::debug_string() const {

std::string OlapTablePartition::debug_string(TupleDescriptor* tuple_desc) const {
std::stringstream ss;
std::stringstream in_keys_ss;
int idx = 0;
in_keys_ss << "[";
for (auto in_key : in_keys) {
if (idx++ > 0) {
in_keys_ss << ",";
}
in_keys_ss << Tuple::to_string(in_key, *tuple_desc);
}
in_keys_ss << "]";
ss << "(id=" << id << ",start_key=" << Tuple::to_string(start_key, *tuple_desc)
<< ",end_key=" << Tuple::to_string(end_key, *tuple_desc) << ",num_buckets=" << num_buckets
<< ",end_key=" << Tuple::to_string(end_key, *tuple_desc)
<< ",in_key=" << in_keys_ss.str()
<< ",num_buckets=" << num_buckets
<< ",indexes=[";
int idx = 0;
idx = 0;
for (auto& index : indexes) {
if (idx++ > 0) {
ss << ",";
Expand Down Expand Up @@ -211,6 +223,12 @@ Status OlapTablePartitionParam::init() {
} else if (t_part.__isset.end_keys) {
RETURN_IF_ERROR(_create_partition_keys(t_part.end_keys, &part->end_key));
}
if (t_part.__isset.in_keys) {
part->in_keys.resize(t_part.in_keys.size());
for (int j = 0; j < t_part.in_keys.size(); j++) {
RETURN_IF_ERROR(_create_partition_keys(t_part.in_keys[j], &part->in_keys[j]));
}
}

part->num_buckets = t_part.num_buckets;
auto num_indexes = _schema->indexes().size();
Expand All @@ -237,14 +255,27 @@ Status OlapTablePartitionParam::init() {
}
}
_partitions.emplace_back(part);
_partitions_map->emplace(part->end_key, part);
if (t_part.__isset.in_keys) {
for (auto in_key : part->in_keys) {
_partitions_map->emplace(in_key, part);
}
} else {
_partitions_map->emplace(part->end_key, part);
}
}
return Status::OK();
}

bool OlapTablePartitionParam::find_tablet(Tuple* tuple, const OlapTablePartition** partition,
uint32_t* dist_hashes) const {
auto it = _partitions_map->upper_bound(tuple);
const TOlapTablePartition& t_part = _t_param.partitions[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

check _t_param.partitions.size() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doris creates at least one partition (unpartitioned table) for the olap table, so here _t_param.partitions.size() is at least 1, no need to worry about.

std::map<Tuple*, OlapTablePartition*, OlapTablePartKeyComparator>::iterator it;
if (t_part.__isset.in_keys) {
it = _partitions_map->find(tuple);
} else {
it = _partitions_map->upper_bound(tuple);

}
if (it == _partitions_map->end()) {
return false;
}
Expand Down Expand Up @@ -312,6 +343,28 @@ Status OlapTablePartitionParam::_create_partition_key(const TExprNode& t_expr, T
memcpy(slot, &val, sizeof(val));
break;
}
case TExprNodeType::STRING_LITERAL: {
int len = t_expr.string_literal.value.size();
const char* str_val = t_expr.string_literal.value.c_str();

// CHAR is a fixed-length string and needs to use the length in the slot definition,
// VARVHAR is a variable-length string and needs to use the length of the string itself
// padding 0 to CHAR field
if (TYPE_CHAR == slot_desc->type().type && len < slot_desc->type().len) {
auto new_ptr = (char*)_mem_pool->allocate(slot_desc->type().len);
memset(new_ptr, 0, slot_desc->type().len);
memcpy(new_ptr, str_val, len);

str_val = new_ptr;
len = slot_desc->type().len;
}
*reinterpret_cast<StringValue*>(slot) = StringValue(const_cast<char*>(str_val), len);
break;
}
case TExprNodeType::BOOL_LITERAL: {
*reinterpret_cast<bool*>(slot) = t_expr.bool_literal.value;
break;
}
default: {
std::stringstream ss;
ss << "unsupported partition column node type, type=" << t_expr.node_type;
Expand Down
15 changes: 14 additions & 1 deletion be/src/exec/tablet_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ struct OlapTablePartition {
int64_t id = 0;
Tuple* start_key = nullptr;
Tuple* end_key = nullptr;
std::vector<Tuple*> in_keys;
int64_t num_buckets = 0;
std::vector<OlapTableIndexTablets> indexes;

Expand Down Expand Up @@ -168,11 +169,23 @@ class OlapTablePartitionParam {

// check if this partition contain this key
bool _part_contains(OlapTablePartition* part, Tuple* key) const {
if (part->start_key == nullptr) {
if ((part->start_key == nullptr) && (part->in_keys.size() == 0)) {
// start_key is nullptr means the lower bound is boundless
return true;
}
OlapTablePartKeyComparator comparator(_partition_slot_descs);
const TOlapTablePartition& t_part = _t_param.partitions[0];
// when list partition, return true if equals.
if (t_part.__isset.in_keys) {
bool ret = false;
for (auto in_key : part->in_keys) {
ret = !comparator(key, in_key) && !comparator(in_key, key);
if (ret) {
break;
}
}
return ret;
}
return !comparator(key, part->start_key);
}

Expand Down
Loading