Repository navigation
Expand file tree
/
Copy patharrow_stream.rs
More file actions
244 lines (209 loc) · 8.31 KB
/
Copy patharrow_stream.rs
File metadata and controls
244 lines (209 loc) · 8.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//! Tests for Arrow streaming functionality.
//!
//! Note: These tests focus on error handling and API correctness since we don't have
//! actual Arrow handles to test with. The Arrow handles would typically come from
//! Arrow C++ or other Arrow implementations.
use chdb_rust::arrow_stream::{ArrowArray, ArrowSchema, ArrowStream};
use chdb_rust::connection::Connection;
use chdb_rust::error::Error;
#[test]
fn test_arrow_stream_wrapper() {
// Test creating ArrowStream from null pointer
let stream = unsafe { ArrowStream::from_raw(std::ptr::null_mut()) };
assert!(stream.as_raw().is_null());
// Test that we can clone and copy
let stream2 = stream;
assert_eq!(stream.as_raw(), stream2.as_raw());
}
#[test]
fn test_arrow_schema_wrapper() {
// Test creating ArrowSchema from null pointer
let null_ptr = std::ptr::null_mut();
let schema = unsafe { ArrowSchema::from_raw(null_ptr) };
assert!(schema.as_raw().is_null());
// Test that we can clone and copy
let schema2 = schema;
assert_eq!(schema.as_raw(), schema2.as_raw());
}
#[test]
fn test_arrow_array_wrapper() {
// Test creating ArrowArray from null pointer
let null_ptr = std::ptr::null_mut();
let array = unsafe { ArrowArray::from_raw(null_ptr) };
assert!(array.as_raw().is_null());
// Test that we can clone and copy
let array2 = array;
assert_eq!(array.as_raw(), array2.as_raw());
}
#[test]
fn test_register_arrow_stream_invalid_table_name() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_stream = unsafe { ArrowStream::from_raw(std::ptr::null_mut()) };
// Test with null byte in table name (should fail)
let result = conn.register_arrow_stream("table\0name", &null_stream);
assert!(result.is_err());
match result {
Err(Error::Nul(_)) => {}
Err(e) => panic!("Expected Nul error, got {:?}", e),
Ok(_) => panic!("Expected error for null byte in table name"),
}
}
#[test]
fn test_register_arrow_stream_with_null_handle() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_stream = unsafe { ArrowStream::from_raw(std::ptr::null_mut()) };
// This will likely fail because the stream handle is null
// The actual behavior depends on the chDB library, but we should handle it gracefully
let result = conn.register_arrow_stream("test_table", &null_stream);
// The function may succeed or fail depending on chDB's validation
// We just ensure it doesn't panic
let _ = result;
}
#[test]
fn test_register_arrow_array_invalid_table_name() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_schema = unsafe { ArrowSchema::from_raw(std::ptr::null_mut()) };
let null_array = unsafe { ArrowArray::from_raw(std::ptr::null_mut()) };
// Test with null byte in table name (should fail)
let result = conn.register_arrow_array("table\0name", &null_schema, &null_array);
assert!(result.is_err());
match result {
Err(Error::Nul(_)) => {}
Err(e) => panic!("Expected Nul error, got {:?}", e),
Ok(_) => panic!("Expected error for null byte in table name"),
}
}
#[test]
fn test_register_arrow_array_with_null_handles() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_schema = unsafe { ArrowSchema::from_raw(std::ptr::null_mut()) };
let null_array = unsafe { ArrowArray::from_raw(std::ptr::null_mut()) };
// This will likely fail because the handles are null
// The actual behavior depends on the chDB library, but we should handle it gracefully
let result = conn.register_arrow_array("test_table", &null_schema, &null_array);
// The function may succeed or fail depending on chDB's validation
// We just ensure it doesn't panic
let _ = result;
}
#[test]
fn test_unregister_arrow_table_invalid_table_name() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
// Test with null byte in table name (should fail)
let result = conn.unregister_arrow_table("table\0name");
assert!(result.is_err());
match result {
Err(Error::Nul(_)) => {}
Err(e) => panic!("Expected Nul error, got {:?}", e),
Ok(_) => panic!("Expected error for null byte in table name"),
}
}
#[test]
fn test_unregister_nonexistent_table() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
// Try to unregister a table that was never registered
// The chDB library may succeed silently or return an error
// We just ensure it doesn't panic
let result = conn.unregister_arrow_table("nonexistent_table_12345");
// Accept either success or error - both are valid behaviors
match result {
Ok(_) => {
// Library allows unregistering nonexistent tables
}
Err(Error::QueryError(_)) => {
// Library returns an error for nonexistent tables
}
Err(e) => panic!("Unexpected error type: {:?}", e),
}
}
#[test]
fn test_arrow_stream_send() {
// Test that ArrowStream implements Send
use std::thread;
let stream = unsafe { ArrowStream::from_raw(std::ptr::null_mut()) };
thread::spawn(move || {
let _ = stream;
})
.join()
.expect("Thread should complete");
}
#[test]
fn test_arrow_schema_send() {
// Test that ArrowSchema implements Send
use std::thread;
let null_ptr = std::ptr::null_mut();
let schema = unsafe { ArrowSchema::from_raw(null_ptr) };
thread::spawn(move || {
let _ = schema;
})
.join()
.expect("Thread should complete");
}
#[test]
fn test_arrow_array_send() {
// Test that ArrowArray implements Send
use std::thread;
let null_ptr = std::ptr::null_mut();
let array = unsafe { ArrowArray::from_raw(null_ptr) };
thread::spawn(move || {
let _ = array;
})
.join()
.expect("Thread should complete");
}
#[test]
fn test_arrow_stream_valid_table_names() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_stream = unsafe { ArrowStream::from_raw(std::ptr::null_mut()) };
// Test various valid table names (they may fail due to null handle, but shouldn't fail on name validation)
let valid_names = [
"simple_table",
"table_with_underscores",
"TableWithCamelCase",
"table123",
"a",
"very_long_table_name_with_many_characters_that_should_still_be_valid",
];
for name in &valid_names {
let result = conn.register_arrow_stream(name, &null_stream);
// May fail due to null handle, but shouldn't fail on name validation
let _ = result;
}
}
#[test]
fn test_arrow_array_valid_table_names() {
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_schema = unsafe { ArrowSchema::from_raw(std::ptr::null_mut()) };
let null_array = unsafe { ArrowArray::from_raw(std::ptr::null_mut()) };
// Test various valid table names
let valid_names = [
"simple_table",
"table_with_underscores",
"TableWithCamelCase",
"table123",
];
for name in &valid_names {
let result = conn.register_arrow_array(name, &null_schema, &null_array);
// May fail due to null handles, but shouldn't fail on name validation
let _ = result;
}
}
#[test]
fn test_connection_methods_consistency() {
// Test that all three methods use consistent error handling
let conn = Connection::open_in_memory().expect("Failed to create connection");
let null_stream = unsafe { ArrowStream::from_raw(std::ptr::null_mut()) };
let null_schema = unsafe { ArrowSchema::from_raw(std::ptr::null_mut()) };
let null_array = unsafe { ArrowArray::from_raw(std::ptr::null_mut()) };
// All should handle null bytes consistently
let result1 = conn.register_arrow_stream("test\0", &null_stream);
let result2 = conn.register_arrow_array("test\0", &null_schema, &null_array);
let result3 = conn.unregister_arrow_table("test\0");
assert!(result1.is_err());
assert!(result2.is_err());
assert!(result3.is_err());
// All should be Nul errors
match (result1, result2, result3) {
(Err(Error::Nul(_)), Err(Error::Nul(_)), Err(Error::Nul(_))) => {}
_ => panic!("All should return Nul errors for null bytes"),
}
}