[Feature](materialized-view) support delete stmt on materialized-view (#25710)
support delete stmt on materialized-view
This commit is contained in:
@ -153,18 +153,16 @@ Status PushHandler::_do_streaming_ingestion(TabletSharedPtr tablet, const TPushR
|
||||
const auto& err_msg =
|
||||
fmt::format("column id={} does not exists, table id={}",
|
||||
delete_cond.column_unique_id, tablet_schema.table_id());
|
||||
LOG(WARNING) << err_msg;
|
||||
DCHECK(false);
|
||||
return Status::Aborted(err_msg);
|
||||
}
|
||||
if (tablet_schema.column_by_uid(delete_cond.column_unique_id).name() !=
|
||||
delete_cond.column_name) {
|
||||
if (!iequal(tablet_schema.column_by_uid(delete_cond.column_unique_id).name(),
|
||||
delete_cond.column_name)) {
|
||||
const auto& err_msg = fmt::format(
|
||||
"colum name={} does not belongs to column uid={}, which column name={}",
|
||||
"colum name={} does not belongs to column uid={}, which column name={}, "
|
||||
"delete_cond.column_name ={}",
|
||||
delete_cond.column_name, delete_cond.column_unique_id,
|
||||
tablet_schema.column_by_uid(delete_cond.column_unique_id).name());
|
||||
LOG(WARNING) << err_msg;
|
||||
DCHECK(false);
|
||||
tablet_schema.column_by_uid(delete_cond.column_unique_id).name(),
|
||||
delete_cond.column_name);
|
||||
return Status::Aborted(err_msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ package org.apache.doris.task;
|
||||
|
||||
import org.apache.doris.analysis.BinaryPredicate;
|
||||
import org.apache.doris.analysis.BinaryPredicate.Operator;
|
||||
import org.apache.doris.analysis.CreateMaterializedViewStmt;
|
||||
import org.apache.doris.analysis.InPredicate;
|
||||
import org.apache.doris.analysis.IsNullPredicate;
|
||||
import org.apache.doris.analysis.LiteralExpr;
|
||||
@ -35,6 +36,7 @@ import org.apache.doris.thrift.TPushType;
|
||||
import org.apache.doris.thrift.TResourceInfo;
|
||||
import org.apache.doris.thrift.TTaskType;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -131,14 +133,24 @@ public class PushTask extends AgentTask {
|
||||
case DELETE:
|
||||
List<TCondition> tConditions = new ArrayList<TCondition>();
|
||||
Map<String, TColumn> colNameToColDesc = columnsDesc.stream()
|
||||
.collect(Collectors.toMap(TColumn::getColumnName, Function.identity()));
|
||||
.collect(Collectors.toMap(c -> c.getColumnName(), Function.identity(), (v1, v2) -> v1,
|
||||
() -> Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER)));
|
||||
for (Predicate condition : conditions) {
|
||||
TCondition tCondition = new TCondition();
|
||||
ArrayList<String> conditionValues = new ArrayList<String>();
|
||||
SlotRef slotRef = (SlotRef) condition.getChild(0);
|
||||
String columnName = slotRef.getColumnName();
|
||||
String columnName = new String(slotRef.getColumnName());
|
||||
tCondition.setColumnName(columnName);
|
||||
int uniqueId = colNameToColDesc.get(columnName).getColUniqueId();
|
||||
TColumn column = colNameToColDesc.get(slotRef.getColumnName());
|
||||
if (column == null) {
|
||||
columnName = CreateMaterializedViewStmt.mvColumnBuilder(columnName);
|
||||
column = colNameToColDesc.get(columnName);
|
||||
// condition's name and column's name may have inconsistent case
|
||||
columnName = column.getColumnName();
|
||||
}
|
||||
|
||||
tCondition.setColumnName(columnName);
|
||||
int uniqueId = column.getColUniqueId();
|
||||
if (uniqueId >= 0) {
|
||||
tCondition.setColumnUniqueId(uniqueId);
|
||||
}
|
||||
|
||||
@ -62,3 +62,15 @@
|
||||
2 4
|
||||
3 \N
|
||||
|
||||
-- !select_mv --
|
||||
\N \N
|
||||
-4 16
|
||||
2 4
|
||||
3 \N
|
||||
|
||||
-- !select_star --
|
||||
\N 4 \N d
|
||||
-4 -4 -4 d
|
||||
2 2 2 b
|
||||
3 -3 \N c
|
||||
|
||||
|
||||
@ -98,4 +98,14 @@ suite ("k1s2m3") {
|
||||
contains "(k1s2m3)"
|
||||
}
|
||||
qt_select_mv "select K1,sum(K2*K3) from d_table group by K1 order by K1;"
|
||||
|
||||
sql "delete from d_table where k1=1;"
|
||||
|
||||
explain {
|
||||
sql("select k1,sum(k2*k3) from d_table group by k1 order by k1;")
|
||||
contains "(k1s2m3)"
|
||||
}
|
||||
qt_select_mv "select k1,sum(k2*k3) from d_table group by k1 order by k1;"
|
||||
|
||||
qt_select_star "select * from d_table order by k1;"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user