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
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ each row must be judged in complete isolation.
`prompt_jev('hello', ...)` costs about one request per 256 rows scanned.
- **Repeated calls** with identical arguments in one query are evaluated once.
Reading several fields from one result does not repeat the request.
- **Anywhere in a query.** `prompt_jev` works in `SELECT`, `WHERE`, `ORDER BY`,
`GROUP BY`, `HAVING`, window `OVER (...)` clauses, and join conditions. A call
in a join condition must use columns from one side of the join only.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: Document that a join-condition call runs on every row of its side, before the join removes any rows (not blocking).

hoist_join projects the call beneath the join input. For big JOIN tiny ON big.id = tiny.id AND prompt_jev(big.body, ..) > 0.5, every big row goes to the service, including rows without a match. Before this change, a matching condition would be evaluated only on joined pairs. Users who pay per request need this cost stated next to the "Filters run first" bullet. The README can suggest joining first in a CTE and filtering with WHERE afterwards.

- **Filters run first.** Rows removed by `WHERE` are never sent to the service,
including when the call sits inside a CTE or subquery.
- **Limits.** Each row's text may be up to 64 KiB after JSON encoding. Longer text
fails the query. Requests are capped at 256 KiB.
- **Outages.** Each request is tried three times with a 30-second timeout. If all
Expand Down
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//!
//! See the README for the SQL syntax and result types.
mod optimizer;
mod planner;
pub mod sql;
mod udf;
use async_trait::async_trait;
Expand Down Expand Up @@ -43,7 +44,23 @@ pub fn register(ctx: &SessionContext, client: Arc<dyn JevClient>) {
ctx.register_udf(udf::function(client));
let state_ref = ctx.state_ref();
let mut state = state_ref.write();
// Keep DataFusion's optimizer list as is, except that the two leaf-pushdown
// rules are skipped for plans calling prompt_jev (see `planner`).
let optimizer_rules = state
.optimizer()
.rules
.iter()
.map(|rule| {
if planner::LeafPushdownGuard::GUARDED.contains(&rule.name()) {
planner::LeafPushdownGuard::wrap(Arc::clone(rule))
} else {
Arc::clone(rule)
}
})
.collect();
*state = datafusion::execution::SessionStateBuilder::new_from_existing(state.clone())
.with_analyzer_rule(Arc::new(planner::HoistJev))
.with_optimizer_rules(optimizer_rules)
.with_physical_optimizer_rule(Arc::new(optimizer::DeduplicateJev))
.build();
}
Expand Down
Loading
Loading