Skip to content

Commit

Permalink
[fix](partial update) keep case insensitivity and use the columns' or…
Browse files Browse the repository at this point in the history
…igin names in partialUpdateCols in origin planner apache#27223 (apache#27255)
  • Loading branch information
bobhan1 authored and gnehil committed Dec 4, 2023
1 parent f715513 commit bc86ef2
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ private void trySetPartialUpdate() throws UserException {
for (Column col : olapTable.getFullSchema()) {
boolean exists = false;
for (Column insertCol : targetColumns) {
if (insertCol.getName() != null && insertCol.getName().equals(col.getName())) {
if (insertCol.getName() != null && insertCol.getName().equalsIgnoreCase(col.getName())) {
if (!col.isVisible() && !Column.DELETE_SIGN.equals(col.getName())) {
throw new UserException("Partial update should not include invisible column except"
+ " delete sign column: " + col.getName());
Expand All @@ -1027,7 +1027,11 @@ private void trySetPartialUpdate() throws UserException {
}

isPartialUpdate = true;
partialUpdateCols.addAll(targetColumnNames);
for (String name : targetColumnNames) {
Column column = olapTable.getFullSchema().stream()
.filter(col -> col.getName().equalsIgnoreCase(name)).findFirst().get();
partialUpdateCols.add(column.getName());
}
if (isPartialUpdate && olapTable.hasSequenceCol() && olapTable.getSequenceMapCol() != null
&& partialUpdateCols.contains(olapTable.getSequenceMapCol())) {
partialUpdateCols.add(Column.SEQUENCE_COL);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
t1 1 \N \N

-- !sql --
t1 1 2 \N

-- !sql --
t1 1 2 \N
t2 \N 20 30

-- !sql --
t1 999 2 888
t2 \N 20 30

-- !sql --
t1 999 2 888
t2 \N 20 30
t3 123 456 789

-- !sql --
t1 1 \N \N

-- !sql --
t1 1 2 \N

-- !sql --
t1 1 2 \N
t2 \N 20 30

-- !sql --
t1 999 2 888
t2 \N 20 30

-- !sql --
t1 999 2 888
t2 \N 20 30
t3 123 456 789

-- !sql --
t1 1 \N \N

-- !sql --
t1 1 2 \N

-- !sql --
t1 1 2 \N
t2 \N 20 30

-- !sql --
t1 999 2 888
t2 \N 20 30

-- !sql --
t1 999 2 888
t2 \N 20 30
t3 123 456 789

-- !sql --
t1 1 \N \N

-- !sql --
t1 1 2 \N

-- !sql --
t1 1 2 \N
t2 \N 20 30

-- !sql --
t1 999 2 888
t2 \N 20 30

-- !sql --
t1 999 2 888
t2 \N 20 30
t3 123 456 789

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

suite("test_partial_update_case_insensitivity", "p0") {
String db = context.config.getDbNameByFile(context.file)
sql "select 1;" // to create database

for (def use_row_store : [false, true]) {
for (def use_nereids_planner : [false, true]) {
logger.info("current params: use_row_store: ${use_row_store}, use_nereids_planner: ${use_nereids_planner}")
connect(user = context.config.jdbcUser, password = context.config.jdbcPassword, url = context.config.jdbcUrl) {
sql "use ${db};"
if (use_nereids_planner) {
sql """ set enable_nereids_dml = true; """
sql """ set enable_nereids_planner=true; """
sql """ set enable_fallback_to_original_planner=false; """
} else {
sql """ set enable_nereids_dml = false; """
sql """ set enable_nereids_planner = false; """
}

def tableName = "test_partial_update_case_insensitivity"
sql """ DROP TABLE IF EXISTS ${tableName} """
sql """ CREATE TABLE ${tableName} (
name varchar(300),
status int,
MY_COLUMN int,
UpAndDown int
) ENGINE=OLAP
UNIQUE KEY(name) COMMENT 'OLAP'
DISTRIBUTED BY HASH(name) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"enable_unique_key_merge_on_write" = "true",
"store_row_column" = "${use_row_store}");"""

sql "set enable_unique_key_partial_update = true;"
sql "set enable_insert_strict = false;"
sql "sync;"

sql """ insert into ${tableName}(name, STATUS) values("t1", 1); """
qt_sql "select * from ${tableName} order by name;"
sql """ insert into ${tableName}(name, my_column) values("t1", 2); """
qt_sql "select * from ${tableName} order by name;"
sql """ insert into ${tableName}(name, My_Column, uPaNddOWN) values("t2", 20, 30); """
qt_sql "select * from ${tableName} order by name;"
sql """ insert into ${tableName}(NAME, StAtUs, upanddown) values("t1", 999, 888); """
qt_sql "select * from ${tableName} order by name;"
sql """ insert into ${tableName}(NaMe, StAtUs, mY_CoLUmN, upAndDoWn) values("t3", 123, 456, 789); """
qt_sql "select * from ${tableName} order by name;"

sql """ DROP TABLE IF EXISTS ${tableName} """
}
}
}
}

0 comments on commit bc86ef2

Please sign in to comment.