Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](cluster key) fix cluster key update #44413

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public LogicalPlan completeQueryPlan(ConnectContext ctx, LogicalPlan logicalQuer
boolean isPartialUpdate = targetTable.getEnableUniqueKeyMergeOnWrite()
&& selectItems.size() < targetTable.getColumns().size()
&& targetTable.getSequenceCol() == null
&& partialUpdateColNameToExpression.size() <= targetTable.getFullSchema().size() * 3 / 10;
&& partialUpdateColNameToExpression.size() <= targetTable.getFullSchema().size() * 3 / 10
&& !targetTable.isUniqKeyMergeOnWriteWithClusterKeys();

List<String> partialUpdateColNames = new ArrayList<>();
List<NamedExpression> partialUpdateSelectItems = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@
2

-- !select_C --
1 \N \N \N
2 \N \N \N
1 1 1 {"a":100, "b":100}
2 2 2 {"a":200, "b":200}

-- !select_CC --
1
Expand All @@ -107,8 +107,8 @@
2

-- !select_D --
1 \N \N \N
2 \N \N \N
1 1 1 {"a":100, "b":100}
2 2 2 {"a":200, "b":200}
3 3 3 {"a":300, "b":300}

-- !select_DD --
Expand All @@ -118,8 +118,8 @@
1

-- !select_E --
1 \N \N \N
2 \N \N \N
1 1 1 {"a":100, "b":100}
2 2 2 {"a":200, "b":200}
3 3 3 {"a":300, "b":300}
4 4 4 {"a":400, "b":400}

Expand Down Expand Up @@ -148,7 +148,7 @@
1

-- !select_C --
1 \N \N \N
1 1 1 {"a":100, "b":100}

-- !select_CC --
1
Expand All @@ -157,7 +157,7 @@
1

-- !select_D --
1 \N \N \N
1 1 1 {"a":100, "b":100}
3 3 3 {"a":300, "b":300}

-- !select_DD --
Expand All @@ -167,7 +167,7 @@
1

-- !select_E --
1 \N \N \N
1 1 1 {"a":100, "b":100}
3 3 3 {"a":300, "b":300}
4 4 4 {"a":400, "b":400}

Expand Down Expand Up @@ -275,8 +275,8 @@
2

-- !select_C --
1 \N \N \N
2 \N \N \N
1 1 1 {"a":100, "b":100}
2 2 2 {"a":200, "b":200}

-- !select_CC --
1
Expand All @@ -285,8 +285,8 @@
2

-- !select_D --
1 \N \N \N
2 \N \N \N
1 1 1 {"a":100, "b":100}
2 2 2 {"a":200, "b":200}
3 3 3 {"a":300, "b":300}

-- !select_DD --
Expand All @@ -296,8 +296,8 @@
1

-- !select_E --
1 \N \N \N
2 \N \N \N
1 1 1 {"a":100, "b":100}
2 2 2 {"a":200, "b":200}
3 3 3 {"a":300, "b":300}
4 4 4 {"a":400, "b":400}

Expand Down Expand Up @@ -326,7 +326,7 @@
1

-- !select_C --
1 \N \N \N
1 1 1 {"a":100, "b":100}

-- !select_CC --
1
Expand All @@ -335,7 +335,7 @@
1

-- !select_D --
1 \N \N \N
1 1 1 {"a":100, "b":100}
3 3 3 {"a":300, "b":300}

-- !select_DD --
Expand All @@ -345,7 +345,7 @@
1

-- !select_E --
1 \N \N \N
1 1 1 {"a":100, "b":100}
3 3 3 {"a":300, "b":300}
4 4 4 {"a":400, "b":400}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select_default --
1 doris 1000 123 1
1 doris 4000 123 1
2 doris2 2000 223 1

-- !select_join --
1 doris 1000 123 1
2 doris4 8000 \N 4321
1 doris 4000 123 1
2 doris4 8000 223 1

-- !select_default --
1 doris 1000 123 1
1 doris 4000 123 1
2 doris2 2000 223 1

-- !select_join --
1 doris 1000 123 1
2 doris4 8000 \N 4321
1 doris 4000 123 1
2 doris4 8000 223 1

6 changes: 6 additions & 0 deletions regression-test/data/unique_with_mow_c_p0/test_update.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
10 200 3
11 200 3
12 22 32

Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ suite("test_primary_key_partial_update_with_update_stmt", "p0") {
"""

// case 1: partially update normally
test {
sql """ update ${tableName} set score = 4000 where id = 1 """
exception "Column has no default value"
}
sql """
update ${tableName} set score = 4000 where id = 1
"""

sql "sync"

Expand All @@ -69,15 +68,12 @@ suite("test_primary_key_partial_update_with_update_stmt", "p0") {
"""

// case 2: partially update non-exist key
test {
def result1 = sql """
def result1 = sql """
update ${tableName} set score = 2000 where id = 3
"""
/*assertTrue(result1.size() == 1)
assertTrue(result1[0].size() == 1)
assertTrue(result1[0][0] == 0, "Query OK, 0 rows affected")*/
exception "Column has no default value"
}
assertTrue(result1.size() == 1)
assertTrue(result1[0].size() == 1)
assertTrue(result1[0][0] == 0, "Query OK, 0 rows affected")

sql "sync"

Expand Down
43 changes: 43 additions & 0 deletions regression-test/suites/unique_with_mow_c_p0/test_update.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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_update") {
def tableName = "test_update"
sql """ DROP TABLE IF EXISTS ${tableName} """
onFinish {
try_sql("DROP TABLE IF EXISTS ${tableName}")
}

sql """
CREATE TABLE `$tableName` (
`a` int NOT NULL,
`b` int NOT NULL,
`c` int NOT NULL
) ENGINE=OLAP
UNIQUE KEY(`a`)
CLUSTER BY (`b`)
DISTRIBUTED BY HASH(`a`) BUCKETS 1
PROPERTIES (
"replication_num" = "1",
"enable_unique_key_merge_on_write" = "true"
);
"""

sql """ insert into $tableName values(10, 20, 3), (11, 21, 3), (12, 22, 32); """
sql """ update $tableName set b = 200 where c = 3; """
order_qt_sql "select * from $tableName"
}
Loading