Skip to content

Commit

Permalink
Support cast varchar to bitmap (StarRocks#1941)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangkaisen authored Dec 8, 2021
1 parent 1b411bb commit 8813710
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions be/src/exprs/vectorized/cast_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "gutil/strings/substitute.h"
#include "runtime/runtime_state.h"
#include "storage/hll.h"
#include "util/bitmap_value.h"
#include "util/date_func.h"

namespace starrocks {
Expand Down Expand Up @@ -157,6 +158,30 @@ ColumnPtr cast_fn<TYPE_VARCHAR, TYPE_HLL>(ColumnPtr& column) {

return builder.build(column->is_constant());
}

template <>
ColumnPtr cast_fn<TYPE_VARCHAR, TYPE_OBJECT>(ColumnPtr& column) {
ColumnBuilder<TYPE_OBJECT> builder;
ColumnViewer<TYPE_VARCHAR> viewer(column);
for (int row = 0; row < viewer.size(); ++row) {
if (viewer.is_null(row)) {
builder.append_null();
continue;
}

auto value = viewer.value(row);
BitmapValue bitmap;
// TODO(kks): check value.data is valid bitmap firstly
if (bitmap.deserialize(value.data)) {
builder.append(&bitmap);
} else {
builder.append_null();
}
}

return builder.build(column->is_constant());
}

// all int(tinyint, smallint, int, bigint, largeint) cast implements
DEFINE_UNARY_FN_WITH_IMPL(ImplicitToNumber, value) {
return value;
Expand Down Expand Up @@ -1033,6 +1058,10 @@ Expr* VectorizedCastExprFactory::from_thrift(const TExprNode& node) {
return new VectorizedCastExpr<TYPE_VARCHAR, TYPE_HLL>(node);
}

if (from_type == TYPE_VARCHAR && to_type == TYPE_OBJECT) {
return new VectorizedCastExpr<TYPE_VARCHAR, TYPE_OBJECT>(node);
}

if (to_type == TYPE_VARCHAR) {
switch (from_type) {
CASE_TO_STRING_FROM(TYPE_BOOLEAN);
Expand Down

0 comments on commit 8813710

Please sign in to comment.