Skip to content

Commit

Permalink
added query
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulworld committed Jun 29, 2018
1 parent 3a80f5c commit 4087fdd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
Binary file not shown.
59 changes: 52 additions & 7 deletions istsos/actions/retrievers/aiopg/observations.py
Expand Up @@ -320,6 +320,15 @@ def __get_array(self, offerings, request):
)
jsonKeys.append("COALESCE(c%s, 'null')" % (idx))

# for idx in range(0, len(columns)):
# unionSelect.append(
# "SUM(c%s)::text as c%s" % (idx, idx)
# )
# unionColumns.append(
# "NULL::double precision as c%s" % (idx)
# )
# jsonKeys.append("COALESCE(c%s, 'null')" % (idx))

unionSelect = ", ".join(unionSelect)

temporal = []
Expand Down Expand Up @@ -361,18 +370,26 @@ def __get_array(self, offerings, request):
print(cols)
print(off_cols)
for col in off_cols:
cols[
columns.index(col)
] = unionColumns[columns.index(col)].replace(
"NULL::double precision",
col+"*'m'::unit@'cm'"
)
# ConvertScript="""np.ting as c0 from(select SUBSTRING(CAST(tmp.num as varchar),'[0-9]+') as ting from(select %s *'m'::unit@ 'mm' as num)as tmp)as np"""% (", ",col)
# print('Printing ConvertScript')
# print(ConvertScript)
# cols[
# columns.index(col)
# ] = unionColumns[columns.index(col)].replace(
# "NULL::double precision", ConvertScript
# )
# cols[
# columns.index(col)
# ] = unionColumns[columns.index(col)].replace(
# "NULL::double precision",
# col
# col+"*'m'::unit@'cm'"
# )
cols[
columns.index(col)
] = unionColumns[columns.index(col)].replace(
"NULL::double precision",
col
)
print('Print col in observations 1')
print(cols)
print(off_cols)
Expand All @@ -384,6 +401,8 @@ def __get_array(self, offerings, request):
""" % (
", ".join(cols), table
)
print('Query Printing uSql')
print(uSql)
# uSql = """
# SELECT
# end_time, %s '*' %s ::unit@ %s
Expand All @@ -397,6 +416,8 @@ def __get_array(self, offerings, request):
'AND'.join(where)
)
unions.append("(%s)" % uSql)
print('Query Printing uSql')
print(uSql)

jsonSql = """
SELECT array_agg(
Expand All @@ -409,6 +430,30 @@ def __get_array(self, offerings, request):
""" % (
", ".join(jsonKeys),
)
print('Query Printing jsonSql')
print(jsonSql)
print('Query Printing unionSelect')
print(unionSelect)
print('union')
print(unions)

# sql = """
# SET enable_seqscan=false;
# SET SESSION TIME ZONE '+00:00';
# %s
# (
# SELECT end_time, %s
# FROM (
# %s
# ) a
# GROUP BY end_time
# ORDER BY end_time
# ) b
# """ % (
# jsonSql,
# unionSelect,
# " UNION ".join(unions)
# )

sql = """
SET enable_seqscan=false;
Expand Down

0 comments on commit 4087fdd

Please sign in to comment.