{"record":{"id":"2c73d3df434274ac","repo":"apache/cassandra","slug":"missing-schema-you-should-provide-the-schema-for","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":"validation","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java","lineNumber":698,"sourceCode":"\n        /**\n         * Use specific compression dictionary upon writing the data.\n         *\n         * @param compressionDictionary compression dictionary to use\n         * @return this builder\n         */\n        public Builder withCompressionDictionary(CompressionDictionary compressionDictionary)\n        {\n            this.compressionDictionary = compressionDictionary;\n            return this;\n        }\n\n        public CQLSSTableWriter build()\n        {\n            if (directory == null)\n                throw new IllegalStateException(\"No ouptut directory specified, you should provide a directory with inDirectory()\");\n            if (schemaStatement == null)\n                throw new IllegalStateException(\"Missing schema, you should provide the schema for the SSTable to create with forTable()\");\n            if (modificationStatement == null)\n                throw new IllegalStateException(\"No modification (INSERT/UPDATE/DELETE) statement specified, you should provide a modification statement through using()\");\n\n            Set<String> activeKeyspaces = new HashSet<>(SchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES);\n\n            if (!DatabaseDescriptor.getAccordTransactionsEnabled())\n                activeKeyspaces.remove(SchemaConstants.ACCORD_KEYSPACE_NAME);\n\n            Preconditions.checkState(Sets.difference(activeKeyspaces, Schema.instance.getKeyspaces()).isEmpty(),\n                                     \"Local keyspaces were not loaded. If this is running as a client, please make sure to add %s=true system property.\",\n                                     CassandraRelevantProperties.FORCE_LOAD_LOCAL_KEYSPACES.getKey());\n\n            // Assign the default max SSTable size if not defined in builder\n            if (isMaxSSTableSizeUnset())\n            {\n                maxSSTableSizeInMiB = sorted ? -1L : DEFAULT_BUFFER_SIZE_IN_MIB_FOR_UNSORTED;\n            }\n","sourceCodeStart":680,"sourceCodeEnd":716,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java#L680-L716","documentation":"Thrown by CQLSSTableWriter.Builder.build() as an IllegalStateException when no schema (CREATE TABLE) statement was provided. The writer needs the table schema to construct the internal column-family metadata used to serialize rows into SSTables.","triggerScenarios":"Calling build() without invoking forTable(...) on the Builder.","commonSituations":"Assembling builder options from variables where the schema string failed to be set (null/empty branch); reordering builder code so build() runs before forTable; generating writers in a loop where one iteration skips the schema setup.","solutions":["Add .forTable(\"CREATE TABLE ...\") to the builder chain before build()","Confirm the schema variable is non-null and a valid CREATE TABLE statement","Ensure the target keyspace exists or include CREATE KEYSPACE handling before building the writer"],"exampleFix":"// before\nCQLSSTableWriter writer = CQLSSTableWriter.builder()\n    .inDirectory(dir).using(insert).build();\n// after\nCQLSSTableWriter writer = CQLSSTableWriter.builder()\n    .inDirectory(dir)\n    .forTable(\"CREATE TABLE ks.tbl (k text PRIMARY KEY, v int)\")\n    .using(insert).build();","handlingStrategy":"validation","validationCode":"if (schemaCql == null || schemaCql.isEmpty()) throw new IllegalStateException(\"forTable() schema required before build()\");","typeGuard":"null","tryCatchPattern":"try { writer = builder.build(); } catch (IllegalStateException e) { if (e.getMessage().contains(\"schema\")) { /* supply forTable() and rebuild */ } throw e; }","preventionTips":["Always pair forTable() and using() in a shared writer-factory method","Validate the CREATE TABLE parses (e.g. via a quick CQL parse) before building","Keep schema strings in version-controlled constants, not inline literals scattered in code"],"tags":["sstable","bulk-loading","builder","schema"],"backgroundTag":"missing-required-config","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"}