Skip to content
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
8 changes: 7 additions & 1 deletion beacon-query/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ pub struct QueryBody {
#[serde(default)]
from: Option<crate::from::From>,
sort_by: Option<Vec<Sort>>,
distinct: Option<Vec<String>>,
distinct: Option<Distinct>,
offset: Option<usize>,
limit: Option<usize>,
}

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct Distinct {
pub on: Vec<Select>,
pub select: Vec<Select>,
}

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
#[serde(untagged)]
pub enum Select {
Expand Down
31 changes: 20 additions & 11 deletions beacon-query/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
use std::sync::Arc;

use beacon_data_lake::DataLake;
use datafusion::{
datasource::file_format::{csv::CsvFormatFactory, format_as_file_type, FileFormat},
logical_expr::{Analyze, LogicalPlan, LogicalPlanBuilder},
logical_expr::LogicalPlan,
prelude::{SQLOptions, SessionContext},
};

use crate::{
output::{Output, OutputFormat, QueryOutputFile},
plan::ParsedPlan,
InnerQuery, QueryBody,
};
use crate::{plan::ParsedPlan, InnerQuery, QueryBody};

use super::Query;

Expand Down Expand Up @@ -107,19 +100,35 @@ impl Parser {
let df_schema = builder.schema().clone();
let schema = df_schema.as_arrow();
if let Some(filter) = query_body.filter {
builder = builder.filter(filter.parse(&session_state, &schema)?)?;
builder = builder.filter(filter.parse(&session_state, schema)?)?;
}

if let Some(filters) = query_body.filters {
for filter in filters {
builder = builder.filter(filter.parse(&session_state, &schema)?)?;
builder = builder.filter(filter.parse(&session_state, schema)?)?;
}
}

if let Some(sort_by) = query_body.sort_by {
builder = builder.sort(sort_by.iter().map(|s| s.to_expr()))?;
}

if let Some(distinct) = query_body.distinct {
let on_exprs = distinct
.on
.iter()
.map(|s| s.to_expr(&session.state()))
.collect::<anyhow::Result<Vec<_>>>()?;

let select_exprs = distinct
.select
.iter()
.map(|s| s.to_expr(&session.state()))
.collect::<anyhow::Result<Vec<_>>>()?;
Comment on lines +117 to +127

Copilot AI Oct 20, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The repeated pattern of mapping to_expr(&session.state()) and collecting results could be extracted into a helper function to reduce code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.

builder = builder.distinct_on(on_exprs, select_exprs, None)?;
}

let offset = query_body.offset.unwrap_or(0);
builder = builder.limit(offset, query_body.limit)?;

Expand Down