Exemplo n.º 1
0
    def test__function_between(self):
        c1 = fn.Coalesce(Field('foo'), 0)[0:1]
        c2 = fn.Coalesce(Field('foo', table=self.t), 0)[0:1]

        self.assertEqual('COALESCE("foo",0) BETWEEN 0 AND 1', str(c1))
        self.assertEqual('COALESCE("btw"."foo",0) BETWEEN 0 AND 1', str(c2))
Exemplo n.º 2
0
    def test__mixed_case_is_not_aggregate(self):
        v = Case() \
            .when(Field('foo') == 1, fn.Sum(Field('bar'))) \
            .when(Field('foo') == 2, Field('fiz'))

        self.assertFalse(v.is_aggregate)
Exemplo n.º 3
0
    def test_to_char(self):
        db = Database()

        to_char = db.to_char(Field('field'))
        self.assertEqual(str(to_char), 'CAST("field" AS VARCHAR)')
Exemplo n.º 4
0
 def test__negative_agg_func_is_aggregate(self):
     v = Negative(fn.Sum(Field('foo')))
     self.assertTrue(v.is_aggregate)
Exemplo n.º 5
0
 def test__mixed_func_arithmetic_is_not_aggregate(self):
     v = Field('foo') / fn.Sum(Field('foo'))
     self.assertFalse(v.is_aggregate)
Exemplo n.º 6
0
    def test_trunc_quarter(self):
        result = SnowflakeDatabase().trunc_date(Field('date'), 'quarter')

        self.assertEqual('TRUNC("date",\'Q\')', str(result))
Exemplo n.º 7
0
 def test__field_arithmetic_is_not_aggregate(self):
     v = Field('foo') + Field('bar')
     self.assertFalse(v.is_aggregate)
Exemplo n.º 8
0
    def test__criterion_eq_str(self):
        c1 = Field('foo') == 'abc'
        c2 = Field('foo', table=self.t).eq('abc')

        self.assertEqual('"foo"=\'abc\'', str(c1))
        self.assertEqual('"crit"."foo"=\'abc\'', str(c2))
Exemplo n.º 9
0
    def test__nested__or(self):
        c = (Field('foo') == 1) | (Field('bar') == 2) | (Field('buz') == 3)

        self.assertEqual('"foo"=1 OR "bar"=2 OR "buz"=3', str(c))
Exemplo n.º 10
0
    def test__function_notin(self):
        c1 = fn.Coalesce(Field('foo'), 0).notin([0, 1])
        c2 = fn.Coalesce(Field('foo', table=self.t), 0).notin([0, 1])

        self.assertEqual('COALESCE("foo",0) NOT IN (0,1)', str(c1))
        self.assertEqual('COALESCE("notin"."foo",0) NOT IN (0,1)', str(c2))
Exemplo n.º 11
0
    def test__nested__and(self):
        c = (Field('foo') == 1) & (Field('bar') == 2) & (Field('buz') == 3)

        self.assertEqual('"foo"=1 AND "bar"=2 AND "buz"=3', str(c))
Exemplo n.º 12
0
    def test__notin_character(self):
        c1 = Field('foo').notin(['a', 'b'])
        c2 = Field('foo', table=self.t).notin(['a', 'b'])

        self.assertEqual('"foo" NOT IN (\'a\',\'b\')', str(c1))
        self.assertEqual('"notin"."foo" NOT IN (\'a\',\'b\')', str(c2))
Exemplo n.º 13
0
    def test__notin_number(self):
        c1 = Field('foo').notin([0, 1])
        c2 = Field('foo', table=self.t).notin([0, 1])

        self.assertEqual('"foo" NOT IN (0,1)', str(c1))
        self.assertEqual('"notin"."foo" NOT IN (0,1)', str(c2))
Exemplo n.º 14
0
    def test__in_unicode(self):
        c1 = Field('foo').isin([u'a', u'b'])
        c2 = Field('foo', table=self.t).isin([u'a', u'b'])

        self.assertEqual('"foo" IN (\'a\',\'b\')', str(c1))
        self.assertEqual('"isin"."foo" IN (\'a\',\'b\')', str(c2))
