diff --git a/src/common/base/src/bytes.rs b/src/common/base/src/bytes.rs index 78a872a5cb..96f47588f1 100644 --- a/src/common/base/src/bytes.rs +++ b/src/common/base/src/bytes.rs @@ -20,6 +20,16 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)] pub struct Bytes(bytes::Bytes); +impl Bytes { + pub fn len(&self) -> usize { + self.0.len() + } + + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + impl From for bytes::Bytes { fn from(value: Bytes) -> Self { value.0 @@ -92,6 +102,14 @@ impl StringBytes { pub fn as_utf8(&self) -> &str { unsafe { std::str::from_utf8_unchecked(&self.0) } } + + pub fn len(&self) -> usize { + self.0.len() + } + + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } } impl From for StringBytes { @@ -178,6 +196,17 @@ mod tests { assert_eq!(world, &bytes); } + #[test] + fn test_bytes_len() { + let hello = b"hello".to_vec(); + let bytes = Bytes::from(hello.clone()); + assert_eq!(bytes.len(), hello.len()); + + let zero = b"".to_vec(); + let bytes = Bytes::from(zero); + assert!(bytes.is_empty()); + } + #[test] fn test_string_bytes_from() { let hello = "hello".to_string(); @@ -191,6 +220,17 @@ mod tests { assert_eq!(&bytes, world); } + #[test] + fn test_string_bytes_len() { + let hello = "hello".to_string(); + let bytes = StringBytes::from(hello.clone()); + assert_eq!(bytes.len(), hello.len()); + + let zero = "".to_string(); + let bytes = StringBytes::from(zero); + assert!(bytes.is_empty()); + } + fn check_str(expect: &str, given: &str) { assert_eq!(expect, given); } diff --git a/src/promql/src/engine.rs b/src/promql/src/engine.rs deleted file mode 100644 index d21a421e22..0000000000 --- a/src/promql/src/engine.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2023 Greptime Team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use std::sync::Arc; - -use promql_parser::parser::Value; - -use crate::error::Result; - -mod evaluator; -mod functions; - -pub use evaluator::*; - -pub struct Context {} - -pub struct Query {} - -pub struct Engine {} - -impl Engine { - pub fn exec(_ctx: &Context, _q: Query) -> Result> { - unimplemented!(); - } -}