Skip to content

Commit e413ed2

Browse files
committed
chore: enhance test coverage by adding support for additional ClickHouse data types and updating related tests
1 parent 89fbaaa commit e413ed2

File tree

2 files changed

+105
-5
lines changed

2 files changed

+105
-5
lines changed

wrappers/src/fdw/clickhouse_fdw/clickhouse_fdw.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,14 @@ impl ForeignDataWrapper<ClickHouseFdwError> for ClickHouseFdw {
815815
};
816816
Ok(val)
817817
}
818+
SqlType::UInt64 | SqlType::Nullable(SqlType::UInt64) => {
819+
let val = if is_nullable {
820+
ChValue::from(Some(*v as u64))
821+
} else {
822+
ChValue::from(*v as u64)
823+
};
824+
Ok(val)
825+
}
818826
_ => Err(ClickHouseFdwError::UnsupportedColumnType(
819827
tgt_type.to_string().into(),
820828
)),
@@ -831,9 +839,25 @@ impl ForeignDataWrapper<ClickHouseFdwError> for ClickHouseFdw {
831839
Cell::String(v) => {
832840
let s = v.as_str();
833841

834-
// i256 and u256 are saved as string in Postgres, so we parse it
835-
// back to ClickHouse if target column is Int256 or UInt256
842+
// big integers are saved as string in Postgres, so we parse it
843+
// back to ClickHouse if target column is big integer type
836844
let val = match tgt_col.sql_type() {
845+
SqlType::Int128 | SqlType::Nullable(SqlType::Int128) => {
846+
let v = i128::from_str(s)?;
847+
if is_nullable {
848+
ChValue::from(Some(v))
849+
} else {
850+
ChValue::from(v)
851+
}
852+
}
853+
SqlType::UInt128 | SqlType::Nullable(SqlType::UInt128) => {
854+
let v = u128::from_str(s)?;
855+
if is_nullable {
856+
ChValue::from(Some(v))
857+
} else {
858+
ChValue::from(v)
859+
}
860+
}
837861
SqlType::Int256 | SqlType::Nullable(SqlType::Int256) => {
838862
let v = i256::from_str(s)?;
839863
if is_nullable {

wrappers/src/fdw/clickhouse_fdw/tests.rs

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod tests {
55
use pgrx::prelude::*;
66
use pgrx::{
77
Uuid,
8-
datum::{Timestamp, TimestampWithTimeZone},
8+
datum::{Date, Timestamp, TimestampWithTimeZone},
99
pg_test,
1010
};
1111
use supabase_wrappers::prelude::create_async_runtime;
@@ -42,6 +42,18 @@ mod tests {
4242
u16col Nullable(UInt16),
4343
i32col Nullable(Int32),
4444
u32col Nullable(UInt32),
45+
u64col Nullable(UInt64),
46+
f32col Nullable(Float32),
47+
i128col Nullable(Int128),
48+
u128col Nullable(UInt128),
49+
i256col Nullable(Int256),
50+
u256col Nullable(UInt256),
51+
dtcol Nullable(Date),
52+
arr_bool Array(Bool) default [],
53+
arr_i16 Array(Int16) default [],
54+
arr_i32 Array(Int32) default [],
55+
arr_f32 Array(Float32) default [],
56+
arr_f64 Array(Float64) default [],
4557
created_at DateTime('UTC'),
4658
updated_at DateTime64(6, 'Asia/Singapore')
4759
) engine = Memory",
@@ -66,6 +78,18 @@ mod tests {
6678
u16col UInt16,
6779
i32col Int32,
6880
u32col UInt32,
81+
u64col UInt64,
82+
f32col Float32,
83+
i128col Int128,
84+
u128col UInt128,
85+
i256col Int256,
86+
u256col UInt256,
87+
dtcol Date,
88+
arr_bool Array(Bool) default [],
89+
arr_i16 Array(Int16) default [],
90+
arr_i32 Array(Int32) default [],
91+
arr_f32 Array(Float32) default [],
92+
arr_f64 Array(Float64) default [],
6993
created_at DateTime('UTC'),
7094
updated_at DateTime64(6, 'Asia/Singapore')
7195
) engine = Memory",
@@ -110,6 +134,17 @@ mod tests {
110134
u16col integer,
111135
i32col integer,
112136
u32col bigint,
137+
u64col bigint,
138+
i128col text,
139+
u128col text,
140+
i256col text,
141+
u256col text,
142+
dtcol date,
143+
arr_bool boolean[],
144+
arr_i16 smallint[],
145+
arr_i32 integer[],
146+
arr_f32 real[],
147+
arr_f64 double precision[],
113148
created_at timestamp,
114149
updated_at timestamptz
115150
)
@@ -143,6 +178,17 @@ mod tests {
143178
u16col integer,
144179
i32col integer,
145180
u32col bigint,
181+
u64col bigint,
182+
i128col text,
183+
u128col text,
184+
i256col text,
185+
u256col text,
186+
dtcol date,
187+
arr_bool boolean[],
188+
arr_i16 smallint[],
189+
arr_i32 integer[],
190+
arr_f32 real[],
191+
arr_f64 double precision[],
146192
created_at timestamp,
147193
updated_at timestamptz
148194
)
@@ -176,6 +222,17 @@ mod tests {
176222
u16col integer,
177223
i32col integer,
178224
u32col bigint,
225+
u64col bigint,
226+
i128col text,
227+
u128col text,
228+
i256col text,
229+
u256col text,
230+
dtcol date,
231+
arr_bool boolean[],
232+
arr_i16 smallint[],
233+
arr_i32 integer[],
234+
arr_f32 real[],
235+
arr_f64 double precision[],
179236
created_at timestamp,
180237
updated_at timestamptz
181238
)
@@ -209,6 +266,17 @@ mod tests {
209266
u16col integer,
210267
i32col integer,
211268
u32col bigint,
269+
u64col bigint,
270+
i128col text,
271+
u128col text,
272+
i256col text,
273+
u256col text,
274+
dtcol date,
275+
arr_bool boolean[],
276+
arr_i16 smallint[],
277+
arr_i32 integer[],
278+
arr_f32 real[],
279+
arr_f64 double precision[],
212280
created_at timestamp,
213281
updated_at timestamptz
214282
)
@@ -239,12 +307,14 @@ mod tests {
239307
"INSERT INTO test_table_nn (
240308
id, name, amt, uid, fstr, bignum, dnum,
241309
is_valid, i8col, u8col, i16col, u16col,
242-
i32col, u32col, created_at, updated_at
310+
i32col, u32col, u64col, i128col, u128col, i256col, u256col,
311+
dtcol, created_at, updated_at
243312
)
244313
VALUES (
245314
$1, $2, $3, $4, $5, $6, $7,
246315
$8, $9, $10, $11, $12,
247-
$13, $14, $15, $16
316+
$13, $14, $15, $16, $17, $18, $19, $20,
317+
$21, $22
248318
)",
249319
None,
250320
&[
@@ -262,6 +332,12 @@ mod tests {
262332
10i32.into(),
263333
11i32.into(),
264334
12i64.into(),
335+
13i64.into(),
336+
"123".into(),
337+
"234".into(),
338+
"345".into(),
339+
"456".into(),
340+
Date::new(2025, 1, 1).into(),
265341
Timestamp::new(2025, 5, 2, 3, 4, 5.0).into(),
266342
TimestampWithTimeZone::with_timezone(2025, 5, 2, 3, 4, 5.0, "Asia/Singapore")
267343
.unwrap()

0 commit comments

Comments
 (0)