apache/cassandra · error · IllegalStateException

Missing schema, you should provide the schema for the SSTabl

Error message

Missing schema, you should provide the schema for the SSTable to create with forTable()

What it means

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.

Source

Thrown at tools/stress/src/org/apache/cassandra/io/sstable/StressCQLSSTableWriter.java:579

         * the rows in order, which is rarely the case. If you can provide the
         * rows in order however, using this sorted might be more efficient.
         * <p>
         * Note that if used, some option like withBufferSizeInMiB will be ignored.
         *
         * @return this builder.
         */
        public Builder sorted()
        {
            this.sorted = true;
            return this;
        }

        public StressCQLSSTableWriter build()
        {
            if (directoryList.isEmpty() && cfs == null)
                throw new IllegalStateException("No output directories specified, you should provide a directory with inDirectory()");
            if (schemaStatement == null && cfs == null)
                throw new IllegalStateException("Missing schema, you should provide the schema for the SSTable to create with forTable()");
            if (insertStatement == null)
                throw new IllegalStateException("No insert statement specified, you should provide an insert statement through using()");

            synchronized (StressCQLSSTableWriter.class)
            {
                if (cfs == null)
                    cfs = createOfflineTable(schemaStatement, typeStatements, directoryList);

                if (partitioner == null)
                    partitioner = cfs.getPartitioner();

                UpdateStatement preparedInsert = prepareInsert();
                AbstractSSTableSimpleWriter writer = sorted
                                                     ? new SSTableSimpleWriter(cfs.getDirectories().getDirectoryForNewSSTables(), cfs.metadata, preparedInsert.updatedColumns(), -1)
                                                     : new SSTableSimpleUnsortedWriter(cfs.getDirectories().getDirectoryForNewSSTables(), cfs.metadata, preparedInsert.updatedColumns(), bufferSizeInMiB);

                if (format != null)
                    writer.setSSTableFormatType(format);

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Add .forTable("CREATE TABLE ...") with the full CREATE TABLE statement to the builder.
  2. Load the CREATE TABLE statement from your schema files if it is maintained externally.
  3. Include any needed type statements via withType(...) for custom types used by the table.
  4. Alternatively, use the variant that builds against an existing column family.

Example fix

// before
builder.using("INSERT ...").build();
// after
builder.forTable("CREATE TABLE ks.tbl (k text PRIMARY KEY, v int)")
       .using("INSERT INTO ks.tbl (k, v) VALUES (?, ?)")
       .build();
Defensive patterns

Strategy: validation

Validate before calling

if (createTableStmt == null || createTableStmt.isBlank()) throw new IllegalStateException("forTable() required before build()");
builder.forTable(createTableStmt);

Try / catch

try { writer = builder.build(); }
catch (IllegalStateException e) { throw new IllegalStateException("supply schema via forTable(): " + e.getMessage(), e); }

Prevention

When it happens

Trigger: Calling build() without forTable(...) (or without an existing cfs) on the Builder.

Common situations: 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.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/39b04aef10519b34. Report an issue: GitHub.