Skip to content

Schema

The schema of a row or table.

Parameters:

Name Type Description Default
schema Map<String, ColumnType> - -
Stub code in Schema.sdsstub

class Schema(
    schema: Map<String, ColumnType>
) {
    /**
     * The number of columns.
     */
    @PythonName("column_count") attr columnCount: Int
    /**
     * The names of the columns.
     */
    @PythonName("column_names") attr columnNames: List<String>

    /**
     * Get the type of a column.
     *
     * @param name The name of the column.
     *
     * @result type The type of the column.
     *
     * @example
     * pipeline example {
     *     val schema = Schema({"a": ColumnType.int64(), "b": ColumnType.float32()});
     *     out schema.getColumnType("a");
     *     // int64
     *     out schema.getColumnType("b");
     *     // float32
     * }
     */
    @Pure
    @PythonName("get_column_type")
    fun getColumnType(
        name: String
    ) -> type: ColumnType

    /**
     * Check if the schema has a column with a specific name.
     *
     * @param name The name of the column.
     *
     * @result hasColumn Whether the schema has a column with the specified name.
     *
     * @example
     * pipeline example {
     *     val schema = Schema({"a": ColumnType.int64(), "b": ColumnType.float32()});
     *     out schema.hasColumn("a");
     *     // true
     *     out schema.hasColumn("c");
     *     // false
     * }
     */
    @Pure
    @PythonName("has_column")
    fun hasColumn(
        name: String
    ) -> hasColumn: Boolean

    /**
     * Return a map from column names to column types.
     *
     * @result data The map representation of the schema.
     *
     * @example
     * pipeline example {
     *     val table = Table({"A": [1, 2, 3], "B": ["a", "b", "c"]});
     *     out table.schema.toMap();
     *     // {'A': int64, 'B': string}
     * }
     */
    @Pure
    @PythonName("to_dict")
    fun toMap() -> data: Map<String, ColumnType>
}

columnCount

The number of columns.

Type: Int

columnNames

The names of the columns.

Type: List<String>

getColumnType

Get the type of a column.

Parameters:

Name Type Description Default
name String The name of the column. -

Results:

Name Type Description
type ColumnType The type of the column.

Examples:

pipeline example {
    val schema = Schema({"a": ColumnType.int64(), "b": ColumnType.float32()});
    out schema.getColumnType("a");
    // int64
    out schema.getColumnType("b");
    // float32
}
Stub code in Schema.sdsstub

@Pure
@PythonName("get_column_type")
fun getColumnType(
    name: String
) -> type: ColumnType

hasColumn

Check if the schema has a column with a specific name.

Parameters:

Name Type Description Default
name String The name of the column. -

Results:

Name Type Description
hasColumn Boolean Whether the schema has a column with the specified name.

Examples:

pipeline example {
    val schema = Schema({"a": ColumnType.int64(), "b": ColumnType.float32()});
    out schema.hasColumn("a");
    // true
    out schema.hasColumn("c");
    // false
}
Stub code in Schema.sdsstub

@Pure
@PythonName("has_column")
fun hasColumn(
    name: String
) -> hasColumn: Boolean

toMap

Return a map from column names to column types.

Results:

Name Type Description
data Map<String, ColumnType> The map representation of the schema.

Examples:

pipeline example {
    val table = Table({"A": [1, 2, 3], "B": ["a", "b", "c"]});
    out table.schema.toMap();
    // {'A': int64, 'B': string}
}
Stub code in Schema.sdsstub

@Pure
@PythonName("to_dict")
fun toMap() -> data: Map<String, ColumnType>