66use GuzzleHttp \Client ;
77use GuzzleHttp \Exception \GuzzleException ;
88use GuzzleHttp \Exception \RequestException ;
9+ use Neo4j \QueryAPI \Objects \ChildQueryPlan ;
910use Neo4j \QueryAPI \Objects \QueryArguments ;
1011use Neo4j \QueryAPI \Objects \ResultCounters ;
1112use Neo4j \QueryAPI \Objects \ProfiledQueryPlan ;
1617use RuntimeException ;
1718use stdClass ;
1819
20+ /**
21+ * @method parseChildren(mixed $children)
22+ */
1923class Neo4jQueryAPI
2024{
2125 private Client $ client ;
@@ -75,43 +79,12 @@ public function run(string $cypher, array $parameters = [], string $database = '
7579 return new ResultRow ($ data );
7680 }, $ values );
7781
78- // Extract profile data, if available
79- $ profiledQueryPlan = null ;
82+
8083 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 ' ]);
11385 }
11486
87+
11588 // Return a ResultSet containing rows, counters, and the profiled query plan
11689 return new ResultSet (
11790 $ rows ,
@@ -131,7 +104,7 @@ public function run(string $cypher, array $parameters = [], string $database = '
131104 containsSystemUpdates: $ data ['counters ' ]['containsSystemUpdates ' ],
132105 systemUpdates: $ data ['counters ' ]['systemUpdates ' ]
133106 ),
134- $ profiledQueryPlan // Pass the profiled query plan here
107+ $ profile
135108 );
136109 } catch (RequestExceptionInterface $ e ) {
137110 $ response = $ e ->getResponse ();
@@ -156,4 +129,50 @@ public function beginTransaction(string $database = 'neo4j'): Transaction
156129
157130 return new Transaction ($ this ->client , $ clusterAffinity , $ transactionId );
158131 }
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+
159178}
0 commit comments