queryparser-python3 0.7.2__py3-none-any.whl → 0.7.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
queryparser/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = '0.7.2'
1
+ __version__ = '0.7.4'
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ ADQL processor. Its task is to check if a query has any syntax errors and
4
+ to extract all accessed columns as well as keywords and functions being
5
+ used in a query.
6
+
7
+ """
8
+
9
+ from __future__ import absolute_import, print_function
10
+
11
+ __all__ = ["ADQLQueryProcessor"]
12
+
13
+ from ..common import SQLQueryProcessor
14
+ from .ADQLLexer import ADQLLexer
15
+ from .ADQLParser import ADQLParser
16
+ from .ADQLParserListener import ADQLParserListener
17
+
18
+
19
+ class ADQLQueryProcessor(SQLQueryProcessor):
20
+ def __init__(self, query=None):
21
+ super().__init__(
22
+ ADQLLexer, ADQLParser, ADQLParserListener, '"', query
23
+ )
@@ -4,6 +4,7 @@ from __future__ import absolute_import
4
4
 
5
5
  import antlr4
6
6
  from antlr4.error.ErrorListener import ErrorListener
7
+ import re
7
8
 
8
9
  from .ADQLLexer import ADQLLexer
9
10
  from .ADQLParser import ADQLParser
@@ -205,7 +206,7 @@ class ADQLGeometryTranslationVisitor(ADQLParserVisitor):
205
206
  if derived_column is not None:
206
207
  ctx_text = f"spoint_to_array_deg({ctx_text})"
207
208
  if not (any([isinstance(child, ADQLParser.As_clauseContext) for child in derived_column.children])):
208
- ctx_text = f"{ctx_text} AS point"
209
+ ctx_text = f"{ctx_text} AS adql_point"
209
210
  else:
210
211
  ctx_text = ''
211
212
 
@@ -297,7 +298,7 @@ class ADQLGeometryTranslationVisitor(ADQLParserVisitor):
297
298
  if derived_column is not None:
298
299
  ctx_text = f"spoly_to_array_deg({ctx_text})"
299
300
  if not (any([isinstance(child, ADQLParser.As_clauseContext) for child in derived_column.children])):
300
- ctx_text = f"{ctx_text} AS polygon"
301
+ ctx_text = f"{ctx_text} AS adql_polygon"
301
302
  else:
302
303
  ctx_text = ''
303
304
 
@@ -470,15 +471,6 @@ class ADQLFunctionsTranslationVisitor(ADQLParserVisitor):
470
471
  _remove_children(ctx)
471
472
  self.contexts[ctx] = ctx_text
472
473
 
473
- def visitMath_function(self, ctx):
474
- ctx_text = ctx.getText()
475
- if self.output_sql == 'postgresql' and ctx_text[:5].lower() == 'log10':
476
- _remove_children(ctx)
477
- self.contexts[ctx] = 'LOG' + ctx_text[5:]
478
- elif self.output_sql == 'postgresql' and ctx_text[:3].lower() == 'log':
479
- _remove_children(ctx)
480
- self.contexts[ctx] = 'LN' + ctx_text[3:]
481
-
482
474
 
483
475
  class SelectQueryListener(ADQLParserListener):
484
476
  def __init__(self):
@@ -691,4 +683,9 @@ class ADQLQueryTranslator(object):
691
683
  translator_visitor.visit(self.tree)
692
684
 
693
685
  translated_query = self.translate(translator_visitor)
686
+
687
+ # Translate LOG10 to LOG and LOG to LN. It's not the most elegant solution but it works.
688
+ translated_query = re.sub(r'(?<=[\+\-\*/\(\s,])log\(', 'LN(', translated_query, flags=re.IGNORECASE)
689
+ translated_query = re.sub(r'(?<=[\+\-\*/\(\s,])log10\(', 'LOG(', translated_query, flags=re.IGNORECASE)
690
+
694
691
  return translated_query