[fix](txn insert) Fix txn insert into values for sequence column or column name is keyword (#33336)
This commit is contained in:
@ -1326,4 +1326,9 @@ public class NativeInsertStmt extends InsertStmt {
|
||||
slotDesc.setIsNullable(col.isAllowNull());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containTargetColumnName(String columnName) {
|
||||
return targetColumnNames != null && targetColumnNames.stream()
|
||||
.anyMatch(col -> col.equalsIgnoreCase(columnName));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1838,13 +1838,11 @@ public class StmtExecutor {
|
||||
int schemaSize = tbl.getBaseSchema(false).size();
|
||||
if (parsedStmt instanceof NativeInsertStmt
|
||||
&& ((NativeInsertStmt) parsedStmt).getTargetColumnNames() != null) {
|
||||
|
||||
if (((NativeInsertStmt) parsedStmt).getTargetColumnNames()
|
||||
.contains(Column.SEQUENCE_COL)) {
|
||||
NativeInsertStmt nativeInsertStmt = (NativeInsertStmt) parsedStmt;
|
||||
if (nativeInsertStmt.containTargetColumnName(Column.SEQUENCE_COL)) {
|
||||
schemaSize++;
|
||||
}
|
||||
if (((NativeInsertStmt) parsedStmt).getTargetColumnNames()
|
||||
.contains(Column.DELETE_SIGN)) {
|
||||
if (nativeInsertStmt.containTargetColumnName(Column.DELETE_SIGN)) {
|
||||
schemaSize++;
|
||||
}
|
||||
}
|
||||
@ -1922,19 +1920,13 @@ public class StmtExecutor {
|
||||
.setExecMemLimit(maxExecMemByte).setTimeout((int) timeoutSecond)
|
||||
.setTimezone(timeZone).setSendBatchParallelism(sendBatchParallelism).setTrimDoubleQuotes(true);
|
||||
if (parsedStmt instanceof NativeInsertStmt && ((NativeInsertStmt) parsedStmt).getTargetColumnNames() != null) {
|
||||
List<String> targetColumnNames = ((NativeInsertStmt) parsedStmt).getTargetColumnNames();
|
||||
if (targetColumnNames.contains(Column.SEQUENCE_COL) || targetColumnNames.contains(Column.DELETE_SIGN)) {
|
||||
if (targetColumnNames.contains(Column.SEQUENCE_COL)) {
|
||||
NativeInsertStmt nativeInsertStmt = (NativeInsertStmt) parsedStmt;
|
||||
if (nativeInsertStmt.containTargetColumnName(Column.SEQUENCE_COL)
|
||||
|| nativeInsertStmt.containTargetColumnName(Column.DELETE_SIGN)) {
|
||||
if (nativeInsertStmt.containTargetColumnName(Column.SEQUENCE_COL)) {
|
||||
request.setSequenceCol(Column.SEQUENCE_COL);
|
||||
}
|
||||
StringBuilder allCols = new StringBuilder();
|
||||
for (String col : ((NativeInsertStmt) parsedStmt).getTargetColumnNames()) {
|
||||
allCols.append(col);
|
||||
allCols.append(",");
|
||||
}
|
||||
allCols.deleteCharAt(allCols.length() - 1);
|
||||
request.setColumns(String.valueOf(allCols));
|
||||
request.setColumnSeparator(",");
|
||||
request.setColumns("`" + String.join("`,`", nativeInsertStmt.getTargetColumnNames()) + "`");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user