@@ -677,7 +677,7 @@ def _infer_schema_type(obj, dataType):
677
677
DoubleType : (float ,),
678
678
DecimalType : (decimal .Decimal ,),
679
679
StringType : (str , unicode ),
680
- TimestampType : (datetime .datetime , datetime . time , datetime . date ),
680
+ TimestampType : (datetime .datetime ,),
681
681
ArrayType : (list , tuple , array ),
682
682
MapType : (dict ,),
683
683
StructType : (tuple , list ),
@@ -1042,12 +1042,15 @@ def applySchema(self, rdd, schema):
1042
1042
[Row(field1=1, field2=u'row1'),..., Row(field1=3, field2=u'row3')]
1043
1043
1044
1044
>>> from datetime import datetime
1045
- >>> rdd = sc.parallelize([(127, -32768, 1.0,
1045
+ >>> rdd = sc.parallelize([(127, -128L, - 32768, 32767, 2147483647L , 1.0,
1046
1046
... datetime(2010, 1, 1, 1, 1, 1),
1047
1047
... {"a": 1}, (2,), [1, 2, 3], None)])
1048
1048
>>> schema = StructType([
1049
- ... StructField("byte", ByteType(), False),
1050
- ... StructField("short", ShortType(), False),
1049
+ ... StructField("byte1", ByteType(), False),
1050
+ ... StructField("byte2", ByteType(), False),
1051
+ ... StructField("short1", ShortType(), False),
1052
+ ... StructField("short2", ShortType(), False),
1053
+ ... StructField("int", IntegerType(), False),
1051
1054
... StructField("float", FloatType(), False),
1052
1055
... StructField("time", TimestampType(), False),
1053
1056
... StructField("map",
@@ -1056,11 +1059,19 @@ def applySchema(self, rdd, schema):
1056
1059
... StructType([StructField("b", ShortType(), False)]), False),
1057
1060
... StructField("list", ArrayType(ByteType(), False), False),
1058
1061
... StructField("null", DoubleType(), True)])
1059
- >>> srdd = sqlCtx.applySchema(rdd, schema).map(
1060
- ... lambda x: (x.byte, x.short, x.float, x.time,
1062
+ >>> srdd = sqlCtx.applySchema(rdd, schema)
1063
+ >>> results = srdd.map(
1064
+ ... lambda x: (x.byte1, x.byte2, x.short1, x.short2, x.int, x.float, x.time,
1061
1065
... x.map["a"], x.struct.b, x.list, x.null))
1062
- >>> srdd.collect()[0]
1063
- (127, -32768, 1.0, ...(2010, 1, 1, 1, 1, 1), 1, 2, [1, 2, 3], None)
1066
+ >>> results.collect()[0]
1067
+ (127, -128, -32768, 32767, 2147483647, 1.0, ...(2010, 1, 1, 1, 1, 1), 1, 2, [1, 2, 3], None)
1068
+
1069
+ >>> srdd.registerTempTable("table2")
1070
+ >>> sqlCtx.sql(
1071
+ ... "SELECT byte1 - 1 AS byte1, byte2 + 1 AS byte2, " +
1072
+ ... "short1 + 1 AS short1, short2 - 1 AS short2, int - 1 AS int, " +
1073
+ ... "float + 1.1 as float FROM table2").collect()
1074
+ [Row(byte1=126, byte2=-127, short1=-32767, short2=32766, int=2147483646, float=2.1)]
1064
1075
1065
1076
>>> rdd = sc.parallelize([(127, -32768, 1.0,
1066
1077
... datetime(2010, 1, 1, 1, 1, 1),
0 commit comments