Skip to content

feat(nanos): column_ts pass timestamp value in nanoseconds instead of microseconds #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions questdb-rs/src/ingress/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
******************************************************************************/
use crate::ingress::ndarr::{check_and_get_array_bytes_size, ArrayElementSealed};
use crate::ingress::{
ndarr, ArrayElement, DebugBytes, NdArrayView, ProtocolVersion, Timestamp, TimestampMicros,
TimestampNanos, ARRAY_BINARY_FORMAT_TYPE, DOUBLE_BINARY_FORMAT_TYPE, MAX_ARRAY_DIMS,
MAX_NAME_LEN_DEFAULT,
ndarr, ArrayElement, DebugBytes, NdArrayView, ProtocolVersion, Timestamp, TimestampNanos,
ARRAY_BINARY_FORMAT_TYPE, DOUBLE_BINARY_FORMAT_TYPE, MAX_ARRAY_DIMS, MAX_NAME_LEN_DEFAULT,
};
use crate::{error, Error};
use std::fmt::{Debug, Formatter};
Expand Down Expand Up @@ -281,7 +280,7 @@ impl<'a> TryFrom<&'a str> for TableName<'a> {
}
}

impl<'a> AsRef<str> for TableName<'a> {
impl AsRef<str> for TableName<'_> {
fn as_ref(&self) -> &str {
self.name
}
Expand Down Expand Up @@ -368,7 +367,7 @@ impl<'a> TryFrom<&'a str> for ColumnName<'a> {
}
}

impl<'a> AsRef<str> for ColumnName<'a> {
impl AsRef<str> for ColumnName<'_> {
fn as_ref(&self) -> &str {
self.name
}
Expand Down Expand Up @@ -1148,11 +1147,11 @@ impl Buffer {
{
self.write_column_key(name)?;
let timestamp: Timestamp = value.try_into()?;
let timestamp: TimestampMicros = timestamp.try_into()?;
let timestamp: TimestampNanos = timestamp.try_into()?;
let mut buf = itoa::Buffer::new();
let printed = buf.format(timestamp.as_i64());
self.output.extend_from_slice(printed.as_bytes());
self.output.push(b't');
self.output.push(b'n');
Ok(self)
}

Expand Down
7 changes: 2 additions & 5 deletions questdb-rs/src/ingress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ use std::str::FromStr;
mod tls;

#[cfg(all(feature = "_sender-tcp", feature = "aws-lc-crypto"))]
use aws_lc_rs::{
rand::SystemRandom,
signature::{EcdsaKeyPair, ECDSA_P256_SHA256_FIXED_SIGNING},
};
use aws_lc_rs::signature::{EcdsaKeyPair, ECDSA_P256_SHA256_FIXED_SIGNING};

#[cfg(all(feature = "_sender-tcp", feature = "ring-crypto"))]
use ring::{
Expand Down Expand Up @@ -1287,7 +1284,7 @@ fn parse_key_pair(auth: &conf::EcdsaAuthParams) -> Result<EcdsaKeyPair> {

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

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

Expand Down
15 changes: 5 additions & 10 deletions questdb-rs/src/tests/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,8 @@ fn test_basics(
let exp = &[
"test,t1=v1 ".as_bytes(),
f64_to_bytes("f1", 0.5, version).as_slice(),
format!(
",ts1=12345t,ts2={}t,ts3={}t {}\n",
ts_micros_num,
ts_nanos_num / 1000i64,
ts_nanos_num
)
.as_bytes(),
format!(",ts1=12345000n,ts2={ts_nanos_num}n,ts3={ts_nanos_num}n {ts_nanos_num}\n",)
.as_bytes(),
]
.concat();
assert_eq!(buffer.as_bytes(), exp);
Expand Down Expand Up @@ -540,8 +535,8 @@ fn test_timestamp_overloads() -> TestResult {
)?)?;

let exp = concat!(
"tbl_name a=12345t,b=-100000000t,c=12345t,d=-12345t,e=-1t,f=-10t 1000\n",
"tbl_name a=1000000t 5000000000\n"
"tbl_name a=12345000n,b=-100000000000n,c=12345678n,d=-12345678n,e=-1000n,f=-10000n 1000\n",
"tbl_name a=1000000000n 5000000000\n"
)
.as_bytes();
assert_eq!(buffer.as_bytes(), exp);
Expand All @@ -561,7 +556,7 @@ fn test_chrono_timestamp() -> TestResult {
let mut buffer = Buffer::new(ProtocolVersion::V2);
buffer.table(tbl_name)?.column_ts("a", ts)?.at(ts)?;

let exp = b"tbl_name a=1000000t 1000000000\n";
let exp = b"tbl_name a=1000000000n 1000000000\n";
assert_eq!(buffer.as_bytes(), exp);

Ok(())
Expand Down
Loading