Skip to content

Commit bac57d3

Browse files
authored
Update Session.php
grpc timeout
1 parent e479cc7 commit bac57d3

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/Session.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,11 @@ public function explainQuery($yql)
430430

431431
/**
432432
* @param string $yql
433+
* @param array $options
433434
* @return Statement
434435
* @throws Exception
435436
*/
436-
public function prepare($yql)
437+
public function prepare($yql, array $options = [])
437438
{
438439
$statement = new Statement($this, $yql);
439440

@@ -442,10 +443,24 @@ public function prepare($yql)
442443
return $statement;
443444
}
444445

445-
$result = $this->request('PrepareDataQuery', [
446+
$data = [
446447
'session_id' => $this->session_id,
447448
'yql_text' => $yql,
448-
]);
449+
];
450+
451+
// Add operation_timeout if specified
452+
if(isset($options['operation_timeout_ms'])){
453+
$operationParams = new OperationParams();
454+
$seconds = intdiv( $options['operation_timeout_ms'], 1000); // get seconds
455+
$nanos = fmod($options['operation_timeout_ms'], 1000) * 1000000; // get ns
456+
$operationParams->setOperationTimeout(new Duration([
457+
'seconds' => $seconds,
458+
'nanos' => $nanos
459+
]));
460+
$data['operation_params'] = $operationParams;
461+
}
462+
463+
$result = $this->request('PrepareDataQuery', $data);
449464

450465
$statement->saveInCache();
451466

0 commit comments

Comments
 (0)