Skip to content

Commit 6e6c04a

Browse files
authored
Merge pull request #382 from auyer/main
[WIP] Adds ltree string type
2 parents e77677d + 1e46833 commit 6e6c04a

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

connectorx-python/connectorx/tests/test_postgres.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,14 @@ def test_postgres_types_binary(postgres_url: str) -> None:
549549
dtype="object",
550550
),
551551
"test_citext": pd.Series(["str_citext", "", "s", None], dtype="object"),
552+
# "test_ltree": pd.Series(["A.B.C.D", "A.B.E", "A", None], dtype="object"), # waiting for https://github.com/sfackler/rust-postgres/issues/960
552553
},
553554
)
554555
assert_frame_equal(df, expected, check_names=True)
555556

556557

557558
def test_postgres_types_csv(postgres_url: str) -> None:
558-
query = "SELECT test_date, test_timestamp, test_timestamptz, test_int16, test_int64, test_float32, test_numeric, test_bpchar, test_char, test_varchar, test_uuid, test_time, test_json, test_jsonb, test_bytea, test_enum::text, test_f4array, test_f8array, test_narray, test_i2array, test_i4array, test_i8array, test_citext FROM test_types"
559+
query = "SELECT test_date, test_timestamp, test_timestamptz, test_int16, test_int64, test_float32, test_numeric, test_bpchar, test_char, test_varchar, test_uuid, test_time, test_json, test_jsonb, test_bytea, test_enum::text, test_f4array, test_f8array, test_narray, test_i2array, test_i4array, test_i8array, test_citext, test_ltree FROM test_types"
559560
df = read_sql(postgres_url, query, protocol="csv")
560561
expected = pd.DataFrame(
561562
index=range(4),
@@ -654,13 +655,14 @@ def test_postgres_types_csv(postgres_url: str) -> None:
654655
dtype="object",
655656
),
656657
"test_citext": pd.Series(["str_citext", None, "s", None], dtype="object"),
658+
"test_ltree": pd.Series(["A.B.C.D", "A.B.E", "A", None], dtype="object"),
657659
},
658660
)
659661
assert_frame_equal(df, expected, check_names=True)
660662

661663

662664
def test_postgres_types_cursor(postgres_url: str) -> None:
663-
query = "SELECT test_date, test_timestamp, test_timestamptz, test_int16, test_int64, test_float32, test_numeric, test_bpchar, test_char, test_varchar, test_uuid, test_time, test_json, test_jsonb, test_bytea, test_enum::text, test_f4array, test_f8array, test_narray, test_i2array, test_i4array, test_i8array, test_citext FROM test_types"
665+
query = "SELECT test_date, test_timestamp, test_timestamptz, test_int16, test_int64, test_float32, test_numeric, test_bpchar, test_char, test_varchar, test_uuid, test_time, test_json, test_jsonb, test_bytea, test_enum::text, test_f4array, test_f8array, test_narray, test_i2array, test_i4array, test_i8array, test_citext, test_ltree FROM test_types"
664666
df = read_sql(postgres_url, query, protocol="cursor")
665667
expected = pd.DataFrame(
666668
index=range(4),
@@ -759,6 +761,7 @@ def test_postgres_types_cursor(postgres_url: str) -> None:
759761
dtype="object",
760762
),
761763
"test_citext": pd.Series(["str_citext", "", "s", None], dtype="object"),
764+
"test_ltree": pd.Series(["A.B.C.D", "A.B.E", "A", None], dtype="object"),
762765
},
763766
)
764767
assert_frame_equal(df, expected, check_names=True)

