Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do a semijoin when there is a filter on an index.
- Loading branch information
Andi Wang
committed
Jul 23, 2020
1 parent
9f9cf34
commit 482d0fc
Showing
13 changed files
with
1,108 additions
and
229 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright Materialize, Inc. All rights reserved. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the LICENSE file. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0. | ||
|
||
use differential_dataflow::lattice::Lattice; | ||
use differential_dataflow::{AsCollection, Collection}; | ||
|
||
use timely::dataflow::operators::map::Map; | ||
use timely::dataflow::operators::to_stream::ToStream; | ||
use timely::dataflow::Scope; | ||
use timely::progress::{timestamp::Refines, Timestamp}; | ||
|
||
use expr::RelationExpr; | ||
use repr::Row; | ||
|
||
use crate::operator::CollectionExt; | ||
use crate::render::context::Context; | ||
|
||
impl<G, T> Context<G, RelationExpr, Row, T> | ||
where | ||
G: Scope, | ||
G::Timestamp: Lattice + Refines<T>, | ||
T: Timestamp + Lattice, | ||
{ | ||
pub fn render_constant( | ||
&mut self, | ||
relation_expr: &RelationExpr, | ||
scope: &mut G, | ||
worker_index: usize, | ||
) { | ||
// The constant collection is instantiated only on worker zero. | ||
if let RelationExpr::Constant { rows, .. } = relation_expr { | ||
let rows = if worker_index == 0 { | ||
rows.clone() | ||
} else { | ||
vec![] | ||
}; | ||
|
||
let collection = rows | ||
.to_stream(scope) | ||
.map(|(x, diff)| (x, timely::progress::Timestamp::minimum(), diff)) | ||
.as_collection(); | ||
|
||
let err_collection = Collection::empty(scope); | ||
|
||
self.collections | ||
.insert(relation_expr.clone(), (collection, err_collection)); | ||
} | ||
} | ||
} |
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,59 @@ | ||
// Copyright Materialize, Inc. All rights reserved. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the LICENSE file. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0. | ||
|
||
use differential_dataflow::lattice::Lattice; | ||
use differential_dataflow::Collection; | ||
|
||
use timely::dataflow::Scope; | ||
use timely::progress::{timestamp::Refines, Timestamp}; | ||
|
||
use dataflow_types::DataflowError; | ||
use expr::{RelationExpr, ScalarExpr}; | ||
use repr::{Datum, Row}; | ||
|
||
use crate::operator::CollectionExt; | ||
use crate::render::context::Context; | ||
|
||
impl<G, T> Context<G, RelationExpr, Row, T> | ||
where | ||
G: Scope, | ||
G::Timestamp: Lattice + Refines<T>, | ||
T: Timestamp + Lattice, | ||
{ | ||
pub fn render_filter( | ||
&mut self, | ||
input: &RelationExpr, | ||
predicates: Vec<ScalarExpr>, | ||
) -> (Collection<G, Row>, Collection<G, DataflowError>) { | ||
let (ok_collection, err_collection) = self.collection(input).unwrap(); | ||
let (ok_collection, new_err_collection) = render_filter_inner(ok_collection, predicates); | ||
let err_collection = err_collection.concat(&new_err_collection); | ||
(ok_collection, err_collection) | ||
} | ||
} | ||
|
||
pub fn render_filter_inner<G>( | ||
collection: Collection<G, Row>, | ||
predicates: Vec<ScalarExpr>, | ||
) -> (Collection<G, Row>, Collection<G, DataflowError>) | ||
where | ||
G: Scope, | ||
G::Timestamp: Lattice, | ||
{ | ||
let temp_storage = repr::RowArena::new(); | ||
collection.filter_fallible(move |input_row| { | ||
let datums = input_row.unpack(); | ||
for p in &predicates { | ||
if p.eval(&datums, &temp_storage)? != Datum::True { | ||
return Ok(false); | ||
} | ||
} | ||
Ok::<_, DataflowError>(true) | ||
}) | ||
} |
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.