deeplearning4j/deeplearning4j · error · java.lang.IllegalStateException

Unexpected column type: " + d.columnType

Error message

Unexpected column type: " + d.columnType

What it means

DeriveColumnsFromTimeTransform.transform(Schema) builds the output schema by adding metadata for each derived column. Only ColumnType.String and ColumnType.Integer are supported when creating the new column metadata; any other DerivedColumn columnType hits the default branch and throws this IllegalStateException. Derived columns should only be created via the Builder's addStringDerivedColumn/addIntegerDerivedColumn methods, so this normally indicates a manually constructed or deserialized DerivedColumn.

Solutions

  1. Change the derived column's type to ColumnType.String (use builder.addStringDerivedColumn) or ColumnType.Integer (use builder.addIntegerDerivedColumn).
  2. If you need a different type (e.g. Long), add explicit support in DeriveColumnsFromTimeTransform.transform (and map/map(Object)) rather than reusing this transform.
  3. If loading from a saved config, re-export/re-save the transform process with a supported columnType after upgrading DataVec versions.

Example fix

// before
derivedColumns.add(new DerivedColumn("hour", ColumnType.Long, null, null, DateTimeFieldType.hourOfDay()));
// after
derivedColumns.add(new DerivedColumn("hour", ColumnType.Integer, null, null, DateTimeFieldType.hourOfDay()));
// or preferably, via Builder:
// new DeriveColumnsFromTimeTransform.Builder("timeCol")
//     .addIntegerDerivedColumn("hour", DateTimeFieldType.hourOfDay()).build();
Defensive patterns

Strategy: validation

Validate before calling

boolean safe = derivedColumns.stream().allMatch(d ->
    d.getColumnType() == ColumnType.String || d.getColumnType() == ColumnType.Integer);
if (!safe) throw new IllegalArgumentException("Derived columns must be String or Integer");

Type guard

boolean isSupportedType(ColumnType t) { return t == ColumnType.String || t == ColumnType.Integer; }

Try / catch

try {
    Schema out = transform.transform(inputSchema);
} catch (IllegalStateException e) {
    if (e.getMessage().startsWith("Unexpected column type")) {
        // rebuild the transform with Builder-supported column types
    } else throw e;
}

Prevention

When it happens

Trigger: Calling transform(Schema) (directly or via a TransformProcess) when a DerivedColumn in the transform has columnType other than String or Integer, e.g. a DerivedColumn constructed with new DerivedColumn(name, ColumnType.Long, ...) or a columnType corrupted/deserialized incorrectly from JSON config.

Common situations: Hand-writing DerivedColumn objects instead of using Builder methods; loading a serialized/YAML/JSON transform config where the columnType enum changed between DataVec versions; copying code that used an unsupported type like Categorical or Long for a time-derived column.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07). Data as JSON: /api/errors/68c6dced062d0407. Report an issue: GitHub.

Appendix: source

Thrown at datavec/datavec-api/src/main/java/org/datavec/api/transform/transform/time/DeriveColumnsFromTimeTransform.java:107

        List<String> oldNames = inputSchema.getColumnNames();

        for (int i = 0; i < oldMeta.size(); i++) {
            String current = oldNames.get(i);
            newMeta.add(oldMeta.get(i));

            if (insertAfter.equals(current)) {
                //Insert the derived columns here
                for (DerivedColumn d : derivedColumns) {
                    switch (d.columnType) {
                        case String:
                            newMeta.add(new StringMetaData(d.columnName));
                            break;
                        case Integer:
                            newMeta.add(new IntegerMetaData(d.columnName)); //TODO: ranges... if it's a day, we know it must be 1 to 31, etc...
                            break;
                        default:
                            throw new IllegalStateException("Unexpected column type: " + d.columnType);
                    }
                }
            }
        }

        return inputSchema.newSchema(newMeta);
    }

    @Override
    public void setInputSchema(Schema inputSchema) {
        insertAfterIdx = inputSchema.getColumnNames().indexOf(insertAfter);
        if (insertAfterIdx == -1) {
            throw new IllegalStateException(
                            "Invalid schema/insert after column: input schema does not contain column \"" + insertAfter
                                            + "\"");
        }

        deriveFromIdx = inputSchema.getColumnNames().indexOf(columnName);

View on GitHub (pinned to 4c22ac5fe4)