# pysparky.schema_ext

*module*

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/schema_ext.py#L1-L1)

## pysparky.schema_ext.filter_columns_by_datatype

*function*

```python
def filter_columns_by_datatype(struct_type: T.StructType, data_type: T.DataType) -> T.StructType
```

Filters and returns a StructType of StructField names from a given StructType schema
that match the specified data type.

**Parameters**

- `struct_type` (`T.StructType`) — The schema of the DataFrame.
- `data_type` (`T.DataType`) — The data type to filter by.

**Returns**

- (`T.StructType`) — T.StructType: A StructType of StructField names that match the specified data type.

> **Example**
>
> ```python
> >>> schema = T.StructType([
> ...     T.StructField("id", T.IntegerType(), True),
> ...     T.StructField("name", T.StringType(), True),
> ...     T.StructField("age", T.IntegerType(), True)
> ... ])
> >>> filtered_schema = filter_columns_by_datatype(schema, T.IntegerType())
> >>> print(filtered_schema)
> StructType([StructField('id', IntegerType(), True), StructField('age', IntegerType(), True)])
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/schema_ext.py#L6-L33)
