Skip to content

Commit

Permalink
[chore](explain) Add algorithm item to VSORT explainition and modify …
Browse files Browse the repository at this point in the history
…dump_data of Block (apache#38543)

## Proposed changes

Issue Number: close #xxx

1.  add algorithm record in `VSORT`'s explain string:

before:
```sql
|   1:VSORT(101)                 |
|   |  order by: xxx             |
|   |  offset: 0                 |
|   |  distribute expr lists:    |
|   |  tuple ids: 2              |
```
after:
```sql
|   1:VSORT(101)                 |
|   |  order by: xxx             |
|   |  algorithm: full sort      |
|   |  offset: 0                 |
|   |  distribute expr lists:    |
|   |  tuple ids: 2              |
```
2. add a new parameter to make `Block::dump_data()` could work when the
nullity of the type of data is different from that of column. it's
useful when in some function call under
`default_implementation_for_nulls()`
  • Loading branch information
zclllyybb committed Aug 23, 2024
1 parent eafad7d commit 7ddca85
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
12 changes: 10 additions & 2 deletions be/src/vec/core/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "vec/columns/columns_number.h"
#include "vec/common/assert_cast.h"
#include "vec/data_types/data_type_factory.hpp"
#include "vec/data_types/data_type_nullable.h"

class SipHash;

Expand Down Expand Up @@ -476,7 +477,7 @@ std::string Block::dump_types() const {
return out;
}

std::string Block::dump_data(size_t begin, size_t row_limit) const {
std::string Block::dump_data(size_t begin, size_t row_limit, bool allow_null_mismatch) const {
std::vector<std::string> headers;
std::vector<size_t> headers_size;
for (const auto& it : data) {
Expand Down Expand Up @@ -515,7 +516,14 @@ std::string Block::dump_data(size_t begin, size_t row_limit) const {
}
std::string s;
if (data[i].column) {
s = data[i].to_string(row_num);
if (data[i].type->is_nullable() && !data[i].column->is_nullable()) {
assert(allow_null_mismatch);
s = assert_cast<const DataTypeNullable*>(data[i].type.get())
->get_nested_type()
->to_string(*data[i].column, row_num);
} else {
s = data[i].to_string(row_num);
}
}
if (s.length() > headers_size[i]) {
s = s.substr(0, headers_size[i] - 3) + "...";
Expand Down
12 changes: 9 additions & 3 deletions be/src/vec/core/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,20 @@ class Block {

bool empty() const { return rows() == 0; }

/** Updates SipHash of the Block, using update method of columns.
/**
* Updates SipHash of the Block, using update method of columns.
* Returns hash for block, that could be used to differentiate blocks
* with same structure, but different data.
*/
void update_hash(SipHash& hash) const;

/** Get block data in string. */
std::string dump_data(size_t begin = 0, size_t row_limit = 100) const;
/**
* Get block data in string.
* If code is in default_implementation_for_nulls or something likely, type and column's nullity could
* temporarily be not same. set allow_null_mismatch to true to dump it correctly.
*/
std::string dump_data(size_t begin = 0, size_t row_limit = 100,
bool allow_null_mismatch = false) const;

static std::string dump_column(ColumnPtr col, DataTypePtr type) {
ColumnWithTypeAndName type_name {col, type, ""};
Expand Down
3 changes: 2 additions & 1 deletion be/src/vec/functions/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ Status PreparedFunctionImpl::default_implementation_for_nulls(
}
RETURN_IF_ERROR(execute_without_low_cardinality_columns(context, block, new_args, result,
block.rows(), dry_run));
// after run with nested, wrap them in null.
// After run with nested, wrap them in null. Before this, block.get_by_position(result).type
// is not compatible with get_by_position(result).column
block.get_by_position(result).column = wrap_in_nullable(
block.get_by_position(result).column, block, args, result, input_rows_count);

Expand Down
13 changes: 13 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/planner/SortNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ public String getNodeExplainString(String detailPrefix, TExplainLevel detailLeve
if (useTwoPhaseReadOpt) {
output.append(detailPrefix + "OPT TWO PHASE\n");
}

output.append(detailPrefix + "algorithm: ");
boolean isFixedLength = info.getOrderingExprs().stream().allMatch(e -> !e.getType().isStringType()
&& !e.getType().isCollectionType());
if (limit > 0 && limit + offset < 1024 && (useTwoPhaseReadOpt || hasRuntimePredicate
|| isFixedLength)) {
output.append("heap sort\n");
} else if (limit > 0 && !isFixedLength && limit + offset < 256) {
output.append("topn sort\n");
} else {
output.append("full sort\n");
}

output.append(detailPrefix).append("offset: ").append(offset).append("\n");
return output.toString();
}
Expand Down

0 comments on commit 7ddca85

Please sign in to comment.