diff --git a/parquet_file/src/chunk.rs b/parquet_file/src/chunk.rs
index b4856579b6..e753ce84b3 100644
--- a/parquet_file/src/chunk.rs
+++ b/parquet_file/src/chunk.rs
@@ -1,4 +1,4 @@
-use snafu::{OptionExt, ResultExt, Snafu};
+use snafu::{ResultExt, Snafu};
use std::{collections::BTreeSet, sync::Arc};
use crate::table::Table;
@@ -64,19 +64,30 @@ pub struct Chunk {
/// Partition this chunk belongs to
partition_key: String,
- /// Tables of this chunk
- tables: Vec
,
+ /// The table in chunk
+ table: Table,
metrics: ChunkMetrics,
}
impl Chunk {
- pub fn new(part_key: String, metrics: ChunkMetrics) -> Self {
+ pub fn new(
+ part_key: impl Into,
+ table_summary: TableSummary,
+ file_location: Path,
+ store: Arc,
+ schema: Schema,
+ range: Option,
+ metrics: ChunkMetrics,
+ ) -> Self {
+ let table = Table::new(table_summary, file_location, store, schema, range);
+
let mut chunk = Self {
- partition_key: part_key,
- tables: Default::default(),
+ partition_key: part_key.into(),
+ table,
metrics,
};
+
chunk.metrics.memory_bytes.set(chunk.size());
chunk
}
@@ -86,77 +97,42 @@ impl Chunk {
self.partition_key.as_ref()
}
- /// Return all paths of this chunks
- pub fn all_paths(&self) -> Vec {
- self.tables.iter().map(|t| t.path()).collect()
+ /// Return object store path for this chunk
+ pub fn table_path(&self) -> Path {
+ self.table.path()
}
- /// Returns a vec of the summary statistics of the tables in this chunk
- pub fn table_summaries(&self) -> Vec {
- self.tables.iter().map(|t| t.table_summary()).collect()
+ /// Returns the summary statistics for this chunk
+ pub fn table_summary(&self) -> TableSummary {
+ self.table.table_summary()
}
- /// Add a chunk's table and its summary
- pub fn add_table(
- &mut self,
- table_summary: TableSummary,
- file_location: Path,
- store: Arc,
- schema: Schema,
- range: Option,
- ) {
- self.tables.push(Table::new(
- table_summary,
- file_location,
- store,
- schema,
- range,
- ));
+ /// Returns the name of the table this chunk holds
+ pub fn table_name(&self) -> &str {
+ self.table.name()
}
/// Return true if this chunk includes the given table
pub fn has_table(&self, table_name: &str) -> bool {
- self.tables.iter().any(|t| t.has_table(table_name))
- }
-
- // Return all tables of this chunk
- pub fn all_table_names(&self, names: &mut BTreeSet) {
- let mut tables = self
- .tables
- .iter()
- .map(|t| t.name())
- .collect::>();
-
- names.append(&mut tables);
+ self.table_name() == table_name
}
/// Return the approximate memory size of the chunk, in bytes including the
/// dictionary, tables, and their rows.
pub fn size(&self) -> usize {
- let size: usize = self.tables.iter().map(|t| t.size()).sum();
-
- size + self.partition_key.len() + mem::size_of::() + mem::size_of::()
+ self.table.size() + self.partition_key.len() + mem::size_of::()
}
- /// Return Schema for the specified table / columns
- pub fn table_schema(&self, table_name: &str, selection: Selection<'_>) -> Result {
- let table = self.find_table(table_name)?;
-
- table
- .schema(selection)
- .context(NamedTableError { table_name })
+ /// Return Schema for the table in this chunk
+ pub fn table_schema(&self, selection: Selection<'_>) -> Result {
+ self.table.schema(selection).context(NamedTableError {
+ table_name: self.table_name(),
+ })
}
- /// Return object store path for specified table
- pub fn table_path(&self, table_name: &str) -> Result {
- let table = self.find_table(table_name)?;
- Ok(table.path())
- }
-
- /// Return Schema for the specified table / columns
- pub fn timestamp_range(&self, table_name: &str) -> Result