@@ -55,14 +55,14 @@ struct Identifier<'n> {
55
55
}
56
56
57
57
impl < ' n > Identifier < ' n > {
58
- pub fn new ( expr : & ' n Expr , random_state : & RandomState ) -> Self {
58
+ fn new ( expr : & ' n Expr , random_state : & RandomState ) -> Self {
59
59
let mut hasher = random_state. build_hasher ( ) ;
60
60
expr. hash_node ( & mut hasher) ;
61
61
let hash = hasher. finish ( ) ;
62
62
Self { hash, expr }
63
63
}
64
64
65
- pub fn combine ( mut self , other : Option < Self > ) -> Self {
65
+ fn combine ( mut self , other : Option < Self > ) -> Self {
66
66
other. map_or ( self , |other_id| {
67
67
self . hash = combine_hashes ( self . hash , other_id. hash ) ;
68
68
self
@@ -76,12 +76,6 @@ impl Hash for Identifier<'_> {
76
76
}
77
77
}
78
78
79
- impl From < Identifier < ' _ > > for String {
80
- fn from ( id : Identifier < ' _ > ) -> Self {
81
- format ! ( "common_{}" , id. hash)
82
- }
83
- }
84
-
85
79
/// A cache that contains the postorder index and the identifier of expression tree nodes
86
80
/// by the preorder index of the nodes.
87
81
///
@@ -1554,42 +1548,34 @@ mod test {
1554
1548
Ok ( ( ) )
1555
1549
}
1556
1550
1551
+ fn test_identifier ( hash : u64 , expr : & Expr ) -> Identifier {
1552
+ Identifier { hash, expr }
1553
+ }
1554
+
1557
1555
#[ test]
1558
1556
fn redundant_project_fields ( ) {
1559
1557
let table_scan = test_table_scan ( ) . unwrap ( ) ;
1560
1558
let c_plus_a = col ( "c" ) + col ( "a" ) ;
1561
1559
let b_plus_a = col ( "b" ) + col ( "a" ) ;
1562
1560
let common_exprs_1 = CommonExprs :: from ( [
1563
1561
(
1564
- Identifier {
1565
- hash : 0 ,
1566
- expr : & c_plus_a,
1567
- } ,
1562
+ test_identifier ( 0 , & c_plus_a) ,
1568
1563
( c_plus_a. clone ( ) , format ! ( "{CSE_PREFIX}_1" ) ) ,
1569
1564
) ,
1570
1565
(
1571
- Identifier {
1572
- hash : 1 ,
1573
- expr : & b_plus_a,
1574
- } ,
1566
+ test_identifier ( 1 , & b_plus_a) ,
1575
1567
( b_plus_a. clone ( ) , format ! ( "{CSE_PREFIX}_2" ) ) ,
1576
1568
) ,
1577
1569
] ) ;
1578
1570
let c_plus_a_2 = col ( format ! ( "{CSE_PREFIX}_1" ) ) ;
1579
1571
let b_plus_a_2 = col ( format ! ( "{CSE_PREFIX}_2" ) ) ;
1580
1572
let common_exprs_2 = CommonExprs :: from ( [
1581
1573
(
1582
- Identifier {
1583
- hash : 3 ,
1584
- expr : & c_plus_a_2,
1585
- } ,
1574
+ test_identifier ( 3 , & c_plus_a_2) ,
1586
1575
( c_plus_a_2. clone ( ) , format ! ( "{CSE_PREFIX}_3" ) ) ,
1587
1576
) ,
1588
1577
(
1589
- Identifier {
1590
- hash : 4 ,
1591
- expr : & b_plus_a_2,
1592
- } ,
1578
+ test_identifier ( 4 , & b_plus_a_2) ,
1593
1579
( b_plus_a_2. clone ( ) , format ! ( "{CSE_PREFIX}_4" ) ) ,
1594
1580
) ,
1595
1581
] ) ;
@@ -1615,35 +1601,23 @@ mod test {
1615
1601
let b_plus_a = col ( "test1.b" ) + col ( "test1.a" ) ;
1616
1602
let common_exprs_1 = CommonExprs :: from ( [
1617
1603
(
1618
- Identifier {
1619
- hash : 0 ,
1620
- expr : & c_plus_a,
1621
- } ,
1604
+ test_identifier ( 0 , & c_plus_a) ,
1622
1605
( c_plus_a. clone ( ) , format ! ( "{CSE_PREFIX}_1" ) ) ,
1623
1606
) ,
1624
1607
(
1625
- Identifier {
1626
- hash : 1 ,
1627
- expr : & b_plus_a,
1628
- } ,
1608
+ test_identifier ( 1 , & b_plus_a) ,
1629
1609
( b_plus_a. clone ( ) , format ! ( "{CSE_PREFIX}_2" ) ) ,
1630
1610
) ,
1631
1611
] ) ;
1632
1612
let c_plus_a_2 = col ( format ! ( "{CSE_PREFIX}_1" ) ) ;
1633
1613
let b_plus_a_2 = col ( format ! ( "{CSE_PREFIX}_2" ) ) ;
1634
1614
let common_exprs_2 = CommonExprs :: from ( [
1635
1615
(
1636
- Identifier {
1637
- hash : 3 ,
1638
- expr : & c_plus_a_2,
1639
- } ,
1616
+ test_identifier ( 3 , & c_plus_a_2) ,
1640
1617
( c_plus_a_2. clone ( ) , format ! ( "{CSE_PREFIX}_3" ) ) ,
1641
1618
) ,
1642
1619
(
1643
- Identifier {
1644
- hash : 4 ,
1645
- expr : & b_plus_a_2,
1646
- } ,
1620
+ test_identifier ( 4 , & b_plus_a_2) ,
1647
1621
( b_plus_a_2. clone ( ) , format ! ( "{CSE_PREFIX}_4" ) ) ,
1648
1622
) ,
1649
1623
] ) ;
0 commit comments