# Path: impala/compat.py
# def lzip(*x):


import sys
import pytest
from impala.compat import _xrange as xrange
from pytest import yield_fixture
def bigger_table(cur):
    table_name = 'tmp_bigger_table'
    ddl = """CREATE TABLE {0} (s string)
             STORED AS PARQUET""".format(table_name)
    cur.execute(ddl)
    dml = """INSERT INTO {0}
             VALUES {1}""".format(table_name,
                 ",".join(["('row{0}')".format(i) for i in xrange(BIGGER_TABLE_NUM_ROWS)]))
    # Disable codegen and expr rewrites so query runs faster.
    cur.execute("set disable_codegen=1")
    cur.execute("set enable_expr_rewrites=0")
    cur.execute(dml)
    try:
        yield table_name
    finally:
        cur.execute("DROP TABLE {0}".format(table_name))


def test_has_more_rows(cur, bigger_table):
    """Test that impyla correctly handles empty row batches returned with the
    hasMoreRows flag."""
    # Set the fetch timeout very low and add sleeps so that Impala will return
    # empty batches. Run on a single node with a single thread to make as predictable
    # as possible.
    cur.execute("set fetch_rows_timeout_ms=1")
    cur.execute("set num_nodes=1")
    cur.execute("set mt_dop=1")
    cur.execute("""select *
                   from {0}
                   where s != cast(sleep(2) as string)""".format(bigger_table))

# Path: impala/compat.py
# def lzip(*x):


# Path: impala/tests/test_impala.py
import sys
import pytest
from impala.compat import _xrange as xrange
from pytest import yield_fixture

def bigger_table(cur):
    table_name = 'tmp_bigger_table'
    ddl = """CREATE TABLE {0} (s string)
             STORED AS PARQUET""".format(table_name)
    cur.execute(ddl)
    dml = """INSERT INTO {0}
             VALUES {1}""".format(table_name,
                 ",".join(["('row{0}')".format(i) for i in xrange(BIGGER_TABLE_NUM_ROWS)]))
    # Disable codegen and expr rewrites so query runs faster.
    cur.execute("set disable_codegen=1")
    cur.execute("set enable_expr_rewrites=0")
    cur.execute(dml)
    try:
        yield table_name
    finally:
        cur.execute("DROP TABLE {0}".format(table_name))


def test_has_more_rows(cur, bigger_table):
    """Test that impyla correctly handles empty row batches returned with the
    hasMoreRows flag."""
    # Set the fetch timeout very low and add sleeps so that Impala will return
    # empty batches. Run on a single node with a single thread to make as predictable
    # as possible.
    cur.execute("set fetch_rows_timeout_ms=1")
    cur.execute("set num_nodes=1")
    cur.execute("set mt_dop=1")
    cur.execute("""select *
                   from {0}
                   where s != cast(sleep(2) as string)""".format(bigger_table))

    expected_rows = [("row{0}".format(i),) for i in xrange(BIGGER_TABLE_NUM_ROWS)]