heavyai/pymapd

SQL ORDER_BY fails inside of nested SQL statements

kcpevey opened this issue · 1 comments

SQL ORDER_BY works fine as the last statement, but fails inside of nested SQL statements.

This code sorts as expected:

import pymapd
client = pymapd.connect(user="mapd", password="HyperInteractive", host="metis.mapd.com", dbname="mapd", port=443, protocol='https')
sql_works = """
SELECT * FROM (
  SELECT * FROM (
    SELECT "StateAbb", "Obama" FROM (
        SELECT *
        FROM demo_vote_clean
        LIMIT 20
    ) t2
  ) t1
) t0
ORDER BY "StateAbb"
"""
cur = client.execute(sql_works)
for c in cur:
    print(c)

('AL', 0.18580634891986847)
('CO', 0.30712711811065674)
('CT', 0.4643782377243042)
('ID', 0.2849028408527374)
('KS', 0.1489061415195465)
('MD', 0.4848048985004425)
('MN', 0.47713688015937805)
('MN', 0.5407902598381042)
('MN', 0.5407902598381042)
('MN', 0.47713688015937805)
('NC', 0.5551937222480774)
('NM', 0.32300713658332825)
('OK', 0.30459102988243103)
('PA', 0.39324700832366943)
('TX', 0.6571882963180542)
('TX', 0.16482913494110107)
('UT', 0.10097683221101761)
('VA', 0.38765329122543335)
('WI', 0.3924614191055298)
('WI', 0.3924614191055298)

But this code does not sort:

sql_broken = """
SELECT * FROM (
  SELECT * FROM (
    SELECT "StateAbb", "Obama" FROM (
        SELECT *
        FROM demo_vote_clean
        LIMIT 20
    ) t2
  ) t1
  ORDER BY "StateAbb"
) t0
"""
cur = client.execute(sql_broken)
for c in cur:
    print(c)

('FL', 0.41378170251846313)
('UT', 0.12890802323818207)
('CA', 0.6887373328208923)
('WA', 0.5431362986564636)
('AL', 0.1945049911737442)
('NC', 0.4005028009414673)
('OH', 0.45410802960395813)
('GA', 0.34286466240882874)
('NM', 0.7473587393760681)
('GA', 0.36215880513191223)
('MO', 0.5869240760803223)
('MS', 0.5395815968513489)
('FL', 0.5820325613021851)
('CA', 0.4763653576374054)
('PA', 0.27808117866516113)
('AL', 0.5125229358673096)
('IA', 0.5512475967407227)
('PA', 0.27808117866516113)
('AL', 0.4752040207386017)
('IA', 0.5220223069190979)

This becomes an issue if I want to apply a limit function after the order_by.

@kcpevey , sorry for the delayed response. This is related to the DB, no the python client, so If this is still an issue, please use https://community.omnisci.com/.