Skip to content

Commit 8abdaf0

Browse files
authored
feat: nanosecond timestamp support (#118)
1 parent 0519513 commit 8abdaf0

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

cpp_test/test_line_sender.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ TEST_CASE("Test timestamp column.")
943943
.at(now_nanos_ts);
944944

945945
std::stringstream ss;
946-
ss << "test ts1=12345t,ts2=" << now_micros << "t,ts3=" << now_micros << "t "
946+
ss << "test ts1=12345t,ts2=" << now_micros << "t,ts3=" << now_nanos << "n "
947947
<< now_nanos << "\n";
948948
const auto exp = ss.str();
949949
CHECK(buffer.peek() == exp);

questdb-rs/src/ingress/buffer.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
******************************************************************************/
2424
use crate::ingress::ndarr::{check_and_get_array_bytes_size, ArrayElementSealed};
2525
use crate::ingress::{
26-
ndarr, ArrayElement, DebugBytes, NdArrayView, ProtocolVersion, Timestamp, TimestampMicros,
27-
TimestampNanos, ARRAY_BINARY_FORMAT_TYPE, DOUBLE_BINARY_FORMAT_TYPE, MAX_ARRAY_DIMS,
28-
MAX_NAME_LEN_DEFAULT,
26+
ndarr, ArrayElement, DebugBytes, NdArrayView, ProtocolVersion, Timestamp, TimestampNanos,
27+
ARRAY_BINARY_FORMAT_TYPE, DOUBLE_BINARY_FORMAT_TYPE, MAX_ARRAY_DIMS, MAX_NAME_LEN_DEFAULT,
2928
};
3029
use crate::{error, Error};
3130
use std::fmt::{Debug, Formatter};
@@ -281,7 +280,7 @@ impl<'a> TryFrom<&'a str> for TableName<'a> {
281280
}
282281
}
283282

284-
impl<'a> AsRef<str> for TableName<'a> {
283+
impl AsRef<str> for TableName<'_> {
285284
fn as_ref(&self) -> &str {
286285
self.name
287286
}
@@ -368,7 +367,7 @@ impl<'a> TryFrom<&'a str> for ColumnName<'a> {
368367
}
369368
}
370369

371-
impl<'a> AsRef<str> for ColumnName<'a> {
370+
impl AsRef<str> for ColumnName<'_> {
372371
fn as_ref(&self) -> &str {
373372
self.name
374373
}
@@ -1148,11 +1147,19 @@ impl Buffer {
11481147
{
11491148
self.write_column_key(name)?;
11501149
let timestamp: Timestamp = value.try_into()?;
1151-
let timestamp: TimestampMicros = timestamp.try_into()?;
11521150
let mut buf = itoa::Buffer::new();
1153-
let printed = buf.format(timestamp.as_i64());
1154-
self.output.extend_from_slice(printed.as_bytes());
1155-
self.output.push(b't');
1151+
match timestamp {
1152+
Timestamp::Micros(ts) => {
1153+
let printed = buf.format(ts.as_i64());
1154+
self.output.extend_from_slice(printed.as_bytes());
1155+
self.output.push(b't');
1156+
}
1157+
Timestamp::Nanos(ts) => {
1158+
let printed = buf.format(ts.as_i64());
1159+
self.output.extend_from_slice(printed.as_bytes());
1160+
self.output.push(b'n');
1161+
}
1162+
}
11561163
Ok(self)
11571164
}
11581165

questdb-rs/src/ingress/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ fn parse_key_pair(auth: &conf::EcdsaAuthParams) -> Result<EcdsaKeyPair> {
12871287

12881288
struct DebugBytes<'a>(pub &'a [u8]);
12891289

1290-
impl<'a> Debug for DebugBytes<'a> {
1290+
impl Debug for DebugBytes<'_> {
12911291
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
12921292
write!(f, "b\"")?;
12931293

questdb-rs/src/tests/sender.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ fn test_basics(
9090
"test,t1=v1 ".as_bytes(),
9191
f64_to_bytes("f1", 0.5, version).as_slice(),
9292
format!(
93-
",ts1=12345t,ts2={}t,ts3={}t {}\n",
94-
ts_micros_num,
95-
ts_nanos_num / 1000i64,
96-
ts_nanos_num
93+
",ts1=12345t,ts2={}t,ts3={ts_nanos_num}n {ts_nanos_num}\n",
94+
ts_micros_num
9795
)
9896
.as_bytes(),
9997
]
@@ -540,7 +538,7 @@ fn test_timestamp_overloads() -> TestResult {
540538
)?)?;
541539

542540
let exp = concat!(
543-
"tbl_name a=12345t,b=-100000000t,c=12345t,d=-12345t,e=-1t,f=-10t 1000\n",
541+
"tbl_name a=12345t,b=-100000000t,c=12345678n,d=-12345678n,e=-1t,f=-10000n 1000\n",
544542
"tbl_name a=1000000t 5000000000\n"
545543
)
546544
.as_bytes();
@@ -561,7 +559,7 @@ fn test_chrono_timestamp() -> TestResult {
561559
let mut buffer = Buffer::new(ProtocolVersion::V2);
562560
buffer.table(tbl_name)?.column_ts("a", ts)?.at(ts)?;
563561

564-
let exp = b"tbl_name a=1000000t 1000000000\n";
562+
let exp = b"tbl_name a=1000000000n 1000000000\n";
565563
assert_eq!(buffer.as_bytes(), exp);
566564

567565
Ok(())

0 commit comments

Comments
 (0)