Skip to content

Commit 586176e

Browse files
authored
Merge pull request #77 from fermitools/impl_76
convert 'ordered' to be order by created_timestamp,file_id...
2 parents a23aff5 + 1cb2f33 commit 586176e

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

metacat/mql/sql_converter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def ordered(self, node, child):
8181
select {t}.*
8282
from (
8383
$child_sql
84-
) {t} order by {t}.id
84+
) {t} order by {t}.created_timestamp,{t}.id
8585
-- end of ordered {t}
8686
""", child_sql = child_sql)
8787
return Node("sql", sql=sql)
@@ -174,7 +174,7 @@ def parents_of(self, node, *args, with_meta=False, with_provenance=False, ordere
174174
c = alias("c")
175175
pc = alias("pc")
176176
columns = self.columns(p, with_meta, with_provenance)
177-
order = f"order by {p}.id" if ordered else ""
177+
order = f"order by {p}.created_timestamp,{p}.id" if ordered else ""
178178
table = "files_with_provenance" if with_provenance else "files"
179179
new_sql = insert_sql(f"""\
180180
-- parents of {p}
@@ -204,7 +204,7 @@ def children_of(self, node, *args, with_meta=False, with_provenance=False, order
204204
c = alias("c")
205205
pc = alias("pc")
206206
columns = self.columns(c, with_meta, with_provenance)
207-
order = f"order by {p}.id" if ordered else ""
207+
order = f"order by {p}.created_timestamp,{p}.id" if ordered else ""
208208
table = "files_with_provenance" if with_provenance else "files"
209209
new_sql = insert_sql(f"""\
210210
-- children of {c}

tests/test_commandline.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ def test_metacat_query_q_1(auth, tst_file_md_list, tst_ds):
164164
for md in tst_file_md_list[:-1]:
165165
assert data.find(md["name"]) >= 0
166166

167+
def test_metacat_query_q_ordered_1(auth, tst_file_md_list, tst_ds):
168+
with open("qfl1", "w") as qf:
169+
qf.write(f"files from {tst_ds} ordered")
170+
with os.popen("metacat query -q qfl1", "r") as fin:
171+
data = fin.read()
172+
os.unlink("qfl1")
173+
for md in tst_file_md_list[:-1]:
174+
assert data.find(md["name"]) >= 0
167175

168176
def test_metacat_query_q_2(auth, tst_file_md_list, tst_ds):
169177
with open("qfl1", "w") as qf:
@@ -390,7 +398,7 @@ def test_metacat_file_show(auth, tst_file_md_list, tst_ds):
390398
assert md['name'] == fname
391399
assert md['namespace'] == ns
392400

393-
assert md['size'] in (38, 39)
401+
assert md['size'] in (37 ,38, 39)
394402
assert md['created_timestamp'] > 0
395403
assert md['creator'] == os.environ["USER"]
396404
assert 'updated_timestamp' in md

0 commit comments

Comments
 (0)