Skip to content

Commit bf684da

Browse files
author
Илья
committed
Set token extension from json to txt
1 parent 1377125 commit bf684da

File tree

4 files changed

+89
-23
lines changed

4 files changed

+89
-23
lines changed

src/QueryResult.php

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

55
use DateTime;
6-
use Ydb\CostInfo;
7-
use Ydb\TableStats\QueryStats;
86

97
class QueryResult
108
{
119
protected $columns = [];
1210
protected $rows = [];
1311
protected $truncated = false;
1412

15-
/**
16-
* @var CostInfo|null
17-
*/
18-
protected $costInfo = null;
19-
2013
/**
2114
* @var QueryStats|null
2215
*/
@@ -55,9 +48,9 @@ public function __construct($result)
5548
throw new Exception('Unknown result');
5649
}
5750

58-
if (method_exists($result, 'getQueryStats'))
51+
if (method_exists($result, 'getQueryStats') && $result->getQueryStats())
5952
{
60-
$this->queryStats = $result->getQueryStats();
53+
$this->queryStats = new QueryStats($result->getQueryStats());
6154
}
6255
}
6356

src/QueryStats.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace YdbPlatform\Ydb;
4+
5+
class QueryStats
6+
{
7+
8+
private $query_phases;
9+
protected $compilation = null;
10+
protected $process_cpu_time_us = 0;
11+
protected $query_plan = '';
12+
protected $query_ast = '';
13+
protected $total_duration_us = 0;
14+
protected $total_cpu_time_us = 0;
15+
public function __construct(\Ydb\TableStats\QueryStats $queryStats)
16+
{
17+
$this->compilation = $queryStats->getCompilation();
18+
$this->query_ast = $queryStats->getQueryAst();
19+
$this->query_plan = $queryStats->getQueryPlan();
20+
$this->query_phases = $queryStats->getQueryPhases();
21+
$this->total_cpu_time_us = $queryStats->getTotalCpuTimeUs();
22+
$this->total_duration_us = $queryStats->getTotalDurationUs();
23+
$this->process_cpu_time_us = $queryStats->getProcessCpuTimeUs();
24+
}
25+
26+
/**
27+
* @return \Google\Protobuf\Internal\RepeatedField
28+
*/
29+
public function getQueryPhases(): \Google\Protobuf\Internal\RepeatedField
30+
{
31+
return $this->query_phases;
32+
}
33+
34+
/**
35+
* @return \Ydb\TableStats\CompilationStats|null
36+
*/
37+
public function getCompilation(): ?\Ydb\TableStats\CompilationStats
38+
{
39+
return $this->compilation;
40+
}
41+
42+
/**
43+
* @return int|string
44+
*/
45+
public function getProcessCpuTimeUs()
46+
{
47+
return $this->process_cpu_time_us;
48+
}
49+
50+
/**
51+
* @return string
52+
*/
53+
public function getQueryPlan(): string
54+
{
55+
return $this->query_plan;
56+
}
57+
58+
/**
59+
* @return string
60+
*/
61+
public function getQueryAst(): string
62+
{
63+
return $this->query_ast;
64+
}
65+
66+
/**
67+
* @return int|string
68+
*/
69+
public function getTotalDurationUs()
70+
{
71+
return $this->total_duration_us;
72+
}
73+
74+
/**
75+
* @return int|string
76+
*/
77+
public function getTotalCpuTimeUs()
78+
{
79+
return $this->total_cpu_time_us;
80+
}
81+
82+
}

src/Session.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public function executeQuery(YdbQuery $query)
345345
* @return bool|QueryResult
346346
* @throws \YdbPlatform\Ydb\Exception
347347
*/
348-
public function query($yql, array $parameters = null)
348+
public function query($yql, array $parameters = null, array $options = [])
349349
{
350350
$tx_id = $this->tx_id;
351351

@@ -363,6 +363,10 @@ public function query($yql, array $parameters = null)
363363
->txControl($tx_control)
364364
->keepInCache($this->keep_query_in_cache ?? ($parameters&&count($parameters)>0));
365365

366+
if(isset($options['collectStats'])){
367+
$query->collectStats($options['collectStats']);
368+
}
369+
366370
return $this->executeQuery($query);
367371
}
368372

src/Traits/RequestTrait.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ trait RequestTrait
4242
*/
4343
protected $lastDiscovery = 0;
4444

45-
protected $collectStats = CollectQueryStatsMode::STATS_COLLECTION_UNSPECIFIED;
4645

4746

4847
/**
@@ -90,10 +89,6 @@ protected function doRequest($service, $method, array $data = [])
9089

9190
$request = new $requestClass($data);
9291

93-
if (method_exists($request, 'setCollectStats')){
94-
$request->setCollectStats($this->collectStats);
95-
}
96-
9792
$this->logger()->debug(
9893
'YDB: Sending API request [' . $requestClass . '].',
9994
json_decode($request->serializeToJsonString(), true)
@@ -383,12 +378,4 @@ protected function checkDiscovery(){
383378
16 => "UNAUTHENTICATED"
384379
];
385380

386-
/**
387-
* @param int $collectStats YdbPlatform\Ydb\Enums\CollectQueryStatsMode
388-
*/
389-
public function setCollectStats(int $collectStats): void
390-
{
391-
$this->collectStats = $collectStats;
392-
}
393-
394381
}

0 commit comments

Comments
 (0)