test_query.py 1.2 KB
Newer Older
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
from datetime import datetime
import taos
import pytest

@pytest.fixture
def conn():
    return taos.connect()

def test_query(conn):
    """This test will use fetch_block for rows fetching, significantly faster than rows_iter"""
    result = conn.query("select * from log.log limit 10000")
    fields = result.fields
    for field in fields:
        print("field: %s" % field)
    start = datetime.now()
    for row in result:
        # print(row)
        None
    end = datetime.now()
    elapsed = end - start
    print("elapsed time: ", elapsed)
    result.close()
    conn.close()

def test_query_row_iter(conn):
    """This test will use fetch_row for each row fetching, this is the only way in async callback"""
    result = conn.query("select * from log.log limit 10000")
    fields = result.fields
    for field in fields:
        print("field: %s" % field)
    start = datetime.now()
    for row in result.rows_iter():
        # print(row)
        None
    end = datetime.now()
    elapsed = end - start
    print("elapsed time: ", elapsed)
    result.close()
    conn.close()

if __name__ == "__main__":
    test_query(taos.connect(database = "log"))
    test_query_row_iter(taos.connect(database = "log"))