Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions beanquery/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _select(self, node: ast.Select):
# should never trigger if the compilation environment does not
# contain any aggregate.
if c_where is not None and is_aggregate(c_where):
raise CompilationError('aggregates are not allowed in WHERE clause')
raise CompilationError('aggregates are not allowed in WHERE clause', node = node.where_clause)

# Combine FROM and WHERE clauses
if c_from_expr is not None:
Expand Down Expand Up @@ -190,10 +190,10 @@ def _compile_from(self, node):

# Check that the FROM clause does not contain aggregates.
if c_expression is not None and is_aggregate(c_expression):
raise CompilationError('aggregates are not allowed in FROM clause')
raise CompilationError('aggregates are not allowed in FROM clause', node)

if node.open and node.close and node.open > node.close:
raise CompilationError('CLOSE date must follow OPEN date')
raise CompilationError('CLOSE date must follow OPEN date', node)

# Apply OPEN, CLOSE, and CLEAR clauses.
if node.open is not None or node.close is not None or node.clear is not None:
Expand Down Expand Up @@ -228,13 +228,13 @@ def _compile_targets(self, targets):

# Check for mixed aggregates and non-aggregates.
if columns and aggregates:
raise CompilationError('mixed aggregates and non-aggregates are not allowed')
raise CompilationError('mixed aggregates and non-aggregates are not allowed', target)

# Check for aggregates of aggregates.
for aggregate in aggregates:
for child in aggregate.childnodes():
if is_aggregate(child):
raise CompilationError('aggregates of aggregates are not allowed')
raise CompilationError('aggregates of aggregates are not allowed', target)

return c_targets

Expand Down Expand Up @@ -414,7 +414,8 @@ def _compile_group_by(self, group_by, c_targets):
# Check if the new expression is an aggregate.
aggregate = is_aggregate(c_expr)
if aggregate:
raise CompilationError(f'GROUP-BY expressions may not be aggregates: "{column}"')
_, agg = get_columns_and_aggregates(c_expr)
raise CompilationError(f'GROUP-BY expressions may not be aggregates: "{column}"', column)

# Attempt to reconcile the expression with one of the existing
# target expressions.
Expand Down
13 changes: 8 additions & 5 deletions beanquery/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ def render_location(text, pos, endpos, lineno, indent, strip, out):

# FIXME: move the error formatting into the exception classes themselves
def render_exception(exc, indent='| ', strip=True):
if isinstance(exc, (beanquery.CompilationError, beanquery.ParseError)) and exc.parseinfo:
if isinstance(exc, beanquery.ProgrammingError):
return str(exc)
if isinstance(exc, (beanquery.CompilationError, beanquery.ParseError)):
out = [str(exc)]
pos = exc.parseinfo.pos
endpos = exc.parseinfo.endpos
lineno = exc.parseinfo.line
render_location(exc.parseinfo.tokenizer.text, pos, endpos, lineno, indent, strip, out)
if exc.parseinfo:
pos = exc.parseinfo.pos
endpos = exc.parseinfo.endpos
lineno = exc.parseinfo.line
render_location(exc.parseinfo.tokenizer.text, pos, endpos, lineno, indent, strip, out)
return '\n'.join(out)
return '\n' + traceback.format_exc()

Expand Down