Skip to content

Commit a0913aa

Browse files
committed
cleanup
1 parent ccc92b9 commit a0913aa

File tree

1 file changed

+14
-40
lines changed

1 file changed

+14
-40
lines changed

datafusion/optimizer/src/common_subexpr_eliminate.rs

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ struct Identifier<'n> {
5555
}
5656

5757
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 {
5959
let mut hasher = random_state.build_hasher();
6060
expr.hash_node(&mut hasher);
6161
let hash = hasher.finish();
6262
Self { hash, expr }
6363
}
6464

65-
pub fn combine(mut self, other: Option<Self>) -> Self {
65+
fn combine(mut self, other: Option<Self>) -> Self {
6666
other.map_or(self, |other_id| {
6767
self.hash = combine_hashes(self.hash, other_id.hash);
6868
self
@@ -76,12 +76,6 @@ impl Hash for Identifier<'_> {
7676
}
7777
}
7878

79-
impl From<Identifier<'_>> for String {
80-
fn from(id: Identifier<'_>) -> Self {
81-
format!("common_{}", id.hash)
82-
}
83-
}
84-
8579
/// A cache that contains the postorder index and the identifier of expression tree nodes
8680
/// by the preorder index of the nodes.
8781
///
@@ -1554,42 +1548,34 @@ mod test {
15541548
Ok(())
15551549
}
15561550

1551+
fn test_identifier(hash: u64, expr: &Expr) -> Identifier {
1552+
Identifier { hash, expr }
1553+
}
1554+
15571555
#[test]
15581556
fn redundant_project_fields() {
15591557
let table_scan = test_table_scan().unwrap();
15601558
let c_plus_a = col("c") + col("a");
15611559
let b_plus_a = col("b") + col("a");
15621560
let common_exprs_1 = CommonExprs::from([
15631561
(
1564-
Identifier {
1565-
hash: 0,
1566-
expr: &c_plus_a,
1567-
},
1562+
test_identifier(0, &c_plus_a),
15681563
(c_plus_a.clone(), format!("{CSE_PREFIX}_1")),
15691564
),
15701565
(
1571-
Identifier {
1572-
hash: 1,
1573-
expr: &b_plus_a,
1574-
},
1566+
test_identifier(1, &b_plus_a),
15751567
(b_plus_a.clone(), format!("{CSE_PREFIX}_2")),
15761568
),
15771569
]);
15781570
let c_plus_a_2 = col(format!("{CSE_PREFIX}_1"));
15791571
let b_plus_a_2 = col(format!("{CSE_PREFIX}_2"));
15801572
let common_exprs_2 = CommonExprs::from([
15811573
(
1582-
Identifier {
1583-
hash: 3,
1584-
expr: &c_plus_a_2,
1585-
},
1574+
test_identifier(3, &c_plus_a_2),
15861575
(c_plus_a_2.clone(), format!("{CSE_PREFIX}_3")),
15871576
),
15881577
(
1589-
Identifier {
1590-
hash: 4,
1591-
expr: &b_plus_a_2,
1592-
},
1578+
test_identifier(4, &b_plus_a_2),
15931579
(b_plus_a_2.clone(), format!("{CSE_PREFIX}_4")),
15941580
),
15951581
]);
@@ -1615,35 +1601,23 @@ mod test {
16151601
let b_plus_a = col("test1.b") + col("test1.a");
16161602
let common_exprs_1 = CommonExprs::from([
16171603
(
1618-
Identifier {
1619-
hash: 0,
1620-
expr: &c_plus_a,
1621-
},
1604+
test_identifier(0, &c_plus_a),
16221605
(c_plus_a.clone(), format!("{CSE_PREFIX}_1")),
16231606
),
16241607
(
1625-
Identifier {
1626-
hash: 1,
1627-
expr: &b_plus_a,
1628-
},
1608+
test_identifier(1, &b_plus_a),
16291609
(b_plus_a.clone(), format!("{CSE_PREFIX}_2")),
16301610
),
16311611
]);
16321612
let c_plus_a_2 = col(format!("{CSE_PREFIX}_1"));
16331613
let b_plus_a_2 = col(format!("{CSE_PREFIX}_2"));
16341614
let common_exprs_2 = CommonExprs::from([
16351615
(
1636-
Identifier {
1637-
hash: 3,
1638-
expr: &c_plus_a_2,
1639-
},
1616+
test_identifier(3, &c_plus_a_2),
16401617
(c_plus_a_2.clone(), format!("{CSE_PREFIX}_3")),
16411618
),
16421619
(
1643-
Identifier {
1644-
hash: 4,
1645-
expr: &b_plus_a_2,
1646-
},
1620+
test_identifier(4, &b_plus_a_2),
16471621
(b_plus_a_2.clone(), format!("{CSE_PREFIX}_4")),
16481622
),
16491623
]);

0 commit comments

Comments
 (0)