{"record":{"id":"18368d6506aebede","repo":"prestodb/presto","slug":"hive-invalid-file-names","errorCode":"HIVE_INVALID_FILE_NAMES","errorMessage":"Hive table '%s' is corrupt. Some of the filenames in the partition: %s are not integers","messagePattern":"Hive table '(.+?)' is corrupt\\. Some of the filenames in the partition: (.+?) are not integers","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/StoragePartitionLoader.java","lineNumber":630,"sourceCode":"                // legacy mode requires exactly one file per bucket\n                if (fileInfos.size() != partitionBucketCount) {\n                    throw new PrestoException(\n                            HIVE_INVALID_BUCKET_FILES,\n                            format(\"Hive table '%s' is corrupt. File '%s' does not match the standard naming pattern, and the number \" +\n                                            \"of files in the directory (%s) does not match the declared bucket count (%s) for partition: %s\",\n                                    table.getSchemaTableName(),\n                                    fileName,\n                                    fileInfos.size(),\n                                    partitionBucketCount,\n                                    partitionName));\n                }\n                if (fileInfos.get(0).getFileName().matches(\"\\\\d+\")) {\n                    try {\n                        // File names are integer if they are created when file_renaming_enabled is set to true\n                        fileInfos.sort(Comparator.comparingInt(fileInfo -> Integer.parseInt(fileInfo.getFileName())));\n                    }\n                    catch (NumberFormatException e) {\n                        throw new PrestoException(\n                                HIVE_INVALID_FILE_NAMES,\n                                format(\"Hive table '%s' is corrupt. Some of the filenames in the partition: %s are not integers\",\n                                        new SchemaTableName(table.getDatabaseName(), table.getTableName()),\n                                        partitionName));\n                    }\n                }\n                else {\n                    // Sort FileStatus objects (instead of, e.g., fileStatus.getPath().toString). This matches org.apache.hadoop.hive.ql.metadata.Table.getSortedPaths\n                    fileInfos.sort(null);\n                }\n\n                // Use position in sorted list as the bucket number\n                bucketToFileInfo.clear();\n                for (int i = 0; i < fileInfos.size(); i++) {\n                    bucketToFileInfo.put(i, fileInfos.get(i));\n                }\n                break;\n            }","sourceCodeStart":612,"sourceCodeEnd":648,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/StoragePartitionLoader.java#L612-L648","documentation":"Thrown when sorting legacy bucket files by numeric filename fails. File names are integers only when written with file_renaming_enabled=true; if the first file matches \\d+ but other files in the partition cannot be parsed as integers, the partition is treated as corrupt.","triggerScenarios":"computeBucketToFileInfoMapping (from bucketToFileInfo) sees the first file name is all digits, sorts all files with Integer.parseInt, and one file name (e.g. '000000_0_copy' or a CRC file) throws NumberFormatException.","commonSituations":"Mixed naming in one partition: some files from a file_renaming_enabled writer, others from a legacy writer; hidden files like .filename.crc or _SUCCESS picked up by the listing; manually added files with suffixes.","solutions":["Remove or rename non-integer-named files in the partition so all files match the integer naming scheme","Make naming consistent: re-run the write with a single file_renaming_enabled setting for the whole partition","Exclude stray files (_SUCCESS, .crc) from the partition directory","If bucketing is not required, unbucket the table/partition to bypass this path"],"exampleFix":"// before: mixed names\n1  2  000000_0.bak\n// after\nhdfs dfs -rm .../000000_0.bak   # or rename to '3'","handlingStrategy":"validation","validationCode":"// before querying: all files must be integer-named if any is\nList<String> names = listPartitionFileNames(partitionDir);\nboolean anyDigits = names.stream().anyMatch(n -> n.matches(\"\\\\d+\"));\nif (anyDigits && names.stream().anyMatch(n -> !n.matches(\"\\\\d+\"))) {\n    throw new IllegalStateException(\"Mixed file naming in partition: \" + names);\n}","typeGuard":"static boolean hasConsistentIntegerNames(List<String> names) {\n    return !names.stream().anyMatch(n -> n.matches(\"\\\\d+\"))\n        || names.stream().allMatch(n -> n.matches(\"\\\\d+\"));\n}","tryCatchPattern":"try {\n    session.execute(query);\n} catch (PrestoException e) {\n    if (HiveErrorCode.HIVE_INVALID_FILE_NAMES.toErrorCode().equals(e.getErrorCode())) {\n        // inspect partition for mixed naming and repair\n    } else throw e;\n}","preventionTips":["Use one file_renaming_enabled setting consistently for all writers of a bucketed table","Exclude hidden/stray files (_SUCCESS, .crc) from partition directories","Never append hand-created files into a renaming-enabled partition","Validate naming consistency after each partition write"],"tags":["hive","bucketing","file-naming","corrupt-table"],"backgroundTag":"hive-invalid-file-names","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"}