Skip to content

Commit ea3f0a8

Browse files
authored
Merge branch 'main' into feature_fix
2 parents e105e53 + dbaf2e5 commit ea3f0a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+481
-579
lines changed

Cargo.lock

Lines changed: 25 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/doc/30-reference/20-functions/30-datetime-functions/todatetime.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The function extracts a date and time from the provided string. If the argument
2222

2323
Returns a value of Timestamp type in the format “YYYY-MM-DD hh:mm:ss.ffffff”.
2424

25+
If the expr matches this format but does not have a time part, it is automatically extended to this pattern. The padding value is 0.
26+
2527
## Examples
2628

2729
### Using a String as Argument
@@ -46,6 +48,11 @@ SELECT TO_DATETIME('2022-01-02T01:12:00-07:00');
4648

4749
---
4850
2022-01-02 08:12:00.000000
51+
52+
SELECT TO_DATETIME('2022-01-02T01');
53+
54+
---
55+
2022-01-02 01:00:00.000000
4956
```
5057

5158
### Using an Integer as Argument

src/binaries/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ common-grpc = { path = "../common/grpc" }
3333
common-macros = { path = "../common/macros" }
3434
common-meta-api = { path = "../meta/api" }
3535
common-meta-app = { path = "../meta/app" }
36+
common-meta-client = { path = "../meta/client" }
3637
common-meta-embedded = { path = "../meta/embedded" }
37-
common-meta-grpc = { path = "../meta/grpc" }
3838
common-meta-raft-store = { path = "../meta/raft-store" }
3939
common-meta-sled-store = { path = "../meta/sled-store" }
4040
common-meta-store = { path = "../meta/store" }

src/binaries/metabench/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use common_meta_app::schema::DatabaseNameIdent;
2727
use common_meta_app::schema::GetTableReq;
2828
use common_meta_app::schema::TableNameIdent;
2929
use common_meta_app::schema::UpsertTableOptionReq;
30-
use common_meta_grpc::ClientHandle;
31-
use common_meta_grpc::MetaGrpcClient;
30+
use common_meta_client::ClientHandle;
31+
use common_meta_client::MetaGrpcClient;
3232
use common_meta_types::MatchSeq;
3333
use common_meta_types::Operation;
3434
use common_meta_types::UpsertKVReq;

src/binaries/metactl/grpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use std::fs::File;
1616
use std::io::Write;
1717

18-
use common_meta_grpc::MetaGrpcClient;
18+
use common_meta_client::MetaGrpcClient;
1919
use common_meta_types::protobuf::Empty;
2020
use tokio_stream::StreamExt;
2121

src/binaries/metactl/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod snapshot;
2020
use clap::Parser;
2121
use common_base::base::tokio;
2222
use common_meta_api::KVApi;
23-
use common_meta_grpc::MetaGrpcClient;
23+
use common_meta_client::MetaGrpcClient;
2424
use common_meta_raft_store::config::get_default_raft_advertise_host;
2525
use common_tracing::init_logging;
2626
use common_tracing::Config as LogConfig;

src/binaries/query/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use std::sync::Arc;
1818

1919
use common_base::base::RuntimeTracker;
2020
use common_macros::databend_main;
21+
use common_meta_client::MIN_METASRV_SEMVER;
2122
use common_meta_embedded::MetaEmbedded;
22-
use common_meta_grpc::MIN_METASRV_SEMVER;
2323
use common_metrics::init_default_metrics_recorder;
2424
use common_tracing::set_panic_hook;
2525
use databend_query::api::HttpService;

src/common/metrics/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ prometheus-parse = "0.2.3"
2323
serde = { version = "1.0.137", features = ["derive"] }
2424
tracing = "0.1.35"
2525

26+
[dev-dependencies]
27+
anyhow = "1.0.58"
28+
2629
[dev-dependencies.tokio]
2730
default-features = false
2831
features = ["io-util", "net", "sync", "rt-multi-thread", "macros"]

src/common/metrics/src/counter.rs

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// Copyright 2022 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+
//! This mod provides mechanism to track the count of active instances of some type `T`.
16+
//! The count is maintained by a `Count` implementation and will be increased or decreased when a wrapper of `T` `WithCounter` is created or dropped.
17+
//!
18+
//! Example:
19+
//!
20+
//! ```ignore
21+
//! struct Connection{}
22+
//! impl Connection {
23+
//! fn ping() {}
24+
//! }
25+
//!
26+
//! struct MyCounter{ identifier: String, }
27+
//! impl Count for MyCounter {/*...*/}
28+
//!
29+
//! {
30+
//! let conn = WithCounter::new(Connection{}, MyCounter{}); // increase count with `MyCounter`
31+
//! conn.ping();
32+
//! } // decrease count with `MyCounter`
33+
//! ```
34+
35+
use std::ops::Deref;
36+
use std::ops::DerefMut;
37+
38+
/// Defines how to report counter metrics.
39+
pub trait Count {
40+
fn incr_count(&mut self, n: i64);
41+
}
42+
43+
/// Binds a counter to a `T`.
44+
///
45+
/// It counts the number of instances of `T` with the provided counter `Count`.
46+
pub struct WithCount<C, T>
47+
where C: Count
48+
{
49+
counter: C,
50+
inner: T,
51+
}
52+
53+
impl<C, T> WithCount<C, T>
54+
where C: Count
55+
{
56+
pub fn new(t: T, counter: C) -> Self {
57+
let mut s = Self { counter, inner: t };
58+
s.counter.incr_count(1);
59+
s
60+
}
61+
62+
pub fn counter(&self) -> &C {
63+
&self.counter
64+
}
65+
}
66+
67+
/// When being dropped, decreases the count.
68+
impl<C, T> Drop for WithCount<C, T>
69+
where C: Count
70+
{
71+
fn drop(&mut self) {
72+
self.counter.incr_count(-1);
73+
}
74+
}
75+
76+
/// Let an app use `WithCount` the same as using `T`.
77+
impl<C, T> Deref for WithCount<C, T>
78+
where C: Count
79+
{
80+
type Target = T;
81+
82+
fn deref(&self) -> &Self::Target {
83+
&self.inner
84+
}
85+
}
86+
87+
/// Let an app use `WithCount` the same as using `T`.
88+
impl<C, T> DerefMut for WithCount<C, T>
89+
where C: Count
90+
{
91+
fn deref_mut(&mut self) -> &mut Self::Target {
92+
&mut self.inner
93+
}
94+
}
95+
96+
#[cfg(test)]
97+
mod tests {
98+
use std::sync::atomic::AtomicI64;
99+
use std::sync::atomic::Ordering;
100+
use std::sync::Arc;
101+
102+
use crate::counter::Count;
103+
use crate::counter::WithCount;
104+
105+
struct Foo {}
106+
struct Counter {
107+
n: Arc<AtomicI64>,
108+
}
109+
impl Count for Counter {
110+
fn incr_count(&mut self, n: i64) {
111+
self.n.fetch_add(n, Ordering::Relaxed);
112+
}
113+
}
114+
115+
#[test]
116+
fn test_with_count() -> anyhow::Result<()> {
117+
let count = Arc::new(AtomicI64::new(0));
118+
assert_eq!(0, count.load(Ordering::Relaxed));
119+
120+
{
121+
let _a = WithCount::new(Foo {}, Counter { n: count.clone() });
122+
assert_eq!(1, count.load(Ordering::Relaxed));
123+
{
124+
let _b = WithCount::new(Foo {}, Counter { n: count.clone() });
125+
assert_eq!(2, count.load(Ordering::Relaxed));
126+
}
127+
assert_eq!(1, count.load(Ordering::Relaxed));
128+
}
129+
assert_eq!(0, count.load(Ordering::Relaxed));
130+
Ok(())
131+
}
132+
}

src/common/metrics/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
pub mod counter;
1516
mod dump;
1617
mod recorder;
1718

0 commit comments

Comments
 (0)