Skip to content

Commit

Permalink
[Bug] Fix NoSuchElementException when accessing empty partition info (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpray authored Jan 30, 2021
1 parent 90c2da5 commit 8fe372f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,9 @@ public Map<Long, MaterializedIndexMeta> getVisibleIndexIdToMeta() {
}

public List<MaterializedIndex> getVisibleIndex() {
Partition partition = idToPartition.values().stream().findFirst().get();
return partition.getMaterializedIndices(IndexExtState.VISIBLE);
Optional<Partition> partition = idToPartition.values().stream().findFirst();
return partition.isPresent() ? partition.get().getMaterializedIndices(IndexExtState.VISIBLE)
: Collections.emptyList();
}

public Column getVisibleColumn(String columnName) {
Expand Down
13 changes: 13 additions & 0 deletions fe/fe-core/src/test/java/org/apache/doris/planner/PlannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public static void setUp() throws Exception {
+ "AGGREGATE KEY(k1, k2,k3,k4) distributed by hash(k1) buckets 3 properties('replication_num' = '1');";
CreateTableStmt createTableStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(createTblStmtStr, ctx);
Catalog.getCurrentCatalog().createTable(createTableStmt);

createTblStmtStr = "create table db1.tbl2(k1 int, k2 int sum) "
+ "AGGREGATE KEY(k1) partition by range(k1) () distributed by hash(k1) buckets 3 properties('replication_num' = '1');";
createTableStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(createTblStmtStr, ctx);
Catalog.getCurrentCatalog().createTable(createTableStmt);
}

@Test
Expand Down Expand Up @@ -324,4 +329,12 @@ public void testWithStmtSoltIsAllowNull() throws Exception {
Assert.assertEquals(3, StringUtils.countMatches(plan1, "nullIndicatorBit=0"));
}

@Test
public void testAccessingVisibleColumnWithoutPartition() throws Exception {
String sql = "select count(k1) from db1.tbl2";
StmtExecutor stmtExecutor = new StmtExecutor(ctx, sql);
stmtExecutor.execute();
Assert.assertNotNull(stmtExecutor.planner());
}

}

0 comments on commit 8fe372f

Please sign in to comment.