Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobhan1 committed Oct 13, 2023
1 parent 1a25bb6 commit 418c70f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ private void analyzeSubquery(Analyzer analyzer, boolean skipCheck) throws UserEx
Set<String> mentionedColumns = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
List<String> realTargetColumnNames;
if (targetColumnNames == null) {
if (!isFromDeleteOrUpdateStmt
&& analyzer.getContext().getSessionVariable().isEnableUniqueKeyPartialUpdate()) {
throw new AnalysisException("using native insert statement to do "
+ "partial update should specify the insert columns.");
}
// the mentioned columns are columns which are visible to user, so here we use
// getBaseSchema(), not getFullSchema()
for (Column col : targetTable.getBaseSchema(false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public List<Rule> buildRules() {
boolean isNeedSequenceCol = child.getOutput().stream()
.anyMatch(slot -> slot.getName().equals(Column.SEQUENCE_COL));

if (sink.getColNames().isEmpty() && sink.isFromNativeInsertStmt()
&& sink.isPartialUpdate()) {
throw new AnalysisException("using native insert statement to do "
+ "partial update should specify the insert columns.");
}

LogicalOlapTableSink<?> boundSink = new LogicalOlapTableSink<>(
database,
table,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ suite("nereids_partial_update_native_insert_stmt", "p0") {
// existing rows should be updated and new rows should be inserted with unmentioned columns filled with default or null value
sql """insert into ${tableName}(id,score) values(2,400),(1,200),(4,400)"""
qt_1 """ select * from ${tableName} order by id; """
test {
sql """insert into ${tableName} values(2,400),(1,200),(4,400)"""
exception "using native insert statement to do partial update should specify the insert columns."
}
sql "set enable_unique_key_partial_update=false;"
sql "sync;"
sql """ DROP TABLE IF EXISTS ${tableName} """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ suite("nereids_partial_update_native_insert_stmt_complex", "p0") {
from ${tbName2} inner join ${tbName3} on ${tbName2}.id = ${tbName3}.id; """

qt_complex_update """select * from ${tbName1} order by id;"""

test {
sql """insert into ${tbName1}
select ${tbName2}.id, ${tbName2}.c1, ${tbName2}.c3 * 100
from ${tbName2} inner join ${tbName3} on ${tbName2}.id = ${tbName3}.id; """
exception "using native insert statement to do partial update should specify the insert columns."
}
sql "truncate table ${tbName1};"
sql "truncate table ${tbName2};"
sql "truncate table ${tbName3};"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ suite("test_partial_update_native_insert_stmt", "p0") {
// existing rows should be updated and new rows should be inserted with unmentioned columns filled with default or null value
sql """insert into ${tableName}(id,score) values(2,400),(1,200),(4,400)"""
qt_1 """ select * from ${tableName} order by id; """
test {
sql """insert into ${tableName} values(2,400),(1,200),(4,400)"""
exception "using native insert statement to do partial update should specify the insert columns."
}
sql "set enable_unique_key_partial_update=false;"
sql "sync;"
sql """ DROP TABLE IF EXISTS ${tableName} """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ suite("test_partial_update_native_insert_stmt_complex", "p0") {
from ${tbName2} inner join ${tbName3} on ${tbName2}.id = ${tbName3}.id; """

qt_complex_update """select * from ${tbName1} order by id;"""

test {
sql """insert into ${tbName1}(id, c1, c3)
select ${tbName2}.id, ${tbName2}.c1, ${tbName2}.c3 * 100
from ${tbName2} inner join ${tbName3} on ${tbName2}.id = ${tbName3}.id; """
exception "using native insert statement to do partial update should specify the insert columns."
}
sql "truncate table ${tbName1};"
sql "truncate table ${tbName2};"
sql "truncate table ${tbName3};"
Expand Down

0 comments on commit 418c70f

Please sign in to comment.