Skip to content

Commit 6066588

Browse files
author
longshan.lu
committed
docs: update CONTRIBUTING.md and Postgres documentation; enhance Postgres transport type conversions
- Added instructions for running the project in a VSCode dev-container in CONTRIBUTING.md. - Updated Postgres documentation to include support for Inet, Vector, HalfVec, Bit, and SparseVec types. - Modified type conversion implementations in Postgres transport to use 'option' for Vector, HalfVec, Bit, and SparseVec types.
1 parent 344c5e9 commit 6066588

File tree

5 files changed

+50
-79
lines changed

5 files changed

+50
-79
lines changed

CONTRIBUTING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,38 @@ This doc describes how you can get started at developing ConnectorX.
99
Please check out [here](https://sfu-db.github.io/connector-x/install.html#build-from-source-code)
1010

1111

12+
### Run In Vscode Dev-Container
13+
14+
1. Install required tools:
15+
- [Docker](https://docs.docker.com/get-docker/)
16+
- [VSCode](https://code.visualstudio.com/)
17+
- [VSCode Remote - Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
18+
19+
2. Clone the repository and open it in VSCode:
20+
```bash
21+
git clone https://github.com/sfu-db/connector-x.git
22+
code connector-x
23+
```
24+
25+
3. When prompted, click "Reopen in Container" or use the command palette (F1) and select "Remote-Containers: Reopen in Container"
26+
27+
4. The dev container includes:
28+
- Rust development environment with rust-analyzer
29+
- PostgreSQL (pgvector) running on port 5433
30+
- MySQL running on port 3306
31+
- All necessary build tools and dependencies
32+
33+
5. The container will automatically:
34+
- Mount your local repository into the container
35+
- Install Rust toolchain and dependencies
36+
- Configure rust-analyzer with clippy for code analysis
37+
- Set up the development workspace
38+
39+
6. You can now start developing with:
40+
- Full Rust development support
41+
- Integrated database services
42+
- All development tools pre-configured
43+
1244
### Run tests
1345

1446
* Set up environment variables by creating a `.env` file under project directory. Here is an example:

connectorx-python/src/pandas/transports/postgres.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ macro_rules! impl_postgres_transport {
5858
{ UUID[Uuid] => String[String] | conversion option }
5959
{ JSON[Value] => String[String] | conversion option }
6060
{ JSONB[Value] => String[String] | conversion none }
61-
{ Inet[IpInet] => String[String] | conversion none }
61+
{ Inet[IpInet] => String[String] | conversion option }
6262
{ Time[NaiveTime] => String[String] | conversion option }
6363
{ ByteA[Vec<u8>] => Bytes[Vec<u8>] | conversion auto }
6464
{ Enum[&'r str] => Str[&'r str] | conversion none }
@@ -77,7 +77,6 @@ impl_postgres_transport!(CursorProtocol, MakeTlsConnector);
7777
impl_postgres_transport!(SimpleProtocol, NoTls);
7878
impl_postgres_transport!(SimpleProtocol, MakeTlsConnector);
7979

80-
8180
impl<'py, P, C> TypeConversion<Vector, Vec<f64>> for PostgresPandasTransport<'py, P, C> {
8281
fn convert(val: Vector) -> Vec<f64> {
8382
val.to_vec().into_iter().map(|v| v as f64).collect()
@@ -108,14 +107,6 @@ impl<'py, P, C> TypeConversion<IpInet, String> for PostgresPandasTransport<'py,
108107
}
109108
}
110109

111-
impl<'py, P, C> TypeConversion<Option<IpInet>, Option<String>>
112-
for PostgresPandasTransport<'py, P, C>
113-
{
114-
fn convert(val: Option<IpInet>) -> Option<String> {
115-
val.map(|val| val.to_string())
116-
}
117-
}
118-
119110
impl<'py, P, C> TypeConversion<HashMap<String, Option<String>>, String>
120111
for PostgresPandasTransport<'py, P, C>
121112
{
@@ -147,7 +138,7 @@ impl<'py, P, C> TypeConversion<Vec<Option<bool>>, Vec<bool>>
147138
fn convert(val: Vec<Option<bool>>) -> Vec<bool> {
148139
val.into_iter()
149140
.map(|v| match v {
150-
Some(v) => v as bool,
141+
Some(v) => v,
151142
None => {
152143
unimplemented!("In-array nullable not implemented for Vec<bool> for Pandas")
153144
}
@@ -173,7 +164,7 @@ impl<'py, P, C> TypeConversion<Vec<Option<f64>>, Vec<f64>> for PostgresPandasTra
173164
fn convert(val: Vec<Option<f64>>) -> Vec<f64> {
174165
val.into_iter()
175166
.map(|v| match v {
176-
Some(v) => v as f64,
167+
Some(v) => v,
177168
None => {
178169
unimplemented!("In-array nullable not implemented for Vec<f64> for Pandas")
179170
}
@@ -212,7 +203,7 @@ impl<'py, P, C> TypeConversion<Vec<Option<i64>>, Vec<i64>> for PostgresPandasTra
212203
fn convert(val: Vec<Option<i64>>) -> Vec<i64> {
213204
val.into_iter()
214205
.map(|v| match v {
215-
Some(v) => v as i64,
206+
Some(v) => v,
216207
None => {
217208
unimplemented!("In-array nullable not implemented for Vec<i64> for Pandas")
218209
}

connectorx/src/transports/postgres_arrow.rs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ macro_rules! impl_postgres_transport {
7777
{ Float4Array[Vec<Option<f32>>] => Float32Array[Vec<Option<f32>>] | conversion auto }
7878
{ Float8Array[Vec<Option<f64>>] => Float64Array[Vec<Option<f64>>] | conversion auto }
7979
{ NumericArray[Vec<Option<Decimal>>] => DecimalArray[Vec<Option<Decimal>>] | conversion auto }
80-
{ Vector[Vector] => Float32Array[Vec<Option<f32>>] | conversion none }
81-
{ HalfVec[HalfVector] => Float32Array[Vec<Option<f32>>] | conversion none }
82-
{ Bit[Bit] => LargeBinary[Vec<u8>] | conversion none }
83-
{ SparseVec[SparseVector] => Float32Array[Vec<Option<f32>>] | conversion none }
80+
{ Vector[Vector] => Float32Array[Vec<Option<f32>>] | conversion option }
81+
{ HalfVec[HalfVector] => Float32Array[Vec<Option<f32>>] | conversion option }
82+
{ Bit[Bit] => LargeBinary[Vec<u8>] | conversion option }
83+
{ SparseVec[SparseVector] => Float32Array[Vec<Option<f32>>] | conversion option }
8484
}
8585
);
8686
}
@@ -152,50 +152,23 @@ impl<P, C> TypeConversion<Vector, Vec<Option<f32>>> for PostgresArrowTransport<P
152152
}
153153
}
154154

155-
impl<P, C> TypeConversion<Option<Vector>, Option<Vec<Option<f32>>>>
156-
for PostgresArrowTransport<P, C>
157-
{
158-
fn convert(val: Option<Vector>) -> Option<Vec<Option<f32>>> {
159-
val.map(|val| val.to_vec().into_iter().map(Some).collect())
160-
}
161-
}
162155

163156
impl<P, C> TypeConversion<HalfVector, Vec<Option<f32>>> for PostgresArrowTransport<P, C> {
164157
fn convert(val: HalfVector) -> Vec<Option<f32>> {
165158
val.to_vec().into_iter().map(|v| Some(v.to_f32())).collect()
166159
}
167160
}
168161

169-
impl<P, C> TypeConversion<Option<HalfVector>, Option<Vec<Option<f32>>>>
170-
for PostgresArrowTransport<P, C>
171-
{
172-
fn convert(val: Option<HalfVector>) -> Option<Vec<Option<f32>>> {
173-
val.map(|val| val.to_vec().into_iter().map(|v| Some(v.to_f32())).collect())
174-
}
175-
}
176162

177163
impl<P, C> TypeConversion<Bit, Vec<u8>> for PostgresArrowTransport<P, C> {
178164
fn convert(val: Bit) -> Vec<u8> {
179165
val.as_bytes().into()
180166
}
181167
}
182168

183-
impl<P, C> TypeConversion<Option<Bit>, Option<Vec<u8>>> for PostgresArrowTransport<P, C> {
184-
fn convert(val: Option<Bit>) -> Option<Vec<u8>> {
185-
val.map(|val| val.as_bytes().into())
186-
}
187-
}
188169

189170
impl<P, C> TypeConversion<SparseVector, Vec<Option<f32>>> for PostgresArrowTransport<P, C> {
190171
fn convert(val: SparseVector) -> Vec<Option<f32>> {
191172
val.to_vec().into_iter().map(Some).collect()
192173
}
193174
}
194-
195-
impl<P, C> TypeConversion<Option<SparseVector>, Option<Vec<Option<f32>>>>
196-
for PostgresArrowTransport<P, C>
197-
{
198-
fn convert(val: Option<SparseVector>) -> Option<Vec<Option<f32>>> {
199-
val.map(|val| val.to_vec().into_iter().map(Some).collect())
200-
}
201-
}

connectorx/src/transports/postgres_arrowstream.rs

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ macro_rules! impl_postgres_transport {
6363
{ JSON[Value] => LargeUtf8[String] | conversion option }
6464
{ JSONB[Value] => LargeUtf8[String] | conversion none }
6565
{ Inet[IpInet] => LargeUtf8[String] | conversion none }
66-
{ Vector[Vector] => Float32Array[Vec<Option<f32>>] | conversion none }
67-
{ HalfVec[HalfVector] => Float32Array[Vec<Option<f32>>] | conversion none }
68-
{ Bit[Bit] => LargeBinary[Vec<u8>] | conversion none }
69-
{ SparseVec[SparseVector] => Float32Array[Vec<Option<f32>>] | conversion none }
66+
{ Vector[Vector] => Float32Array[Vec<Option<f32>>] | conversion option }
67+
{ HalfVec[HalfVector] => Float32Array[Vec<Option<f32>>] | conversion option }
68+
{ Bit[Bit] => LargeBinary[Vec<u8>] | conversion option }
69+
{ SparseVec[SparseVector] => Float32Array[Vec<Option<f32>>] | conversion option }
7070
}
7171
);
7272
}
@@ -111,50 +111,20 @@ impl<P, C> TypeConversion<Vector, Vec<Option<f32>>> for PostgresArrowTransport<P
111111
}
112112
}
113113

114-
impl<P, C> TypeConversion<Option<Vector>, Option<Vec<Option<f32>>>>
115-
for PostgresArrowTransport<P, C>
116-
{
117-
fn convert(val: Option<Vector>) -> Option<Vec<Option<f32>>> {
118-
val.map(|val| val.to_vec().into_iter().map(Some).collect())
119-
}
120-
}
121-
122114
impl<P, C> TypeConversion<HalfVector, Vec<Option<f32>>> for PostgresArrowTransport<P, C> {
123115
fn convert(val: HalfVector) -> Vec<Option<f32>> {
124116
val.to_vec().into_iter().map(|v| Some(v.to_f32())).collect()
125117
}
126118
}
127119

128-
impl<P, C> TypeConversion<Option<HalfVector>, Option<Vec<Option<f32>>>>
129-
for PostgresArrowTransport<P, C>
130-
{
131-
fn convert(val: Option<HalfVector>) -> Option<Vec<Option<f32>>> {
132-
val.map(|val| val.to_vec().into_iter().map(|v| Some(v.to_f32())).collect())
133-
}
134-
}
135-
136120
impl<P, C> TypeConversion<Bit, Vec<u8>> for PostgresArrowTransport<P, C> {
137121
fn convert(val: Bit) -> Vec<u8> {
138122
val.as_bytes().into()
139123
}
140124
}
141125

142-
impl<P, C> TypeConversion<Option<Bit>, Option<Vec<u8>>> for PostgresArrowTransport<P, C> {
143-
fn convert(val: Option<Bit>) -> Option<Vec<u8>> {
144-
val.map(|val| val.as_bytes().into())
145-
}
146-
}
147-
148126
impl<P, C> TypeConversion<SparseVector, Vec<Option<f32>>> for PostgresArrowTransport<P, C> {
149127
fn convert(val: SparseVector) -> Vec<Option<f32>> {
150128
val.to_vec().into_iter().map(Some).collect()
151129
}
152-
}
153-
154-
impl<P, C> TypeConversion<Option<SparseVector>, Option<Vec<Option<f32>>>>
155-
for PostgresArrowTransport<P, C>
156-
{
157-
fn convert(val: Option<SparseVector>) -> Option<Vec<Option<f32>>> {
158-
val.map(|val| val.to_vec().into_iter().map(Some).collect())
159-
}
160-
}
130+
}

docs/databases/postgres.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ cx.read_sql(conn, query) # read data from
4646
| ltree | object | binary protocol supported only after Postgres version 13 |
4747
| lquery | object | binary protocol supported only after Postgres version 13 |
4848
| ltxtquery | object | binary protocol supported only after Postgres version 13 |
49+
| Inet | object | |
50+
| Vector | object | list of f32 |
51+
| HalfVec | object | list of f32 |
52+
| Bit | object | |
53+
| SparseVec | object | list of f32 |
4954
| INT2[] | object | list of i64 |
5055
| INT4[] | object | list of i64 |
5156
| INT8[] | object | list of i64 |

0 commit comments

Comments
 (0)