code: def test_primitive(spark_test_ctx):
      schema = StructType(
          [
              StructField("bool_col", BooleanType(), False),
              StructField("float_col", FloatType(), False),
              StructField("double_col", DoubleType(), False),
              StructField("short_col", ShortType(), False),
              StructField("int_col", IntegerType(), False),
              StructField("long_col", LongType(), False),
              StructField("str_col", StringType(), False),
              StructField("bin_col", BinaryType(), False),
              StructField("byte_col", ByteType(), False),
          ]
      )
      df = spark_test_ctx.spark.createDataFrame(
          [
              (
                  True,
                  0.12,
                  432.1,
                  5,
                  5,
                  0,
                  "hello",
                  bytearray(b"spark\x01\x02"),
                  -128,
              ),
              (
                  False,
                  123.45,
                  0.987,
                  9,
                  908,
                  765,
                  "petastorm",
                  bytearray(b"\x0012345"),
                  127,
              ),
          ],
          schema=schema,
      ).coalesce(1)
      # If we use numPartition > 1, the order of the loaded dataset would
      # be non-deterministic.
      expected_df = df.collect()
  
      converter = make_spark_converter(df)
      with converter.make_tf_dataset() as dataset:
          iterator = dataset.make_one_shot_iterator()
          tensor = iterator.get_next()
          with tf.Session() as sess:
              ts = sess.run(tensor)
              # TODO: we will improve the test once the batch_size argument
              #  added.
              # Now we only have one batch.
          for i in range(converter.dataset_size):
              for col in df.schema.names:
                  actual_ele = getattr(ts, col)[i]
                  expected_ele = expected_df[i][col]
                  if col == "str_col":
                      actual_ele = actual_ele.decode()
                  if col == "bin_col":
                      actual_ele = bytearray(actual_ele)
                  if col == "float_col" or col == "double_col":
                      # Note that the default dtype is float32
                      assert (
                          pytest.approx(expected_ele, rel=1e-6)
                          == actual_ele
                      )
                  else:
                      assert expected_ele == actual_ele
  
          assert len(expected_df) == len(converter)
  
      assert np.bool_ == ts.bool_col.dtype.type
      assert np.float32 == ts.float_col.dtype.type
      # Default dtype float32
      assert np.float32 == ts.double_col.dtype.type
      assert np.int16 == ts.short_col.dtype.type
      assert np.int32 == ts.int_col.dtype.type
      assert np.int64 == ts.long_col.dtype.type
      assert np.object_ == ts.str_col.dtype.type
      assert np.object_ == ts.bin_col.dtype.type
  
imports: import os
  import subprocess
  import sys
  import tempfile
  import threading
  import time
  from distutils.version import LooseVersion
  import numpy
  import pyspark
  import pytest
  import py4j
  import tensorflow.compat.v1
  from pyspark.sql.functions import pandas_udf
  from pyspark.sql.types import ArrayType, BinaryType, BooleanType, ByteType, DoubleType, FloatType, IntegerType, LongType, ShortType, StringType, StructField, StructType
  from six.moves.urllib.parse import urlparse
  from petastorm import make_batch_reader
  from petastorm.fs_utils import FilesystemResolver
  from petastorm.spark import SparkDatasetConverter, make_spark_converter, spark_dataset_converter
  from petastorm.spark.spark_dataset_converter import _check_dataset_file_median_size, _check_parent_cache_dir_url, _check_rank_and_size_consistent_with_horovod, _check_url, _get_horovod_rank_and_size, _get_spark_session, _make_sub_dir_url, register_delete_dir_handler, _wait_file_available, _normalize_databricks_dbfs_url
  from unittest import mock
  from petastorm.tests.test_tf_utils import create_tf_graph
label_desc: Use image node_id 1 for calling a global function with example usage: test_primitive(spark_test_ctx) without return types