Skip to content

Commit

Permalink
[Fix](iot) Fix unexpected error when iot auto detect get no data (#40657
Browse files Browse the repository at this point in the history
)

## Proposed changes

Issue Number: close #xxx

before:
```
ERROR 1105 (HY000): errCode = 2, detailMessage = Index 0 out of bounds for length 0
```
now:
```
Query OK, 0 rows affected
```
  • Loading branch information
zclllyybb authored Sep 11, 2024
1 parent cd2062a commit d736a50
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public static void replacePartition(TableIf olapTable, List<String> partitionNam
ReplacePartitionClause replacePartitionClause = new ReplacePartitionClause(
new PartitionNames(false, partitionNames),
new PartitionNames(true, tempPartitionNames), true, properties);
if (replacePartitionClause.getTempPartitionNames().isEmpty()) {
return;
}
Env.getCurrentEnv()
.replaceTempPartition((Database) olapTable.getDatabase(),
(OlapTable) olapTable, replacePartitionClause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,18 @@ suite("test_iot_auto_detect") {
sql """ insert into dt values ("2005-01-01"), ("2013-02-02"), ("2022-03-03"); """
sql """ insert overwrite table dt partition(*) values ("2008-01-01"), ("2008-02-02"); """
qt_sql " select * from dt order by k0; "
try {
test {
sql """ insert overwrite table dt partition(*) values ("2023-02-02"), ("3000-12-12"); """
} catch (Exception e) {
log.info(e.getMessage())
assertTrue(e.getMessage().contains('Insert has filtered data in strict mode') ||
e.getMessage().contains('Cannot found origin partitions in auto detect overwriting'))
}

check { result, exception, startTime, endTime ->
assertTrue(exception.getMessage().contains('Insert has filtered data in strict mode') ||
exception.getMessage().contains('Cannot found origin partitions in auto detect overwriting'))
}
}
// test no rows(no partition hits) overwrite
sql " drop table if exists dt2"
sql " create table dt2 like dt"
sql " insert overwrite table dt2 partition(*) select * from dt2"
sql " insert overwrite table dt partition(*) select * from dt2"
sql " insert overwrite table dt partition(p10, pMAX) select * from dt2"
sql " insert overwrite table dt select * from dt2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ suite("test_auto_partition_behavior") {
result = sql "show partitions from unique_table"
assertEquals(result.size(), 10)
// add partition
try {
test {
sql """ alter table unique_table add partition padd values in ("Xxx") """
fail()
} catch (Exception e) {
assertTrue(e.getMessage().contains("is conflict with current partitionKeys"))
exception "is conflict with current partitionKeys"
}
// drop partition
def partitions = sql "show partitions from unique_table order by PartitionName"
Expand Down Expand Up @@ -94,11 +92,9 @@ suite("test_auto_partition_behavior") {
result = sql "show partitions from dup_table"
assertEquals(result.size(), 10)
// add partition
try {
test {
sql """ alter table dup_table add partition padd values in ("Xxx") """
fail()
} catch (Exception e) {
assertTrue(e.getMessage().contains("is conflict with current partitionKeys"))
exception "is conflict with current partitionKeys"
}
// drop partition
partitions = sql "show partitions from dup_table order by PartitionName"
Expand Down Expand Up @@ -168,11 +164,9 @@ suite("test_auto_partition_behavior") {
);
"""
sql """ insert into rewrite values ("Xxx"); """
try {
test {
sql """ insert overwrite table rewrite partition(p1) values ("") """
fail()
} catch (Exception e) {
assertTrue(e.getMessage().contains("Insert has filtered data in strict mode"))
exception "Insert has filtered data in strict mode"
}
sql """ insert overwrite table rewrite partition(p1) values ("Xxx") """
qt_sql_overwrite """ select * from rewrite """ // Xxx
Expand Down Expand Up @@ -297,6 +291,9 @@ suite("test_auto_partition_behavior") {
part_result = sql " show tablets from test_change "
assertEquals(part_result.size, 52 * replicaNum)



// test not auto partition have expr.
test {
sql """
CREATE TABLE not_auto_expr (
Expand All @@ -310,4 +307,11 @@ suite("test_auto_partition_behavior") {
"""
exception "Non-auto partition table not support partition expr!"
}


// test insert empty
sql "create table if not exists empty_range like test_change"
sql "insert into test_change select * from empty_range"
sql "create table if not exists empty_list like long_value"
sql "insert into long_value select * from empty_list"
}

0 comments on commit d736a50

Please sign in to comment.