Example #1
0
 def test_cast_map_to_string(self):
     self.assertEqual(
         cast_to_string(
             {
                 True:
                 collections.OrderedDict([("one", 1), ("nothing", None),
                                          ("three", 3)])
             },
             MapType(BooleanType(), MapType(StringType(), IntegerType())),
             options=BASE_OPTIONS),
         "[true -> [one -> 1, nothing ->, three -> 3]]")
Example #2
0
 def test_cast_row_to_string(self):
     self.assertEqual(
         cast_to_string(Row(a=collections.OrderedDict([("value", None),
                                                       ("b", {
                                                           "c": 7
                                                       })]),
                            b=None,
                            c=True,
                            d=5.2),
                        StructType([
                            StructField(
                                "a",
                                MapType(
                                    StringType(),
                                    MapType(StringType(), LongType(), True),
                                    True), True),
                            StructField("b", LongType(), True),
                            StructField("c", BooleanType(), True),
                            StructField("d", DoubleType(), True)
                        ]),
                        options=BASE_OPTIONS),
         "[[value ->, b -> [c -> 7]],, true, 5.2]")
Example #3
0
 def test_cast_array_to_string(self):
     self.assertEqual(
         cast_to_string([[[1, None, 2], []]],
                        ArrayType(ArrayType(ArrayType(IntegerType()))),
                        options=BASE_OPTIONS), "[[[1,, 2], []]]")
Example #4
0
 def test_cast_timestamp_to_string(self):
     self.assertEqual(
         cast_to_string(datetime.datetime(2019, 8, 28, 13, 5, 0),
                        TimestampType(),
                        options=BASE_OPTIONS), "2019-08-28 13:05:00")
Example #5
0
 def test_cast_date_to_string(self):
     self.assertEqual(
         cast_to_string(datetime.date(2019, 8, 28),
                        DateType(),
                        options=BASE_OPTIONS), "2019-08-28")
Example #6
0
 def test_cast_null_to_string(self):
     self.assertEqual(
         cast_to_string(None, NullType(), options=BASE_OPTIONS), "null")