Skip to content

Commit

Permalink
[BugFix] Fix create table use order by case sensitive (#52513)
Browse files Browse the repository at this point in the history
Signed-off-by: meegoo <[email protected]>
  • Loading branch information
meegoo authored Nov 4, 2024
1 parent 442f969 commit 236e303
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.validation.constraints.NotNull;

public class OlapTableFactory implements AbstractTableFactory {
Expand Down Expand Up @@ -179,7 +180,9 @@ public Table createTable(LocalMetastore metastore, Database db, CreateTableStmt
Set<Integer> addedSortKey = new HashSet<>();
List<String> baseSchemaNames = baseSchema.stream().map(Column::getName).collect(Collectors.toList());
for (String column : stmt.getSortKeys()) {
int idx = baseSchemaNames.indexOf(column);
int idx = IntStream.range(0, baseSchemaNames.size())
.filter(i -> baseSchemaNames.get(i).equalsIgnoreCase(column))
.findFirst().orElse(-1);
if (idx == -1) {
throw new DdlException("Invalid column '" + column + "': not exists in all columns.");
}
Expand Down
10 changes: 10 additions & 0 deletions test/sql/test_create_table/R/test_create_table_case_sensitive
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- name: test_create_table_sensitive
create table t1(k int) order by (K);
-- result:
-- !result
create table t2(K int) order by (k);
-- result:
-- !result
create table t3 order by (k) as select * from t2;
-- result:
-- !result
4 changes: 4 additions & 0 deletions test/sql/test_create_table/T/test_create_table_case_sensitive
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- name: test_create_table_sensitive
create table t1(k int) order by (K);
create table t2(K int) order by (k);
create table t3 order by (k) as select * from t2;

0 comments on commit 236e303

Please sign in to comment.