Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/core/src/config/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::config::{ConfigParser, HudiConfigValue};
/// use hudi_core::table::Table as HudiTable;
///
/// let options = [(SkipConfigValidation, "true")];
/// HudiTable::new_with_options("/tmp/hudi_data", options)
/// HudiTable::new_with_options_blocking("/tmp/hudi_data", options);
/// ```
///
#[derive(Clone, Debug, PartialEq, Eq, Hash, EnumIter)]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/config/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::config::{ConfigParser, HudiConfigValue};
/// use hudi_core::table::Table as HudiTable;
///
/// let options = [(InputPartitions, "2")];
/// HudiTable::new_with_options("/tmp/hudi_data", options)
/// HudiTable::new_with_options_blocking("/tmp/hudi_data", options);
/// ```
///

Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/file_group/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ impl FileGroupReader {
/// Creates a new reader with the given base URI and options.
///
/// # Arguments
/// * `base_uri` - The base URI of the file group's residing table.
/// * `options` - Additional options for the reader.
/// * `base_uri` - The base URI of the file group's residing table.
/// * `options` - Additional options for the reader.
///
/// # Notes
/// This API uses [`OptionResolver`] that loads table properties from storage to resolve options.
Expand Down Expand Up @@ -164,7 +164,7 @@ impl FileGroupReader {
/// Reads the data from the base file at the given relative path.
///
/// # Arguments
/// * `relative_path` - The relative path to the base file.
/// * `relative_path` - The relative path to the base file.
///
/// # Returns
/// A record batch read from the base file.
Expand Down Expand Up @@ -216,7 +216,7 @@ impl FileGroupReader {
/// Reads the data from the given file slice.
///
/// # Arguments
/// * `file_slice` - The file slice to read.
/// * `file_slice` - The file slice to read.
///
/// # Returns
/// A record batch read from the file slice.
Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
//! **Example**
//!
//! ```rust
//! use hudi_core::config::read::HudiReadConfig::{AsOfTimestamp, InputPartitions};
//! use hudi_core::config::read::HudiReadConfig::InputPartitions;
//! use hudi_core::table::Table as HudiTable;
//!
//! let options = [(InputPartitions, "2"), (AsOfTimestamp, "20240101010100000")];
//! HudiTable::new_with_options("/tmp/hudi_data", options);
//! let options = [(InputPartitions, "2")];
//! HudiTable::new_with_options_blocking("/tmp/hudi_data", options);
//! ```
//!
//! # The [table] module is responsible for managing Hudi tables.
Expand Down
36 changes: 18 additions & 18 deletions crates/core/src/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ impl Table {
/// Get all the [FileSlice]s in splits from the table.
///
/// # Arguments
/// * `n` - The number of chunks to split the file slices into.
/// * `filters` - Partition filters to apply.
/// * `n` - The number of chunks to split the file slices into.
/// * `filters` - Partition filters to apply.
pub async fn get_file_slices_splits<I, S>(
&self,
n: usize,
Expand Down Expand Up @@ -333,9 +333,9 @@ impl Table {
/// Get all the [FileSlice]s in splits from the table at a given timestamp.
///
/// # Arguments
/// * `n` - The number of chunks to split the file slices into.
/// * `timestamp` - The timestamp which file slices associated with.
/// * `filters` - Partition filters to apply.
/// * `n` - The number of chunks to split the file slices into.
/// * `timestamp` - The timestamp which file slices associated with.
/// * `filters` - Partition filters to apply.
pub async fn get_file_slices_splits_as_of<I, S>(
&self,
n: usize,
Expand Down Expand Up @@ -395,10 +395,10 @@ impl Table {
/// Get all the [FileSlice]s in the table.
///
/// # Arguments
/// * `filters` - Partition filters to apply.
/// * `filters` - Partition filters to apply.
///
/// # Notes
/// * This API is useful for implementing snapshot query.
/// * This API is useful for implementing snapshot query.
pub async fn get_file_slices<I, S>(&self, filters: I) -> Result<Vec<FileSlice>>
where
I: IntoIterator<Item = (S, S, S)>,
Expand Down Expand Up @@ -427,11 +427,11 @@ impl Table {
/// Get all the [FileSlice]s in the table at a given timestamp.
///
/// # Arguments
/// * `timestamp` - The timestamp which file slices associated with.
/// * `filters` - Partition filters to apply.
/// * `timestamp` - The timestamp which file slices associated with.
/// * `filters` - Partition filters to apply.
///
/// # Notes
/// * This API is useful for implementing time travel query.
/// * This API is useful for implementing time travel query.
pub async fn get_file_slices_as_of<I, S>(
&self,
timestamp: &str,
Expand Down Expand Up @@ -482,11 +482,11 @@ impl Table {
/// Get all the changed [FileSlice]s in the table between the given timestamps.
///
/// # Arguments
/// * `start_timestamp` - If provided, only file slices that were changed after this timestamp will be returned.
/// * `end_timestamp` - If provided, only file slices that were changed before or at this timestamp will be returned.
/// * `start_timestamp` - If provided, only file slices that were changed after this timestamp will be returned.
/// * `end_timestamp` - If provided, only file slices that were changed before or at this timestamp will be returned.
///
/// # Notes
/// * This API is useful for implementing incremental query.
/// * This API is useful for implementing incremental query.
pub async fn get_file_slices_between(
&self,
start_timestamp: Option<&str>,
Expand Down Expand Up @@ -565,7 +565,7 @@ impl Table {
/// Get all the latest records in the table.
///
/// # Arguments
/// * `filters` - Partition filters to apply.
/// * `filters` - Partition filters to apply.
pub async fn read_snapshot<I, S>(&self, filters: I) -> Result<Vec<RecordBatch>>
where
I: IntoIterator<Item = (S, S, S)>,
Expand Down Expand Up @@ -594,8 +594,8 @@ impl Table {
/// Get all the records in the table at a given timestamp.
///
/// # Arguments
/// * `timestamp` - The timestamp which records associated with.
/// * `filters` - Partition filters to apply.
/// * `timestamp` - The timestamp which records associated with.
/// * `filters` - Partition filters to apply.
pub async fn read_snapshot_as_of<I, S>(
&self,
timestamp: &str,
Expand Down Expand Up @@ -648,8 +648,8 @@ impl Table {
/// the time span being returned.
///
/// # Arguments
/// * `start_timestamp` - Only records that were inserted or updated after this timestamp will be returned.
/// * `end_timestamp` - If provided, only records that were inserted or updated before or at this timestamp will be returned.
/// * `start_timestamp` - Only records that were inserted or updated after this timestamp will be returned.
/// * `end_timestamp` - If provided, only records that were inserted or updated before or at this timestamp will be returned.
pub async fn read_incremental_records(
&self,
start_timestamp: &str,
Expand Down
101 changes: 101 additions & 0 deletions crates/core/src/timeline/builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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::table::HudiTableConfig::{TableVersion, TimelineLayoutVersion};
use crate::config::HudiConfigs;
use crate::error::CoreError;
use crate::storage::Storage;
use crate::timeline::loader::TimelineLoader;
use crate::timeline::Timeline;
use crate::Result;
use std::sync::Arc;

pub struct TimelineBuilder {
hudi_configs: Arc<HudiConfigs>,
storage: Arc<Storage>,
}

impl TimelineBuilder {
pub fn new(hudi_configs: Arc<HudiConfigs>, storage: Arc<Storage>) -> Self {
Self {
hudi_configs,
storage,
}
}

pub async fn build(self) -> Result<Timeline> {
let (active_loader, archived_loader) = self.resolve_loader_config()?;
let timeline = Timeline::new(
self.hudi_configs,
self.storage,
active_loader,
archived_loader,
);
Ok(timeline)
}

fn resolve_loader_config(&self) -> Result<(TimelineLoader, Option<TimelineLoader>)> {
let table_version = match self.hudi_configs.get(TableVersion) {
Ok(v) => v.to::<isize>(),
Err(_) => {
return Ok((
TimelineLoader::LayoutOneActive(self.storage.clone()),
Some(TimelineLoader::LayoutOneArchived(self.storage.clone())),
))
}
};

let layout_version = self
.hudi_configs
.try_get(TimelineLayoutVersion)
.map(|v| v.to::<isize>())
.unwrap_or_else(|| if table_version == 8 { 2 } else { 1 });

match layout_version {
1 => {
if !(5..=8).contains(&table_version) {
return Err(CoreError::Unsupported(format!(
"Unsupported table version {} with timeline layout version {}",
table_version, layout_version
)));
}
Ok((
TimelineLoader::LayoutOneActive(self.storage.clone()),
Some(TimelineLoader::LayoutOneArchived(self.storage.clone())),
))
}
2 => {
if table_version != 8 {
return Err(CoreError::Unsupported(format!(
"Unsupported table version {} with timeline layout version {}",
table_version, layout_version
)));
}
Ok((
TimelineLoader::LayoutTwoActive(self.storage.clone()),
Some(TimelineLoader::LayoutTwoCompacted(self.storage.clone())),
))
}
_ => Err(CoreError::Unsupported(format!(
"Unsupported timeline layout version: {}",
layout_version
))),
}
}
}
111 changes: 111 additions & 0 deletions crates/core/src/timeline/loader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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::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>),
LayoutTwoCompacted(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.starts_with('_') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can enhance the storage.list_files() to support a listing for only immediate files under the prefix, then we dont need explicit check and just grab the instant files. What is the case with having _ prefix?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it also occurs to me that we may need to enhance the listing by ignoring .crc files by default.. we'll track this separately.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensured sorted results; removed _ filter; ignoring .crc. Will do a shallow-listing enhancement on Storage in a follow-up.

continue;
}
match selector.try_create_instant(file_info.name.as_str()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this API needs to handle v8 instants as the completed ones have completion ts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codope this is the only blocker for merging. if we need to pass v8 timeline loading test cases, this parsing needs to be there.

Ok(instant) => instants.push(instant),
Err(e) => {
debug!(
"Instant not created from file {:?} due to: {:?}",
file_info, e
);
}
}
}
Ok(instants)
}
_ => Err(CoreError::Unsupported(
"Loading from this timeline layout is not implemented yet.".to_string(),
)),
}
}

pub async fn load_archived_instants(
&self,
_selector: &TimelineSelector,
_desc: bool,
) -> Result<Vec<Instant>> {
match self {
TimelineLoader::LayoutOneArchived(_) => Err(CoreError::Unsupported(
"Archived timeline for layout v1 not implemented yet".to_string(),
)),
TimelineLoader::LayoutTwoCompacted(_) => Err(CoreError::Unsupported(
"Compacted timeline for layout v2 not implemented yet".to_string(),
)),
_ => Ok(Vec::new()), // Active loaders don't have archived parts.
}
}
}
Loading
Loading