25
25
import org .neo4j .gds .core .concurrency .Pools ;
26
26
import org .neo4j .gds .core .utils .ProgressTimer ;
27
27
import org .neo4j .gds .core .utils .statistics .CentralityStatistics ;
28
+ import org .neo4j .gds .scaling .ScalarScaler ;
28
29
import org .neo4j .internal .kernel .api .procs .ProcedureCallContext ;
29
30
31
+ import java .util .HashMap ;
30
32
import java .util .Map ;
31
33
import java .util .Optional ;
32
34
import java .util .function .LongToDoubleFunction ;
33
35
34
36
public abstract class AbstractCentralityResultBuilder <WRITE_RESULT > extends AbstractResultBuilder <WRITE_RESULT > {
35
37
38
+ private static final String HISTOGRAM_ERROR_KEY = "Error" ;
39
+
36
40
private final int concurrency ;
37
41
protected boolean buildHistogram ;
38
42
39
43
protected long postProcessingMillis = -1L ;
40
44
protected Optional <DoubleHistogram > maybeCentralityHistogram = Optional .empty ();
41
45
46
+ protected Map <String , Object > histogramError ;
47
+
42
48
protected @ Nullable Map <String , Object > centralityHistogramOrNull () {
43
49
return maybeCentralityHistogram .map (histogram -> MapUtil .map (
44
50
"min" , histogram .getMinValue (),
@@ -50,10 +56,11 @@ public abstract class AbstractCentralityResultBuilder<WRITE_RESULT> extends Abst
50
56
"p95" , histogram .getValueAtPercentile (95 ),
51
57
"p99" , histogram .getValueAtPercentile (99 ),
52
58
"p999" , histogram .getValueAtPercentile (99.9 )
53
- )).orElse (null );
59
+ )).orElse (histogramError );
54
60
}
55
61
56
62
protected LongToDoubleFunction centralityFunction = null ;
63
+ protected ScalarScaler .Variant scaler ;
57
64
58
65
protected AbstractCentralityResultBuilder (
59
66
ProcedureCallContext callContext ,
@@ -63,6 +70,7 @@ protected AbstractCentralityResultBuilder(
63
70
.outputFields ()
64
71
.anyMatch (s -> s .equalsIgnoreCase ("centralityDistribution" ));
65
72
this .concurrency = concurrency ;
73
+ this .histogramError = new HashMap <>();
66
74
}
67
75
68
76
protected abstract WRITE_RESULT buildResult ();
@@ -72,17 +80,36 @@ public AbstractCentralityResultBuilder<WRITE_RESULT> withCentralityFunction(Long
72
80
return this ;
73
81
}
74
82
83
+ public AbstractCentralityResultBuilder <WRITE_RESULT > withScalerVariant (ScalarScaler .Variant scaler ) {
84
+ this .scaler = scaler ;
85
+ return this ;
86
+ }
87
+
75
88
@ Override
76
89
public WRITE_RESULT build () {
77
90
final ProgressTimer timer = ProgressTimer .start ();
78
91
92
+ var logScaler = scaler == ScalarScaler .Variant .LOG ;
79
93
if (buildHistogram && centralityFunction != null ) {
80
- maybeCentralityHistogram = Optional .of (CentralityStatistics .histogram (nodeCount , centralityFunction ,Pools .DEFAULT , concurrency ));
94
+ if (logScaler ) {
95
+ logScalerHistogramError ();
96
+ } else {
97
+ maybeCentralityHistogram = Optional .of (CentralityStatistics .histogram (
98
+ nodeCount ,
99
+ centralityFunction ,
100
+ Pools .DEFAULT ,
101
+ concurrency
102
+ ));
103
+ }
81
104
}
82
105
timer .stop ();
83
106
this .postProcessingMillis = timer .getDuration ();
84
107
85
108
return buildResult ();
86
109
}
87
110
111
+ private void logScalerHistogramError () {
112
+ this .histogramError .put (HISTOGRAM_ERROR_KEY , "Unable to create histogram when using scaler of type " + ScalarScaler .Variant .LOG );
113
+ }
114
+
88
115
}
0 commit comments