Skip to content

[Spark api] infer schema like pyspark - #18051

Closed
jayhan94 wants to merge 1 commit into
duckdb:mainfrom
jayhan94:jayhan/infer_schema_like_pyspark
Closed

jayhan94 wants to merge 1 commit into
duckdb:mainfrom
jayhan94:jayhan/infer_schema_like_pyspark

Conversation

@jayhan94

Copy link
Copy Markdown
Contributor

Close #17187

@jayhan94
jayhan94 force-pushed the jayhan/infer_schema_like_pyspark branch from 4cb8294 to e4a23ef Compare June 25, 2025 06:31
_INTERVAL_DAYTIME = re.compile(r"interval (day|hour|minute|second)( to (day|hour|minute|second))?")


# Mapping Python types to Spark SQL DataType

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes of this file is nearly copied from pyspark and only make a few changes

df = df.toDF(*names)
return df

def _inferSchemaFromList(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is copied from pyspark

@jayhan94
jayhan94 marked this pull request as ready for review June 25, 2025 06:36
@jayhan94 jayhan94 changed the title infer schema like pyspark [Spark api] infer schema like pyspark Jun 25, 2025
@Mytherin
Mytherin requested a review from evertlammerts June 25, 2025 10:46
@jayhan94

jayhan94 commented Jul 8, 2025 •

Copy link
Copy Markdown
Contributor Author

Could anyone help review to push this forward? @Mytherin @evertlammerts

@hannes

hannes commented Aug 31, 2025

Copy link
Copy Markdown
Member

@hannes hannes closed this Aug 31, 2025
mariotaddeucci added a commit to mariotaddeucci/duckdb-python that referenced this pull request Mar 19, 2026
Port schema inference from duckdb/duckdb#18051 to fix duckdb#183.

When calling spark.createDataFrame([{"col": value}, ...]), the Spark API
now infers the schema from dict keys, matching PySpark behavior.

Changes:
- Add _type_mappings, _array_type_mappings, _has_nulltype, _merge_type,
  _infer_type, and _infer_schema functions to types.py
- Update session.py to handle dict rows in _combine_data_and_schema and
  add schema inference branch in createDataFrame for list[dict]
- Add _inferSchemaFromList method to SparkSession
- Fix test_struct_column to use inferred field names instead of col0/col1
- Add test_dataframe_from_list_dicts test case
mariotaddeucci added a commit to mariotaddeucci/duckdb-python that referenced this pull request Mar 19, 2026
Port schema inference from duckdb/duckdb#18051 to fix duckdb#183.

When calling spark.createDataFrame([{"col": value}, ...]), the Spark API
now infers the schema from dict keys, matching PySpark behavior.

Changes:
- Add _type_mappings, _array_type_mappings, _has_nulltype, _merge_type,
  _infer_type, and _infer_schema functions to types.py
- Update session.py to handle dict rows in _combine_data_and_schema and
  add schema inference branch in createDataFrame for list[dict]
- Add _inferSchemaFromList method to SparkSession
- Fix test_struct_column to use inferred field names instead of col0/col1
- Add test_dataframe_from_list_dicts test case
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

Successfully merging this pull request may close these issues.

[Python] PySpark-API: spark.createDataframe(data: List[Dict]) does not work properly

2 participants