Skip to content
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

[CHORE] Pass in file size and num rows to Rust query planner #1282

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion daft/logical/rust_logical_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ def from_tabular_scan(
)
paths_details = file_info_partition_set.to_pydict()
filepaths = paths_details[runner_io.FS_LISTING_PATH_COLUMN_NAME]
filesizes = paths_details[runner_io.FS_LISTING_SIZE_COLUMN_NAME]
filerows = paths_details[runner_io.FS_LISTING_ROWS_COLUMN_NAME]

rs_schema = inferred_or_provided_schema._schema
builder = _LogicalPlanBuilder.table_scan(filepaths, rs_schema, file_format_config)
builder = _LogicalPlanBuilder.table_scan(filepaths, filesizes, filerows, rs_schema, file_format_config)
return cls(builder)

def project(
Expand Down
4 changes: 3 additions & 1 deletion src/daft-plan/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ impl LogicalPlanBuilder {
#[staticmethod]
pub fn table_scan(
file_paths: Vec<String>,
file_sizes: Vec<Option<i64>>,
file_rows: Vec<Option<i64>>,
schema: &PySchema,
file_format_config: PyFileFormatConfig,
) -> PyResult<LogicalPlanBuilder> {
let num_partitions = file_paths.len();
let source_info = SourceInfo::ExternalInfo(ExternalSourceInfo::new(
schema.schema.clone(),
InputFileInfo::new(file_paths, None, None, None).into(),
InputFileInfo::new(file_paths, file_sizes, file_rows).into(),
file_format_config.into(),
));
let partition_spec = PartitionSpec::new(PartitionScheme::Unknown, num_partitions, None);
Expand Down
4 changes: 2 additions & 2 deletions src/daft-plan/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ pub fn plan(logical_plan: &LogicalPlan) -> DaftResult<PhysicalPlan> {
PhysicalPlan::ReduceMerge(ReduceMerge::new(split_op.into()))
};

let _second_stage_agg = PhysicalPlan::Aggregate(Aggregate::new(
let second_stage_agg = PhysicalPlan::Aggregate(Aggregate::new(
gather_plan.into(),
second_stage_aggs.values().cloned().collect(),
groupby.clone(),
Expand All @@ -379,7 +379,7 @@ pub fn plan(logical_plan: &LogicalPlan) -> DaftResult<PhysicalPlan> {
PhysicalPlan::Project(Project::new(
final_exprs,
Default::default(),
_second_stage_agg.into(),
second_stage_agg.into(),
))
}
};
Expand Down
23 changes: 6 additions & 17 deletions src/daft-plan/src/source_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,20 @@ impl ExternalInfo {
#[derive(Debug, Serialize, Deserialize)]
pub struct FileInfo {
pub file_paths: Vec<String>,
pub file_sizes: Option<Vec<i64>>,
pub num_rows: Option<Vec<i64>>,
pub file_formats: Option<Vec<FileFormat>>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out the "file format" data Daft currently ingests is probably file vs directory. I only see instances of the string "file"

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes - I believe the other value returned by the S3 API is "directory"

pub file_sizes: Vec<Option<i64>>,
pub num_rows: Vec<Option<i64>>,
}

impl FileInfo {
pub fn new(
file_paths: Vec<String>,
file_sizes: Option<Vec<i64>>,
num_rows: Option<Vec<i64>>,
file_formats: Option<Vec<FileFormat>>,
file_sizes: Vec<Option<i64>>,
num_rows: Vec<Option<i64>>,
) -> Self {
Self {
file_paths,
file_sizes,
num_rows,
file_formats,
}
}
pub fn to_table(&self) -> DaftResult<Table> {
Expand All @@ -170,11 +167,7 @@ impl FileInfo {
))?,
Series::try_from((
"size",
arrow2::array::PrimitiveArray::<i64>::new_null(
arrow2::datatypes::DataType::Int64,
num_files,
)
.to_boxed(),
arrow2::array::PrimitiveArray::<i64>::from(&self.file_sizes).to_boxed(),
))?,
Series::try_from((
"type",
Expand All @@ -186,11 +179,7 @@ impl FileInfo {
))?,
Series::try_from((
"rows",
arrow2::array::PrimitiveArray::<i64>::new_null(
arrow2::datatypes::DataType::Int64,
num_files,
)
.to_boxed(),
arrow2::array::PrimitiveArray::<i64>::from(&self.num_rows).to_boxed(),
))?,
];
Table::new(
Expand Down