Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fill_unspecified_columns_with_nulls won't work for inner fields. #580

Open
jromerosk opened this issue Jan 10, 2025 · 0 comments
Open

fill_unspecified_columns_with_nulls won't work for inner fields. #580

jromerosk opened this issue Jan 10, 2025 · 0 comments

Comments

@jromerosk
Copy link
Contributor

The function transform_to_schema has an flag to populate with nulls the resulting DataSet when the columns are not in the data or in the transformations. However this won't work for fields inside structs.

Example:

from pyspark.sql import types as T
import typedspark as TS

class TestStructType(TS.Schema):
    f1: TS.Column[T.StringType]
    f2: TS.Column[T.StringType]

class TestSchema(TS.Schema):
    a: TS.Column[TS.StructType[TestStructType]]

df = spark.createDataFrame([({"f1":"a"},)],"struct<a:struct<f1:string>>")
ds = TS.transform_to_schema(
    df,
    TestSchema,
    fill_unspecified_columns_with_nulls=True
)

Expected behaviour:
The resulting dataset should have the f2 field populated with nulls.

Actual behaviour
Error:
TypeError: Schema TestSchema.a contains the following columns not present in data: {'f2'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant