{"record":{"id":"73b687cd91b85359","repo":"prestodb/presto","slug":"could-not-save-table-statistics-data","errorCode":null,"errorMessage":"Could not save table statistics data","messagePattern":"Could not save table statistics data","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"presto-tpcds/src/main/java/com/facebook/presto/tpcds/statistics/TableStatisticsDataRepository.java","lineNumber":68,"sourceCode":"    {\n        return schemaName.trim()\n                .replaceAll(\"\\\\.0+$\", \"\");\n    }\n\n    private void writeStatistics(Path path, TableStatisticsData tableStatisticsData)\n    {\n        File file = path.toFile();\n        file.getParentFile().mkdirs();\n        try {\n            objectMapper\n                    .writerWithDefaultPrettyPrinter()\n                    .writeValue(file, tableStatisticsData);\n            try (BufferedWriter fileWriter = Files.newBufferedWriter(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {\n                fileWriter.append('\\n');\n            }\n        }\n        catch (IOException e) {\n            throw new RuntimeException(\"Could not save table statistics data\", e);\n        }\n    }\n\n    public Optional<TableStatisticsData> load(String schemaName, Table table)\n    {\n        schemaName = normalizeSchemaName(schemaName);\n        String filename = table.getName();\n        String resourcePath = \"/tpcds/statistics/\" + schemaName + \"/\" + filename + \".json\";\n        return readStatistics(resourcePath);\n    }\n\n    private Optional<TableStatisticsData> readStatistics(String resourcePath)\n    {\n        URL resource = getClass().getResource(resourcePath);\n        if (resource == null) {\n            return Optional.empty();\n        }\n        try {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-tpcds/src/main/java/com/facebook/presto/tpcds/statistics/TableStatisticsDataRepository.java#L50-L86","documentation":"TableStatisticsDataRepository.writeStatistics serializes TableStatisticsData to a JSON file in the statistics directory. Any IOException during write or trailing-newline append is wrapped in a RuntimeException 'Could not save table statistics data'. It indicates the connector could not persist statistics to disk.","triggerScenarios":"Calling save(schemaName, table, statistics) when the target file cannot be written: stats directory missing, permission denied, disk full, or the file is a directory.","commonSituations":"Read-only mount or wrong permissions on the tpcds statistics directory; disk full on the coordinator node; statistics directory deleted while the catalog is running.","solutions":["Ensure the configured statistics directory exists and is writable by the Presto process","Check disk space on the node holding the statistics files","Fix filesystem permissions (chown/chmod) on the stats directory","Re-run the query / ANALYZE after fixing storage; statistics persistence failure is not fatal to query results"],"exampleFix":"// before\nmkdir /data/tpcds-stats   # owned by root\n// after\nmkdir -p /data/tpcds-stats && chown presto:presto /data/tpcds-stats","handlingStrategy":"try-catch","validationCode":"java.nio.file.Path dir = Path.of(statsDir);\nif (!Files.isDirectory(dir) || !Files.isWritable(dir)) {\n    throw new IllegalStateException(\"Statistics dir missing or not writable: \" + statsDir);\n}\nif (dir.toFile().getUsableSpace() < 1_000_000) throw new IllegalStateException(\"Low disk space for stats\");","typeGuard":null,"tryCatchPattern":"try {\n    repository.save(schemaName, table, stats);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().equals(\"Could not save table statistics data\")) {\n        logger.warn(e, \"Stats persistence failed; continuing without persisted stats\");\n    } else { throw e; }\n}","preventionTips":["Provision the stats directory with correct ownership (presto user) before startup","Monitor disk space on nodes hosting the stats directory","Verify after config changes that the configured stats path still exists"],"tags":["io","statistics","filesystem"],"backgroundTag":"stats-write-failed","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}