xushiyan commented on code in PR #395: URL: https://github.com/apache/hudi-rs/pull/395#discussion_r2384494738
########## crates/core/src/timeline/loader.rs: ########## @@ -0,0 +1,172 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 crate::config::internal::HudiInternalConfig::{ + TimelineArchivedReadEnabled, TimelineArchivedUnavailableBehavior, +}; +use crate::config::table::HudiTableConfig::ArchiveLogFolder; +use crate::config::HudiConfigs; +use crate::error::CoreError; +use crate::metadata::HUDI_METADATA_DIR; +use crate::storage::Storage; +use crate::timeline::instant::Instant; +use crate::timeline::lsm_tree::LSM_TIMELINE_DIR; +use crate::timeline::selector::TimelineSelector; +use crate::Result; +use log::debug; +use std::sync::Arc; + +#[derive(Debug, Clone)] +pub enum TimelineLoader { + LayoutOneActive(Arc<Storage>), + LayoutOneArchived(Arc<Storage>), + LayoutTwoActive(Arc<Storage>), + LayoutTwoArchived(Arc<Storage>), +} + +impl TimelineLoader { + pub async fn load_instants( + &self, + selector: &TimelineSelector, + desc: bool, + ) -> Result<Vec<Instant>> { + match self { + TimelineLoader::LayoutOneActive(storage) => { + let files = storage.list_files(Some(HUDI_METADATA_DIR)).await?; + let mut instants = Vec::with_capacity(files.len() / 3); + + for file_info in files { + match selector.try_create_instant(file_info.name.as_str()) { + Ok(instant) => instants.push(instant), + Err(e) => { + debug!( + "Instant not created from file {:?} due to: {:?}", + file_info, e + ); + } + } + } + + instants.sort_unstable(); + instants.shrink_to_fit(); + + if desc { + Ok(instants.into_iter().rev().collect()) + } else { + Ok(instants) + } + } + TimelineLoader::LayoutTwoActive(storage) => { + let files = storage.list_files(Some(LSM_TIMELINE_DIR)).await?; + let mut instants = Vec::new(); + + for file_info in files { + if file_info.name.starts_with("history/") || file_info.name.ends_with(".crc") { + continue; + } + match selector.try_create_instant(file_info.name.as_str()) { Review Comment: @codope this is the only blocker for merging. if we need to pass v8 timeline loading test cases, this parsing needs to be there. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
