{"record":{"id":"39b04aef10519b34","repo":"apache/cassandra","slug":"missing-schema-you-should-provide-the-schema-for-39b04a","errorCode":null,"errorMessage":"Missing schema, you should provide the schema for the SSTable to create with forTable()","messagePattern":"Missing schema, you should provide the schema for the SSTable to create with forTable\\(\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"tools/stress/src/org/apache/cassandra/io/sstable/StressCQLSSTableWriter.java","lineNumber":579,"sourceCode":"         * the rows in order, which is rarely the case. If you can provide the\n         * rows in order however, using this sorted might be more efficient.\n         * <p>\n         * Note that if used, some option like withBufferSizeInMiB will be ignored.\n         *\n         * @return this builder.\n         */\n        public Builder sorted()\n        {\n            this.sorted = true;\n            return this;\n        }\n\n        public StressCQLSSTableWriter build()\n        {\n            if (directoryList.isEmpty() && cfs == null)\n                throw new IllegalStateException(\"No output directories specified, you should provide a directory with inDirectory()\");\n            if (schemaStatement == null && cfs == null)\n                throw new IllegalStateException(\"Missing schema, you should provide the schema for the SSTable to create with forTable()\");\n            if (insertStatement == null)\n                throw new IllegalStateException(\"No insert statement specified, you should provide an insert statement through using()\");\n\n            synchronized (StressCQLSSTableWriter.class)\n            {\n                if (cfs == null)\n                    cfs = createOfflineTable(schemaStatement, typeStatements, directoryList);\n\n                if (partitioner == null)\n                    partitioner = cfs.getPartitioner();\n\n                UpdateStatement preparedInsert = prepareInsert();\n                AbstractSSTableSimpleWriter writer = sorted\n                                                     ? new SSTableSimpleWriter(cfs.getDirectories().getDirectoryForNewSSTables(), cfs.metadata, preparedInsert.updatedColumns(), -1)\n                                                     : new SSTableSimpleUnsortedWriter(cfs.getDirectories().getDirectoryForNewSSTables(), cfs.metadata, preparedInsert.updatedColumns(), bufferSizeInMiB);\n\n                if (format != null)\n                    writer.setSSTableFormatType(format);","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/tools/stress/src/org/apache/cassandra/io/sstable/StressCQLSSTableWriter.java#L561-L597","documentation":"StressCQLSSTableWriter.Builder.build() requires the target table schema, normally supplied via forTable(schemaStatement). It throws IllegalStateException when no schema statement was provided and no pre-existing column family (cfs) is available, so the writer cannot determine the SSTable layout.","triggerScenarios":"Calling build() without forTable(...) (or without an existing cfs) on the Builder.","commonSituations":"Building a writer only from an INSERT statement assuming schema is inferred; copying example code and deleting the forTable line; generating SSTables for a table whose CREATE statement lives in a file never loaded.","solutions":["Add .forTable(\"CREATE TABLE ...\") with the full CREATE TABLE statement to the builder.","Load the CREATE TABLE statement from your schema files if it is maintained externally.","Include any needed type statements via withType(...) for custom types used by the table.","Alternatively, use the variant that builds against an existing column family."],"exampleFix":"// before\nbuilder.using(\"INSERT ...\").build();\n// after\nbuilder.forTable(\"CREATE TABLE ks.tbl (k text PRIMARY KEY, v int)\")\n       .using(\"INSERT INTO ks.tbl (k, v) VALUES (?, ?)\")\n       .build();","handlingStrategy":"validation","validationCode":"if (createTableStmt == null || createTableStmt.isBlank()) throw new IllegalStateException(\"forTable() required before build()\");\nbuilder.forTable(createTableStmt);","typeGuard":null,"tryCatchPattern":"try { writer = builder.build(); }\ncatch (IllegalStateException e) { throw new IllegalStateException(\"supply schema via forTable(): \" + e.getMessage(), e); }","preventionTips":["Keep CREATE TABLE statements in versioned schema files and load them.","Always pair forTable() with matching using() insert in a shared factory.","Include withType() for custom types.","Validate the schema string parses before building."],"tags":["sstable","schema","builder"],"backgroundTag":"missing-required-config-field","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}