Skip to content
This repository was archived by the owner on May 5, 2024. It is now read-only.

Commit fc734aa

Browse files
committed
feat: add basic map support
1 parent 7fcfe30 commit fc734aa

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::duckly::*;
22

3-
#[derive(num_derive::FromPrimitive)]
3+
#[derive(Debug, Eq, PartialEq, num_derive::FromPrimitive)]
44
pub enum DuckDBType {
55
Boolean = DUCKDB_TYPE_DUCKDB_TYPE_BOOLEAN as isize,
66
Tinyint = DUCKDB_TYPE_DUCKDB_TYPE_TINYINT as isize,

src/logical_type.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::constants::DuckDBType;
22
use crate::duckly::{
3-
duckdb_create_logical_type, duckdb_destroy_logical_type, duckdb_get_type_id,
4-
duckdb_logical_type,
3+
duckdb_create_logical_type, duckdb_create_map_type, duckdb_destroy_logical_type,
4+
duckdb_get_type_id, duckdb_logical_type,
55
};
66
use num_traits::FromPrimitive;
77

@@ -18,12 +18,26 @@ impl LogicalType {
1818
}
1919
}
2020
}
21+
pub fn new_map_type(key: &LogicalType, value: &LogicalType) -> Self {
22+
unsafe {
23+
Self {
24+
typ: duckdb_create_map_type(key.typ, value.typ),
25+
}
26+
}
27+
}
2128
pub fn type_id(&self) -> DuckDBType {
2229
let id = unsafe { duckdb_get_type_id(self.typ) };
2330

2431
FromPrimitive::from_u32(id).unwrap()
2532
}
2633
}
34+
impl Clone for LogicalType {
35+
fn clone(&self) -> Self {
36+
let type_id = self.type_id();
37+
38+
Self::new(type_id)
39+
}
40+
}
2741

2842
impl From<duckdb_logical_type> for LogicalType {
2943
fn from(ptr: duckdb_logical_type) -> Self {
@@ -38,3 +52,19 @@ impl Drop for LogicalType {
3852
}
3953
}
4054
}
55+
56+
#[cfg(test)]
57+
mod test {
58+
use crate::constants::DuckDBType;
59+
use crate::LogicalType;
60+
#[test]
61+
fn test_logi() {
62+
let key = LogicalType::new(DuckDBType::Varchar);
63+
64+
let value = LogicalType::new(DuckDBType::Utinyint);
65+
66+
let map = LogicalType::new_map_type(&key, &value);
67+
68+
assert_eq!(map.type_id(), DuckDBType::Map);
69+
}
70+
}

0 commit comments

Comments
 (0)