Skip to content

Commit

Permalink
Return -1 when external table row count is unknown.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jibing-Li committed Aug 7, 2024
1 parent 76c984a commit 2ef5638
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,54 +88,47 @@ protected Optional<Long> doLoad(RowCountKey rowCountKey) {
} catch (Exception e) {
LOG.warn("Failed to get table with catalogId {}, dbId {}, tableId {}", rowCountKey.catalogId,
rowCountKey.dbId, rowCountKey.tableId);
return Optional.empty();
return null;
}
}
}

/**
* Get cached row count for the given table. Return 0 if cached not loaded or table not exists.
* Cached will be loaded async.
* @param catalogId
* @param dbId
* @param tableId
* @return Cached row count or 0 if not exist
* @return Cached row count or -1 if not exist
*/
public long getCachedRowCount(long catalogId, long dbId, long tableId) {
RowCountKey key = new RowCountKey(catalogId, dbId, tableId);
try {
CompletableFuture<Optional<Long>> f = rowCountCache.get(key);
if (f.isDone()) {
return f.get().orElse(0L);
return f.get().orElse(-1L);
}
} catch (Exception e) {
LOG.warn("Unexpected exception while returning row count", e);
}
return 0;
return -1;
}

/**
* Get cached row count for the given table if present. Return 0 if cached not loaded.
* Get cached row count for the given table if present. Return -1 if cached not loaded.
* This method will not trigger async loading if cache is missing.
*
* @param catalogId
* @param dbId
* @param tableId
* @return
* @return Cached row count or -1 if not exist
*/
public long getCachedRowCountIfPresent(long catalogId, long dbId, long tableId) {
RowCountKey key = new RowCountKey(catalogId, dbId, tableId);
try {
CompletableFuture<Optional<Long>> f = rowCountCache.getIfPresent(key);
if (f == null) {
return 0;
return -1;
} else if (f.isDone()) {
return f.get().orElse(0L);
return f.get().orElse(-1L);
}
} catch (Exception e) {
LOG.warn("Unexpected exception while returning row count if present", e);
}
return 0;
return -1;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -187,27 +187,27 @@ public String getMysqlType() {

@Override
public long getRowCount() {
// Return 0 if makeSureInitialized throw exception.
// Return -1 if makeSureInitialized throw exception.
// For example, init hive table may throw NotSupportedException.
try {
makeSureInitialized();
} catch (Exception e) {
LOG.warn("Failed to initialize table {}.{}.{}", catalog.getName(), dbName, name, e);
return 0;
return -1;
}
// All external table should get external row count from cache.
return Env.getCurrentEnv().getExtMetaCacheMgr().getRowCountCache().getCachedRowCount(catalog.getId(), dbId, id);
}

@Override
public long getCachedRowCount() {
// Return 0 if makeSureInitialized throw exception.
// Return -1 if makeSureInitialized throw exception.
// For example, init hive table may throw NotSupportedException.
try {
makeSureInitialized();
} catch (Exception e) {
LOG.warn("Failed to initialize table {}.{}.{}", catalog.getName(), dbName, name, e);
return 0;
return -1;
}
return Env.getCurrentEnv().getExtMetaCacheMgr().getRowCountCache().getCachedRowCount(catalog.getId(), dbId, id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ suite("test_iceberg_table_stats", "p0,external,doris,external_docker,external_do
while (retry < 10) {
def result = sql """ show table stats ${table_name} """
act = result[0][2]
if (act != "0") {
if (act != "-1") {
break;
}
Thread.sleep(2000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ suite("test_paimon_table_stats", "p0,external,doris,external_docker,external_doc
while (retry < 10) {
def result = sql """ show table stats ${table_name} """
act = result[0][2]
if (act != "0") {
if (act != "-1") {
break;
}
Thread.sleep(2000)
Expand Down

0 comments on commit 2ef5638

Please sign in to comment.