prestodb/presto · error · RuntimeException

Could not save table statistics data

Error message

Could not save table statistics data

What it means

TableStatisticsDataRepository.writeStatistics serializes TableStatisticsData to JSON via ObjectMapper and writes it to a file in the statistics directory. Any IOException during the write is wrapped in a RuntimeException with this message. It indicates the TPCH statistics cache could not be persisted to disk.

Source

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

        String filename = tableStatisticsDataFilename(table, partitionColumn, partitionValue);
        Path path = Paths.get("presto-tpch", "src", "main", "resources", "tpch", "statistics", schemaName, filename + ".json");
        writeStatistics(path, statisticsData);
    }

    private void writeStatistics(Path path, TableStatisticsData tableStatisticsData)
    {
        File file = path.toFile();
        file.getParentFile().mkdirs();
        try {
            objectMapper
                    .writerWithDefaultPrettyPrinter()
                    .writeValue(file, tableStatisticsData);
            try (BufferedWriter fileWriter = Files.newBufferedWriter(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
                fileWriter.append('\n');
            }
        }
        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);
        }
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Check that the configured statistics directory exists and the process has write permission; create it or fix permissions.
  2. Verify free disk space and that the mount is not read-only.
  3. Inspect the wrapped IOException (getCause) for the precise filesystem error.
  4. Make statistics saving non-fatal or point the stats directory to a reliably writable location (e.g. local disk instead of NFS).

Example fix

// before
throw new RuntimeException("Could not save table statistics data", e);
// after
// ensure dir exists before write
Files.createDirectories(file.getParentFile().toPath());
throw new RuntimeException("Could not save table statistics data to " + file, e);
Defensive patterns

Strategy: try-catch

Validate before calling

// before saving: verify the stats directory is writable
Path dir = Paths.get(statisticsDirectory);
if (!Files.isDirectory(dir) || !Files.isWritable(dir)) {
    throw new IllegalStateException("Statistics directory missing or not writable: " + dir);
}

Try / catch

try {
    repository.save(schemaName, table, partitionColumn, partitionValue, stats);
} catch (RuntimeException e) {
    if (e.getCause() instanceof IOException) {
        log.warn(e, "Statistics persistence failed; continuing without caching");
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling save(schemaName, table, partitionColumn, partitionValue, statisticsData) when the target directory does not exist or is not writable, the disk is full, or the filesystem rejects the write.

Common situations: Statistics directory configured with wrong permissions or a read-only mount; disk full in a container; the stats directory was deleted while the connector was running; saving stats on NFS with transient I/O failures.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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