Code review comment: Under what circumstances does this problem occur?

Code under review:
protected void doSample() throws Exception {
        LOG.info(String.format("Will do sample collection for column %s", col.getName()));
        Pair<List<Long>, Long> pair = calcActualSampleTablets(isPartitionColumn());
        LOG.info(String.format("Number of tablets selected %d, rows in tablets %d", pair.first.size(), pair.second));
        List<Long> tabletIds = pair.first;
        double scaleFactor = (double) tbl.getRowCount() / (double) pair.second;
        
        if (Double.isInfinite(scaleFactor) || Double.isNaN(scaleFactor)) {
            LOG.warn("Scale factor is infinite or Nan, will set scale factor to 1.");
            scaleFactor = 1;
            tabletIds = Collections.emptyList();
            pair.second = tbl.getRowCount();
        }
        String tabletStr = tabletIds.stream()
                .map(Object::toString)
                .collect(Collectors.joining(", "));
        try (AutoCloseConnectContext r = StatisticsUtil.buildConnectContext(info.jobType.equals(JobType.SYSTEM))) {
            
            ResultRow basicStats = collectBasicStat(r);
            long rowCount = tbl.getRowCount();
            String min = Base64.getEncoder().encodeToString(basicStats.get(0).getBytes(StandardCharsets.UTF_8));
            String max = Base64.getEncoder().encodeToString(basicStats.get(1).getBytes(StandardCharsets.UTF_8));

            boolean limitFlag = false;
            long rowsToSample = pair.second;
            Map<String, String> params = new HashMap<>();
            params.put("internalDB", FeConstants.INTERNAL_DB_NAME);
            params.put("columnStatTbl", StatisticConstants.STATISTIC_TBL_NAME);
            params.put("catalogId", String.valueOf(catalog.getId()));
            params.put("catalogName", catalog.getName());
            params.put("dbId", String.valueOf(db.getId()));
            params.put("tblId", String.valueOf(tbl.getId()));
            params.put("idxId", String.valueOf(info.indexId));
            params.put("colId", String.valueOf(info.colName));
            params.put("dataSizeFunction", getDataSizeFunction(col, false));
            params.put("dbName", db.getFullName());
            params.put("colName", info.colName);
            params.put("tblName", tbl.getName());
            params.put("scaleFactor", String.valueOf(scaleFactor));
            params.put("sampleHints", tabletStr.isEmpty() ? "" : String.format("TABLET(%s)", tabletStr));
            params.put("ndvFunction", getNdvFunction(String.valueOf(rowCount)));
            params.put("min", min);
            params.put("max", max);
            params.put("rowCount", String.valueOf(rowCount));
            params.put("type", col.getType().toString());
            params.put("limit", "");
            if (needLimit()) {
                
                
                limitFlag = true;
                rowsToSample = Math.min(getSampleRows(), pair.second);
                params.put("limit", "limit " + rowsToSample);
                params.put("scaleFactor", String.valueOf(scaleFactor * (double) pair.second / rowsToSample));
            }
            StringSubstitutor stringSubstitutor = new StringSubstitutor(params);
            String sql;
            
            if (isDistributionColumn()) {
                params.put("min", StatisticsUtil.quote(min));
                params.put("max", StatisticsUtil.quote(max));
                sql = stringSubstitutor.replace(LINEAR_ANALYZE_TEMPLATE);
            } else {
                params.put("dataSizeFunction", getDataSizeFunction(col, true));
                sql = stringSubstitutor.replace(DUJ1_ANALYZE_TEMPLATE);
            }
            LOG.info(String.format("Sample for column [%s]. Total rows [%s], rows to sample [%d], scale factor [%s], "
                    + "limited [%b], distribute column [%b], partition column [%b], key column [%b]",
                    col.getName(), params.get("rowCount"), rowsToSample, params.get("scaleFactor"),
                    limitFlag, isDistributionColumn(), isPartitionColumn(), col.isKey()));
            runQuery(sql, false);
        }
    }

