File size: 2,758 Bytes
88f23be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
"""Read-only validation over the packaged Parquet and SQLite artifacts."""
import json, sqlite3
from pathlib import Path
import pyarrow.parquet as pq

base=Path(__file__).resolve().parents[1]
root=base if base.name=='release' else base / 'release'
splits={s:pq.read_table(root/'data'/f'{s}.parquet').to_pylist() for s in ('train','validation','test')}
seen_ids=set(); seen_db={}; seen_tables={}; seen_questions={}; counts={}
for split,rows in splits.items():
    counts[split]={'rows':len(rows),'execute':0,'clarify':0,'unanswerable':0}
    for x in rows:
        assert x['split']==split and x['id'] not in seen_ids
        seen_ids.add(x['id'])
        assert x['database_id'] not in seen_db or seen_db[x['database_id']]==split
        seen_db[x['database_id']]=split
        assert x['question_ar'] not in seen_questions or seen_questions[x['question_ar']]==split
        seen_questions[x['question_ar']]=split
        assert x['human_native_speaker_reviewed'] is False
        assert x['database_provenance']=='fictional_programmatically_generated'
        p=(root/x['database_path']).resolve()
        assert p.is_file() and p.parent==(root/'databases').resolve()
        db=sqlite3.connect(p.as_uri()+'?mode=ro',uri=True)
        db.execute('PRAGMA query_only=ON')
        assert db.execute('PRAGMA integrity_check').fetchone()[0]=='ok'
        assert not db.execute('PRAGMA foreign_key_check').fetchall()
        defs=db.execute("SELECT name, sql FROM sqlite_master WHERE type='table' ORDER BY name").fetchall()
        assert x['schema_sql']=='\n'.join(ddl+';' for _,ddl in defs)
        for name,_ in defs:
            assert name not in seen_tables or seen_tables[name]==split
            seen_tables[name]=split
        if x['decision']=='execute':
            counts[split]['execute']+=1
            sql=x['reference_sql']; assert sql.startswith('SELECT ') and ';' not in sql
            assert [list(row) for row in db.execute(sql).fetchall()]==json.loads(x['expected_result_json'])
        else:
            assert x['decision'] in ('clarify','unanswerable') and x['reference_sql'] is None and x['expected_result_json'] is None
            counts[split][x['decision']]+=1
            assert (x['decision']=='clarify') == (x['operation']=='unspecified_best_metric')
        db.close()
assert len(seen_db)==12
print(json.dumps({'status':'passed','counts':counts,'distinct_database_ids':len(seen_db),'distinct_table_names':len(seen_tables),'exact_question_strings_unique_across_splits':True,'checks':['packaged parquet and databases','read-only gold SQL execution','expected result comparison','foreign keys and integrity','clarification rows','database/table-name split isolation','schema DDL match','provenance flags']}))