compileTimeSchema

inline fun <reified T> DataFrame<T>.compileTimeSchema(ordered: Boolean = true): DataFrameSchema

Returns the compile-time DataFrameSchema of this DataFrame: the schema that follows from its type argument T, not from the columns it holds.

T is a schema marker — a DataSchema declaration you wrote yourself, or the one the compiler plugin produced for the result of an operation. The columns are the properties of T, whether or not it carries the DataSchema annotation. A type with no properties therefore gives a schema with no columns — as does DataFrame<*>, where T is Any?.

A DataFrame has two schemas that do not have to agree: the runtime one, read from the columns it holds, and the compile-time one, read from the type argument T of DataFrame<T>. They differ when the type does not fit the columns, for example after a cast to a schema the data does not have; comparing them is how you notice.

Use print to write a schema out as a tree, and compare to relate two schemas to each other.

For more information: See schema on the documentation website.

On schema markers and the plugin that writes them: See Compiler Plugin on the documentation website.

Example

@DataSchema
interface Person {
val name: String
val age: Int
}

val df = dataFrameOf("name", "age")("Alice", 15).cast<Person>()

// name: String, age: Int — sorted like the columns of df
df.compileTimeSchema()

// age: Int, name: String — `Person` is an interface and has no constructor to take an order
// from, so this is the reflection order, neither the declaration order nor the order of df
df.compileTimeSchema(ordered = false)

Return

The DataFrameSchema that follows from the type argument T of this DataFrame.

Parameters

ordered

If true (the default), the columns are sorted to match the order of the runtime schema, so that the two schemas are easy to compare; a column the runtime schema does not have comes first. If false, the columns are ordered as they are represented in the compiler plugin: when T has a primary constructor, or a single constructor, its parameter order wins. That holds for any class with such a constructor, data or not; a Java record is the one exception, its constructor cannot be read. Without such a constructor — for an interface marker, for instance — the order is the one reflection reports the properties of T in, which is neither their declaration order nor the order of the columns.

See also