Beispiel #1
0
def test_alias__long_bigint():
    schema = StructType.fromDDL('i1: long, i2: bigint')
    assert schema == StructType([
        StructField('i1', LongType(), True),
        StructField('i2', LongType(), True),
    ])
    assert str(schema) == 'StructType(List(StructField(i1,LongType,true),StructField(i2,LongType,true)))'
Beispiel #2
0
def test_double_string():
    schema = StructType.fromDDL("a DOUBLE, b STRING")
    assert schema == StructType([
        StructField('a', DoubleType(), True),
        StructField('b', StringType(), True),
    ])
    assert str(schema) == 'StructType(List(StructField(a,DoubleType,true),StructField(b,StringType,true)))'
Beispiel #3
0
def test_byte_decimal():
    schema = StructType.fromDDL("a: byte, b: decimal(  16 , 8   ) ")
    assert schema == StructType([
        StructField('a', ByteType(), True),
        StructField('b', DecimalType(16, 8), True),
    ])
    assert str(schema) == 'StructType(List(StructField(a,ByteType,true),StructField(b,DecimalType(16,8),true)))'
Beispiel #4
0
def test_nested_array():
    schema = StructType.fromDDL('some_str: string, arr: array<array<string>>')
    assert schema == StructType([
        StructField('some_str', StringType(), True),
        StructField('arr', ArrayType(ArrayType(StringType())), True),
    ])
    assert str(schema) == 'StructType(List(' \
                          'StructField(some_str,StringType,true),' \
                          'StructField(arr,ArrayType(ArrayType(StringType,true),true),true)' \
                          '))'
Beispiel #5
0
def test_basic_entries():
    schema = StructType.fromDDL('some_str: string, some_int: integer, some_date: date')
    assert schema == StructType([
        StructField('some_str', StringType(), True),
        StructField('some_int', IntegerType(), True),
        StructField('some_date', DateType(), True),
    ])
    assert str(schema) == (
        'StructType(List('
        'StructField(some_str,StringType,true),'
        'StructField(some_int,IntegerType,true),'
        'StructField(some_date,DateType,true)'
        '))'
    )
Beispiel #6
0
def test_too_much_closed_map():
    with pytest.raises(ParseException):
        StructType.fromDDL("map<int, boolean>>")
Beispiel #7
0
def test_comma_at_end():
    with pytest.raises(ParseException):
        print(StructType.fromDDL("a: int,"))
Beispiel #8
0
def test_wrong_type():
    with pytest.raises(ParseException):
        StructType.fromDDL("blabla")
Beispiel #9
0
def test_array_short():
    schema = StructType.fromDDL("a: array< short>")
    assert schema == StructType([
        StructField('a', ArrayType(ShortType()), True),
    ])
    assert str(schema) == 'StructType(List(StructField(a,ArrayType(ShortType,true),true)))'