Skip to content

Commit 2a77e6d

Browse files
committed
Implement shared graph/node setup helpers in cp_solver
- Shared graph/node setup helpers; assertions unchanged.
1 parent 59148b1 commit 2a77e6d

1 file changed

Lines changed: 34 additions & 32 deletions

File tree

‎datafusion/physical-expr/src/intervals/cp_solver.rs‎

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -837,12 +837,29 @@ mod tests {
837837
+ edges * size_of::<petgraph::graph::Edge<Option<usize>>>()
838838
}
839839

840+
fn graph_with_capacity(nodes: usize, edges: usize) -> ExprIntervalGraph {
841+
ExprIntervalGraph {
842+
graph: StableGraph::with_capacity(nodes, edges),
843+
root: NodeIndex::new(0),
844+
}
845+
}
846+
847+
fn add_interval_node(
848+
graph: &mut ExprIntervalGraph,
849+
expr: Arc<dyn PhysicalExpr>,
850+
lower: ScalarValue,
851+
upper: ScalarValue,
852+
) -> Result<NodeIndex> {
853+
let node = ExprIntervalGraphNode::new_with_interval(
854+
expr,
855+
Interval::try_new(lower, upper)?,
856+
);
857+
Ok(graph.graph.add_node(node))
858+
}
859+
840860
#[test]
841861
fn graph_size_counts_retained_capacity() -> Result<()> {
842-
let mut graph = ExprIntervalGraph {
843-
graph: StableGraph::with_capacity(0, 0),
844-
root: NodeIndex::new(0),
845-
};
862+
let mut graph = graph_with_capacity(0, 0);
846863
assert_eq!(graph.size(), size_of_val(&graph));
847864

848865
let expr: Arc<dyn PhysicalExpr> = Arc::new(Column::new("a", 0));
@@ -873,19 +890,13 @@ mod tests {
873890
// A large expression allocation is shared, not owned by the graph.
874891
let expr: Arc<dyn PhysicalExpr> =
875892
Arc::new(Literal::new(ScalarValue::Utf8(Some("x".repeat(4096)))));
876-
let mut graph = ExprIntervalGraph {
877-
graph: StableGraph::with_capacity(8, 8),
878-
root: NodeIndex::new(0),
879-
};
880-
graph
881-
.graph
882-
.add_node(ExprIntervalGraphNode::new_with_interval(
883-
Arc::clone(&expr),
884-
Interval::try_new(
885-
ScalarValue::Utf8(Some(lower)),
886-
ScalarValue::Utf8(Some(upper)),
887-
)?,
888-
));
893+
let mut graph = graph_with_capacity(8, 8);
894+
add_interval_node(
895+
&mut graph,
896+
Arc::clone(&expr),
897+
ScalarValue::Utf8(Some(lower)),
898+
ScalarValue::Utf8(Some(upper)),
899+
)?;
889900
assert_eq!(
890901
graph.size(),
891902
expected_graph_backing_size(&graph) + string_bytes
@@ -897,21 +908,12 @@ mod tests {
897908
let timezone_bytes = 2 * size_of::<usize>() + timezone.len();
898909
let mut timezone_nodes = Vec::with_capacity(2);
899910
for _ in 0..2 {
900-
timezone_nodes.push(graph.graph.add_node(
901-
ExprIntervalGraphNode::new_with_interval(
902-
Arc::clone(&expr),
903-
Interval::try_new(
904-
ScalarValue::TimestampNanosecond(
905-
Some(0),
906-
Some(Arc::clone(&timezone)),
907-
),
908-
ScalarValue::TimestampNanosecond(
909-
Some(1),
910-
Some(Arc::clone(&timezone)),
911-
),
912-
)?,
913-
),
914-
));
911+
timezone_nodes.push(add_interval_node(
912+
&mut graph,
913+
Arc::clone(&expr),
914+
ScalarValue::TimestampNanosecond(Some(0), Some(Arc::clone(&timezone))),
915+
ScalarValue::TimestampNanosecond(Some(1), Some(Arc::clone(&timezone))),
916+
)?);
915917
}
916918
assert_eq!(
917919
graph.size(),

0 commit comments

Comments
 (0)