def test_taql_factory(ms, ant_table, readonly): """ Test that we can do a somewhat complicated taql query """ ms_proxy = TableProxy(pt.table, ms, ack=False, readonly=True) ant_proxy = TableProxy(pt.table, ant_table, ack=False, readonly=True) query = "SELECT [SELECT NAME FROM $2][ANTENNA1] AS NAME FROM $1 " taql_proxy = TableProxy(taql_factory, query, tables=[ms_proxy, ant_proxy], readonly=readonly) ant1 = ms_proxy.getcol("ANTENNA1").result() actual_ant_row_names = taql_proxy.getcol("NAME").result() expected_ant_row_names = ['ANTENNA-%d' % i for i in ant1] assert_array_equal(actual_ant_row_names, expected_ant_row_names)
def test_embedding_table_proxy_in_taql(ms, reverse): """ Test using a TableProxy to create a TAQL TableProxy """ proxy = TableProxy(pt.table, ms, ack=False, readonly=True) query = "SELECT UNIQUE ANTENNA1 FROM $1" taql_proxy = TableProxy(taql_factory, query, tables=[proxy]) assert_array_equal(taql_proxy.getcol("ANTENNA1").result(), [0, 1, 2]) # TAQL and original table assert_liveness(2, 1) if reverse: del proxy # TAQL still references original table assert_liveness(2, 1) # Remove TAQL now results in everything clearing up del taql_proxy assert_liveness(0, 0) else: # Removing TAQL should leave original table del taql_proxy assert_liveness(1, 1) # Removing proxy removes the last del proxy assert_liveness(0, 0)
def test_row_query(ms, index_cols): T = TableProxy(pt.table, ms, readonly=True, lockoptions='auto', ack=False) # Get the expected row ordering by lexically # sorting the indexing columns cols = [(name, T.getcol(name).result()) for name in index_cols] expected_rows = np.lexsort(tuple(c for n, c in reversed(cols))) del T xds = xds_from_ms(ms, columns=index_cols, group_cols="__row__", index_cols=index_cols, chunks={"row": 2}) actual_rows = da.concatenate([ds.ROWID.data for ds in xds]) assert_array_equal(actual_rows, expected_rows)