Skip to content
This repository was archived by the owner on Dec 29, 2021. It is now read-only.

Commit f48ce45

Browse files
committed
remove unsused code
1 parent 69e7e92 commit f48ce45

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

src/io/postgres.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use chrono::Timelike;
77
use postgres::types::*;
88
use postgres::{Client, NoTls, Row};
99

10+
/// Convert Postgres Type to Arrow DataType
11+
///
12+
/// Not all types are covered, but can be easily added
1013
fn pg_to_arrow_type(dt: &Type) -> Option<DataType> {
1114
match dt {
1215
&Type::BOOL => Some(DataType::Boolean),
@@ -60,24 +63,6 @@ fn pg_to_arrow_type(dt: &Type) -> Option<DataType> {
6063
}
6164
}
6265

63-
fn from_field(f: &Field, capacity: usize) -> Box<ArrayBuilder> {
64-
match f.data_type() {
65-
DataType::Boolean => Box::new(BooleanBuilder::new(capacity)),
66-
DataType::Int8 => Box::new(Int8Builder::new(capacity)),
67-
DataType::Int16 => Box::new(Int16Builder::new(capacity)),
68-
DataType::Int32 => Box::new(Int32Builder::new(capacity)),
69-
DataType::Int64 => Box::new(Int64Builder::new(capacity)),
70-
DataType::UInt8 => Box::new(UInt8Builder::new(capacity)),
71-
DataType::UInt16 => Box::new(UInt16Builder::new(capacity)),
72-
DataType::UInt32 => Box::new(UInt32Builder::new(capacity)),
73-
DataType::UInt64 => Box::new(UInt64Builder::new(capacity)),
74-
DataType::Float32 => Box::new(Float32Builder::new(capacity)),
75-
DataType::Float64 => Box::new(Float64Builder::new(capacity)),
76-
DataType::Utf8 => Box::new(BinaryBuilder::new(capacity)),
77-
t @ _ => panic!("Data type {:?} is not currently supported", t),
78-
}
79-
}
80-
8166
// TODO can make this a common trait for DB sources
8267
pub fn read_table(
8368
connection_string: &str,
@@ -105,14 +90,20 @@ pub fn read_table(
10590
let field_builder = builder.field_builder::<Int32Builder>(j).unwrap();
10691
for i in 0..chunk.len() {
10792
let row: &Row = chunk.get(i).unwrap();
108-
field_builder.append_value(row.get(j)).unwrap();
93+
match row.try_get(j) {
94+
Ok(value) => field_builder.append_value(value).unwrap(),
95+
Err(_) => field_builder.append_null().unwrap(),
96+
};
10997
}
11098
}
11199
DataType::Int64 => {
112100
let field_builder = builder.field_builder::<Int64Builder>(j).unwrap();
113101
for i in 0..chunk.len() {
114102
let row: &Row = chunk.get(i).unwrap();
115-
field_builder.append_value(row.get(j)).unwrap();
103+
match row.try_get(j) {
104+
Ok(value) => field_builder.append_value(value).unwrap(),
105+
Err(_) => field_builder.append_null().unwrap(),
106+
};
116107
}
117108
}
118109
DataType::Timestamp(TimeUnit::Millisecond) => {
@@ -160,13 +151,12 @@ pub fn read_table(
160151
}
161152
}
162153
builder.append(true).unwrap();
163-
batches.push(builder.finish().flatten());
154+
batches.push(RecordBatch::from(&builder.finish()));
164155
});
165156
Ok(batches)
166157
}
167158

168-
fn populate_builder() {}
169-
159+
/// Generate Arrow schema from a row
170160
fn row_to_schema(row: &postgres::Row) -> Result<Schema, ()> {
171161
let fields = row
172162
.columns()

0 commit comments

Comments
 (0)