Ejemplo n.º 1
0
    def test_persistent_tables(self):
        with Session() as session1:
            session1 = Session()
            session1.run_script('t = None')
            t = session1.empty_table(10)
            session1.bind_table('t', t)


        with Session(sync_fields=SYNC_ONCE) as session2:
            self.assertIn('t', session2.tables)
Ejemplo n.º 2
0
 def test_never_timeout(self):
     session = Session()
     for _ in range(2):
         token1 = session.session_token
         sleep(300)
         token2 = session.session_token
         self.assertNotEqual(token1, token2)
     session.close()
Ejemplo n.º 3
0
    def test_shared_tables(self):
        session1 = Session(sync_fields=SYNC_REPEATED)
        session1.run_script('t = None')

        session2 = Session()
        t = session2.empty_table(10)
        session2.bind_table('t', t)

        @timeout_decorator.timeout(seconds=1)
        def wait_for_table():
            while 't' not in session1.tables:
                pass

        try:
            wait_for_table()
        except timeout_decorator.TimeoutError:
            self.fail('table did not get synced to session1')
Ejemplo n.º 4
0
def main():
    with Session(host="localhost", port=10000) as dh_session:
        taxi_data_table = import_taxi_records(dh_session)
        bottom_5_fares_table = demo_chained_table_ops(taxi_data_table)

        # download the table to the client in the form of pyarrow table and convert it into a Pandas DataFrame
        snapshot_data = bottom_5_fares_table.snapshot()
        df = snapshot_data.to_pandas()

        pd.set_option("max_columns", 20)
        print(df)
Ejemplo n.º 5
0
def main():
    with Session(host="localhost", port=10000) as dh_session:
        taxi_data_table = import_taxi_records(dh_session)
        variable_name = "t"
        dh_session.bind_table(taxi_data_table, variable_name)

        bottom_5_fares_table = run_script(dh_session=dh_session)
        snapshot_data = bottom_5_fares_table.snapshot()
        df = snapshot_data.to_pandas()

        pd.set_option("max_columns", 20)
        print(df)
Ejemplo n.º 6
0
    def test_merge_tables(self):
        session = Session()
        pa_table = csv.read_csv(self.csv_file)
        table1 = session.import_table(pa_table)
        table2 = table1.group_by(by=["a", "c"]).ungroup(cols=["b", "d", "e"])
        table3 = table1.where(["a % 2 > 0 && b % 3 == 1"])
        result_table = session.merge_tables(tables=[table1, table2, table3],
                                            order_by="a")

        self.assertTrue(result_table.size > table1.size)
        self.assertTrue(result_table.size > table2.size)
        self.assertTrue(result_table.size > table3.size)
Ejemplo n.º 7
0
def main():
    with Session(host="localhost", port=10000) as dh_session:
        taxi_data_table = import_taxi_records(dh_session)

        top_5_fares_table = demo_query(dh_session=dh_session, taxi_data_table=taxi_data_table)
        bottom_5_fares_table = demo_chained_table_ops(taxi_data_table)

        combined_fares_table = dh_session.merge_tables(tables=[top_5_fares_table, bottom_5_fares_table])
        snapshot_data = combined_fares_table.snapshot()
        df = snapshot_data.to_pandas()

        pd.set_option("max_columns", 20)
        print(df)
Ejemplo n.º 8
0
    def test_multiple_sessions(self):
        sessions = []
        for i in range(100):
            sessions.append(Session())

        tables = []
        for session in sessions:
            pa_table = csv.read_csv(self.csv_file)
            table1 = session.import_table(pa_table)
            table2 = table1.group_by()
            self.assertEqual(table2.size, 1)
            tables.append(table1)

        for i, table in enumerate(tables[:-1]):
            j_table = table.natural_join(tables[i + 1],
                                         on=["a", "b", "c", "d", "e"])
            self.assertEqual(table.size, j_table.size)

        for session in sessions:
            session.close()
Ejemplo n.º 9
0
 def setUp(self) -> None:
     self.session = Session()
Ejemplo n.º 10
0
def main():
    with Session(host="localhost", port=10000) as dh_session:
        joined_table = demo_asof_join(dh_session)
        df = joined_table.snapshot().to_pandas()
        print(df)
Ejemplo n.º 11
0
 def test_time_table(self):
     session = Session()
     t = session.time_table(period=100000)
     self.assertFalse(t.is_static)
     session.close()
Ejemplo n.º 12
0
 def test_empty_table(self):
     session = Session()
     t = session.empty_table(1000)
     self.assertEqual(t.size, 1000)
     session.close()
Ejemplo n.º 13
0
 def test_connect_failure(self):
     with self.assertRaises(DHError):
         session = Session(port=80)
Ejemplo n.º 14
0
 def test_close(self):
     session = Session()
     session.close()
     self.assertEqual(False, session.is_connected)
     self.assertEqual(False, session.is_alive)