connectorx/src/sources/postgres/typesystem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'a> From<&'a Type> for PostgresTypeSystem {
8383
"_numeric" => NumericArray(true),
8484
"bool" => Bool(true),
8585
"char" => Char(true),
86-
"text" | "citext" => Text(true),
86+
"text" | "citext" | "ltree" => Text(true),
8787
"bpchar" => BpChar(true),
8888
"varchar" => VarChar(true),
8989
"bytea" => ByteA(true),

docs/databases/postgres.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ cx.read_sql(conn, query) # read data from
4141
| JSON | object | |
4242
| JSONB | object | |
4343
| ENUM | object | need to convert enum column to text manually (`::text`) when using `csv` and `cursor` protocol |
44+
| ltree | object | binary protocol returns with a hex char prefix. Check https://github.com/sfu-db/connector-x/pull/382 and https://github.com/sfackler/rust-postgres/issues/960 for status |
4445
| INT2[] | object | list of i64 |
4546
| INT4[] | object | list of i64 |
4647
| INT8[] | object | list of i64 |

scripts/postgres.sql

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ DROP TABLE IF EXISTS test_str;
33
DROP TABLE IF EXISTS test_types;
44
DROP TYPE IF EXISTS happiness;
55
DROP EXTENSION IF EXISTS citext;
6+
DROP EXTENSION IF EXISTS ltree;
67

78
CREATE TABLE IF NOT EXISTS test_table(
89
test_int INTEGER NOT NULL,
@@ -37,6 +38,7 @@ INSERT INTO test_str VALUES (8, '', NULL);
3738

3839
CREATE TYPE happiness AS ENUM ('happy', 'very happy', 'ecstatic');
3940
CREATE EXTENSION citext;
41+
CREATE EXTENSION ltree;
4042
CREATE TABLE IF NOT EXISTS test_types(
4143
test_date DATE,
4244
test_timestamp TIMESTAMP,
@@ -61,16 +63,17 @@ CREATE TABLE IF NOT EXISTS test_types(
6163
test_i2array SMALLINT[],
6264
test_i4array Integer[],
6365
test_i8array BIGINT[],
64-
test_citext CITEXT
66+
test_citext CITEXT,
67+
test_ltree ltree
6568
);
6669

67-
INSERT INTO test_types VALUES ('1970-01-01', '1970-01-01 00:00:01', '1970-01-01 00:00:01-00', 0, -9223372036854775808, NULL, NULL, 'a', 'a', NULL, '86b494cc-96b2-11eb-9298-3e22fbb9fe9d', '08:12:40', '1 year 2 months 3 days', '{"customer": "John Doe", "items": {"product": "Beer","qty": 6}}', '{"product": "Beer","qty": 6}', NULL, 'happy','{}', '{}', '{}', '{-1, 0, 1}', '{-1, 0, 1123}', '{-9223372036854775808, 9223372036854775807}', 'str_citext');
68-
INSERT INTO test_types VALUES ('2000-02-28', '2000-02-28 12:00:10', '2000-02-28 12:00:10-04', 1, 0, 3.1415926535, 521.34, 'bb', 'b', 'bb', '86b49b84-96b2-11eb-9298-3e22fbb9fe9d', NULL, '2 weeks ago', '{"customer": "Lily Bush", "items": {"product": "Diaper","qty": 24}}', '{"product": "Diaper","qty": 24}', 'Здра́вствуйте', 'very happy', NULL, NULL, NULL, '{}', '{}', '{}', '');
69-
INSERT INTO test_types VALUES ('2038-01-18', '2038-01-18 23:59:59', '2038-01-18 23:59:59+08', 2, 9223372036854775807, 2.71, 999.99, 'ccc', NULL, 'c', '86b49c42-96b2-11eb-9298-3e22fbb9fe9d', '23:00:10', '3 months 2 days ago', '{"customer": "Josh William", "items": {"product": "Toy Car","qty": 1}}', '{"product": "Toy Car","qty": 1}', '', 'ecstatic', '{123.123}', '{-1e-307, 1e308}', '{521.34}', '{-32768, 32767}', '{-2147483648, 2147483647}', '{0}', 's');
70-
INSERT INTO test_types VALUES (NULL, NULL, NULL, 3, NULL, 0.00, -1e-37, NULL, 'd', 'defghijklm', NULL, '18:30:00', '3 year', NULL, NULL, '😜', NULL, '{-1e-37, 1e37}', '{0.000234, -12.987654321}', '{0.12, 333.33, 22.22}', NULL, NULL, NULL, NULL);
70+
INSERT INTO test_types VALUES ('1970-01-01', '1970-01-01 00:00:01', '1970-01-01 00:00:01-00', 0, -9223372036854775808, NULL, NULL, 'a', 'a', NULL, '86b494cc-96b2-11eb-9298-3e22fbb9fe9d', '08:12:40', '1 year 2 months 3 days', '{"customer": "John Doe", "items": {"product": "Beer","qty": 6}}', '{"product": "Beer","qty": 6}', NULL, 'happy','{}', '{}', '{}', '{-1, 0, 1}', '{-1, 0, 1123}', '{-9223372036854775808, 9223372036854775807}', 'str_citext', 'A.B.C.D');
71+
INSERT INTO test_types VALUES ('2000-02-28', '2000-02-28 12:00:10', '2000-02-28 12:00:10-04', 1, 0, 3.1415926535, 521.34, 'bb', 'b', 'bb', '86b49b84-96b2-11eb-9298-3e22fbb9fe9d', NULL, '2 weeks ago', '{"customer": "Lily Bush", "items": {"product": "Diaper","qty": 24}}', '{"product": "Diaper","qty": 24}', 'Здра́вствуйте', 'very happy', NULL, NULL, NULL, '{}', '{}', '{}', '', 'A.B.E');
72+
INSERT INTO test_types VALUES ('2038-01-18', '2038-01-18 23:59:59', '2038-01-18 23:59:59+08', 2, 9223372036854775807, 2.71, 999.99, 'ccc', NULL, 'c', '86b49c42-96b2-11eb-9298-3e22fbb9fe9d', '23:00:10', '3 months 2 days ago', '{"customer": "Josh William", "items": {"product": "Toy Car","qty": 1}}', '{"product": "Toy Car","qty": 1}', '', 'ecstatic', '{123.123}', '{-1e-307, 1e308}', '{521.34}', '{-32768, 32767}', '{-2147483648, 2147483647}', '{0}', 's', 'A');
73+
INSERT INTO test_types VALUES (NULL, NULL, NULL, 3, NULL, 0.00, -1e-37, NULL, 'd', 'defghijklm', NULL, '18:30:00', '3 year', NULL, NULL, '😜', NULL, '{-1e-37, 1e37}', '{0.000234, -12.987654321}', '{0.12, 333.33, 22.22}', NULL, NULL, NULL, NULL, NULL);
7174

7275
CREATE OR REPLACE FUNCTION increment(i integer) RETURNS integer AS $$
7376
BEGIN
7477
RETURN i + 1;
7578
END;
76-
$$ LANGUAGE plpgsql;
79+
$$ LANGUAGE plpgsql;

0 commit comments

Comments
 (0)