Exemplo n.º 1
0
class TestToFixedString(unittest.TestCase):

    @parameterized.expand([
        (
            ToFixedString(Field('field_name'), 100),
            'toFixedString("field_name",100)',
        ),
        (
            ToFixedString('100', 100),
            "toFixedString('100',100)",
        ),
    ])
    def test_get_sql(self, func, expected):
        self.assertEqual(func.get_sql(), expected)
Exemplo n.º 2
0
    def test_get_sql_with_table(self):
        table = Table('example')
        query = ClickHouseQuery.from_(table).select(table.name, ).where(
            table.name == ToFixedString('name', 50), )

        self.assertEqual(
            'SELECT "name" FROM "example" WHERE "name"=toFixedString(\'name\',50)',
            query.get_sql())
Exemplo n.º 3
0
class TestIfCondition(unittest.TestCase):

    @parameterized.expand([
        (
            If(Field('filmmaker').isnull(), ToFixedString('Tarantino', 20), Field('filmmaker')),
            'if(filmmaker IS NULL,toFixedString(\'Tarantino\',20),filmmaker)'
        ),
        (
            If(
                Field('created') == Field('updated'),
                ToFixedString('yes', 3),
                ToFixedString('no', 3)
            ),
            'if(created=updated,toFixedString(\'yes\',3),toFixedString(\'no\',3))'
        ),
    ])
    def test_get_sql(self, func, expected):
        self.assertEqual(func.get_sql(), expected)
Exemplo n.º 4
0
class TestSearchString(unittest.TestCase):
    @parameterized.expand([(
        IfNull(Field('name'), Field('login')),
        'ifNull(name,login)',
    ),
                           (
                               IfNull(Field('builder'),
                                      ToFixedString('pypika', 100)),
                               "ifNull(builder,toFixedString('pypika',100))",
                           )])
    def test_get_sql(self, func, expected):
        self.assertEqual(func.get_sql(), expected)
Exemplo n.º 5
0
class TestIfCondition(unittest.TestCase):
    @parameterized.expand([
        (
            If(
                Field("filmmaker").isnull(),
                ToFixedString("Tarantino", 20),
                Field("filmmaker"),
            ),
            "if(filmmaker IS NULL,toFixedString('Tarantino',20),filmmaker)",
        ),
        (
            If(
                Field("created") == Field("updated"),
                ToFixedString("yes", 3),
                ToFixedString("no", 3),
            ),
            "if(created=updated,toFixedString('yes',3),toFixedString('no',3))",
        ),
    ])
    def test_get_sql(self, func, expected):
        self.assertEqual(func.get_sql(), expected)
Exemplo n.º 6
0
class TestSearchString(unittest.TestCase):
    @parameterized.expand([
        (
            IfNull(Field("name"), Field("login")),
            "ifNull(name,login)",
        ),
        (
            IfNull(Field("builder"), ToFixedString("pypika", 100)),
            "ifNull(builder,toFixedString('pypika',100))",
        ),
    ])
    def test_get_sql(self, func, expected):
        self.assertEqual(func.get_sql(), expected)
Exemplo n.º 7
0
class TestMultiIfCondition(unittest.TestCase):
    @parameterized.expand(
        [
            (
                MultiIf(
                    Field("filmmaker").isnull(),
                    ToFixedString("Tarantino", 20),
                    Field("filmmaker") == ToFixedString("undefined", 20),
                    ToFixedString("Tarantino", 20),
                    Field("filmmaker"),
                ),
                "multiIf(filmmaker IS NULL,"
                "toFixedString('Tarantino',20),"
                "filmmaker=toFixedString('undefined',20),"
                "toFixedString('Tarantino',20),filmmaker)",
            ),
            (
                MultiIf(
                    Field("color") == ToFixedString("black", 20),
                    ToFixedString("dark", 20),
                    Field("color") == ToFixedString("grey", 20),
                    ToFixedString("dark", 20),
                    Field("color") == ToFixedString("white", 20),
                    ToFixedString("light", 20),
                    ToFixedString("undefined", 20),
                ),
                "multiIf(color=toFixedString('black',20),"
                "toFixedString('dark',20),"
                "color=toFixedString('grey',20),"
                "toFixedString('dark',20),"
                "color=toFixedString('white',20),"
                "toFixedString('light',20),"
                "toFixedString('undefined',20))",
            ),
        ]
    )
    def test_get_sql(self, func, expected):
        self.assertEqual(func.get_sql(), expected)
