Skip to content

Commit 98d1878

Browse files
author
Илья
committed
Add queryStats and contInfo
1 parent 89ab62b commit 98d1878

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/QueryResult.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@
33
namespace YdbPlatform\Ydb;
44

55
use DateTime;
6+
use Ydb\CostInfo;
7+
use Ydb\TableStats\QueryStats;
68

79
class QueryResult
810
{
911
protected $columns = [];
1012
protected $rows = [];
1113
protected $truncated = false;
1214

15+
/**
16+
* @var CostInfo|null
17+
*/
18+
protected $costInfo = null;
19+
20+
/**
21+
* @var QueryStats|null
22+
*/
23+
protected $queryStats = null;
24+
1325
public function __construct($result)
1426
{
1527
if (method_exists($result, 'getResultSets'))
@@ -42,6 +54,14 @@ public function __construct($result)
4254
{
4355
throw new Exception('Unknown result');
4456
}
57+
58+
if(isset($result->costInfo)){
59+
$this->costInfo = $result->costInfo;
60+
}
61+
if (method_exists($result, 'getQueryStats'))
62+
{
63+
$this->queryStats = $result->getQueryStats();
64+
}
4565
}
4666

4767
public function isTruncated()
@@ -233,4 +253,13 @@ protected function fillRows($rows)
233253
$this->rows[] = $_row;
234254
}
235255
}
256+
257+
/**
258+
* @return CostInfo|null
259+
*/
260+
public function costInfo()
261+
{
262+
return $this->costInfo;
263+
}
264+
236265
}

src/Traits/RequestTrait.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace YdbPlatform\Ydb\Traits;
44

5+
use Ydb\Operations\OperationParams;
56
use Ydb\StatusIds\StatusCode;
67

78
use YdbPlatform\Ydb\Issue;
@@ -52,6 +53,13 @@ trait RequestTrait
5253
*/
5354
protected function doRequest($service, $method, array $data = [])
5455
{
56+
57+
$data['operation_params'] = new OperationParams([
58+
'report_cost_info' => 1
59+
]);
60+
if($method==='ExecuteDataQuery')
61+
$data['collect_stats'] = 10;
62+
5563
$this->checkDiscovery();
5664

5765
$this->meta['x-ydb-auth-ticket'] = [$this->credentials->token()];
@@ -234,7 +242,7 @@ protected function processResponse($service, $method, $response, $resultClass)
234242
}
235243

236244
$this->resetLastRequest();
237-
245+
$result->costInfo = $response->getCostInfo();
238246
return $result;
239247
}
240248
$statusName = StatusCode::name($statusCode);

0 commit comments

Comments
 (0)