From deec8a59180406932397a74db011bc82f33461b4 Mon Sep 17 00:00:00 2001 From: Gal Matijevic Date: Tue, 24 Apr 2018 15:23:43 +0200 Subject: [PATCH] cast test --- .../postgresql/postgresqlprocessor.py | 4 ++-- src/queryparser/testing/test_postgresql.py | 21 +++++++++++++++++++ utils/test_pg.py | 12 +++++++++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/queryparser/postgresql/postgresqlprocessor.py b/src/queryparser/postgresql/postgresqlprocessor.py index 4666528..016f7c9 100644 --- a/src/queryparser/postgresql/postgresqlprocessor.py +++ b/src/queryparser/postgresql/postgresqlprocessor.py @@ -504,10 +504,10 @@ def process_query(self, replace_schema_name={}): list(self._strip_column(i[1]))) for i in display_columns] - self.tables = [[i[0].lstrip('"').rstrip('"') + self.tables = list(set([tuple([i[0].lstrip('"').rstrip('"') if i[0] is not None else i[0], i[1].lstrip('"').rstrip('"') - if i[1] is not None else i[1]] for i in tables] + if i[1] is not None else i[1]]) for i in tables])) # If there are any pg_sphere objects that are indexed we need # to replace the ADQL translated query parts with the indexed column diff --git a/src/queryparser/testing/test_postgresql.py b/src/queryparser/testing/test_postgresql.py index 0c013f4..25fdbee 100644 --- a/src/queryparser/testing/test_postgresql.py +++ b/src/queryparser/testing/test_postgresql.py @@ -209,3 +209,24 @@ def test_query050(self): 'phase: gdr1.rrlyrae.p1'), ('gdr1.phot_variable_time_series_gfov', 'gdr1.rrlyrae') ) + + def test_query051(self): + self._test_postgresql_parsing( + """ + SELECT q2.c / q1.c FROM ( + SELECT CAST(COUNT(*) AS FLOAT) AS c + FROM gdr1.tgas_source + ) AS q1 + CROSS JOIN ( + SELECT COUNT(*) AS c + FROM gdr1.tgas_source + WHERE parallax / parallax_error > 10 + ) AS q2 + """, + ('gdr1.tgas_source.parallax', 'gdr1.tgas_source.parallax_error', + 'gdr1.tgas_source.None'), + ('where', ), + ('COUNT',), + (), + ('gdr1.tgas_source',) + ) diff --git a/utils/test_pg.py b/utils/test_pg.py index e6e798b..084ff84 100644 --- a/utils/test_pg.py +++ b/utils/test_pg.py @@ -116,7 +116,15 @@ def f2(): def f3(): query = """ - SELECT a, arr[1:3], b FROM gdr1.gaia_source LIMIT 10 + SELECT q2.c / q1.c FROM ( + SELECT CAST(COUNT(*) AS FLOAT) AS c + FROM gdr1.tgas_source + ) AS q1 + CROSS JOIN ( + SELECT COUNT(*) AS c + FROM gdr1.tgas_source + WHERE parallax / parallax_error > 10 + ) AS q2 """ qp = PostgreSQLQueryProcessor() qp.set_query(query) @@ -129,7 +137,7 @@ def f3(): print(qp.keywords) print(qp.functions) -f1() +f3() exit() alpha = (13 + 26 / 60 + 47.28 / 3600) * 15 - 180