Skip to content

Commit 4975be7

Browse files
author
Илья
committed
Add params in RequestTrait.php
1 parent 98d1878 commit 4975be7

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/Traits/RequestTrait.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
namespace YdbPlatform\Ydb\Traits;
44

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

9+
use Ydb\Table\QueryStatsCollection\Mode;
10+
use Ydb\TableStats\QueryStats;
811
use YdbPlatform\Ydb\Issue;
912
use YdbPlatform\Ydb\Exception;
1013
use YdbPlatform\Ydb\QueryResult;
@@ -42,6 +45,10 @@ trait RequestTrait
4245
*/
4346
protected $lastDiscovery = 0;
4447

48+
protected $collectStats = Mode::STATS_COLLECTION_UNSPECIFIED;
49+
50+
protected $reportCostInfo = Status::STATUS_UNSPECIFIED;
51+
4552
/**
4653
* Make a request to the service with the given method.
4754
*
@@ -54,12 +61,6 @@ trait RequestTrait
5461
protected function doRequest($service, $method, array $data = [])
5562
{
5663

57-
$data['operation_params'] = new OperationParams([
58-
'report_cost_info' => 1
59-
]);
60-
if($method==='ExecuteDataQuery')
61-
$data['collect_stats'] = 10;
62-
6364
$this->checkDiscovery();
6465

6566
$this->meta['x-ydb-auth-ticket'] = [$this->credentials->token()];
@@ -91,8 +92,16 @@ protected function doRequest($service, $method, array $data = [])
9192
$resultClass = '\\Ydb\\' . $service . '\\' . $method . 'Result';
9293
}
9394

95+
$data['operation_params'] = new OperationParams([
96+
'report_cost_info' => $this->reportCostInfo
97+
]);
98+
9499
$request = new $requestClass($data);
95100

101+
if (method_exists($request, 'setCollectStats')){
102+
$request->setCollectStats($this->collectStats);
103+
}
104+
96105
$this->logger()->debug(
97106
'YDB: Sending API request [' . $requestClass . '].',
98107
json_decode($request->serializeToJsonString(), true)
@@ -382,4 +391,21 @@ protected function checkDiscovery(){
382391
15 => "DATA_LOSS",
383392
16 => "UNAUTHENTICATED"
384393
];
394+
395+
/**
396+
* @param int $collectStats \Ydb\Table\QueryStatsCollection\Mode
397+
*/
398+
public function setCollectStats(int $collectStats): void
399+
{
400+
$this->collectStats = $collectStats;
401+
}
402+
403+
/**
404+
* @param int $reportCostInfo Ydb.FeatureFlag.Status
405+
*/
406+
public function setReportCostInfo(int $reportCostInfo): void
407+
{
408+
$this->reportCostInfo = $reportCostInfo;
409+
}
410+
385411
}

0 commit comments

Comments
 (0)