def test_functions_using_constructor_param_nested(self): """ We don't show aliases of fields that are arguments of a function. """ q = Query.from_(self.t).select(fn.Sqrt(fn.Count("*", alias="foo"), alias="bar")) self.assertEqual('SELECT SQRT(COUNT(*)) "bar" FROM "abc"', str(q))
def test_complicated(self): t = Table("abc") is_placebo = t.campaign_extra_info == "placebo" pixel_mobile_search = Case().when( is_placebo, t.action_fb_pixel_search + t.action_fb_mobile_search) unique_impressions = Case().when(is_placebo, t.unique_impressions) v = fn.Sum(pixel_mobile_search) / fn.Sum( unique_impressions) - 1.96 * fn.Sqrt( 1 / fn.Sum(unique_impressions) * fn.Sum(pixel_mobile_search) / fn.Sum(unique_impressions) * (1 - fn.Sum(pixel_mobile_search) / fn.Sum(unique_impressions))) self.assertTrue(v.is_aggregate)
def test_functions_using_constructor_param_nested(self): q = Query.from_(self.t).select( fn.Sqrt(fn.Count("*", alias="foo"), alias="bar")) self.assertEqual('SELECT SQRT(COUNT(*) "foo") "bar" FROM "abc"', str(q))
def test_function_using_as_nested(self): q = Query.from_(self.t).select( fn.Sqrt(fn.Count("*").as_("foo")).as_("bar")) self.assertEqual('SELECT SQRT(COUNT(*) "foo") "bar" FROM "abc"', str(q))
def test__non_aggregate_function_with_aggregated_arg(self): t = Table('abc') expr = fn.Sqrt(fn.Sum(t.a)) self.assertTrue(expr.is_aggregate)