Repository: kayak/pypika
Pull request #449 (2020-06-22 12:43:55)

Add implementation of fields_() for EmptyCriterion
This issue would have also been solved if `EmptyCriterion` was a subclass of `Criterion`, which would make sense but adds a lot of unnecessary overhead.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/31602262/badge)](https://coveralls.io/builds/31602262)

Coverage remained the same at ?% when pulling **26510d54f1efb1fc6f88ba5a237e23fc041eab6c on gl3nn:EmptyCriterion-extension** into **1562a35d83ccbfc522d3b4feb9bba6fd86f15f83 on kayak:master**.


Patch:
diff --git a/pypika/__init__.py b/pypika/__init__.py
index 538b235..e20dca7 100644
--- a/pypika/__init__.py
+++ b/pypika/__init__.py
@@ -94,4 +94,4 @@ from pypika.utils import (
 
 __author__ = "Timothy Heys"
 __email__ = "theys@kayak.com"
-__version__ = "0.37.8"
+__version__ = "0.37.6"
diff --git a/pypika/dialects.py b/pypika/dialects.py
index 65ef870..df3fb3f 100644
--- a/pypika/dialects.py
+++ b/pypika/dialects.py
@@ -26,7 +26,6 @@ from pypika.utils import (
 
 class SnowFlakeQueryBuilder(QueryBuilder):
     QUOTE_CHAR = None
-    ALIAS_QUOTE_CHAR = '"'
 
     def __init__(self, **kwargs: Any) -> None:
         super().__init__(
diff --git a/pypika/terms.py b/pypika/terms.py
index 95def41..44cf4f9 100644
--- a/pypika/terms.py
+++ b/pypika/terms.py
@@ -454,6 +454,9 @@ class EmptyCriterion:
     is_aggregate = None
     tables_ = set()
 
+    def fields_(self) -> Set["Field"]:
+        return set()
+
     def __and__(self, other: Any) -> Any:
         return other
 
@@ -974,9 +977,9 @@ class Case(Term):
 
     @property
     def is_aggregate(self) -> Optional[bool]:
-        # True if all criterions/cases are True or None. None all cases are None. Otherwise, False
+        # True if all cases are True or None. None all cases are None. Otherwise, False
         return resolve_is_aggregate(
-              [criterion.is_aggregate or term.is_aggregate for criterion, term in self._cases]
+              [term.is_aggregate for _, term in self._cases]
               + [self._else.is_aggregate if self._else else None]
         )
 
diff --git a/setup.cfg b/setup.cfg
index b08a2f2..d9ab4af 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 0.37.8
+current_version = 0.37.6
 commit = True
 tag = True
 


Test patch:
diff --git a/pypika/tests/dialects/test_snowflake.py b/pypika/tests/dialects/test_snowflake.py
index 49dbb92..8ac55a8 100644
--- a/pypika/tests/dialects/test_snowflake.py
+++ b/pypika/tests/dialects/test_snowflake.py
@@ -13,7 +13,7 @@ class QuoteTests(unittest.TestCase):
     def test_use_double_quotes_on_alias_but_not_on_terms(self):
         q = SnowflakeQuery.from_(self.table_abc).select(self.table_abc.a.as_("bar"))
 
-        self.assertEqual('SELECT a "bar" FROM abc', q.get_sql(with_namespace=True))
+        self.assertEqual('SELECT a bar FROM abc', q.get_sql(with_namespace=True))
 
     def test_use_double_quotes_on_alias_but_not_on_terms_with_joins(self):
         foo = self.table_abc.as_("foo")
@@ -28,8 +28,8 @@ class QuoteTests(unittest.TestCase):
 
         self.assertEqual(
             "SELECT foo.a,bar.b "
-            'FROM abc "foo" '
-            'JOIN efg "bar" '
+            'FROM abc foo '
+            'JOIN efg bar '
             "ON foo.fk=bar.id",
             q.get_sql(with_namespace=True),
         )
@@ -45,9 +45,9 @@ class QuoteTests(unittest.TestCase):
         )
 
         self.assertEqual(
-            'SELECT index "idx",SUM(value) "val" '
+            'SELECT index idx,SUM(value) val '
             "FROM abc "
-            'GROUP BY "idx" '
-            'ORDER BY "idx"',
+            'GROUP BY idx '
+            'ORDER BY idx',
             q.get_sql(with_namespace=True),
         )
diff --git a/pypika/tests/test_aggregate.py b/pypika/tests/test_aggregate.py
index 72b1769..44a7112 100644
--- a/pypika/tests/test_aggregate.py
+++ b/pypika/tests/test_aggregate.py
@@ -53,15 +53,6 @@ class IsAggregateTests(unittest.TestCase):
         v = 1 / fn.Sum(Field("foo"))
         self.assertTrue(v.is_aggregate)
 
-    def test__agg_case_criterion_is_aggregate(self):
-        v = (
-            Case()
-            .when(fn.Sum(Field("foo")) > 666, 'More than 666')
-            .else_('Less than 666')
-        )
-
-        self.assertTrue(v.is_aggregate)
-
     def test__agg_case_is_aggregate(self):
         v = (
             Case()
@@ -106,7 +97,7 @@ class IsAggregateTests(unittest.TestCase):
 
         self.assertFalse(v.is_aggregate)
 
-    def test__case_with_single_aggregate_field_in_one_criterion_is_aggregate(self):
+    def test__case_with_single_aggregate_field_is_not_aggregate(self):
         v = (
             Case()
             .when(Field("foo") == 1, 1)
@@ -114,7 +105,12 @@ class IsAggregateTests(unittest.TestCase):
             .else_(3)
         )
 
-        self.assertTrue(v.is_aggregate)
+        self.assertFalse(v.is_aggregate)
+
+    def test__case_all_constants_is_aggregate_none(self):
+        v = Case().when(True, 1).when(False, 2).else_(3)
+
+        self.assertIsNone(v.is_aggregate)
 
     def test__non_aggregate_function_with_aggregated_arg(self):
         t = Table("abc")
diff --git a/pypika/tests/test_criterions.py b/pypika/tests/test_criterions.py
index 4d35653..8fcbc1e 100644
--- a/pypika/tests/test_criterions.py
+++ b/pypika/tests/test_criterions.py
@@ -763,6 +763,13 @@ class AnyTests(unittest.TestCase):
         self.assertEqual(str(crit), '"a" OR "b" OR "c" OR "d"')
 
 
+class EmptyCriterionTests(unittest.TestCase):
+    def test_fields_(self):
+        empty_criterion = EmptyCriterion()
+
+        self.assertEqual(len(empty_criterion.fields_()), 0)
+
+
 class AllTests(unittest.TestCase):
     def test_zero_args_returns_empty_criterion(self):
         crit = Criterion.all()