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
1 change: 1 addition & 0 deletions be/src/exec/union_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ Status UnionNode::get_next_const(RuntimeState* state, RowBatch* row_batch) {
while (_const_expr_list_idx < _const_expr_lists.size() && !row_batch->at_capacity()) {
materialize_exprs(
_const_expr_lists[_const_expr_list_idx], nullptr, tuple_buf, row_batch);
RETURN_IF_ERROR(get_error_msg(_const_expr_lists[_const_expr_list_idx]));
tuple_buf += _tuple_desc->byte_size();
++_const_expr_list_idx;
}
Expand Down
2 changes: 2 additions & 0 deletions be/src/exec/union_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class UnionNode : public ExecNode {
void materialize_exprs(const std::vector<ExprContext*>& exprs,
TupleRow* row, uint8_t* tuple_buf, RowBatch* dst_batch);

Status get_error_msg(const std::vector<ExprContext*>& exprs);

/// Returns true if the child at 'child_idx' can be passed through.
bool is_child_passthrough(int child_idx) const {
DCHECK_LT(child_idx, _children.size());
Expand Down
11 changes: 11 additions & 0 deletions be/src/exec/union_node_ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.

#include "exec/union_node.h"
#include "exprs/expr_context.h"
#include "runtime/tuple_row.h"

namespace doris {
Expand Down Expand Up @@ -52,4 +53,14 @@ void UnionNode::materialize_batch(RowBatch* dst_batch, uint8_t** tuple_buf) {
*tuple_buf = cur_tuple;
}

Status UnionNode::get_error_msg(const std::vector<ExprContext*>& exprs) {
for (auto expr_ctx: exprs) {
std::string expr_error = expr_ctx->get_error_msg();
if (!expr_error.empty()) {
return Status::RuntimeError(expr_error);
}
}
return Status::OK();
}

}
3 changes: 3 additions & 0 deletions docs/en/administrator-guide/materialized_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ The aggregate functions currently supported by the materialized view function ar
+ SUM, MIN, MAX (Version 0.12)
+ COUNT, BITMAP\_UNION, HLL\_UNION (Version 0.13)

+ The form of BITMAP\_UNION must be: `BITMAP_UNION(TO_BITMAP(COLUMN))` The column type can only be an integer (largeint also does not support), or `BITMAP_UNION(COLUMN)` and the base table is an AGG model.
+ The form of HLL\_UNION must be: `HLL_UNION(HLL_HASH(COLUMN))` The column type cannot be DECIMAL, or `HLL_UNION(COLUMN)` and the base table is an AGG model.

### Update strategy

In order to ensure the data consistency between the materialized view table and the Base table, Doris will import, delete and other operations on the Base table are synchronized to the materialized view table. And through incremental update to improve update efficiency. To ensure atomicity through transaction.
Expand Down
3 changes: 3 additions & 0 deletions docs/zh-CN/administrator-guide/materialized_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ HELP CREATE MATERIALIZED VIEW
+ SUM, MIN, MAX (Version 0.12)
+ COUNT, BITMAP\_UNION, HLL\_UNION (Version 0.13)

+ BITMAP\_UNION 的形式必须为:`BITMAP_UNION(TO_BITMAP(COLUMN))` column 列的类型只能是整数(largeint也不支持), 或者 `BITMAP_UNION(COLUMN)` 且 base 表为 AGG 模型。
+ HLL\_UNION 的形式必须为:`HLL_UNION(HLL_HASH(COLUMN))` column 列的类型不能是 DECIMAL , 或者 `HLL_UNION(COLUMN)` 且 base 表为 AGG 模型。

### 更新策略

为保证物化视图表和 Base 表的数据一致性, Doris 会将导入,删除等对 base 表的操作都同步到物化视图表中。并且通过增量更新的方式来提升更新效率。通过事务方式来保证原子性。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ public boolean match(Expr expr) {
if (!child0FnExpr.getFnName().getFunction().equalsIgnoreCase(FunctionSet.TO_BITMAP)) {
return false;
}
if (child0FnExpr.getChild(0).unwrapSlotRef() == null) {
SlotRef slotRef = child0FnExpr.getChild(0).unwrapSlotRef();
if (slotRef == null) {
return false;
} else {
} else if (slotRef.getType().isIntegerType()) {
return true;
}
return false;
} else {
return false;
}
}

@Override
public String toString() {
return FunctionSet.BITMAP_UNION + "(" + FunctionSet.TO_BITMAP + "(column)) "
+ "or " + FunctionSet.BITMAP_UNION + "(bitmap_column) in agg table";
return FunctionSet.BITMAP_UNION + "(" + FunctionSet.TO_BITMAP + "(column)), type of column could not be integer. "
+ "Or " + FunctionSet.BITMAP_UNION + "(bitmap_column) in agg table";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.doris.catalog.FunctionSet;
import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.Type;

public class MVColumnHLLUnionPattern implements MVColumnPattern {
@Override
Expand All @@ -43,19 +44,21 @@ public boolean match(Expr expr) {
if (!child0FnExpr.getFnName().getFunction().equalsIgnoreCase(FunctionSet.HLL_HASH)) {
return false;
}
if (child0FnExpr.getChild(0).unwrapSlotRef() == null) {
SlotRef slotRef = child0FnExpr.getChild(0).unwrapSlotRef();
if (slotRef == null) {
return false;
} else if (slotRef.getType() == Type.DECIMALV2) {
return false;
} else {
return true;
}
return true;
} else {
return false;
}
}

@Override
public String toString() {
return FunctionSet.HLL_UNION + "(" + FunctionSet.HLL_HASH + "(column))"
+ "or " + FunctionSet.HLL_UNION + "(hll_column) in agg table";
return FunctionSet.HLL_UNION + "(" + FunctionSet.HLL_HASH + "(column)) column could not be decimal. "
+ "Or " + FunctionSet.HLL_UNION + "(hll_column) in agg table";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.FunctionSet;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.jmockit.Deencapsulation;

import com.google.common.collect.Lists;

Expand All @@ -37,6 +38,7 @@ public class MVColumnBitmapUnionPatternTest {
public void testCorrectExpr1() {
TableName tableName = new TableName("db", "table");
SlotRef slotRef = new SlotRef(tableName, "c1");
Deencapsulation.setField(slotRef, "type", Type.INT);
List<Expr> child0Params = Lists.newArrayList();
child0Params.add(slotRef);
FunctionCallExpr child0 = new FunctionCallExpr(FunctionSet.TO_BITMAP, child0Params);
Expand All @@ -51,6 +53,7 @@ public void testCorrectExpr1() {
public void testCorrectExpr2(@Injectable CastExpr castExpr) {
TableName tableName = new TableName("db", "table");
SlotRef slotRef = new SlotRef(tableName, "c1");
Deencapsulation.setField(slotRef, "type", Type.INT);
new Expectations() {
{
castExpr.unwrapSlotRef();
Expand All @@ -71,6 +74,7 @@ public void testCorrectExpr2(@Injectable CastExpr castExpr) {
public void testUpperCaseOfFunction() {
TableName tableName = new TableName("db", "table");
SlotRef slotRef = new SlotRef(tableName, "c1");
Deencapsulation.setField(slotRef, "type", Type.INT);
List<Expr> child0Params = Lists.newArrayList();
child0Params.add(slotRef);
FunctionCallExpr child0 = new FunctionCallExpr(FunctionSet.TO_BITMAP.toUpperCase(), child0Params);
Expand Down Expand Up @@ -110,6 +114,21 @@ public void testIncorrectArithmeticExpr2() {
Assert.assertFalse(pattern.match(expr));
}

@Test
public void testIncorrectDecimalSlotRef() {
TableName tableName = new TableName("db", "table");
SlotRef slotRef1 = new SlotRef(tableName, "c1");
Deencapsulation.setField(slotRef1, "type", Type.DECIMALV2);
List<Expr> child0Params = Lists.newArrayList();
child0Params.add(slotRef1);
FunctionCallExpr child0 = new FunctionCallExpr(FunctionSet.TO_BITMAP, child0Params);
List<Expr> params = Lists.newArrayList();
params.add(child0);
FunctionCallExpr expr = new FunctionCallExpr(FunctionSet.BITMAP_UNION, params);
MVColumnBitmapUnionPattern pattern = new MVColumnBitmapUnionPattern();
Assert.assertFalse(pattern.match(expr));
}

@Test
public void testAggTableBitmapColumn(@Injectable SlotDescriptor desc,
@Injectable Column column) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.FunctionSet;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.jmockit.Deencapsulation;

import com.google.common.collect.Lists;

Expand Down Expand Up @@ -104,6 +105,21 @@ public void testIncorrectLiteralExpr2() {
Assert.assertFalse(pattern.match(expr));
}

@Test
public void testIncorrectDecimalSlotRef() {
TableName tableName = new TableName("db", "table");
SlotRef slotRef = new SlotRef(tableName, "c1");
Deencapsulation.setField(slotRef, "type", Type.DECIMALV2);
List<Expr> child0Params = Lists.newArrayList();
child0Params.add(slotRef);
FunctionCallExpr child0 = new FunctionCallExpr(FunctionSet.HLL_HASH, child0Params);
List<Expr> params = Lists.newArrayList();
params.add(child0);
FunctionCallExpr expr = new FunctionCallExpr(FunctionSet.HLL_UNION, params);
MVColumnHLLUnionPattern pattern = new MVColumnHLLUnionPattern();
Assert.assertFalse(pattern.match(expr));
}

@Test
public void testAggTableHLLColumn(@Injectable SlotDescriptor desc,
@Injectable Column column) {
Expand Down