Skip to content

Commit 1425359

Browse files
author
Davies Liu
committed
DecimalType should not be singleton
1 parent f7fe9e4 commit 1425359

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

python/pyspark/sql/tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ def test_data_type_eq(self):
100100
lt2 = pickle.loads(pickle.dumps(LongType()))
101101
self.assertEquals(lt, lt2)
102102

103+
# regression test for SPARK-
104+
def test_decimal_type(self):
105+
t1 = DecimalType()
106+
t2 = DecimalType(10, 2)
107+
self.assertTrue(t2 is not t1)
108+
self.assertNotEqual(t1, t2)
109+
t3 = DecimalType(8)
110+
self.assertNotEqual(t2, t3)
111+
103112

104113
class SQLTests(ReusedPySparkTestCase):
105114

python/pyspark/sql/types.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ class AtomicType(DataType):
9797
"""An internal type used to represent everything that is not
9898
null, UDTs, arrays, structs, and maps."""
9999

100-
__metaclass__ = DataTypeSingleton
101-
102100

103101
class NumericType(AtomicType):
104102
"""Numeric data types.
@@ -109,6 +107,8 @@ class IntegralType(NumericType):
109107
"""Integral data types.
110108
"""
111109

110+
__metaclass__ = DataTypeSingleton
111+
112112

113113
class FractionalType(NumericType):
114114
"""Fractional data types.
@@ -119,26 +119,36 @@ class StringType(AtomicType):
119119
"""String data type.
120120
"""
121121

122+
__metaclass__ = DataTypeSingleton
123+
122124

123125
class BinaryType(AtomicType):
124126
"""Binary (byte array) data type.
125127
"""
126128

129+
__metaclass__ = DataTypeSingleton
130+
127131

128132
class BooleanType(AtomicType):
129133
"""Boolean data type.
130134
"""
131135

136+
__metaclass__ = DataTypeSingleton
137+
132138

133139
class DateType(AtomicType):
134140
"""Date (datetime.date) data type.
135141
"""
136142

143+
__metaclass__ = DataTypeSingleton
144+
137145

138146
class TimestampType(AtomicType):
139147
"""Timestamp (datetime.datetime) data type.
140148
"""
141149

150+
__metaclass__ = DataTypeSingleton
151+
142152

143153
class DecimalType(FractionalType):
144154
"""Decimal (decimal.Decimal) data type.
@@ -172,11 +182,15 @@ class DoubleType(FractionalType):
172182
"""Double data type, representing double precision floats.
173183
"""
174184

185+
__metaclass__ = DataTypeSingleton
186+
175187

176188
class FloatType(FractionalType):
177189
"""Float data type, representing single precision floats.
178190
"""
179191

192+
__metaclass__ = DataTypeSingleton
193+
180194

181195
class ByteType(IntegralType):
182196
"""Byte data type, i.e. a signed integer in a single byte.

0 commit comments

Comments
 (0)