From bac57d34efeeb5ecd744fe26f1dfd967c32574d9 Mon Sep 17 00:00:00 2001 From: gfh31fgh2 Date: Fri, 5 Dec 2025 15:21:55 +0500 Subject: [PATCH] Update Session.php grpc timeout --- src/Session.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Session.php b/src/Session.php index 3722b570..ac63399c 100644 --- a/src/Session.php +++ b/src/Session.php @@ -430,10 +430,11 @@ public function explainQuery($yql) /** * @param string $yql + * @param array $options * @return Statement * @throws Exception */ - public function prepare($yql) + public function prepare($yql, array $options = []) { $statement = new Statement($this, $yql); @@ -442,10 +443,24 @@ public function prepare($yql) return $statement; } - $result = $this->request('PrepareDataQuery', [ + $data = [ 'session_id' => $this->session_id, 'yql_text' => $yql, - ]); + ]; + + // Add operation_timeout if specified + if(isset($options['operation_timeout_ms'])){ + $operationParams = new OperationParams(); + $seconds = intdiv( $options['operation_timeout_ms'], 1000); // get seconds + $nanos = fmod($options['operation_timeout_ms'], 1000) * 1000000; // get ns + $operationParams->setOperationTimeout(new Duration([ + 'seconds' => $seconds, + 'nanos' => $nanos + ])); + $data['operation_params'] = $operationParams; + } + + $result = $this->request('PrepareDataQuery', $data); $statement->saveInCache();