Parent: #1511
Description
Spark datasets return a PySpark DataFrame, not pandas. Stats are empty for those today. This ticket covers the main spark kedro-datasets types:
spark.SparkDataset
spark.SparkDatasetV2
spark.SparkHiveDataset
spark.SparkJDBCDataset
Context
Same hook as the other tickets: DatasetStatsHook in package/kedro_viz/integrations/kedro/hooks.py.
Spark data is lazy and distributed. Getting row count means calling .count(), which kicks off a job. Column count is cheap. Many Spark datasets also have no single local file path, so file size will often stay N/A like it does for SQL backed pandas datasets.
Possible implementation
Detect pyspark.sql.DataFrame with a lazy import.
- columns from
len(data.columns)
- rows from
data.count() (call out the cost in docs or RELEASE)
- optional partition count from
data.rdd.getNumPartitions() if we want another label in the UI
- file size only when we can resolve a filepath on the dataset object
Wrap Spark calls in try/except so tests do not need a live cluster. Mock the DataFrame in unit tests.
If we add partitions as a stat, update format_stats() and datasetStatLabels.
Example:
{
"model_input@spark": {
"rows": 1000000,
"columns": 42,
"partitions": 8
}
}
Possible alternatives
Columns only in v1 and skip row count unless the user opts in via settings.
Use table metadata for approximate counts on Hive/Delta instead of a full scan. Harder to do generically.
Bigger refactor with a plugin point for custom stat extractors. Probably overkill for now.
Deliverables
- Hook handles
pyspark.sql.DataFrame
- Stats in
.viz/stats.json for Spark catalog entries
- Document when row count runs a Spark action and when file size is unavailable
- Unit tests with mocks
Checklist
Parent: #1511
Description
Spark datasets return a PySpark DataFrame, not pandas. Stats are empty for those today. This ticket covers the main spark kedro-datasets types:
spark.SparkDatasetspark.SparkDatasetV2spark.SparkHiveDatasetspark.SparkJDBCDatasetContext
Same hook as the other tickets:
DatasetStatsHookinpackage/kedro_viz/integrations/kedro/hooks.py.Spark data is lazy and distributed. Getting row count means calling
.count(), which kicks off a job. Column count is cheap. Many Spark datasets also have no single local file path, so file size will often stay N/A like it does for SQL backed pandas datasets.Possible implementation
Detect
pyspark.sql.DataFramewith a lazy import.len(data.columns)data.count()(call out the cost in docs or RELEASE)data.rdd.getNumPartitions()if we want another label in the UIWrap Spark calls in try/except so tests do not need a live cluster. Mock the DataFrame in unit tests.
If we add
partitionsas a stat, updateformat_stats()anddatasetStatLabels.Example:
{ "model_input@spark": { "rows": 1000000, "columns": 42, "partitions": 8 } }Possible alternatives
Columns only in v1 and skip row count unless the user opts in via settings.
Use table metadata for approximate counts on Hive/Delta instead of a full scan. Harder to do generically.
Bigger refactor with a plugin point for custom stat extractors. Probably overkill for now.
Deliverables
pyspark.sql.DataFrame.viz/stats.jsonfor Spark catalog entriesChecklist
create_dataset_stats()test_hooks.py