diff --git a/python/pyspark/sql/tests.py b/python/pyspark/sql/tests.py index b93b7ed192104..d6a9d68092981 100644 --- a/python/pyspark/sql/tests.py +++ b/python/pyspark/sql/tests.py @@ -188,6 +188,10 @@ def test_empty_row(self): row = Row() self.assertEqual(len(row), 0) + def test_struct_field_type_name(self): + struct_field = StructField("a", IntegerType()) + self.assertRaises(TypeError, struct_field.typeName) + class SQLTests(ReusedPySparkTestCase): diff --git a/python/pyspark/sql/types.py b/python/pyspark/sql/types.py index 26b54a7fb3709..d9206dd14ca2d 100644 --- a/python/pyspark/sql/types.py +++ b/python/pyspark/sql/types.py @@ -438,6 +438,11 @@ def toInternal(self, obj): def fromInternal(self, obj): return self.dataType.fromInternal(obj) + def typeName(self): + raise TypeError( + "StructField does not have typeName. " + "Use typeName on its type explicitly instead.") + class StructType(DataType): """Struct type, consisting of a list of :class:`StructField`.