Exemplo n.º 15
0
    def test_date_add_year(self):
        result = SnowflakeDatabase().date_add(Field('date'), 'year', 1)

        self.assertEqual('TIMESTAMPADD(\'year\',1,"date")', str(result))
Exemplo n.º 16
0
    def test__nested__mixed(self):
        c = ((Field('foo') == 1) & (Field('bar') == 2)) | (Field('buz') == 3)

        self.assertEqual('("foo"=1 AND "bar"=2) OR "buz"=3', str(c))
Exemplo n.º 17
0
    def test_trunc_week(self):
        result = SnowflakeDatabase().trunc_date(Field('date'), 'week')

        self.assertEqual('TRUNC("date",\'IW\')', str(result))
Exemplo n.º 18
0
    def test__between_and_isin(self):
        c = Field('foo').isin([1, 2, 3]) & Field('bar').between(0, 1)

        self.assertEqual('"foo" IN (1,2,3) AND "bar" BETWEEN 0 AND 1', str(c))
Exemplo n.º 19
0
 def test__field_is_not_aggregate(self):
     v = Field('foo')
     self.assertFalse(v.is_aggregate)
Exemplo n.º 20
0
    def test__criterion_eq_datetime(self):
        c1 = Field('foo') == datetime(2000, 1, 1, 12, 30, 55)
        c2 = Field('foo', table=self.t).eq(datetime(2000, 1, 1, 12, 30, 55))

        self.assertEqual('"foo"=\'2000-01-01T12:30:55\'', str(c1))
        self.assertEqual('"crit"."foo"=\'2000-01-01T12:30:55\'', str(c2))
Exemplo n.º 21
0
 def test__field_arithmetic_constant_is_not_aggregate(self):
     v = Field('foo') + 1
     self.assertFalse(v.is_aggregate)
Exemplo n.º 22
0
    def test__criterion_eq_right(self):
        c1 = 1 == Field('foo')
        c2 = -1 == Field('foo', table=self.t)

        self.assertEqual('"foo"=1', str(c1))
        self.assertEqual('"crit"."foo"=-1', str(c2))
Exemplo n.º 23
0
 def test__agg_func_arithmetic_is_aggregate(self):
     v = fn.Sum(Field('foo')) / fn.Sum(Field('foo'))
     self.assertTrue(v.is_aggregate)
Exemplo n.º 24
0
    def test__criterion_is_null(self):
        c1 = Field('foo').isnull()
        c2 = Field('foo', table=self.t).isnull()

        self.assertEqual('"foo" IS NULL', str(c1))
        self.assertEqual('"crit"."foo" IS NULL', str(c2))
Exemplo n.º 25
0
 def test__func_arithmetic_constant_is_not_aggregate(self):
     v = 1 / fn.Sum(Field('foo'))
     self.assertTrue(v.is_aggregate)
Exemplo n.º 26
0
    def test__criterion_ne_str(self):
        c1 = Field('foo') != 'abc'
        c2 = Field('foo', table=self.t).ne('abc')

        self.assertEqual('"foo"<>\'abc\'', str(c1))
        self.assertEqual('"crit"."foo"<>\'abc\'', str(c2))
Exemplo n.º 27
0
    def test_use_different_table_objects_for_same_table(self):
        table = Table("t")
        q = Query.from_(table).select('*').where(Field('id', table=table) == 1)

        self.assertEqual('SELECT * FROM "t" WHERE "id"=1', str(q))
Exemplo n.º 28
0
    def test__criterion_ne_date(self):
        c1 = Field('foo') != date(2000, 1, 1)
        c2 = Field('foo', table=self.t).ne(date(2000, 1, 1))

        self.assertEqual('"foo"<>\'2000-01-01\'', str(c1))
        self.assertEqual('"crit"."foo"<>\'2000-01-01\'', str(c2))
Exemplo n.º 29
0
 def test_to_fixed_string_field(self):
     self.assertEqual(
         ToFixedString(Field('field_name'), 100).get_sql(),
         'toFixedString("field_name",100)'
     )
Exemplo n.º 30
0
    def test__criterion_eq_decimal(self):
        c1 = Field('foo') == 1.0
        c2 = Field('foo', table=self.t).eq(0.5)

        self.assertEqual('"foo"=1.0', str(c1))
        self.assertEqual('"crit"."foo"=0.5', str(c2))