Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxiaoying committed Apr 22, 2024
1 parent 5652316 commit bfa6fff
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions connectorx-python/connectorx/tests/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ def postgres_sslkey() -> str:


@pytest.mark.xfail
def test_on_non_select(postgres_url: str) -> None:
def test_postgres_on_non_select(postgres_url: str) -> None:
query = "CREATE TABLE non_select(id INTEGER NOT NULL)"
df = read_sql(postgres_url, query)

def test_postgres_aaa(postgres_url: str) -> None:
query = "SELECT test_int, test_str FROM test_table"
# query = "SELECT test_bytea FROM test_types"
# query = "SELECT test_boolarray FROM test_types"
df = read_sql(postgres_url, query, partition_on="test_int", partition_num=2)
print(df)

def test_aggregation(postgres_url: str) -> None:
def test_postgres_aggregation(postgres_url: str) -> None:
query = "SELECT test_bool, SUM(test_float) FROM test_table GROUP BY test_bool"
df = read_sql(postgres_url, query)
expected = pd.DataFrame(
Expand All @@ -56,7 +62,7 @@ def test_aggregation(postgres_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_partition_on_aggregation(postgres_url: str) -> None:
def test_postgres_partition_on_aggregation(postgres_url: str) -> None:
query = (
"SELECT test_bool, SUM(test_int) AS test_int FROM test_table GROUP BY test_bool"
)
Expand All @@ -72,7 +78,7 @@ def test_partition_on_aggregation(postgres_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_aggregation2(postgres_url: str) -> None:
def test_postgres_aggregation2(postgres_url: str) -> None:
query = "select DISTINCT(test_bool) from test_table"
df = read_sql(postgres_url, query)
expected = pd.DataFrame(
Expand All @@ -84,7 +90,7 @@ def test_aggregation2(postgres_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_partition_on_aggregation2(postgres_url: str) -> None:
def test_postgres_partition_on_aggregation2(postgres_url: str) -> None:
query = "select MAX(test_int), MIN(test_int) from test_table"
df = read_sql(postgres_url, query, partition_on="max", partition_num=2)
expected = pd.DataFrame(
Expand All @@ -97,7 +103,7 @@ def test_partition_on_aggregation2(postgres_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_udf(postgres_url: str) -> None:
def test_postgres_udf(postgres_url: str) -> None:
query = "select increment(test_int) as test_int from test_table ORDER BY test_int"
df = read_sql(postgres_url, query, partition_on="test_int", partition_num=2)
expected = pd.DataFrame(
Expand All @@ -110,7 +116,7 @@ def test_udf(postgres_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_manual_partition(postgres_url: str) -> None:
def test_postgres_manual_partition(postgres_url: str) -> None:

queries = [
"SELECT * FROM test_table WHERE test_int < 2",
Expand Down Expand Up @@ -869,7 +875,7 @@ def test_postgres_types_simple(postgres_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_empty_result(postgres_url: str) -> None:
def test_postgres_empty_result(postgres_url: str) -> None:
query = "SELECT * FROM test_table where test_int < -100"
df = read_sql(postgres_url, query)
expected = pd.DataFrame(
Expand All @@ -884,7 +890,7 @@ def test_empty_result(postgres_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_empty_result_on_partition(postgres_url: str) -> None:
def test_postgres_empty_result_on_partition(postgres_url: str) -> None:
query = "SELECT * FROM test_table where test_int < -100"
df = read_sql(postgres_url, query, partition_on="test_int", partition_num=3)
expected = pd.DataFrame(
Expand All @@ -899,7 +905,7 @@ def test_empty_result_on_partition(postgres_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_empty_result_on_some_partition(postgres_url: str) -> None:
def test_postgres_empty_result_on_some_partition(postgres_url: str) -> None:
query = "SELECT * FROM test_table where test_int < 1"
df = read_sql(postgres_url, query, partition_on="test_int", partition_num=3)
expected = pd.DataFrame(
Expand All @@ -914,7 +920,7 @@ def test_empty_result_on_some_partition(postgres_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_posix_regex(postgres_url: str) -> None:
def test_postgres_posix_regex(postgres_url: str) -> None:
query = "select test_int, case when test_str ~* 'str.*' then 'convert_str' end as converted_str from test_table"
df = read_sql(postgres_url, query)
expected = pd.DataFrame(
Expand All @@ -928,7 +934,7 @@ def test_posix_regex(postgres_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_json(postgres_url: str) -> None:
def test_postgres_json(postgres_url: str) -> None:
query = "select test_json->>'customer' as customer from test_types"
df = read_sql(postgres_url, query)
expected = pd.DataFrame(
Expand All @@ -941,7 +947,7 @@ def test_json(postgres_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_partition_on_json(postgres_url: str) -> None:
def test_postgres_partition_on_json(postgres_url: str) -> None:
query = "select test_int16, test_jsonb->>'qty' as qty from test_types"
df = read_sql(postgres_url, query, partition_on="test_int16", partition_num=3)
expected = pd.DataFrame(
Expand All @@ -954,7 +960,7 @@ def test_partition_on_json(postgres_url: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_cte(postgres_url: str) -> None:
def test_postgres_cte(postgres_url: str) -> None:
query = "with test_cte (test_int, test_str) as (select test_int, test_str from test_table where test_float > 0) select test_int, test_str from test_cte"
df = read_sql(postgres_url, query, partition_on="test_int", partition_num=3)
df.sort_values(by="test_int", inplace=True, ignore_index=True)
Expand Down Expand Up @@ -999,7 +1005,7 @@ def test_postgres_tls(postgres_url_tls: str) -> None:
assert_frame_equal(df, expected, check_names=True)


def test_partition_on_decimal(postgres_url: str) -> None:
def test_postgres_partition_on_decimal(postgres_url: str) -> None:
# partition column can not have None
query = "SELECT * FROM test_table where test_int<>1"
df = read_sql(postgres_url, query, partition_on="test_float", partition_num=3)
Expand Down

0 comments on commit bfa6fff

Please sign in to comment.