[fix](txn insert) Txn insert can not write to table with mv (#31167)
This commit is contained in:
@ -550,7 +550,6 @@ public class NativeInsertStmt extends InsertStmt {
|
||||
private void analyzeSubquery(Analyzer analyzer, boolean skipCheck) throws UserException {
|
||||
// Analyze columns mentioned in the statement.
|
||||
Set<String> mentionedColumns = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
|
||||
List<String> realTargetColumnNames;
|
||||
if (targetColumnNames == null) {
|
||||
hasEmptyTargetColumns = true;
|
||||
// the mentioned columns are columns which are visible to user, so here we use
|
||||
@ -600,35 +599,38 @@ public class NativeInsertStmt extends InsertStmt {
|
||||
* will be used in as a mapping from queryStmt.getResultExprs() to targetColumns define expr
|
||||
*/
|
||||
List<Pair<Integer, Column>> origColIdxsForExtendCols = Lists.newArrayList();
|
||||
for (Column column : targetTable.getFullSchema()) {
|
||||
if (column.isNameWithPrefix(SchemaChangeHandler.SHADOW_NAME_PREFIX)) {
|
||||
String origName = Column.removeNamePrefix(column.getName());
|
||||
for (int i = 0; i < targetColumns.size(); i++) {
|
||||
if (targetColumns.get(i).nameEquals(origName, false)) {
|
||||
// Rule A
|
||||
origColIdxsForExtendCols.add(Pair.of(i, null));
|
||||
targetColumns.add(column);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (column.isNameWithPrefix(CreateMaterializedViewStmt.MATERIALIZED_VIEW_NAME_PREFIX)
|
||||
|| column.isNameWithPrefix(CreateMaterializedViewStmt.MATERIALIZED_VIEW_AGGREGATE_NAME_PREFIX)) {
|
||||
List<SlotRef> refColumns = column.getRefColumns();
|
||||
if (refColumns == null) {
|
||||
ErrorReport.reportAnalysisException(ErrorCode.ERR_BAD_FIELD_ERROR,
|
||||
column.getName(), targetTable.getName());
|
||||
}
|
||||
for (SlotRef refColumn : refColumns) {
|
||||
String origName = refColumn.getColumnName();
|
||||
for (int originColumnIdx = 0; originColumnIdx < targetColumns.size(); originColumnIdx++) {
|
||||
if (targetColumns.get(originColumnIdx).nameEquals(origName, false)) {
|
||||
origColIdxsForExtendCols.add(Pair.of(originColumnIdx, column));
|
||||
if (!ConnectContext.get().isTxnModel()) {
|
||||
for (Column column : targetTable.getFullSchema()) {
|
||||
if (column.isNameWithPrefix(SchemaChangeHandler.SHADOW_NAME_PREFIX)) {
|
||||
String origName = Column.removeNamePrefix(column.getName());
|
||||
for (int i = 0; i < targetColumns.size(); i++) {
|
||||
if (targetColumns.get(i).nameEquals(origName, false)) {
|
||||
// Rule A
|
||||
origColIdxsForExtendCols.add(Pair.of(i, null));
|
||||
targetColumns.add(column);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (column.isNameWithPrefix(CreateMaterializedViewStmt.MATERIALIZED_VIEW_NAME_PREFIX)
|
||||
|| column.isNameWithPrefix(
|
||||
CreateMaterializedViewStmt.MATERIALIZED_VIEW_AGGREGATE_NAME_PREFIX)) {
|
||||
List<SlotRef> refColumns = column.getRefColumns();
|
||||
if (refColumns == null) {
|
||||
ErrorReport.reportAnalysisException(ErrorCode.ERR_BAD_FIELD_ERROR,
|
||||
column.getName(), targetTable.getName());
|
||||
}
|
||||
for (SlotRef refColumn : refColumns) {
|
||||
String origName = refColumn.getColumnName();
|
||||
for (int originColumnIdx = 0; originColumnIdx < targetColumns.size(); originColumnIdx++) {
|
||||
if (targetColumns.get(originColumnIdx).nameEquals(origName, false)) {
|
||||
origColIdxsForExtendCols.add(Pair.of(originColumnIdx, column));
|
||||
targetColumns.add(column);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -669,7 +671,7 @@ public class NativeInsertStmt extends InsertStmt {
|
||||
checkColumnCoverage(mentionedColumns, targetTable.getBaseSchema());
|
||||
}
|
||||
|
||||
realTargetColumnNames = targetColumns.stream().map(Column::getName).collect(Collectors.toList());
|
||||
List<String> realTargetColumnNames = targetColumns.stream().map(Column::getName).collect(Collectors.toList());
|
||||
|
||||
// handle VALUES() or SELECT constant list
|
||||
if (isValuesOrConstantSelect) {
|
||||
|
||||
Reference in New Issue
Block a user