Skip to content

Commit 3dcf6ca

Browse files
authored
refactor: split value.rs (#711)
1 parent 98a07d2 commit 3dcf6ca

File tree

10 files changed

+2435
-2331
lines changed

10 files changed

+2435
-2331
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
199
2-
2020,4,12,1,2,2020-12-01,9E,20363,9E,N315PQ,4628,11193,1119302,33105,CVG,"Cincinnati, OH",KY,21,Kentucky,52,10721,1072102,30721,BOS,"Boston, MA",MA,25,Massachusetts,13,730,851,81,81,1,5,0700-0759,60,951,1127,6,939,1133,114,114,1,7,0900-0959,0,NULL,0,129,162,96,1,752,4,0,81,33,0,0,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL

cli/tests/http/03-load_file_gzip.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ ${BENDSQL} \
1212
--data=@cli/tests/data/ontime_200.csv.gz
1313

1414
echo "SELECT COUNT(*) FROM http_ontime_03;" | ${BENDSQL} --output=tsv
15-
echo 'SELECT * FROM http_ontime_03 LIMIT 1;' | ${BENDSQL} --output=csv
1615

1716
cat <<SQL | ${BENDSQL}
1817
DROP TABLE http_ontime_03;

sql/src/value.rs

Lines changed: 0 additions & 2329 deletions
This file was deleted.

sql/src/value/arrow_decoder.rs

Lines changed: 416 additions & 0 deletions
Large diffs are not rendered by default.

sql/src/value/base.rs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright 2021 Datafuse Labs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use arrow_buffer::i256;
16+
use chrono::{DateTime, FixedOffset};
17+
use chrono_tz::Tz;
18+
use databend_client::schema::{DataType, DecimalDataType, DecimalSize, NumberDataType};
19+
20+
// Thu 1970-01-01 is R.D. 719163
21+
pub(crate) const DAYS_FROM_CE: i32 = 719_163;
22+
pub(crate) const TIMESTAMP_FORMAT: &str = "%Y-%m-%d %H:%M:%S%.6f";
23+
pub(crate) const TIMESTAMP_TIMEZONE_FORMAT: &str = "%Y-%m-%d %H:%M:%S%.6f %z";
24+
25+
#[derive(Clone, Debug, PartialEq)]
26+
pub enum NumberValue {
27+
Int8(i8),
28+
Int16(i16),
29+
Int32(i32),
30+
Int64(i64),
31+
UInt8(u8),
32+
UInt16(u16),
33+
UInt32(u32),
34+
UInt64(u64),
35+
Float32(f32),
36+
Float64(f64),
37+
Decimal128(i128, DecimalSize),
38+
Decimal256(i256, DecimalSize),
39+
}
40+
41+
#[derive(Clone, Debug, PartialEq)]
42+
pub enum Value {
43+
Null,
44+
EmptyArray,
45+
EmptyMap,
46+
Boolean(bool),
47+
Binary(Vec<u8>),
48+
String(String),
49+
Number(NumberValue),
50+
/// Microseconds from 1970-01-01 00:00:00 UTC
51+
Timestamp(i64, Tz),
52+
TimestampTz(DateTime<FixedOffset>),
53+
Date(i32),
54+
Array(Vec<Value>),
55+
Map(Vec<(Value, Value)>),
56+
Tuple(Vec<Value>),
57+
Bitmap(String),
58+
Variant(String),
59+
Geometry(String),
60+
Geography(String),
61+
Interval(String),
62+
Vector(Vec<f32>),
63+
}
64+
65+
impl Value {
66+
pub fn get_type(&self) -> DataType {
67+
match self {
68+
Self::Null => DataType::Null,
69+
Self::EmptyArray => DataType::EmptyArray,
70+
Self::EmptyMap => DataType::EmptyMap,
71+
Self::Boolean(_) => DataType::Boolean,
72+
Self::Binary(_) => DataType::Binary,
73+
Self::String(_) => DataType::String,
74+
Self::Number(n) => match n {
75+
NumberValue::Int8(_) => DataType::Number(NumberDataType::Int8),
76+
NumberValue::Int16(_) => DataType::Number(NumberDataType::Int16),
77+
NumberValue::Int32(_) => DataType::Number(NumberDataType::Int32),
78+
NumberValue::Int64(_) => DataType::Number(NumberDataType::Int64),
79+
NumberValue::UInt8(_) => DataType::Number(NumberDataType::UInt8),
80+
NumberValue::UInt16(_) => DataType::Number(NumberDataType::UInt16),
81+
NumberValue::UInt32(_) => DataType::Number(NumberDataType::UInt32),
82+
NumberValue::UInt64(_) => DataType::Number(NumberDataType::UInt64),
83+
NumberValue::Float32(_) => DataType::Number(NumberDataType::Float32),
84+
NumberValue::Float64(_) => DataType::Number(NumberDataType::Float64),
85+
NumberValue::Decimal128(_, s) => DataType::Decimal(DecimalDataType::Decimal128(*s)),
86+
NumberValue::Decimal256(_, s) => DataType::Decimal(DecimalDataType::Decimal256(*s)),
87+
},
88+
Self::Timestamp(_, _) => DataType::Timestamp,
89+
Self::TimestampTz(_) => DataType::TimestampTz,
90+
Self::Date(_) => DataType::Date,
91+
Self::Interval(_) => DataType::Interval,
92+
Self::Array(vals) => {
93+
if vals.is_empty() {
94+
DataType::EmptyArray
95+
} else {
96+
DataType::Array(Box::new(vals[0].get_type()))
97+
}
98+
}
99+
Self::Map(kvs) => {
100+
if kvs.is_empty() {
101+
DataType::EmptyMap
102+
} else {
103+
let inner_ty = DataType::Tuple(vec![kvs[0].0.get_type(), kvs[0].1.get_type()]);
104+
DataType::Map(Box::new(inner_ty))
105+
}
106+
}
107+
Self::Tuple(vals) => {
108+
let inner_tys = vals.iter().map(|v| v.get_type()).collect::<Vec<_>>();
109+
DataType::Tuple(inner_tys)
110+
}
111+
Self::Bitmap(_) => DataType::Bitmap,
112+
Self::Variant(_) => DataType::Variant,
113+
Self::Geometry(_) => DataType::Geometry,
114+
Self::Geography(_) => DataType::Geography,
115+
Self::Vector(v) => DataType::Vector(v.len() as u64),
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)