Skip to content

Commit

Permalink
use eixsiting utils mod
Browse files Browse the repository at this point in the history
  • Loading branch information
dantengsky committed Aug 5, 2024
1 parent fa2dd1d commit ba89996
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/query/catalog/src/plan/internal_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ use databend_common_expression::SEARCH_MATCHED_COLUMN_ID;
use databend_common_expression::SEARCH_SCORE_COLUMN_ID;
use databend_common_expression::SEGMENT_NAME_COLUMN_ID;
use databend_common_expression::SNAPSHOT_NAME_COLUMN_ID;
use databend_storages_common_table_meta::meta::try_extract_uuid_str_from_path;
use databend_storages_common_table_meta::meta::NUM_BLOCK_ID_BITS;
use databend_storages_common_table_meta::try_extract_uuid_str_from_path;

// Segment and Block id Bits when generate internal column `_row_id`
// Assumes that the max block count of a segment is 2 ^ NUM_BLOCK_ID_BITS
Expand Down
2 changes: 1 addition & 1 deletion src/query/catalog/src/plan/stream_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use databend_common_expression::ORIGIN_BLOCK_ID_COLUMN_ID;
use databend_common_expression::ORIGIN_BLOCK_ROW_NUM_COLUMN_ID;
use databend_common_expression::ORIGIN_VERSION_COLUMN_ID;
use databend_common_expression::ROW_VERSION_COLUMN_ID;
use databend_storages_common_table_meta::try_extract_uuid_str_from_path;
use databend_storages_common_table_meta::meta::try_extract_uuid_str_from_path;

use crate::plan::PartInfo;
use crate::plan::PartInfoPtr;
Expand Down
4 changes: 0 additions & 4 deletions src/query/storages/common/table_meta/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@
pub mod meta;
pub mod readers;
pub mod table;

mod util;

pub use util::*;
3 changes: 3 additions & 0 deletions src/query/storages/common/table_meta/src/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ pub use statistics::*;
// export legacy versioned table meta types locally,
// currently, used by versioned readers only
pub(crate) use testing::*;
pub use utils::trim_v5_object_prefix;
pub use utils::try_extract_uuid_str_from_path;
pub use utils::uuid_from_date_time;
pub use utils::TableMetaTimestamps;
pub use utils::V5_OBJET_KEY_PREFIX;
pub(crate) use utils::*;
pub use versions::testify_version;
pub use versions::SegmentInfoVersion;
Expand Down
31 changes: 31 additions & 0 deletions src/query/storages/common/table_meta/src/meta/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use std::ops::Add;
use std::path::Path;
use std::sync::Arc;

use chrono::DateTime;
Expand All @@ -23,9 +24,12 @@ use chrono::Utc;
use databend_common_base::base::uuid;
use databend_common_base::base::uuid::NoContext;
use databend_common_base::base::uuid::Uuid;
use databend_common_exception::ErrorCode;

use crate::meta::TableSnapshot;
use crate::readers::snapshot_reader::TableSnapshotAccessor;

pub const V5_OBJET_KEY_PREFIX: char = 'g';
pub fn trim_timestamp_to_micro_second(ts: DateTime<Utc>) -> DateTime<Utc> {
Utc.with_ymd_and_hms(
ts.year(),
Expand Down Expand Up @@ -103,6 +107,33 @@ pub fn uuid_from_date_time(ts: DateTime<Utc>) -> Uuid {
Uuid::new_v7(uuid_ts)
}

// Extracts the UUID part from the object key.
// For example, given a path like:
// bucket/root/115/122/_b/g0191114d30fd78b89fae8e5c88327725_v2.parquet
// bucket/root/115/122/_b/0191114d30fd78b89fae8e5c88327725_v2.parquet
// The function should return: 0191114d30fd78b89fae8e5c88327725
pub fn try_extract_uuid_str_from_path(path: &str) -> databend_common_exception::Result<&str> {
if let Some(file_stem) = Path::new(path).file_stem() {
let file_name = file_stem
.to_str()
.unwrap() // path is always valid utf8 string
.split('_')
.collect::<Vec<&str>>();
let uuid = trim_v5_object_prefix(file_name[0]);
Ok(uuid)
} else {
Err(ErrorCode::StorageOther(format!(
"Illegal object key, no file stem found: {}",
path
)))
}
}

#[inline]
pub fn trim_v5_object_prefix(key: &str) -> &str {
key.strip_prefix(V5_OBJET_KEY_PREFIX).unwrap_or(key)
}

#[cfg(test)]
mod tests {
fn assert_order_preserved(
Expand Down
47 changes: 0 additions & 47 deletions src/query/storages/common/table_meta/src/util.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/query/storages/fuse/src/io/locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ use std::marker::PhantomData;

use databend_common_exception::Result;
use databend_common_expression::DataBlock;
use databend_storages_common_table_meta::meta::trim_v5_object_prefix;
use databend_storages_common_table_meta::meta::uuid_from_date_time;
use databend_storages_common_table_meta::meta::Location;
use databend_storages_common_table_meta::meta::SegmentInfo;
use databend_storages_common_table_meta::meta::SnapshotVersion;
use databend_storages_common_table_meta::meta::TableMetaTimestamps;
use databend_storages_common_table_meta::meta::TableSnapshotStatisticsVersion;
use databend_storages_common_table_meta::meta::Versioned;
use databend_storages_common_table_meta::trim_v5_object_prefix;
use databend_storages_common_table_meta::V5_OBJET_KEY_PREFIX;
use databend_storages_common_table_meta::meta::V5_OBJET_KEY_PREFIX;
use uuid::Uuid;

use crate::constants::FUSE_TBL_BLOCK_PREFIX;
Expand Down

0 comments on commit ba89996

Please sign in to comment.