Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public enum OlapTableState {
WAITING_STABLE
}

public static long ROW_COUNT_BEFORE_REPORT = -1;

@SerializedName(value = "tst", alternate = {"state"})
private volatile OlapTableState state;

Expand Down Expand Up @@ -1615,10 +1617,10 @@ public long getRowCountForIndex(long indexId, boolean strict) {
if (index == null) {
LOG.warn("Index {} not exist in partition {}, table {}, {}",
indexId, entry.getValue().getName(), id, name);
return -1;
return ROW_COUNT_BEFORE_REPORT;
}
if (strict && !index.getRowCountReported()) {
return -1;
return ROW_COUNT_BEFORE_REPORT;
}
rowCount += index.getRowCount() == -1 ? 0 : index.getRowCount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ protected void processOneJob(TableIf table, Set<Pair<String, String>> columns,
return;
}
AnalysisInfo analyzeJob = createAnalyzeJobForTbl(table, columns, priority);
if (analyzeJob == null) {
return;
}
LOG.debug("Auto analyze job : {}", analyzeJob.toString());
try {
executeSystemAnalysisJob(analyzeJob);
Expand Down Expand Up @@ -203,6 +206,13 @@ protected AnalysisInfo createAnalyzeJobForTbl(
if (StatisticsUtil.enablePartitionAnalyze() && table.isPartitionedTable()) {
analysisMethod = AnalysisMethod.FULL;
}
if (table instanceof OlapTable && analysisMethod.equals(AnalysisMethod.SAMPLE)) {
OlapTable ot = (OlapTable) table;
if (ot.getRowCountForIndex(ot.getBaseIndexId(), true) == OlapTable.ROW_COUNT_BEFORE_REPORT) {
LOG.info("Table {} row count is not fully reported, skip auto analyzing this time.", ot.getName());
return null;
}
}
AnalysisManager manager = Env.getServingEnv().getAnalysisManager();
TableStatsMeta tableStatsStatus = manager.findTableStatsStatus(table.getId());
long rowCount = StatisticsUtil.isEmptyTable(table, analysisMethod) ? 0 :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,34 @@ public DLAType getDlaType() {
ExternalTable hiveExternalTable = new HMSExternalTable(1, "hmsTable", "hmsDb", null);
Assertions.assertTrue(collector.supportAutoAnalyze(hiveExternalTable));
}

@Test
public void testCreateAnalyzeJobForTbl() {
StatisticsAutoCollector collector = new StatisticsAutoCollector();
OlapTable table = new OlapTable();
new MockUp<OlapTable>() {
@Mock
public long getDataSize(boolean singleReplica) {
return 100;
}

@Mock
public long getRowCountForIndex(long indexId, boolean strict) {
return -1;
}

@Mock
public boolean isPartitionedTable() {
return false;
}
};
Assertions.assertNull(collector.createAnalyzeJobForTbl(table, null, null));
new MockUp<OlapTable>() {
@Mock
public long getRowCountForIndex(long indexId, boolean strict) {
return 100;
}
};
Assertions.assertThrows(NullPointerException.class, () -> collector.createAnalyzeJobForTbl(table, null, null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,36 @@

suite("test_auto_analyze_black_white_list") {

def wait_row_count_reported = { db, table, row, column, expected ->
def result = sql """show frontends;"""
logger.info("show frontends result origin: " + result)
def host
def port
for (int i = 0; i < result.size(); i++) {
if (result[i][8] == "true") {
host = result[i][1]
port = result[i][4]
}
}
def tokens = context.config.jdbcUrl.split('/')
def url=tokens[0] + "//" + host + ":" + port
logger.info("Master url is " + url)
connect(user = context.config.jdbcUser, password = context.config.jdbcPassword, url) {
sql """use ${db}"""
result = sql """show frontends;"""
logger.info("show frontends result master: " + result)
for (int i = 0; i < 120; i++) {
Thread.sleep(5000)
result = sql """show index stats ${table} ${table};"""
logger.info("result " + result)
if (result[row][column] == expected) {
return;
}
}
throw new Exception("Row count report timeout.")
}
}

sql """drop database if exists test_auto_analyze_black_white_list"""
sql """create database test_auto_analyze_black_white_list"""
sql """use test_auto_analyze_black_white_list"""
Expand All @@ -38,6 +68,13 @@ suite("test_auto_analyze_black_white_list") {
)
"""

try {
wait_row_count_reported("test_auto_analyze_black_white_list", "test_bw", 0, 4, "0")
} catch (Exception e) {
logger.info(e.getMessage());
return;
}

// Test show index row count
def result = sql """show table stats test_bw"""
assertEquals(1, result.size())
Expand Down