@@ -72,6 +72,18 @@ public final class TablesSystemTableProvider implements SystemTableProvider {
7272 .addSingleValueDimension ("tableConfig" , FieldSpec .DataType .STRING )
7373 .build ();
7474
75+ private static final boolean IS_ADMIN_CLIENT_AVAILABLE ;
76+ static {
77+ boolean available ;
78+ try {
79+ Class .forName ("org.apache.pinot.client.admin.PinotAdminClient" );
80+ available = true ;
81+ } catch (ClassNotFoundException e ) {
82+ available = false ;
83+ }
84+ IS_ADMIN_CLIENT_AVAILABLE = available ;
85+ }
86+
7587 private final TableCache _tableCache ;
7688 private final @ Nullable HelixAdmin _helixAdmin ;
7789 private final @ Nullable String _clusterName ;
@@ -130,12 +142,12 @@ public SystemTableResponse getRows(SystemTableRequest request) {
130142 List <String > sortedTableNames = new ArrayList <>(tableNamesWithType );
131143 sortedTableNames .sort (Comparator .naturalOrder ());
132144
133- List <GenericRow > rows = new ArrayList <>(sortedTableNames .size ());
134- int offset = request .getOffset ();
145+ int offset = Math .max (0 , request .getOffset ());
135146 int limit = request .getLimit ();
136- if (limit == 0 ) {
137- return new SystemTableResponse (List .of (), System .currentTimeMillis (), 0 );
138- }
147+ boolean hasLimit = limit > 0 ;
148+ int totalRows = 0 ;
149+ int initialCapacity = hasLimit ? Math .min (sortedTableNames .size (), limit ) : 0 ;
150+ List <GenericRow > rows = new ArrayList <>(initialCapacity );
139151 for (String tableNameWithType : sortedTableNames ) {
140152 TableType tableType = TableNameBuilder .getTableTypeFromTableName (tableNameWithType );
141153 if (tableType == null ) {
@@ -146,6 +158,17 @@ public SystemTableResponse getRows(SystemTableRequest request) {
146158 if (!matchesFilter (request .getFilter (), stats , rawTableName )) {
147159 continue ;
148160 }
161+ totalRows ++;
162+ if (offset > 0 ) {
163+ offset --;
164+ continue ;
165+ }
166+ if (limit == 0 ) {
167+ continue ;
168+ }
169+ if (hasLimit && rows .size () >= limit ) {
170+ continue ;
171+ }
149172 GenericRow row = new GenericRow ();
150173 row .putValue ("tableName" , rawTableName );
151174 row .putValue ("type" , stats ._type );
@@ -159,16 +182,9 @@ public SystemTableResponse getRows(SystemTableRequest request) {
159182 row .putValue ("serverTenant" , stats ._serverTenant );
160183 row .putValue ("replicas" , stats ._replicas );
161184 row .putValue ("tableConfig" , stats ._tableConfig );
162- if (offset > 0 ) {
163- offset --;
164- continue ;
165- }
166185 rows .add (row );
167- if (limit > 0 && rows .size () >= limit ) {
168- break ;
169- }
170186 }
171- return new SystemTableResponse (rows , System .currentTimeMillis (), rows . size () );
187+ return new SystemTableResponse (rows , System .currentTimeMillis (), totalRows );
172188 }
173189
174190 private TableStats buildStats (String tableNameWithType , TableType tableType ) {
@@ -364,7 +380,7 @@ private boolean matchesNumber(List<String> candidates, long actual, SystemTableF
364380 baseUrl , response .statusCode (), response .body ());
365381 }
366382 } catch (Exception e ) {
367- LOGGER .warn ("system.tables: error fetching table size for {} via {}: {} " , tableName , baseUrl , e . toString () , e );
383+ LOGGER .warn ("system.tables: error fetching table size for {} via {}" , tableName , baseUrl , e );
368384 }
369385 }
370386 return null ;
@@ -453,13 +469,10 @@ private List<String> discoverControllersFromHelix() {
453469 }
454470
455471 private boolean isAdminClientAvailable () {
456- try {
457- Class .forName ("org.apache.pinot.client.admin.PinotAdminClient" );
458- return true ;
459- } catch (ClassNotFoundException e ) {
472+ if (!IS_ADMIN_CLIENT_AVAILABLE ) {
460473 LOGGER .debug ("PinotAdminClient not on classpath; falling back to HTTP for table size fetch" );
461- return false ;
462474 }
475+ return IS_ADMIN_CLIENT_AVAILABLE ;
463476 }
464477
465478 private @ Nullable TableSize fetchWithAdminClient (List <String > controllers , String tableNameWithType ) {
0 commit comments