Exemplo n.º 8
0
class TestMultiIfCondition(unittest.TestCase):

    @parameterized.expand([
        (
            MultiIf(
                Field('filmmaker').isnull(),
                ToFixedString('Tarantino', 20),
                Field('filmmaker') == ToFixedString('undefined', 20),
                ToFixedString('Tarantino', 20),
                Field('filmmaker')
            ),
            'multiIf(filmmaker IS NULL,'
            'toFixedString(\'Tarantino\',20),'
            'filmmaker=toFixedString(\'undefined\',20),'
            'toFixedString(\'Tarantino\',20),filmmaker)'
        ),
        (
            MultiIf(
                Field('color') == ToFixedString('black', 20),
                ToFixedString('dark', 20),
                Field('color') == ToFixedString('grey', 20),
                ToFixedString('dark', 20),
                Field('color') == ToFixedString('white', 20),
                ToFixedString('light', 20),
                ToFixedString('undefined', 20)
            ),
            'multiIf(color=toFixedString(\'black\',20),'
            'toFixedString(\'dark\',20),'
            'color=toFixedString(\'grey\',20),'
            'toFixedString(\'dark\',20),'
            'color=toFixedString(\'white\',20),'
            'toFixedString(\'light\',20),'
            'toFixedString(\'undefined\',20))'
        ),
    ])
    def test_get_sql(self, func, expected):
        self.assertEqual(func.get_sql(), expected)
Exemplo n.º 9
0
class TestBasicTypeConverters(unittest.TestCase):
    @parameterized.expand([
        (
            'toString("field_name")',
            ToString(Field("field_name")),
        ),
        (
            'toInt8("field_name")',
            ToInt8(Field("field_name")),
        ),
        (
            'toInt16("field_name")',
            ToInt16(Field("field_name")),
        ),
        (
            'toInt32("field_name")',
            ToInt32(Field("field_name")),
        ),
        (
            'toInt64("field_name")',
            ToInt64(Field("field_name")),
        ),
        (
            'toUInt8("field_name")',
            ToUInt8(Field("field_name")),
        ),
        (
            'toUInt16("field_name")',
            ToUInt16(Field("field_name")),
        ),
        (
            'toUInt32("field_name")',
            ToUInt32(Field("field_name")),
        ),
        (
            'toUInt64("field_name")',
            ToUInt64(Field("field_name")),
        ),
        (
            'toFloat32("field_name")',
            ToFloat32(Field("field_name")),
        ),
        (
            'toFloat64("field_name")',
            ToFloat64(Field("field_name")),
        ),
        (
            'toFloat64("field_name")',
            ToFloat64(Field("field_name")),
        ),
        (
            'toDate("field_name")',
            ToDate(Field("field_name")),
        ),
        (
            'toDateTime("field_name")',
            ToDateTime(Field("field_name")),
        ),
        (
            'toFixedString("field_name",100)',
            ToFixedString(Field("field_name"), 100),
        ),
    ])
    def test_basic_types_field(self, expected, func):
        self.assertEqual(func, expected)

    @parameterized.expand([
        (
            "toString('100')",
            ToString("100"),
        ),
        (
            "toInt8('100')",
            ToInt8("100"),
        ),
        (
            "toInt16('100')",
            ToInt16("100"),
        ),
        (
            "toInt32('100')",
            ToInt32("100"),
        ),
        (
            "toInt64('100')",
            ToInt64("100"),
        ),
        (
            "toUInt8('100')",
            ToUInt8("100"),
        ),
        (
            "toUInt16('100')",
            ToUInt16("100"),
        ),
        (
            "toUInt32('100')",
            ToUInt32("100"),
        ),
        (
            "toUInt64('100')",
            ToUInt64("100"),
        ),
        (
            "toFloat32('100')",
            ToFloat32("100"),
        ),
        (
            "toFloat64('100')",
            ToFloat64("100"),
        ),
        (
            "toFloat64('100')",
            ToFloat64("100"),
        ),
        (
            "toDate('100')",
            ToDate("100"),
        ),
        (
            "toDateTime('100')",
            ToDateTime("100"),
        ),
        (
            "toFixedString('100',100)",
            ToFixedString("100", 100),
        ),
    ])
    def test_basic_types_value(self, expected, func):
        self.assertEqual(func, expected)
Exemplo n.º 10
0
 def test_to_fixed_string_value(self):
     self.assertEqual(
         ToFixedString('100', 100).get_sql(),
         "toFixedString('100',100)"
     )
Exemplo n.º 11
0
 def test_to_fixed_string_field(self):
     self.assertEqual(
         ToFixedString(Field('field_name'), 100).get_sql(),
         'toFixedString("field_name",100)'
     )