Line commented on: if (Double.isInfinite(scaleFactor) || Double.isNaN(scaleFactor)) {

Revised code:
protected void doSample() throws Exception {
        LOG.debug("Will do sample collection for column {}", col.getName());
        Pair<List<Long>, Long> pair = calcActualSampleTablets(tbl.isPartitionColumn(col.getName()));
        LOG.info("Number of tablets selected {}, rows in tablets {}", pair.first.size(), pair.second);
        List<Long> tabletIds = pair.first;
        double scaleFactor = (double) tbl.getRowCount() / (double) pair.second;
        
        if (Double.isInfinite(scaleFactor) || Double.isNaN(scaleFactor)) {
            LOG.warn("Scale factor is infinite or Nan, will set scale factor to 1.");
            scaleFactor = 1;
            tabletIds = Collections.emptyList();
            pair.second = tbl.getRowCount();
        }
        String tabletStr = tabletIds.stream()
                .map(Object::toString)
                .collect(Collectors.joining(", "));
        try (AutoCloseConnectContext r = StatisticsUtil.buildConnectContext(info.jobType.equals(JobType.SYSTEM))) {
            
            ResultRow basicStats = collectBasicStat(r);
            long rowCount = tbl.getRowCount();
            String min = Base64.getEncoder().encodeToString(basicStats.get(0).getBytes(StandardCharsets.UTF_8));
            String max = Base64.getEncoder().encodeToString(basicStats.get(1).getBytes(StandardCharsets.UTF_8));

            boolean limitFlag = false;
            long rowsToSample = pair.second;
            Map<String, String> params = new HashMap<>();
            params.put("internalDB", FeConstants.INTERNAL_DB_NAME);
            params.put("columnStatTbl", StatisticConstants.STATISTIC_TBL_NAME);
            params.put("catalogId", String.valueOf(catalog.getId()));
            params.put("catalogName", catalog.getName());
            params.put("dbId", String.valueOf(db.getId()));
            params.put("tblId", String.valueOf(tbl.getId()));
            params.put("idxId", String.valueOf(info.indexId));
            params.put("colId", String.valueOf(info.colName));
            params.put("dataSizeFunction", getDataSizeFunction(col, false));
            params.put("dbName", db.getFullName());
            params.put("colName", info.colName);
            params.put("tblName", tbl.getName());
            params.put("scaleFactor", String.valueOf(scaleFactor));
            params.put("sampleHints", tabletStr.isEmpty() ? "" : String.format("TABLET(%s)", tabletStr));
            params.put("ndvFunction", getNdvFunction(String.valueOf(rowCount)));
            params.put("min", min);
            params.put("max", max);
            params.put("rowCount", String.valueOf(rowCount));
            params.put("type", col.getType().toString());
            params.put("limit", "");
            if (needLimit()) {
                
                
                limitFlag = true;
                rowsToSample = Math.min(getSampleRows(), pair.second);
                params.put("limit", "limit " + rowsToSample);
                params.put("scaleFactor", String.valueOf(scaleFactor * (double) pair.second / rowsToSample));
            }
            StringSubstitutor stringSubstitutor = new StringSubstitutor(params);
            String sql;
            
            if (tbl.isDistributionColumn(col.getName())) {
                params.put("min", StatisticsUtil.quote(min));
                params.put("max", StatisticsUtil.quote(max));
                sql = stringSubstitutor.replace(LINEAR_ANALYZE_TEMPLATE);
            } else {
                params.put("dataSizeFunction", getDataSizeFunction(col, true));
                sql = stringSubstitutor.replace(DUJ1_ANALYZE_TEMPLATE);
            }
            LOG.info("Sample for column [{}]. Total rows [{}], rows to sample [{}], scale factor [{}], "
                    + "limited [{}], distribute column [{}], partition column [{}], key column [{}]",
                    col.getName(), params.get("rowCount"), rowsToSample, params.get("scaleFactor"),
                    limitFlag, tbl.isDistributionColumn(col.getName()),
                    tbl.isPartitionColumn(col.getName()), col.isKey());
            runQuery(sql, false);
        }
    }