-
Notifications
You must be signed in to change notification settings - Fork 705
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7535 from zhyass/feature_fix
feat(storage): add clustering_history system table
- Loading branch information
Showing
11 changed files
with
350 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/query/service/src/interpreters/interpreter_clustering_history.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2022 Datafuse Labs. | ||
// | ||
// 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 std::time::SystemTime; | ||
use std::time::UNIX_EPOCH; | ||
|
||
use common_catalog::catalog::CATALOG_DEFAULT; | ||
use common_datablocks::DataBlock; | ||
use common_datavalues::prelude::Series; | ||
use common_datavalues::prelude::SeriesFrom; | ||
use common_exception::Result; | ||
|
||
use crate::sessions::QueryContext; | ||
use crate::sessions::TableContext; | ||
use crate::storages::system::ClusteringHistoryTable; | ||
|
||
pub struct InterpreterClusteringHistory { | ||
ctx: Arc<QueryContext>, | ||
} | ||
|
||
impl InterpreterClusteringHistory { | ||
pub fn create(ctx: Arc<QueryContext>) -> Self { | ||
InterpreterClusteringHistory { ctx } | ||
} | ||
|
||
pub async fn write_log( | ||
&self, | ||
start: SystemTime, | ||
db_name: &str, | ||
table_name: &str, | ||
) -> Result<()> { | ||
let start_time = start | ||
.duration_since(UNIX_EPOCH) | ||
.expect("Time went backwards") | ||
.as_micros() as i64; | ||
let end_time = SystemTime::now() | ||
.duration_since(UNIX_EPOCH) | ||
.expect("Time went backwards") | ||
.as_micros() as i64; | ||
let reclustered_bytes = self.ctx.get_scan_progress_value().bytes as u64; | ||
let reclustered_rows = self.ctx.get_scan_progress_value().rows as u64; | ||
|
||
let table = self | ||
.ctx | ||
.get_table(CATALOG_DEFAULT, "system", "clustering_history") | ||
.await?; | ||
let schema = table.get_table_info().meta.schema.clone(); | ||
|
||
let block = DataBlock::create(schema.clone(), vec![ | ||
Series::from_data(vec![start_time]), | ||
Series::from_data(vec![end_time]), | ||
Series::from_data(vec![db_name]), | ||
Series::from_data(vec![table_name]), | ||
Series::from_data(vec![reclustered_bytes]), | ||
Series::from_data(vec![reclustered_rows]), | ||
]); | ||
let blocks = vec![Ok(block)]; | ||
let input_stream = futures::stream::iter::<Vec<Result<DataBlock>>>(blocks); | ||
|
||
let clustering_history_table: &ClusteringHistoryTable = | ||
table.as_any().downcast_ref().unwrap(); | ||
clustering_history_table | ||
.append_data(self.ctx.clone(), Box::pin(input_stream)) | ||
.await?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
fa49f1c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
databend – ./
databend.vercel.app
databend.rs
databend-git-main-databend.vercel.app
databend-databend.vercel.app