Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Murphy <[email protected]>
  • Loading branch information
murphyatwork committed Dec 2, 2024
1 parent 110fbcf commit 51e9707
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,9 @@ public static List<Pair<Table, Column>> resolveColumnRefRecursive(ColumnRefOpera
ScalarOperator impl = expr.getOp().getProjection().resolveColumnRef(ref);
if (impl != null) {
List<ColumnRefOperator> subRefs = Utils.extractColumnRef(impl);
subRefs.remove(impl);
if (impl instanceof ColumnRefOperator) {
subRefs.remove(impl);
}
List<Pair<Table, Column>> subColumns = Lists.newArrayList();
for (ColumnRefOperator subRef : subRefs) {
subColumns.addAll(ListUtils.emptyIfNull(resolveColumnRefRecursive(subRef, factory, expr)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,6 @@ analyzeStatement

analyzeColumnClause
: '(' qualifiedName (',' qualifiedName)* ')' #regularColumns
| qualifiedName (',' qualifiedName)* #regularColumns
| ALL COLUMNS #allColumns
| PREDICATE COLUMNS #predicateColumns
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TaskRunHistoryTest {

Expand Down Expand Up @@ -179,7 +178,6 @@ public void testKeeper(@Mocked RepoExecutor repo) {
}
};
keeper.run();
assertTrue(keeper.isTableExisted());
assertFalse(keeper.isTableCorrected());

new MockUp<SystemInfoService>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.starrocks.common.MetaNotFoundException;
import com.starrocks.qe.ConnectContext;
import com.starrocks.qe.DDLStmtExecutor;
import com.starrocks.scheduler.history.TableKeeper;
import com.starrocks.server.CatalogMgr;
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.sql.ast.AnalyzeHistogramDesc;
Expand Down Expand Up @@ -54,7 +55,9 @@
import com.starrocks.statistic.NativeAnalyzeStatus;
import com.starrocks.statistic.StatisticSQLBuilder;
import com.starrocks.statistic.StatisticUtils;
import com.starrocks.statistic.StatisticsMetaManager;
import com.starrocks.statistic.StatsConstants;
import com.starrocks.statistic.columns.PredicateColumnsStorage;
import com.starrocks.utframe.StarRocksAssert;
import com.starrocks.utframe.UtFrameUtils;
import mockit.Mock;
Expand Down Expand Up @@ -103,13 +106,14 @@ public static void beforeClass() throws Exception {
" \"replication_num\" = \"1\"\n" +
");";
starRocksAssert.withTable(createStructTableSql);

}

@Test
public void testAllColumns() {
String sql = "analyze table db.tbl";
AnalyzeStmt analyzeStmt = (AnalyzeStmt) analyzeSuccess(sql);
Assert.assertEquals(analyzeStmt.getColumnNames().size(), 0);
Assert.assertEquals(4, analyzeStmt.getColumnNames().size());
}

@Test
Expand All @@ -136,7 +140,7 @@ public void testSelectedColumns() {

sql = "analyze table test.t0";
analyzeStmt = (AnalyzeStmt) analyzeSuccess(sql);
Assert.assertEquals(analyzeStmt.getColumnNames().size(), 0);
Assert.assertEquals(3, analyzeStmt.getColumnNames().size());
}

@Test
Expand Down Expand Up @@ -471,6 +475,11 @@ public void testTypeKeys() throws Exception {

@Test
public void testAnalyzePredicateColumns() {
StatisticsMetaManager statistic = new StatisticsMetaManager();
statistic.createStatisticsTablesForTest();
TableKeeper keeper = PredicateColumnsStorage.createKeeper();
keeper.run();

AnalyzeStmt stmt = (AnalyzeStmt) analyzeSuccess("analyze table db.tbl all columns");
Assert.assertTrue(stmt.isAllColumns());
stmt = (AnalyzeStmt) analyzeSuccess("analyze table db.tbl predicate columns");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ void testUnexpectedTokenSqls(String sql, String expecting) {
SessionVariable sessionVariable = new SessionVariable();
try {
SqlParser.parse(sql, sessionVariable).get(0);
fail("sql should fail.");
fail("sql should fail: " + sql);
} catch (Exception e) {
System.out.println(e.getMessage());
assertContains(e.getMessage(), expecting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,34 @@
package com.starrocks.statistic.columns;

import com.google.common.base.Splitter;
import com.starrocks.common.FeConstants;
import com.starrocks.scheduler.history.TableKeeper;
import com.starrocks.sql.analyzer.AnalyzeTestUtil;
import com.starrocks.sql.ast.AnalyzeStmt;
import com.starrocks.sql.plan.PlanTestBase;
import com.starrocks.statistic.StatisticsMetaManager;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import java.util.List;
import java.util.stream.Collectors;

class ColumnUsageTest extends PlanTestBase {

@BeforeAll
public static void beforeClass() {
StatisticsMetaManager statistic = new StatisticsMetaManager();
statistic.createStatisticsTablesForTest();
TableKeeper keeper = PredicateColumnsStorage.createKeeper();
keeper.run();
FeConstants.runningUnitTest = true;
}

@BeforeEach
public void before() {
PredicateColumnsMgr.getInstance().reset();
Expand All @@ -39,23 +53,24 @@ public void testColumnUsage() throws Exception {
// normal predicate
starRocksAssert.query("select * from t0 where v1 > 1").explainQuery();
starRocksAssert.query("select * from information_schema.column_stats_usage where table_name = 't0'")
.explainContains("constant exprs", "'v1' | 'predicate'");
.explainContains("constant exprs", "'v1' | 'normal,predicate'");

starRocksAssert.query("select * from test_all_type where lower(t1a) = '123' and t1e < 1.1").explainQuery();
starRocksAssert.query("select * from information_schema.column_stats_usage where table_name = 'test_all_type'")
.explainContains("constant exprs", "'t1a' | 'predicate'");
.explainContains("constant exprs", "'t1a' | 'normal,predicate'");

// group by
starRocksAssert.query("select v2, v3, count(*) from t0 group by v2, v3").explainQuery();
starRocksAssert.query("select * from information_schema.column_stats_usage where table_name = 't0'")
.explainContains("constant exprs", "'v1' | 'predicate'");
.explainContains("constant exprs", "'v1' | 'normal,predicate'");

// join
starRocksAssert.query("select * from t0 join t1 on t0.v2 = t1.v4").explainQuery();
starRocksAssert.query("select * from information_schema.column_stats_usage where table_name = 't0'")
.explainContains(" 'v3' | 'group_by'", "'v2' | 'predicate,join,group_by'", "'v1' | 'predicate'");
.explainContains(" 'v3' | 'normal,group_by'", "'v2' | 'normal,predicate,join,group_by'",
"'v1' | 'normal,predicate'");
starRocksAssert.query("select * from information_schema.column_stats_usage where table_name = 't1'")
.explainContains("constant exprs", "'v4' | 'predicate,join'");
.explainContains("constant exprs", "'v4' | 'normal,predicate,join'");
}

@ParameterizedTest
Expand Down Expand Up @@ -132,6 +147,7 @@ public void testAnalyzePredicateColumns(String query, String analyzeStmt, String
AnalyzeStmt stmt = (AnalyzeStmt) AnalyzeTestUtil.analyzeSuccess(analyzeStmt);
List<String> expect =
StringUtils.isNotEmpty(expectedColumns) ? Splitter.on(",").splitToList(expectedColumns) : List.of();
Assertions.assertEquals(expect, stmt.getColumnNames());
Assertions.assertEquals(expect.stream().sorted().collect(Collectors.toList()),
stmt.getColumnNames().stream().sorted().collect(Collectors.toList()));
}
}

0 comments on commit 51e9707

Please sign in to comment.