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

[opt](partial update) Allow to only specify key columns in partial update #40736

Merged
merged 3 commits into from
Sep 14, 2024
Merged
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
2 changes: 1 addition & 1 deletion be/src/olap/rowset/segment_v2/segment_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ Status SegmentWriter::probe_key_for_mow(
// 3. set columns to data convertor and then write all columns
Status SegmentWriter::append_block_with_partial_content(const vectorized::Block* block,
size_t row_pos, size_t num_rows) {
if (block->columns() <= _tablet_schema->num_key_columns() ||
if (block->columns() < _tablet_schema->num_key_columns() ||
block->columns() >= _tablet_schema->num_columns()) {
return Status::InvalidArgument(
fmt::format("illegal partial update block columns: {}, num key columns: {}, total "
Expand Down
2 changes: 1 addition & 1 deletion be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ Status VerticalSegmentWriter::batch_block(const vectorized::Block* block, size_t
_opts.rowset_ctx->partial_update_info->is_partial_update &&
_opts.write_type == DataWriteType::TYPE_DIRECT &&
!_opts.rowset_ctx->is_transient_rowset_writer) {
if (block->columns() <= _tablet_schema->num_key_columns() ||
if (block->columns() < _tablet_schema->num_key_columns() ||
block->columns() >= _tablet_schema->num_columns()) {
return Status::InvalidArgument(fmt::format(
"illegal partial update block columns: {}, num key columns: {}, total "
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1, 1
2, 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
0 0 0 0
1 1 1 1
2 2 2 2

-- !sql --
0 0 0 0
1 1 1 1
2 2 2 2
4 \N \N \N
5 \N \N \N
6 \N \N \N

-- !sql --
0 0 0 0
1 1 1 1
2 2 2 2
4 \N \N \N
5 \N \N \N
6 \N \N \N

-- !sql --
0 0 0 0
1 1 1 1
2 2 2 2
4 \N \N \N
5 \N \N \N
6 \N \N \N

-- !sql --
0 0 0 0
1 1 1 1
2 2 2 2

-- !sql --
0 0 0 0
1 1 1 1
2 2 2 2
4 \N \N \N
5 \N \N \N
6 \N \N \N

-- !sql --
0 0 0 0
1 1 1 1
2 2 2 2
4 \N \N \N
5 \N \N \N
6 \N \N \N

-- !sql --
0 0 0 0
1 1 1 1
2 2 2 2
4 \N \N \N
5 \N \N \N
6 \N \N \N

Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ suite("test_partial_update_insert_light_schema_change", "p0") {
sql "sync"

// test insert data with all key column, should fail because
// it don't have any value columns
// it inserts a new row in strict mode
sql "set enable_unique_key_partial_update=true;"
test {
sql "insert into ${tableName}(c0,c1) values(1, 1);"
exception "INTERNAL_ERROR"
exception "Insert has filtered data in strict mode"
}
sql "insert into ${tableName}(c0,c1,c2) values(1,0,10);"
sql "set enable_unique_key_partial_update=false;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ suite("test_partial_update_insert_schema_change", "p0") {
sql "sync"

// test insert data with all key column, should fail because
// it don't have any value columns
// it inserts a new row in strict mode
sql "set enable_unique_key_partial_update=true;"
test {
sql "insert into ${tableName}(c0,c1) values(1, 1);"
exception "INTERNAL_ERROR"
exception "Insert has filtered data in strict mode"
}
sql "insert into ${tableName}(c0,c1,c2) values(1,0,10);"
sql "set enable_unique_key_partial_update=false;"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

// 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_only_keys", "p0") {

String db = context.config.getDbNameByFile(context.file)
sql "select 1;" // to create database

for (def use_row_store : [false, true]) {
logger.info("current params: use_row_store: ${use_row_store}")

connect(user = context.config.jdbcUser, password = context.config.jdbcPassword, url = context.config.jdbcUrl) {
sql "use ${db};"
def tableName = "test_primary_key_partial_update"
sql """ DROP TABLE IF EXISTS ${tableName} force"""
sql """ CREATE TABLE ${tableName} (
`k` BIGINT NOT NULL,
`c1` int,
`c2` int,
`c3` int)
UNIQUE KEY(`k`) DISTRIBUTED BY HASH(`k`) BUCKETS 1
PROPERTIES(
"replication_num" = "1",
"enable_unique_key_merge_on_write" = "true",
"store_row_column" = "${use_row_store}"); """
sql """insert into ${tableName} select number,number,number,number from numbers("number"="3");"""
qt_sql """select * from ${tableName} order by k;"""
// new rows will be appended
sql "set enable_unique_key_partial_update=true;"
sql "set enable_insert_strict=false;"
sql "sync"
sql "insert into ${tableName}(k) values(0),(1),(4),(5),(6);"
qt_sql """select * from ${tableName} order by k;"""

// fail if has new rows
sql "set enable_insert_strict=true;"
sql "sync"
sql "insert into ${tableName}(k) values(0),(1),(4),(5),(6);"
qt_sql """select * from ${tableName} order by k;"""
test {
sql "insert into ${tableName}(k) values(0),(1),(10),(11);"
exception "Insert has filtered data in strict mode"
}
qt_sql """select * from ${tableName} order by k;"""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,13 @@ suite("test_partial_update_schema_change", "p0") {
});

// test load data with all key column, should fail because
// it don't have any value columns
// it inserts a new row in strict mode
streamLoad {
table "${tableName}"

set 'column_separator', ','
set 'partial_columns', 'true'
set 'strict_mode', 'true'
set 'columns', 'c0, c1'

file 'schema_change/load_with_key_column.csv'
Expand All @@ -434,7 +435,7 @@ suite("test_partial_update_schema_change", "p0") {
def json = parseJson(result)
assertEquals("fail", json.Status.toLowerCase())
assertEquals(1, json.NumberTotalRows)
assertEquals(0, json.NumberFilteredRows)
assertEquals(1, json.NumberFilteredRows)
assertEquals(0, json.NumberUnselectedRows)
}
}
Expand Down Expand Up @@ -1001,6 +1002,7 @@ suite("test_partial_update_schema_change", "p0") {

set 'column_separator', ','
set 'partial_columns', 'true'
set 'strict_mode', 'true'
set 'columns', 'c0, c1'

file 'schema_change/load_with_key_column.csv'
Expand All @@ -1014,7 +1016,7 @@ suite("test_partial_update_schema_change", "p0") {
def json = parseJson(result)
assertEquals("fail", json.Status.toLowerCase())
assertEquals(1, json.NumberTotalRows)
assertEquals(0, json.NumberFilteredRows)
assertEquals(1, json.NumberFilteredRows)
assertEquals(0, json.NumberUnselectedRows)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,13 @@ suite("test_partial_update_row_store_schema_change", "p0") {
});

// test load data with all key column, should fail because
// it don't have any value columns
// it inserts a new row in strict mode
streamLoad {
table "${tableName}"

set 'column_separator', ','
set 'partial_columns', 'true'
set 'strict_mode', 'true'
set 'columns', 'c0, c1'

file 'schema_change/load_with_key_column.csv'
Expand All @@ -438,7 +439,7 @@ suite("test_partial_update_row_store_schema_change", "p0") {
def json = parseJson(result)
assertEquals("fail", json.Status.toLowerCase())
assertEquals(1, json.NumberTotalRows)
assertEquals(0, json.NumberFilteredRows)
assertEquals(1, json.NumberFilteredRows)
assertEquals(0, json.NumberUnselectedRows)
}
}
Expand Down Expand Up @@ -1014,6 +1015,7 @@ suite("test_partial_update_row_store_schema_change", "p0") {

set 'column_separator', ','
set 'partial_columns', 'true'
set 'strict_mode', 'true'
set 'columns', 'c0, c1'

file 'schema_change/load_with_key_column.csv'
Expand All @@ -1027,7 +1029,7 @@ suite("test_partial_update_row_store_schema_change", "p0") {
def json = parseJson(result)
assertEquals("fail", json.Status.toLowerCase())
assertEquals(1, json.NumberTotalRows)
assertEquals(0, json.NumberFilteredRows)
assertEquals(1, json.NumberFilteredRows)
assertEquals(0, json.NumberUnselectedRows)
}
}
Expand Down
Loading