prestodb/presto · error · RuntimeException

Failed to parse stats from resource [%s]

Error message

Failed to parse stats from resource [%s]

What it means

TableStatisticsDataRepository.load reads a classpath resource containing pre-computed TPC-H table statistics and deserializes it with ObjectMapper into TableStatisticsData. Any exception during parse is wrapped in a RuntimeException naming the resource path, so malformed or incompatible statistics JSON fails fast.

Source

Thrown at presto-tpch/src/main/java/com/facebook/presto/tpch/statistics/TableStatisticsDataRepository.java:84

        }
        catch (IOException e) {
            throw new RuntimeException("Could not save table statistics data", e);
        }
    }

    public Optional<TableStatisticsData> load(String schemaName, TpchTable<?> table, Optional<TpchColumn<?>> partitionColumn, Optional<String> partitionValue)
    {
        String filename = tableStatisticsDataFilename(table, partitionColumn, partitionValue);
        String resourcePath = "/tpch/statistics/" + schemaName + "/" + filename + ".json";
        URL resource = getClass().getResource(resourcePath);
        if (resource == null) {
            return Optional.empty();
        }
        try {
            return Optional.of(objectMapper.readValue(resource, TableStatisticsData.class));
        }
        catch (Exception e) {
            throw new RuntimeException(format("Failed to parse stats from resource [%s]", resourcePath), e);
        }
    }

    private String tableStatisticsDataFilename(TpchTable<?> table, Optional<TpchColumn<?>> partitionColumn, Optional<String> partitionValue)
    {
        Optional<String> partitionDescription = getPartitionDescription(partitionColumn, partitionValue);
        return table.getTableName() + partitionDescription.map(value -> "." + value).orElse("");
    }

    private Optional<String> getPartitionDescription(Optional<TpchColumn<?>> partitionColumn, Optional<String> partitionValue)
    {
        checkArgument(partitionColumn.isPresent() == partitionValue.isPresent());
        return withBoth(partitionColumn, partitionValue, (column, value) -> column.getColumnName() + "." + value);
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Open the resource named in the message and validate it is well-formed JSON matching TableStatisticsData fields (columnNames, columnStatistics, rowCounts, etc.).
  2. Restore the resource from the presto-presto source for your version (files under presto-tpch/src/main/resources/tpch/stats).
  3. If TableStatisticsData was changed, regenerate the resource files to the new schema.
  4. Catch/handle the RuntimeException at the call site to fall back to no statistics (Optional.empty) if stats are optional.

Example fix

// before
throw new RuntimeException(format("Failed to parse stats from resource [%s]", resourcePath), e);
// after
throw new RuntimeException(format("Failed to parse stats from resource [%s]: %s", resourcePath, e.getMessage()), e);
// or at call site: wrap load() in try-catch and return Optional.empty()
Defensive patterns

Strategy: try-catch

Validate before calling

// validate resource JSON before trusting stats
Optional<TableStatisticsData> stats;
try (InputStream in = getClass().getResourceAsStream(resourcePath)) {
    if (in == null) return Optional.empty();
    OBJECT_MAPPER.readTree(in); // throws if malformed
}

Try / catch

try {
    stats = repository.load(schemaName, table, partitionColumn, partitionValue);
} catch (RuntimeException e) {
    if (e.getMessage().startsWith("Failed to parse stats")) {
        stats = Optional.empty(); // proceed without statistics
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling load(schemaName, table, partitionColumn, partitionValue) where the corresponding resource file exists but is not valid JSON, or its schema does not match TableStatisticsData (wrong field types, missing required fields, corrupted resource).

Common situations: Bundled statistics resources edited or truncated by hand; a TableStatisticsData schema change across Presto versions making older resource files incompatible; build packaging corrupting resources; manually added stats files with invalid JSON.

Understand the failure class

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/e6f5c6561bf5e2bc. Report an issue: GitHub.