2626 "ShortType" , "ArrayType" , "MapType" , "StructField" , "StructType" ,
2727 "SQLContext" , "HiveContext" , "LocalHiveContext" , "TestHiveContext" , "SchemaRDD" , "Row" ]
2828
29+
2930class PrimitiveTypeSingleton (type ):
3031 _instances = {}
32+
3133 def __call__ (cls ):
3234 if cls not in cls ._instances :
3335 cls ._instances [cls ] = super (PrimitiveTypeSingleton , cls ).__call__ ()
3436 return cls ._instances [cls ]
3537
38+
3639class StringType (object ):
3740 """Spark SQL StringType
3841
@@ -44,6 +47,7 @@ class StringType(object):
4447 def __repr__ (self ):
4548 return "StringType"
4649
50+
4751class BinaryType (object ):
4852 """Spark SQL BinaryType
4953
@@ -55,6 +59,7 @@ class BinaryType(object):
5559 def __repr__ (self ):
5660 return "BinaryType"
5761
62+
5863class BooleanType (object ):
5964 """Spark SQL BooleanType
6065
@@ -66,6 +71,7 @@ class BooleanType(object):
6671 def __repr__ (self ):
6772 return "BooleanType"
6873
74+
6975class TimestampType (object ):
7076 """Spark SQL TimestampType
7177
@@ -77,6 +83,7 @@ class TimestampType(object):
7783 def __repr__ (self ):
7884 return "TimestampType"
7985
86+
8087class DecimalType (object ):
8188 """Spark SQL DecimalType
8289
@@ -88,6 +95,7 @@ class DecimalType(object):
8895 def __repr__ (self ):
8996 return "DecimalType"
9097
98+
9199class DoubleType (object ):
92100 """Spark SQL DoubleType
93101
@@ -99,13 +107,15 @@ class DoubleType(object):
99107 def __repr__ (self ):
100108 return "DoubleType"
101109
110+
102111class FloatType (object ):
103112 """Spark SQL FloatType
104113
105114 For now, please use L{DoubleType} instead of using L{FloatType}.
106115 Because query evaluation is done in Scala, java.lang.Double will be be used
107116 for Python float numbers. Because the underlying JVM type of FloatType is
108- java.lang.Float (in Java) and Float (in scala), there will be a java.lang.ClassCastException
117+ java.lang.Float (in Java) and Float (in scala), and we are trying to cast the type,
118+ there will be a java.lang.ClassCastException
109119 if FloatType (Python) is used.
110120
111121 """
@@ -114,13 +124,15 @@ class FloatType(object):
114124 def __repr__ (self ):
115125 return "FloatType"
116126
127+
117128class ByteType (object ):
118129 """Spark SQL ByteType
119130
120131 For now, please use L{IntegerType} instead of using L{ByteType}.
121132 Because query evaluation is done in Scala, java.lang.Integer will be be used
122133 for Python int numbers. Because the underlying JVM type of ByteType is
123- java.lang.Byte (in Java) and Byte (in scala), there will be a java.lang.ClassCastException
134+ java.lang.Byte (in Java) and Byte (in scala), and we are trying to cast the type,
135+ there will be a java.lang.ClassCastException
124136 if ByteType (Python) is used.
125137
126138 """
@@ -129,6 +141,7 @@ class ByteType(object):
129141 def __repr__ (self ):
130142 return "ByteType"
131143
144+
132145class IntegerType (object ):
133146 """Spark SQL IntegerType
134147
@@ -140,6 +153,7 @@ class IntegerType(object):
140153 def __repr__ (self ):
141154 return "IntegerType"
142155
156+
143157class LongType (object ):
144158 """Spark SQL LongType
145159
@@ -152,13 +166,15 @@ class LongType(object):
152166 def __repr__ (self ):
153167 return "LongType"
154168
169+
155170class ShortType (object ):
156171 """Spark SQL ShortType
157172
158173 For now, please use L{IntegerType} instead of using L{ShortType}.
159174 Because query evaluation is done in Scala, java.lang.Integer will be be used
160175 for Python int numbers. Because the underlying JVM type of ShortType is
161- java.lang.Short (in Java) and Short (in scala), there will be a java.lang.ClassCastException
176+ java.lang.Short (in Java) and Short (in scala), and we are trying to cast the type,
177+ there will be a java.lang.ClassCastException
162178 if ShortType (Python) is used.
163179
164180 """
@@ -167,6 +183,7 @@ class ShortType(object):
167183 def __repr__ (self ):
168184 return "ShortType"
169185
186+
170187class ArrayType (object ):
171188 """Spark SQL ArrayType
172189
@@ -196,9 +213,9 @@ def __repr__(self):
196213 str (self .containsNull ).lower () + ")"
197214
198215 def __eq__ (self , other ):
199- return (isinstance (other , self .__class__ ) and \
200- self .elementType == other .elementType and \
201- self .containsNull == other .containsNull )
216+ return (isinstance (other , self .__class__ ) and
217+ self .elementType == other .elementType and
218+ self .containsNull == other .containsNull )
202219
203220 def __ne__ (self , other ):
204221 return not self .__eq__ (other )
@@ -238,14 +255,15 @@ def __repr__(self):
238255 str (self .valueContainsNull ).lower () + ")"
239256
240257 def __eq__ (self , other ):
241- return (isinstance (other , self .__class__ ) and \
242- self .keyType == other .keyType and \
243- self .valueType == other .valueType and \
244- self .valueContainsNull == other .valueContainsNull )
258+ return (isinstance (other , self .__class__ ) and
259+ self .keyType == other .keyType and
260+ self .valueType == other .valueType and
261+ self .valueContainsNull == other .valueContainsNull )
245262
246263 def __ne__ (self , other ):
247264 return not self .__eq__ (other )
248265
266+
249267class StructField (object ):
250268 """Spark SQL StructField
251269
@@ -278,14 +296,15 @@ def __repr__(self):
278296 str (self .nullable ).lower () + ")"
279297
280298 def __eq__ (self , other ):
281- return (isinstance (other , self .__class__ ) and \
282- self .name == other .name and \
283- self .dataType == other .dataType and \
284- self .nullable == other .nullable )
299+ return (isinstance (other , self .__class__ ) and
300+ self .name == other .name and
301+ self .dataType == other .dataType and
302+ self .nullable == other .nullable )
285303
286304 def __ne__ (self , other ):
287305 return not self .__eq__ (other )
288306
307+
289308class StructType (object ):
290309 """Spark SQL StructType
291310
@@ -315,12 +334,13 @@ def __repr__(self):
315334 "," .join ([field .__repr__ () for field in self .fields ]) + "))"
316335
317336 def __eq__ (self , other ):
318- return (isinstance (other , self .__class__ ) and \
319- self .fields == other .fields )
337+ return (isinstance (other , self .__class__ ) and
338+ self .fields == other .fields )
320339
321340 def __ne__ (self , other ):
322341 return not self .__eq__ (other )
323342
343+
324344def _parse_datatype_list (datatype_list_string ):
325345 """Parses a list of comma separated data types.
326346
@@ -348,6 +368,7 @@ def _parse_datatype_list(datatype_list_string):
348368 datatype_list .append (_parse_datatype_string (datatype_string ))
349369 return datatype_list
350370
371+
351372def _parse_datatype_string (datatype_string ):
352373 """Parses the given data type string.
353374
@@ -472,6 +493,7 @@ def _parse_datatype_string(datatype_string):
472493 fields = _parse_datatype_list (field_list_string )
473494 return StructType (fields )
474495
496+
475497class SQLContext :
476498 """Main entry point for SparkSQL functionality.
477499
0 commit comments