code: def test_spark_examples_iterable_shard():
      spark = (
          pyspark.sql.SparkSession.builder.master("local[*]")
          .appName("pyspark")
          .getOrCreate()
      )
      df = spark.range(20).repartition(4)
  
      # Partitions 0 and 2
      shard_it_1 = SparkExamplesIterable(df).shard_data_sources(
          worker_id=0, num_workers=2
      )
      assert shard_it_1.n_shards == 2
      expected_row_ids_and_row_dicts_1 = (
          _get_expected_row_ids_and_row_dicts_for_partition_order(
              df, [0, 2]
          )
      )
      for i, (row_id, row_dict) in enumerate(shard_it_1):
          (
              expected_row_id,
              expected_row_dict,
          ) = expected_row_ids_and_row_dicts_1[i]
          assert row_id == expected_row_id
          assert row_dict == expected_row_dict
  
      # Partitions 1 and 3
      shard_it_2 = SparkExamplesIterable(df).shard_data_sources(
          worker_id=1, num_workers=2
      )
      assert shard_it_2.n_shards == 2
      expected_row_ids_and_row_dicts_2 = (
          _get_expected_row_ids_and_row_dicts_for_partition_order(
              df, [1, 3]
          )
      )
      for i, (row_id, row_dict) in enumerate(shard_it_2):
          (
              expected_row_id,
              expected_row_dict,
          ) = expected_row_ids_and_row_dicts_2[i]
          assert row_id == expected_row_id
          assert row_dict == expected_row_dict
  
file_path: datasets/tests/packaged_modules/test_spark.py
imports: from unittest.mock import patch
  import pyspark
  from datasets.packaged_modules.spark.spark import Spark, SparkExamplesIterable, _generate_iterable_examples
  from ..utils import require_dill_gt_0_3_2, require_not_windows
label_desc: Use image node_id 6 for calling a global function with example usage: test_spark_examples_iterable_shard() without return types