MCPcopy Create free account
hub / github.com/apache/datafusion / id_array_visitor

Function id_array_visitor

datafusion/common/src/cse.rs:762–911  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

760
761 #[test]
762 fn id_array_visitor() -> Result<()> {
763 let alias_generator = AliasGenerator::new();
764 let eliminator = CSE::new(TestTreeNodeCSEController::new(
765 &alias_generator,
766 TestTreeNodeMask::Normal,
767 ));
768
769 let a_plus_1 = TestTreeNode::new(
770 vec![
771 TestTreeNode::new_leaf("a".to_string()),
772 TestTreeNode::new_leaf("1".to_string()),
773 ],
774 "+".to_string(),
775 );
776 let avg_c = TestTreeNode::new(
777 vec![TestTreeNode::new_leaf("c".to_string())],
778 "avg".to_string(),
779 );
780 let sum_a_plus_1 = TestTreeNode::new(vec![a_plus_1], "sum".to_string());
781 let sum_a_plus_1_minus_avg_c =
782 TestTreeNode::new(vec![sum_a_plus_1, avg_c], "-".to_string());
783 let root = TestTreeNode::new(
784 vec![
785 sum_a_plus_1_minus_avg_c,
786 TestTreeNode::new_leaf("2".to_string()),
787 ],
788 "*".to_string(),
789 );
790
791 let [sum_a_plus_1_minus_avg_c, _] = root.children.as_slice() else {
792 panic!("Cannot extract subtree references")
793 };
794 let [sum_a_plus_1, avg_c] = sum_a_plus_1_minus_avg_c.children.as_slice() else {
795 panic!("Cannot extract subtree references")
796 };
797 let [a_plus_1] = sum_a_plus_1.children.as_slice() else {
798 panic!("Cannot extract subtree references")
799 };
800
801 // skip aggregates
802 let mut id_array = vec![];
803 eliminator.node_to_id_array(&root, &mut NodeStats::new(), &mut id_array)?;
804
805 // Collect distinct hashes and set them to 0 in `id_array`
806 fn collect_hashes(
807 id_array: &mut IdArray<'_, TestTreeNode<String>>,
808 ) -> HashSet<u64> {
809 id_array
810 .iter_mut()
811 .flat_map(|(_, id_option)| {
812 id_option.as_mut().map(|node_id| {
813 let hash = node_id.hash;
814 node_id.hash = 0;
815 hash
816 })
817 })
818 .collect::<HashSet<_>>()
819 }

Callers

nothing calls this directly

Calls 4

newFunction · 0.85
collect_hashesFunction · 0.85
node_to_id_arrayMethod · 0.80
to_stringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…