-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bigtable: Read modify write row model #1334
Changes from 8 commits
3b96555
b80a932
fe48a4c
28a566a
0c3e14c
aca3752
c2e6594
4b6c0eb
9095645
dac3592
b3b9181
8781563
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Copyright 2018, Google LLC All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Google\Cloud\Bigtable; | ||
|
||
/** | ||
* This class contains utility to convert integer to byte string and backward. | ||
*/ | ||
class DataUtil | ||
{ | ||
/** | ||
* Utility method to convert integer value in to 64 bit signed BigEndian | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
* representation. | ||
* | ||
* @param string|int $intValue Integer value to convert to. | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
* @return string Returns string of bytes representing 64 bit big signed BigEndian. | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
* @throws \InvalidArgumentException If value is not numberic. | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
*/ | ||
public static function intToByteString($intValue) | ||
{ | ||
if (!is_numeric($intValue)) { | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
throw new \InvalidArgumentException( | ||
sprintf( | ||
'Expected argument to be of type int, instead got \'%s\'.', | ||
gettype($intValue) | ||
) | ||
); | ||
} | ||
$hex = base_convert($intValue, 10, 16); | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
$hex = str_pad($hex, 16, '0', STR_PAD_LEFT); | ||
return hex2bin($hex); | ||
} | ||
|
||
/** | ||
* Convertes string bytes of 64 bit signed BigEndian to int. | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
* | ||
* @param string|array $bytes String of bytes to convert. | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
* @return int Integer value of the string bytes. | ||
*/ | ||
public static function byteStringToInt($bytes) | ||
{ | ||
$hex = bin2hex($bytes); | ||
return hexdec($hex); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
/** | ||
* Copyright 2018, Google LLC All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Google\Cloud\Bigtable; | ||
|
||
use Google\Cloud\Bigtable\V2\ReadModifyWriteRule; | ||
|
||
/** | ||
* Represents collection of ReadModifyWriteRule to perform operation on Bigtable table. | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
* This is used in readModifyWriteRow operation on row in Bigtable table. | ||
*/ | ||
class ReadModifyWriteRowRules | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $options; | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
|
||
/** | ||
* @var array ReadModifyWriteRule | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
*/ | ||
private $rules = []; | ||
|
||
public function __construct(array $options = []) | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
{ | ||
$this->options = $options; | ||
} | ||
|
||
/** | ||
* Appends the value to the existing value of the cell. If targeted cell is unset, | ||
* it will be treated as containing the empty string. | ||
* | ||
* @param string $familyName Family name of the row. | ||
* @param string $qualifier Column qualifier of the row. | ||
* @param string $value Value of the Column qualifier. | ||
* | ||
* @return ReadModifyWriteRowRules returns current ReadModifyWriteRowRules object. | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
*/ | ||
public function append($familyName, $qualifier, $value) | ||
{ | ||
$this->rules[] = (new ReadModifyWriteRule) | ||
->setFamilyName($familyName) | ||
->setColumnQualifier($qualifier) | ||
->setAppendValue($value); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Adds `amount` to the existing value. If the targeted cell is unset, it will be treated | ||
* as containing a zero. Otherwise, the targeted cell must containt an 8-byte value (interpreted | ||
* as a 64-bit big-endian signed integer), or the entire request will fail. | ||
* | ||
* @param string $familyName Family name of the row. | ||
* @param string $qualifier Column qualifier of the row. | ||
* @param int $amount Amount to add to value of Column qualifier. | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
* | ||
* @return ReadModifyWriteRowRules returns current ReadModifyWriteRowRules object. | ||
*/ | ||
public function increment($familyName, $qualifier, $amount) | ||
{ | ||
$this->rules[] = (new ReadModifyWriteRule) | ||
->setFamilyName($familyName) | ||
->setColumnQualifier($qualifier) | ||
->setIncrementAmount($amount); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Returns proto representation of ReadModifyWriteRule. | ||
* | ||
* @return array ReadModifyWriteRule Returns array of ReadModifyWriteRule rules. | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
*/ | ||
public function toProto() | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
{ | ||
return $this->rules; | ||
} | ||
} |
This comment was marked as spam.
Sorry, something went wrong.