From 1bec360439b6be070d853bf2d06062029a256f15 Mon Sep 17 00:00:00 2001 From: Anthony Yeh Date: Wed, 30 Mar 2016 12:19:24 -0700 Subject: [PATCH] php: Prepare for SplitQueryV2 migration. See #1599 --- .../Vitess/Proto/Query/SplitQueryRequest.php | 181 +++++++++++++++++- .../Query/SplitQueryRequest/Algorithm.php | 11 ++ .../Vitess/Proto/Vtgate/SplitQueryRequest.php | 181 +++++++++++++++++- php/src/Vitess/VTGateConn.php | 4 +- 4 files changed, 360 insertions(+), 17 deletions(-) create mode 100644 php/src/Vitess/Proto/Query/SplitQueryRequest/Algorithm.php diff --git a/php/src/Vitess/Proto/Query/SplitQueryRequest.php b/php/src/Vitess/Proto/Query/SplitQueryRequest.php index 24048f3037..a65a84c7dc 100644 --- a/php/src/Vitess/Proto/Query/SplitQueryRequest.php +++ b/php/src/Vitess/Proto/Query/SplitQueryRequest.php @@ -18,15 +18,24 @@ namespace Vitess\Proto\Query { /** @var \Vitess\Proto\Query\BoundQuery */ public $query = null; - /** @var string */ - public $split_column = null; + /** @var string[] */ + public $split_column = array(); /** @var int */ public $split_count = null; + /** @var int */ + public $num_rows_per_query_part = null; + /** @var int */ public $session_id = null; + /** @var int - \Vitess\Proto\Query\SplitQueryRequest\Algorithm */ + public $algorithm = null; + + /** @var boolean */ + public $use_split_query_v2 = null; + /** @var \Closure[] */ protected static $__extensions = array(); @@ -71,12 +80,12 @@ namespace Vitess\Proto\Query { $f->reference = '\Vitess\Proto\Query\BoundQuery'; $descriptor->addField($f); - // OPTIONAL STRING split_column = 5 + // REPEATED STRING split_column = 5 $f = new \DrSlump\Protobuf\Field(); $f->number = 5; $f->name = "split_column"; $f->type = \DrSlump\Protobuf::TYPE_STRING; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->rule = \DrSlump\Protobuf::RULE_REPEATED; $descriptor->addField($f); // OPTIONAL INT64 split_count = 6 @@ -87,6 +96,14 @@ namespace Vitess\Proto\Query { $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $descriptor->addField($f); + // OPTIONAL INT64 num_rows_per_query_part = 8 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 8; + $f->name = "num_rows_per_query_part"; + $f->type = \DrSlump\Protobuf::TYPE_INT64; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $descriptor->addField($f); + // OPTIONAL INT64 session_id = 7 $f = new \DrSlump\Protobuf\Field(); $f->number = 7; @@ -95,6 +112,23 @@ namespace Vitess\Proto\Query { $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $descriptor->addField($f); + // OPTIONAL ENUM algorithm = 9 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 9; + $f->name = "algorithm"; + $f->type = \DrSlump\Protobuf::TYPE_ENUM; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->reference = '\Vitess\Proto\Query\SplitQueryRequest\Algorithm'; + $descriptor->addField($f); + + // OPTIONAL BOOL use_split_query_v2 = 10 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 10; + $f->name = "use_split_query_v2"; + $f->type = \DrSlump\Protobuf::TYPE_BOOL; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $descriptor->addField($f); + foreach (self::$__extensions as $cb) { $descriptor->addField($cb(), true); } @@ -271,10 +305,11 @@ namespace Vitess\Proto\Query { /** * Get value * + * @param int $idx * @return string */ - public function getSplitColumn(){ - return $this->_get(5); + public function getSplitColumn($idx = NULL){ + return $this->_get(5, $idx); } /** @@ -283,8 +318,27 @@ namespace Vitess\Proto\Query { * @param string $value * @return \Vitess\Proto\Query\SplitQueryRequest */ - public function setSplitColumn( $value){ - return $this->_set(5, $value); + public function setSplitColumn( $value, $idx = NULL){ + return $this->_set(5, $value, $idx); + } + + /** + * Get all elements of + * + * @return string[] + */ + public function getSplitColumnList(){ + return $this->_get(5); + } + + /** + * Add a new element to + * + * @param string $value + * @return \Vitess\Proto\Query\SplitQueryRequest + */ + public function addSplitColumn( $value){ + return $this->_add(5, $value); } /** @@ -324,6 +378,43 @@ namespace Vitess\Proto\Query { return $this->_set(6, $value); } + /** + * Check if has a value + * + * @return boolean + */ + public function hasNumRowsPerQueryPart(){ + return $this->_has(8); + } + + /** + * Clear value + * + * @return \Vitess\Proto\Query\SplitQueryRequest + */ + public function clearNumRowsPerQueryPart(){ + return $this->_clear(8); + } + + /** + * Get value + * + * @return int + */ + public function getNumRowsPerQueryPart(){ + return $this->_get(8); + } + + /** + * Set value + * + * @param int $value + * @return \Vitess\Proto\Query\SplitQueryRequest + */ + public function setNumRowsPerQueryPart( $value){ + return $this->_set(8, $value); + } + /** * Check if has a value * @@ -360,6 +451,80 @@ namespace Vitess\Proto\Query { public function setSessionId( $value){ return $this->_set(7, $value); } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasAlgorithm(){ + return $this->_has(9); + } + + /** + * Clear value + * + * @return \Vitess\Proto\Query\SplitQueryRequest + */ + public function clearAlgorithm(){ + return $this->_clear(9); + } + + /** + * Get value + * + * @return int - \Vitess\Proto\Query\SplitQueryRequest\Algorithm + */ + public function getAlgorithm(){ + return $this->_get(9); + } + + /** + * Set value + * + * @param int - \Vitess\Proto\Query\SplitQueryRequest\Algorithm $value + * @return \Vitess\Proto\Query\SplitQueryRequest + */ + public function setAlgorithm( $value){ + return $this->_set(9, $value); + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasUseSplitQueryV2(){ + return $this->_has(10); + } + + /** + * Clear value + * + * @return \Vitess\Proto\Query\SplitQueryRequest + */ + public function clearUseSplitQueryV2(){ + return $this->_clear(10); + } + + /** + * Get value + * + * @return boolean + */ + public function getUseSplitQueryV2(){ + return $this->_get(10); + } + + /** + * Set value + * + * @param boolean $value + * @return \Vitess\Proto\Query\SplitQueryRequest + */ + public function setUseSplitQueryV2( $value){ + return $this->_set(10, $value); + } } } diff --git a/php/src/Vitess/Proto/Query/SplitQueryRequest/Algorithm.php b/php/src/Vitess/Proto/Query/SplitQueryRequest/Algorithm.php new file mode 100644 index 0000000000..c5562d4cea --- /dev/null +++ b/php/src/Vitess/Proto/Query/SplitQueryRequest/Algorithm.php @@ -0,0 +1,11 @@ +reference = '\Vitess\Proto\Query\BoundQuery'; $descriptor->addField($f); - // OPTIONAL STRING split_column = 4 + // REPEATED STRING split_column = 4 $f = new \DrSlump\Protobuf\Field(); $f->number = 4; $f->name = "split_column"; $f->type = \DrSlump\Protobuf::TYPE_STRING; - $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->rule = \DrSlump\Protobuf::RULE_REPEATED; $descriptor->addField($f); // OPTIONAL INT64 split_count = 5 @@ -71,6 +80,31 @@ namespace Vitess\Proto\Vtgate { $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; $descriptor->addField($f); + // OPTIONAL INT64 num_rows_per_query_part = 6 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 6; + $f->name = "num_rows_per_query_part"; + $f->type = \DrSlump\Protobuf::TYPE_INT64; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $descriptor->addField($f); + + // OPTIONAL ENUM algorithm = 7 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 7; + $f->name = "algorithm"; + $f->type = \DrSlump\Protobuf::TYPE_ENUM; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $f->reference = '\Vitess\Proto\Query\SplitQueryRequest\Algorithm'; + $descriptor->addField($f); + + // OPTIONAL BOOL use_split_query_v2 = 8 + $f = new \DrSlump\Protobuf\Field(); + $f->number = 8; + $f->name = "use_split_query_v2"; + $f->type = \DrSlump\Protobuf::TYPE_BOOL; + $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; + $descriptor->addField($f); + foreach (self::$__extensions as $cb) { $descriptor->addField($cb(), true); } @@ -210,10 +244,11 @@ namespace Vitess\Proto\Vtgate { /** * Get value * + * @param int $idx * @return string */ - public function getSplitColumn(){ - return $this->_get(4); + public function getSplitColumn($idx = NULL){ + return $this->_get(4, $idx); } /** @@ -222,8 +257,27 @@ namespace Vitess\Proto\Vtgate { * @param string $value * @return \Vitess\Proto\Vtgate\SplitQueryRequest */ - public function setSplitColumn( $value){ - return $this->_set(4, $value); + public function setSplitColumn( $value, $idx = NULL){ + return $this->_set(4, $value, $idx); + } + + /** + * Get all elements of + * + * @return string[] + */ + public function getSplitColumnList(){ + return $this->_get(4); + } + + /** + * Add a new element to + * + * @param string $value + * @return \Vitess\Proto\Vtgate\SplitQueryRequest + */ + public function addSplitColumn( $value){ + return $this->_add(4, $value); } /** @@ -262,6 +316,117 @@ namespace Vitess\Proto\Vtgate { public function setSplitCount( $value){ return $this->_set(5, $value); } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasNumRowsPerQueryPart(){ + return $this->_has(6); + } + + /** + * Clear value + * + * @return \Vitess\Proto\Vtgate\SplitQueryRequest + */ + public function clearNumRowsPerQueryPart(){ + return $this->_clear(6); + } + + /** + * Get value + * + * @return int + */ + public function getNumRowsPerQueryPart(){ + return $this->_get(6); + } + + /** + * Set value + * + * @param int $value + * @return \Vitess\Proto\Vtgate\SplitQueryRequest + */ + public function setNumRowsPerQueryPart( $value){ + return $this->_set(6, $value); + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasAlgorithm(){ + return $this->_has(7); + } + + /** + * Clear value + * + * @return \Vitess\Proto\Vtgate\SplitQueryRequest + */ + public function clearAlgorithm(){ + return $this->_clear(7); + } + + /** + * Get value + * + * @return int - \Vitess\Proto\Query\SplitQueryRequest\Algorithm + */ + public function getAlgorithm(){ + return $this->_get(7); + } + + /** + * Set value + * + * @param int - \Vitess\Proto\Query\SplitQueryRequest\Algorithm $value + * @return \Vitess\Proto\Vtgate\SplitQueryRequest + */ + public function setAlgorithm( $value){ + return $this->_set(7, $value); + } + + /** + * Check if has a value + * + * @return boolean + */ + public function hasUseSplitQueryV2(){ + return $this->_has(8); + } + + /** + * Clear value + * + * @return \Vitess\Proto\Vtgate\SplitQueryRequest + */ + public function clearUseSplitQueryV2(){ + return $this->_clear(8); + } + + /** + * Get value + * + * @return boolean + */ + public function getUseSplitQueryV2(){ + return $this->_get(8); + } + + /** + * Set value + * + * @param boolean $value + * @return \Vitess\Proto\Vtgate\SplitQueryRequest + */ + public function setUseSplitQueryV2( $value){ + return $this->_set(8, $value); + } } } diff --git a/php/src/Vitess/VTGateConn.php b/php/src/Vitess/VTGateConn.php index 6c2a42822f..1c0a6a34f5 100644 --- a/php/src/Vitess/VTGateConn.php +++ b/php/src/Vitess/VTGateConn.php @@ -204,13 +204,15 @@ class VTGateConn return new VTGateTx($this->client, $response->getSession()); } + // TODO(erez): Migrate to SplitQueryV2 after it's stable. public function splitQuery(Context $ctx, $keyspace, $query, array $bind_vars, $split_column, $split_count) { $request = new Proto\Vtgate\SplitQueryRequest(); $request->setKeyspace($keyspace); $request->setQuery(ProtoUtils::BoundQuery($query, $bind_vars)); - $request->setSplitColumn($split_column); + $request->addSplitColumn($split_column); $request->setSplitCount($split_count); + $request->setUseSplitQueryV2(false); if ($ctx->getCallerId()) { $request->setCallerId($ctx->getCallerId()); }