-
-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes required for Parseable Enterprise #1215
Open
parmesant
wants to merge
3
commits into
parseablehq:main
Choose a base branch
from
parmesant:enterprise-changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+280
−16
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ | ||
pub mod utils; |
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,159 @@ | ||
use std::{collections::HashMap, path::PathBuf, sync::Arc}; | ||
|
||
use datafusion::{common::Column, prelude::Expr}; | ||
use itertools::Itertools; | ||
use relative_path::RelativePathBuf; | ||
|
||
use crate::query::stream_schema_provider::extract_primary_filter; | ||
use crate::{ | ||
catalog::{ | ||
manifest::{File, Manifest}, | ||
snapshot, Snapshot, | ||
}, | ||
event, | ||
parseable::PARSEABLE, | ||
query::{stream_schema_provider::ManifestExt, PartialTimeFilter}, | ||
storage::{ObjectStorage, ObjectStorageError, ObjectStoreFormat, STREAM_ROOT_DIRECTORY}, | ||
utils::time::TimeRange, | ||
}; | ||
|
||
pub fn create_time_filter( | ||
time_range: &TimeRange, | ||
time_partition: Option<String>, | ||
table_name: &str, | ||
) -> Vec<Expr> { | ||
let mut new_filters = vec![]; | ||
let start_time = time_range.start.naive_utc(); | ||
let end_time = time_range.end.naive_utc(); | ||
let mut _start_time_filter: Expr; | ||
let mut _end_time_filter: Expr; | ||
|
||
match time_partition { | ||
Some(time_partition) => { | ||
_start_time_filter = PartialTimeFilter::Low(std::ops::Bound::Included(start_time)) | ||
.binary_expr(Expr::Column(Column::new( | ||
Some(table_name.to_owned()), | ||
time_partition.clone(), | ||
))); | ||
_end_time_filter = | ||
PartialTimeFilter::High(std::ops::Bound::Excluded(end_time)).binary_expr( | ||
Expr::Column(Column::new(Some(table_name.to_owned()), time_partition)), | ||
); | ||
} | ||
None => { | ||
_start_time_filter = PartialTimeFilter::Low(std::ops::Bound::Included(start_time)) | ||
.binary_expr(Expr::Column(Column::new( | ||
Some(table_name.to_owned()), | ||
event::DEFAULT_TIMESTAMP_KEY, | ||
))); | ||
_end_time_filter = PartialTimeFilter::High(std::ops::Bound::Excluded(end_time)) | ||
.binary_expr(Expr::Column(Column::new( | ||
Some(table_name.to_owned()), | ||
event::DEFAULT_TIMESTAMP_KEY, | ||
))); | ||
} | ||
} | ||
|
||
new_filters.push(_start_time_filter); | ||
new_filters.push(_end_time_filter); | ||
|
||
new_filters | ||
} | ||
|
||
pub async fn fetch_parquet_file_paths( | ||
stream: &str, | ||
time_range: &TimeRange, | ||
) -> Result<HashMap<RelativePathBuf, Vec<File>>, ObjectStorageError> { | ||
let glob_storage = PARSEABLE.storage.get_object_store(); | ||
|
||
let object_store_format = glob_storage.get_object_store_format(stream).await?; | ||
|
||
let time_partition = object_store_format.time_partition; | ||
|
||
let time_filter_expr = create_time_filter(time_range, time_partition.clone(), stream); | ||
|
||
let time_filters = extract_primary_filter(&time_filter_expr, &time_partition); | ||
|
||
let mut merged_snapshot: snapshot::Snapshot = snapshot::Snapshot::default(); | ||
|
||
let path = RelativePathBuf::from_iter([stream, STREAM_ROOT_DIRECTORY]); | ||
let obs = glob_storage | ||
.get_objects( | ||
Some(&path), | ||
Box::new(|file_name| file_name.ends_with("stream.json")), | ||
) | ||
.await; | ||
if let Ok(obs) = obs { | ||
for ob in obs { | ||
if let Ok(object_store_format) = serde_json::from_slice::<ObjectStoreFormat>(&ob) { | ||
let snapshot = object_store_format.snapshot; | ||
for manifest in snapshot.manifest_list { | ||
merged_snapshot.manifest_list.push(manifest); | ||
} | ||
} | ||
} | ||
} | ||
|
||
let manifest_files = collect_manifest_files( | ||
glob_storage, | ||
merged_snapshot | ||
.manifests(&time_filters) | ||
.into_iter() | ||
.sorted_by_key(|file| file.time_lower_bound) | ||
.map(|item| item.manifest_path) | ||
.collect(), | ||
) | ||
.await?; | ||
|
||
let mut parquet_files: HashMap<RelativePathBuf, Vec<File>> = HashMap::new(); | ||
|
||
let mut selected_files = manifest_files | ||
.into_iter() | ||
.flat_map(|file| file.files) | ||
.rev() | ||
.collect_vec(); | ||
|
||
for filter in time_filter_expr { | ||
selected_files.retain(|file| !file.can_be_pruned(&filter)) | ||
} | ||
|
||
selected_files | ||
.into_iter() | ||
.map(|file| { | ||
let date = file.file_path.split("/").collect_vec(); | ||
|
||
let date = date.as_slice()[1..4].iter().map(|s| s.to_string()); | ||
|
||
let date = RelativePathBuf::from_iter(date); | ||
|
||
parquet_files.entry(date).or_default().push(file); | ||
}) | ||
.for_each(|_| {}); | ||
|
||
Ok(parquet_files) | ||
} | ||
|
||
async fn collect_manifest_files( | ||
storage: Arc<dyn ObjectStorage>, | ||
manifest_urls: Vec<String>, | ||
) -> Result<Vec<Manifest>, ObjectStorageError> { | ||
let mut tasks = Vec::new(); | ||
manifest_urls.into_iter().for_each(|path| { | ||
let path = RelativePathBuf::from_path(PathBuf::from(path)).expect("Invalid path"); | ||
let storage = Arc::clone(&storage); | ||
tasks.push(tokio::task::spawn(async move { | ||
storage.get_object(&path).await | ||
})); | ||
}); | ||
|
||
let mut op = Vec::new(); | ||
for task in tasks { | ||
let file = task.await??; | ||
op.push(file); | ||
} | ||
|
||
Ok(op | ||
.into_iter() | ||
.map(|res| serde_json::from_slice(&res).expect("Data is invalid for Manifest")) | ||
.collect()) | ||
} |
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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Check for potential out-of-bounds slice access.
Splitting on
"/"
and callingdate.as_slice()[1..4]
can panic if the path has fewer than four segments. Handle or verify the path structure before slicing to prevent a runtime panic.Possible fix:
📝 Committable suggestion