Skip to content

Commit ce460ad

Browse files
committed
Update calamine
Closes #317
1 parent 9bba5a9 commit ce460ad

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ categories = ["database"]
2121
[workspace.dependencies]
2222
arrow = { version = "55", default-features = false }
2323
bindgen = { version = "0.71.1", default-features = false }
24-
calamine = "0.22.0"
24+
calamine = "0.28.0"
2525
cast = "0.3"
2626
cc = "1.0"
2727
chrono = { version = "0.4.22", default-features = false, features = [

crates/duckdb/src/vtab/excel.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use std::sync::atomic::{self, AtomicUsize};
22

33
use super::{BindInfo, DataChunkHandle, InitInfo, LogicalTypeHandle, TableFunctionInfo, VTab};
44
use crate::core::{Inserter, LogicalTypeId};
5-
use calamine::{open_workbook_auto, DataType, Range, Reader};
5+
use calamine::{open_workbook_auto, Data, DataType, Range, Reader};
66

77
#[repr(C)]
88
struct ExcelBindData {
9-
range: Range<DataType>,
9+
range: Range<Data>,
1010
width: usize,
1111
height: usize,
1212
}
@@ -35,7 +35,7 @@ impl VTab for ExcelVTab {
3535
let mut workbook = open_workbook_auto(path)?;
3636
let range = workbook
3737
.worksheet_range(&sheet)
38-
.unwrap_or_else(|| panic!("Can't find sheet: {sheet} ?"))?;
38+
.unwrap_or_else(|_| panic!("Can't find sheet: {sheet} ?"));
3939
let _column_count = range.get_size().1;
4040
let mut rows = range.rows();
4141
let header = rows.next().unwrap();
@@ -44,7 +44,7 @@ impl VTab for ExcelVTab {
4444
let mut found = true;
4545
for cell in data.iter() {
4646
match cell {
47-
DataType::Error(_) | DataType::Empty => {
47+
Data::Error(_) | Data::Empty => {
4848
found = false;
4949
break;
5050
}
@@ -58,39 +58,39 @@ impl VTab for ExcelVTab {
5858
// use the first row as data type
5959
for (idx, cell) in data.iter().enumerate() {
6060
match cell {
61-
DataType::String(_) => {
61+
Data::String(_) => {
6262
bind.add_result_column(
6363
header[idx]
6464
.get_string()
6565
.unwrap_or_else(|| panic!("idx {idx} header empty?")),
6666
LogicalTypeHandle::from(LogicalTypeId::Varchar),
6767
);
6868
}
69-
DataType::Float(_) => {
69+
Data::Float(_) => {
7070
bind.add_result_column(
7171
header[idx]
7272
.get_string()
7373
.unwrap_or_else(|| panic!("idx {idx} header empty?")),
7474
LogicalTypeHandle::from(LogicalTypeId::Double),
7575
);
7676
}
77-
DataType::Int(_) => {
77+
Data::Int(_) => {
7878
bind.add_result_column(
7979
header[idx]
8080
.get_string()
8181
.unwrap_or_else(|| panic!("idx {idx} header empty?")),
8282
LogicalTypeHandle::from(LogicalTypeId::Bigint),
8383
);
8484
}
85-
DataType::Bool(_) => {
85+
Data::Bool(_) => {
8686
bind.add_result_column(
8787
header[idx]
8888
.get_string()
8989
.unwrap_or_else(|| panic!("idx {idx} header empty?")),
9090
LogicalTypeHandle::from(LogicalTypeId::Boolean),
9191
);
9292
}
93-
DataType::DateTime(_) => {
93+
Data::DateTime(_) => {
9494
bind.add_result_column(
9595
header[idx]
9696
.get_string()
@@ -133,20 +133,21 @@ impl VTab for ExcelVTab {
133133
continue;
134134
}
135135
match cell.unwrap() {
136-
DataType::String(s) => {
136+
Data::String(s) => {
137137
vector.insert(j, s.as_str());
138138
}
139-
DataType::Float(f) => {
139+
Data::Float(f) => {
140140
vector.as_mut_slice::<f64>()[j] = *f;
141141
}
142-
DataType::Int(ii) => {
142+
Data::Int(ii) => {
143143
vector.as_mut_slice::<i64>()[j] = *ii;
144144
}
145-
DataType::Bool(b) => {
145+
Data::Bool(b) => {
146146
vector.as_mut_slice::<bool>()[j] = *b;
147147
}
148-
DataType::DateTime(d) => {
149-
vector.as_mut_slice::<i32>()[j] = d.round() as i32 - 25569;
148+
Data::DateTime(d) => {
149+
// 25569 = number of days between Unix and Excel epochs
150+
vector.as_mut_slice::<i32>()[j] = d.as_f64().round() as i32 - 25569;
150151
}
151152
_ => {
152153
vector.set_null(j);

0 commit comments

Comments
 (0)