Coverage for dj/sql/parse.py: 100%
9 statements
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-17 20:05 -0700
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-17 20:05 -0700
1"""
2SQL parsing functions.
3"""
5from typing import Optional
8def is_metric(query: Optional[str]) -> bool:
9 """
10 Return if a SQL query defines a metric.
12 The SQL query should have a single expression in its projections, and it should
13 be an aggregation function in order for it to be considered a metric.
14 """
16 from dj.sql.parsing.backends.antlr4 import parse # pylint: disable=C0415
18 if query is None:
19 return False
21 tree = parse(query)
23 # must have a single expression
24 if len(tree.select.projection) != 1:
25 return False
27 return tree.select.projection[0].is_aggregation() # type: ignore