Skip to content

Commit 63d4e5c

Browse files
authored
feat: support new DataType TimestampTz (#696)
1 parent bf091a9 commit 63d4e5c

File tree

6 files changed

+21
-2
lines changed

6 files changed

+21
-2
lines changed

bindings/nodejs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ impl ToNapiValue for Value<'_> {
339339
String::to_napi_value(env, s.to_string())
340340
}
341341
}
342+
databend_driver::Value::TimestampTz(s) => String::to_napi_value(env, s.to_string()),
342343
databend_driver::Value::Geometry(s) => String::to_napi_value(env, s.to_string()),
343344
databend_driver::Value::Interval(s) => String::to_napi_value(env, s.to_string()),
344345
databend_driver::Value::Geography(s) => String::to_napi_value(env, s.to_string()),

bindings/python/src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ impl<'py> IntoPyObject<'py> for Value {
9999
let tuple = PyTuple::new(py, inner.into_iter().map(Value))?;
100100
tuple.into_bound_py_any(py)?
101101
}
102+
databend_driver::Value::TimestampTz(s) => s.into_bound_py_any(py)?,
102103
databend_driver::Value::Bitmap(s) => s.into_bound_py_any(py)?,
103104
databend_driver::Value::Variant(s) => s.into_bound_py_any(py)?,
104105
databend_driver::Value::Geometry(s) => s.into_bound_py_any(py)?,

cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ clap = { version = "4.5", features = ["derive", "env"] }
2525
comfy-table = "7.1"
2626
csv = "1.3"
2727
ctrlc = { version = "3.4.6", features = ["termination"] }
28-
databend-common-ast = "0.2.1"
28+
databend-common-ast = "0.2.3"
2929
fern = { version = "0.7", features = ["colored"] }
3030
indicatif = "0.17"
3131
log = "0.4"

driver/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tonic = { workspace = true, optional = true }
3838

3939
async-trait = "0.1"
4040
csv = "1.3"
41-
databend-common-ast = "0.2.2"
41+
databend-common-ast = "0.2.3"
4242
derive-visitor = { version = "0.4.0", features = ["std-types-drive"] }
4343
glob = "0.3"
4444
log = "0.4"

sql/src/schema.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub enum DataType {
8787
Number(NumberDataType),
8888
Decimal(DecimalDataType),
8989
Timestamp,
90+
TimestampTz,
9091
Date,
9192
Nullable(Box<DataType>),
9293
Array(Box<DataType>),
@@ -137,6 +138,7 @@ impl std::fmt::Display for DataType {
137138
write!(f, "Decimal({}, {})", size.precision, size.scale)
138139
}
139140
DataType::Timestamp => write!(f, "Timestamp"),
141+
DataType::TimestampTz => write!(f, "TimestampTz"),
140142
DataType::Date => write!(f, "Date"),
141143
DataType::Nullable(inner) => write!(f, "Nullable({inner})"),
142144
DataType::Array(inner) => write!(f, "Array({inner})"),
@@ -283,6 +285,7 @@ impl TryFrom<&TypeDesc<'_>> for DataType {
283285
let dimension = desc.args[0].name.parse::<u64>()?;
284286
DataType::Vector(dimension)
285287
}
288+
"TimestampTz" => DataType::TimestampTz,
286289
_ => return Err(Error::Parsing(format!("Unknown type: {desc:?}"))),
287290
};
288291
Ok(dt)

sql/src/value.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub enum Value {
8585
Number(NumberValue),
8686
/// Microseconds from 1970-01-01 00:00:00 UTC
8787
Timestamp(i64),
88+
TimestampTz(String),
8889
Date(i32),
8990
Array(Vec<Value>),
9091
Map(Vec<(Value, Value)>),
@@ -121,6 +122,7 @@ impl Value {
121122
NumberValue::Decimal256(_, s) => DataType::Decimal(DecimalDataType::Decimal256(*s)),
122123
},
123124
Self::Timestamp(_) => DataType::Timestamp,
125+
Self::TimestampTz(_) => DataType::TimestampTz,
124126

125127
Self::Date(_) => DataType::Date,
126128
Self::Interval(_) => DataType::Interval,
@@ -223,6 +225,7 @@ impl TryFrom<(&DataType, String)> for Value {
223225
.and_utc()
224226
.timestamp_micros(),
225227
)),
228+
DataType::TimestampTz => Ok(Self::TimestampTz(v)),
226229
DataType::Date => Ok(Self::Date(
227230
NaiveDate::parse_from_str(v.as_str(), "%Y-%m-%d")?.num_days_from_ce()
228231
- DAYS_FROM_CE,
@@ -884,6 +887,7 @@ fn encode_value(f: &mut std::fmt::Formatter<'_>, val: &Value, raw: bool) -> std:
884887
| Value::Bitmap(s)
885888
| Value::Variant(s)
886889
| Value::Interval(s)
890+
| Value::TimestampTz(s)
887891
| Value::Geometry(s)
888892
| Value::Geography(s) => {
889893
if raw {
@@ -1670,6 +1674,7 @@ impl ValueDecoder {
16701674
DataType::String => self.read_string(reader),
16711675
DataType::Binary => self.read_binary(reader),
16721676
DataType::Timestamp => self.read_timestamp(reader),
1677+
DataType::TimestampTz => self.read_timestamp_tz(reader),
16731678
DataType::Date => self.read_date(reader),
16741679
DataType::Bitmap => self.read_bitmap(reader),
16751680
DataType::Variant => self.read_variant(reader),
@@ -1817,6 +1822,14 @@ impl ValueDecoder {
18171822
Ok(Value::Interval(unsafe { String::from_utf8_unchecked(buf) }))
18181823
}
18191824

1825+
fn read_timestamp_tz<R: AsRef<[u8]>>(&self, reader: &mut Cursor<R>) -> Result<Value> {
1826+
let mut buf = Vec::new();
1827+
reader.read_quoted_text(&mut buf, b'\'')?;
1828+
Ok(Value::TimestampTz(unsafe {
1829+
String::from_utf8_unchecked(buf)
1830+
}))
1831+
}
1832+
18201833
fn read_bitmap<R: AsRef<[u8]>>(&self, reader: &mut Cursor<R>) -> Result<Value> {
18211834
let mut buf = Vec::new();
18221835
reader.read_quoted_text(&mut buf, b'\'')?;
@@ -2191,6 +2204,7 @@ impl Value {
21912204
let dt = DateTime::from_timestamp_micros(*ts).unwrap();
21922205
format!("'{}'", dt.format(TIMESTAMP_FORMAT))
21932206
}
2207+
Value::TimestampTz(t) => format!("'{t}'"),
21942208
Value::Date(d) => {
21952209
let date = NaiveDate::from_num_days_from_ce_opt(*d + DAYS_FROM_CE).unwrap();
21962210
format!("'{}'", date.format("%Y-%m-%d"))

0 commit comments

Comments
 (0)