query_planning/plan/graph_algorithm/
structure.rs1use std::fmt;
3
4use super::{GraphConstructionOptions, GraphEdgeColumnBindings};
5
6#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct EdgeNormalizeSpec {
13 pub edge_columns: GraphEdgeColumnBindings,
15 pub add_reverse: bool,
17 pub dedup: EdgeDedupStrategy,
19 pub weight_combiner: EdgeWeightCombiner,
21}
22
23impl EdgeNormalizeSpec {
24 pub fn python_cugraph(edge_columns: GraphEdgeColumnBindings, graph_options: &GraphConstructionOptions) -> Self {
26 let has_weight = edge_columns.weight.is_some();
27 let (dedup, weight_combiner) = match (graph_options.directed, has_weight) {
28 (_, false) => (EdgeDedupStrategy::KeepLast, EdgeWeightCombiner::None),
29 (true, true) => (EdgeDedupStrategy::KeepLast, EdgeWeightCombiner::KeepLastInputOrder),
30 (false, true) => (EdgeDedupStrategy::KeepFirst, EdgeWeightCombiner::MinWeight),
31 };
32 Self { edge_columns, add_reverse: !graph_options.directed, dedup, weight_combiner }
33 }
34}
35
36#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
38pub enum EdgeDedupStrategy {
39 None,
41 KeepFirst,
43 KeepLast,
45}
46
47impl EdgeDedupStrategy {
48 pub const fn as_str(self) -> &'static str {
50 match self {
51 Self::None => "none",
52 Self::KeepFirst => "keep_first",
53 Self::KeepLast => "keep_last",
54 }
55 }
56}
57
58impl fmt::Display for EdgeDedupStrategy {
59 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60 f.write_str(self.as_str())
61 }
62}
63
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
66pub enum EdgeWeightCombiner {
67 None,
69 MinWeight,
71 KeepLastInputOrder,
73}
74
75impl EdgeWeightCombiner {
76 pub const fn as_str(self) -> &'static str {
78 match self {
79 Self::None => "none",
80 Self::MinWeight => "min_weight",
81 Self::KeepLastInputOrder => "keep_last_input_order",
82 }
83 }
84}
85
86impl fmt::Display for EdgeWeightCombiner {
87 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
88 f.write_str(self.as_str())
89 }
90}
91
92#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
98pub enum GraphKCoreDegreeType {
99 In,
101 Out,
103 #[default]
104 InOut,
106}
107
108impl GraphKCoreDegreeType {
109 pub const fn as_str(self) -> &'static str {
111 match self {
112 Self::In => "in",
113 Self::Out => "out",
114 Self::InOut => "in_out",
115 }
116 }
117}
118
119impl fmt::Display for GraphKCoreDegreeType {
120 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
121 f.write_str(self.as_str())
122 }
123}
124
125#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
129pub struct GraphDegreesAllParams;
130
131#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
136pub struct GraphInDegreesAllParams;
137
138#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
143pub struct GraphOutDegreesAllParams;
144
145#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
149pub struct GraphTriangleCountAllParams;
150
151#[derive(Debug, Clone, Copy, PartialEq, Eq)]
153pub struct GraphCoreNumberParams {
154 pub degree_type: GraphKCoreDegreeType,
156}
157
158impl Default for GraphCoreNumberParams {
159 fn default() -> Self {
160 Self { degree_type: GraphKCoreDegreeType::InOut }
161 }
162}
163
164#[derive(Debug, Clone, Copy, PartialEq, Eq)]
169pub struct GraphKCoreParams {
170 pub k: u32,
172 pub degree_type: GraphKCoreDegreeType,
174}
175
176impl Default for GraphKCoreParams {
177 fn default() -> Self {
178 Self { k: 2, degree_type: GraphKCoreDegreeType::InOut }
179 }
180}
181
182#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
186pub struct GraphMstParams;