Beispiel #1
0
 def test_it_throws_for_unconvertable_matches(self):
     with pytest.raises(ValueError):
         convert_to_col_type(
             "mystr", "test_col", {
                 "StorageDescriptor": {
                     "Columns": [{
                         "Name": "test_col",
                         "Type": "int"
                     }]
                 }
             })
Beispiel #2
0
 def test_it_throws_for_unknown_col(self):
     with pytest.raises(ValueError):
         convert_to_col_type(
             "mystr", "doesnt_exist", {
                 "StorageDescriptor": {
                     "Columns": [{
                         "Name": "test_col",
                         "Type": "string"
                     }]
                 }
             })
Beispiel #3
0
 def test_it_throws_for_unsupported_col_types(self):
     with pytest.raises(ValueError):
         convert_to_col_type(
             "mystr", "test_col", {
                 "StorageDescriptor": {
                     "Columns": [{
                         "Name": "test_col",
                         "Type": "map"
                     }]
                 }
             })
 def test_it_throws_for_unsupported_col_types(self):
     with pytest.raises(ValueError) as e:
         convert_to_col_type(
             "2.56",
             "test_col",
             {
                 "StorageDescriptor": {
                     "Columns": [{
                         "Name": "test_col",
                         "Type": "decimal"
                     }]
                 }
             },
         )
     assert (e.value.args[0] ==
             "Column test_col is not a supported column type for querying")
 def test_it_converts_supported_types_when_nested_in_struct(self):
     column_type = "struct<type:int,x:map<string,struct<a:int>>,info:struct<user_id:int,name:string>>"
     table = {
         "StorageDescriptor": {
             "Columns": [{
                 "Name": "user",
                 "Type": column_type
             }]
         }
     }
     for scenario in [
         {
             "value": "john_doe",
             "id": "user.info.name",
             "expected": "john_doe"
         },
         {
             "value": "1234567890",
             "id": "user.info.user_id",
             "expected": 1234567890
         },
         {
             "value": "1",
             "id": "user.type",
             "expected": 1
         },
     ]:
         res = convert_to_col_type(scenario["value"], scenario["id"], table)
         assert res == scenario["expected"]
Beispiel #6
0
 def test_it_converts_bigints(self):
     res = convert_to_col_type(
         "1572438253", "test_col", {
             "StorageDescriptor": {
                 "Columns": [{
                     "Name": "test_col",
                     "Type": "bigint"
                 }]
             }
         })
     assert 1572438253 == res
Beispiel #7
0
 def test_it_converts_ints(self):
     res = convert_to_col_type(
         "2", "test_col", {
             "StorageDescriptor": {
                 "Columns": [{
                     "Name": "test_col",
                     "Type": "int"
                 }]
             }
         })
     assert 2 == res
Beispiel #8
0
 def test_it_converts_varchar(self):
     res = convert_to_col_type(
         "mystr", "test_col", {
             "StorageDescriptor": {
                 "Columns": [{
                     "Name": "test_col",
                     "Type": "varchar"
                 }]
             }
         })
     assert "mystr" == res
 def test_it_throws_for_unsupported_complex_nested_types(self):
     for scenario in [
             "array<x:int>",
             "array<struct<x:int>>",
             "struct<a:array<struct<a:int,x:int>>>",
             "array<struct<a:int,b:struct<x:int>>>",
             "struct<a:map<string,struct<x:int>>>",
             "map<string,struct<x:int>>",
     ]:
         with pytest.raises(ValueError):
             convert_to_col_type(
                 123,
                 "user.x",
                 {
                     "StorageDescriptor": {
                         "Columns": [{
                             "Name": "user",
                             "Type": scenario
                         }]
                     }
                 },
             )
    def test_it_converts_supported_types(self):
        for scenario in [
            {
                "value": "m",
                "type": "char",
                "expected": "m"
            },
            {
                "value": "mystr",
                "type": "string",
                "expected": "mystr"
            },
            {
                "value": "mystr",
                "type": "varchar",
                "expected": "mystr"
            },
            {
                "value": "2",
                "type": "bigint",
                "expected": 2
            },
            {
                "value": "2",
                "type": "int",
                "expected": 2
            },
            {
                "value": "2",
                "type": "smallint",
                "expected": 2
            },
            {
                "value": "2",
                "type": "tinyint",
                "expected": 2
            },
            {
                "value": "2.23",
                "type": "double",
                "expected": 2.23
            },
            {
                "value": "2.23",
                "type": "float",
                "expected": 2.23
            },
        ]:
            res = convert_to_col_type(
                scenario["value"],
                "test_col",
                {
                    "StorageDescriptor": {
                        "Columns": [{
                            "Name": "test_col",
                            "Type": scenario["type"]
                        }]
                    }
                },
            )

            assert res == scenario["expected"]