6
6
use GuzzleHttp \Client ;
7
7
use GuzzleHttp \Exception \GuzzleException ;
8
8
use GuzzleHttp \Exception \RequestException ;
9
+ use Neo4j \QueryAPI \Objects \ChildQueryPlan ;
9
10
use Neo4j \QueryAPI \Objects \QueryArguments ;
10
11
use Neo4j \QueryAPI \Objects \ResultCounters ;
11
12
use Neo4j \QueryAPI \Objects \ProfiledQueryPlan ;
16
17
use RuntimeException ;
17
18
use stdClass ;
18
19
20
+ /**
21
+ * @method parseChildren(mixed $children)
22
+ */
19
23
class Neo4jQueryAPI
20
24
{
21
25
private Client $ client ;
@@ -75,43 +79,12 @@ public function run(string $cypher, array $parameters = [], string $database = '
75
79
return new ResultRow ($ data );
76
80
}, $ values );
77
81
78
- // Extract profile data, if available
79
- $ profiledQueryPlan = null ;
82
+
80
83
if (isset ($ data ['profiledQueryPlan ' ])) {
81
- $ profiledQueryPlan = new ProfiledQueryPlan (
82
- $ data ['profile ' ]['dbHits ' ],
83
- $ data ['profile ' ]['records ' ],
84
- $ data ['profile ' ]['hasPageCacheStats ' ],
85
- $ data ['profile ' ]['pageCacheHits ' ],
86
- $ data ['profile ' ]['pageCacheMisses ' ],
87
- $ data ['profile ' ]['pageCacheHitRatio ' ],
88
- $ data ['profile ' ]['time ' ],
89
- $ data ['profile ' ]['operatorType ' ],
90
- $ data ['profile ' ]['arguments ' ]
91
- );
92
- }
93
- $ queryArguments = null ;
94
- if (isset ($ data ['profiledQueryPlan ' ]['arguments ' ])) {
95
- $ queryArguments = new QueryArguments (
96
- $ data ['profile ' ]['globalMemory ' ] ?? 0 ,
97
- $ data ['profile ' ]['plannerImpl ' ] ?? '' ,
98
- $ data ['profile ' ]['memory ' ] ?? 0 ,
99
- $ data ['profile ' ]['stringRepresentation ' ] ?? '' ,
100
- $ data ['profile ' ]['runtime ' ] ?? '' ,
101
- $ data ['profile ' ]['runtimeImpl ' ] ?? '' ,
102
- $ data ['profile ' ]['dbHits ' ] ?? 0 ,
103
- $ data ['profile ' ]['batchSize ' ] ?? 0 ,
104
- $ data ['profile ' ]['details ' ] ?? '' ,
105
- $ data ['profile ' ]['plannerVersion ' ] ?? '' ,
106
- $ data ['profile ' ]['pipelineInfo ' ] ?? '' ,
107
- $ data ['profile ' ]['runtimeVersion ' ] ?? '' ,
108
- $ data ['profile ' ]['id ' ] ?? 0 ,
109
- $ data ['profile ' ]['estimatedRows ' ] ?? 0.0 ,
110
- $ data ['profile ' ]['planner ' ] ?? '' ,
111
- $ data ['profile ' ]['rows ' ] ?? 0
112
- );
84
+ $ profile = $ this ->createProfileData ($ data ['profiledQueryPlan ' ]);
113
85
}
114
86
87
+
115
88
// Return a ResultSet containing rows, counters, and the profiled query plan
116
89
return new ResultSet (
117
90
$ rows ,
@@ -131,7 +104,7 @@ public function run(string $cypher, array $parameters = [], string $database = '
131
104
containsSystemUpdates: $ data ['counters ' ]['containsSystemUpdates ' ],
132
105
systemUpdates: $ data ['counters ' ]['systemUpdates ' ]
133
106
),
134
- $ profiledQueryPlan // Pass the profiled query plan here
107
+ $ profile
135
108
);
136
109
} catch (RequestExceptionInterface $ e ) {
137
110
$ response = $ e ->getResponse ();
@@ -156,4 +129,50 @@ public function beginTransaction(string $database = 'neo4j'): Transaction
156
129
157
130
return new Transaction ($ this ->client , $ clusterAffinity , $ transactionId );
158
131
}
132
+
133
+ private function createProfileData (array $ data ): ProfiledQueryPlan
134
+ {
135
+ $ arguments = $ data ['arguments ' ];
136
+
137
+ $ queryArguments = new QueryArguments (
138
+ $ arguments ['globalMemory ' ] ?? 0 ,
139
+ $ arguments ['plannerImpl ' ] ?? '' ,
140
+ $ arguments ['memory ' ] ?? 0 ,
141
+ $ arguments ['stringRepresentation ' ] ?? '' ,
142
+ is_string ($ arguments ['runtime ' ] ?? '' ) ? $ arguments ['runtime ' ] : json_encode ($ arguments ['runtime ' ]),
143
+ $ arguments ['runtimeImpl ' ] ?? '' ,
144
+ $ arguments ['dbHits ' ] ?? 0 ,
145
+ $ arguments ['batchSize ' ] ?? 0 ,
146
+ $ arguments ['details ' ] ?? '' ,
147
+ $ arguments ['plannerVersion ' ] ?? '' ,
148
+ $ arguments ['pipelineInfo ' ] ?? '' ,
149
+ $ arguments ['runtimeVersion ' ] ?? '' ,
150
+ $ arguments ['id ' ] ?? 0 ,
151
+ $ arguments ['estimatedRows ' ] ?? 0.0 ,
152
+ is_string ($ arguments ['planner ' ] ?? '' ) ? $ arguments ['planner ' ] : json_encode ($ arguments ['planner ' ]),
153
+ $ arguments ['rows ' ] ?? 0
154
+ );
155
+
156
+ $ profiledQueryPlan = new ProfiledQueryPlan (
157
+ $ data ['dbHits ' ],
158
+ $ data ['records ' ],
159
+ $ data ['hasPageCacheStats ' ],
160
+ $ data ['pageCacheHits ' ],
161
+ $ data ['pageCacheMisses ' ],
162
+ $ data ['pageCacheHitRatio ' ],
163
+ $ data ['time ' ],
164
+ $ data ['operatorType ' ],
165
+ $ queryArguments
166
+ );
167
+
168
+ foreach ($ data ['children ' ] as $ child ) {
169
+ $ childQueryPlan = $ this ->createProfileData ($ child );
170
+
171
+ $ profiledQueryPlan ->addChild ($ childQueryPlan );
172
+ }
173
+
174
+ return $ profiledQueryPlan ;
175
+ }
176
+
177
+
159
178
}
0 commit comments