Skip to content

Commit b23529a

Browse files
committed
cleanup
1 parent ccc92b9 commit b23529a

File tree

1 file changed

+17
-40
lines changed

1 file changed

+17
-40
lines changed

datafusion/optimizer/src/common_subexpr_eliminate.rs

Lines changed: 17 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,37 @@ mod test {
15541548
Ok(())
15551549
}
15561550

1551+
fn test_identifier(hash: u64, expr: &Expr) -> Identifier {
1552+
Identifier {
1553+
hash,
1554+
expr,
1555+
}
1556+
}
1557+
15571558
#[test]
15581559
fn redundant_project_fields() {
15591560
let table_scan = test_table_scan().unwrap();
15601561
let c_plus_a = col("c") + col("a");
15611562
let b_plus_a = col("b") + col("a");
15621563
let common_exprs_1 = CommonExprs::from([
15631564
(
1564-
Identifier {
1565-
hash: 0,
1566-
expr: &c_plus_a,
1567-
},
1565+
test_identifier(0, &c_plus_a),
15681566
(c_plus_a.clone(), format!("{CSE_PREFIX}_1")),
15691567
),
15701568
(
1571-
Identifier {
1572-
hash: 1,
1573-
expr: &b_plus_a,
1574-
},
1569+
test_identifier(1, &b_plus_a),
15751570
(b_plus_a.clone(), format!("{CSE_PREFIX}_2")),
15761571
),
15771572
]);
15781573
let c_plus_a_2 = col(format!("{CSE_PREFIX}_1"));
15791574
let b_plus_a_2 = col(format!("{CSE_PREFIX}_2"));
15801575
let common_exprs_2 = CommonExprs::from([
15811576
(
1582-
Identifier {
1583-
hash: 3,
1584-
expr: &c_plus_a_2,
1585-
},
1577+
test_identifier(3, &c_plus_a_2),
15861578
(c_plus_a_2.clone(), format!("{CSE_PREFIX}_3")),
15871579
),
15881580
(
1589-
Identifier {
1590-
hash: 4,
1591-
expr: &b_plus_a_2,
1592-
},
1581+
test_identifier(4, &b_plus_a_2),
15931582
(b_plus_a_2.clone(), format!("{CSE_PREFIX}_4")),
15941583
),
15951584
]);
@@ -1615,35 +1604,23 @@ mod test {
16151604
let b_plus_a = col("test1.b") + col("test1.a");
16161605
let common_exprs_1 = CommonExprs::from([
16171606
(
1618-
Identifier {
1619-
hash: 0,
1620-
expr: &c_plus_a,
1621-
},
1607+
test_identifier(0, &c_plus_a),
16221608
(c_plus_a.clone(), format!("{CSE_PREFIX}_1")),
16231609
),
16241610
(
1625-
Identifier {
1626-
hash: 1,
1627-
expr: &b_plus_a,
1628-
},
1611+
test_identifier(1, &b_plus_a),
16291612
(b_plus_a.clone(), format!("{CSE_PREFIX}_2")),
16301613
),
16311614
]);
16321615
let c_plus_a_2 = col(format!("{CSE_PREFIX}_1"));
16331616
let b_plus_a_2 = col(format!("{CSE_PREFIX}_2"));
16341617
let common_exprs_2 = CommonExprs::from([
16351618
(
1636-
Identifier {
1637-
hash: 3,
1638-
expr: &c_plus_a_2,
1639-
},
1619+
test_identifier(3, &c_plus_a_2),
16401620
(c_plus_a_2.clone(), format!("{CSE_PREFIX}_3")),
16411621
),
16421622
(
1643-
Identifier {
1644-
hash: 4,
1645-
expr: &b_plus_a_2,
1646-
},
1623+
test_identifier(4, &b_plus_a_2),
16471624
(b_plus_a_2.clone(), format!("{CSE_PREFIX}_4")),
16481625
),
16491626
]);

0 commit comments

Comments
 (0)