Skip to content
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

Google bigtable readRows function always returns empty object #1972

Closed
chintansureliya opened this issue May 27, 2019 · 4 comments
Closed

Google bigtable readRows function always returns empty object #1972

chintansureliya opened this issue May 27, 2019 · 4 comments
Assignees
Labels
api: bigtable Issues related to the Bigtable API. type: question Request for information or clarification. Not an issue.

Comments

@chintansureliya
Copy link

chintansureliya commented May 27, 2019

I've been trying to query in google bigtable and i am able to retrieve below object everytime.
I have used the example code mentioned here

I am able to get the response with same instance id, table id and row key if i try out the nodejs example.

Google\Cloud\Bigtable\ChunkFormatter Object
(
    [state] => 
    [rowKey] => 
    [prevRowKey] => 
    [row] => Array
        (
        )
)

Code i am using

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH.'libraries/google-cloud-php-master/vendor/autoload.php';
use Google\Cloud\Bigtable\BigtableClient;

class CI_DB_bigtable_driver extends CI_DB {
    
    /**
     * Non-persistent database connection
     *
     * @access  private called by the base class
     * @return  resource
     */
    function db_connect() {
        return @new BigtableClient([
            'projectId' => $this->project_id
        ]);
    }

    function query($instance_id = "", $table_id = "", $row_key = "", $column_family_id = "", $column_id = ""){

        $table = $this->conn_id->table($this->instance_id, $this->table_id);
        
        $key = 1965443;

        // Read a row from table using a row key
        $rows = $table->readRows(array(
            "rowKeys" => array($key)
            )
        );  

       // i get an empty object if i print this
       print_r($rows);
        
        $column_family_id = 'event';
        $column_id = 'view';

        // Get the Value from the Row, using the column_family_id and column_id
        $value = $row[$column_family_id][$column_id][0]['value'];
       
        printf("Row key: %s\nData: %s\n", $key, $value);
    }
}
@jdpedrie jdpedrie added api: bigtable Issues related to the Bigtable API. type: question Request for information or clarification. Not an issue. labels May 27, 2019
@jdpedrie
Copy link
Contributor

Hi @chintansureliya,

You need to iterate over the ChunkFormatter to get the data.

$readOptions = [
    'rowKeys' => [$key]
];

foreach ($table->readRows($readOptions) as $row) {
   print_r($row);
}

@chintansureliya
Copy link
Author

chintansureliya commented May 29, 2019

Hi @jdpedrie,

I tried the same using below code and i get the error mentioned below the code.

Code:

$readOptions = array(
    "rowKeys" => array($key),
    "rowsLimit" => 20
);

foreach ($table->readRows($readOptions) as $row) {
    print_r($row);
}

I even face the same issue when im using readRow method too.

$row = $table->readRow($key);

Error:

Fatal error: Uncaught exception 'BadMethodCallException' with message 'Streaming calls are not supported while using the REST transport.' in C:\xampp\htdocs\manage_dev\application\libraries\google-cloud-php-master\vendor\google\gax\src\ApiCore\Transport\RestTransport.php:183 Stack trace: #0 C:\xampp\htdocs\manage_dev\application\libraries\google-cloud-php-master\vendor\google\gax\src\ApiCore\Transport\RestTransport.php(113): Google\ApiCore\Transport\RestTransport->throwUnsupportedException() #1 C:\xampp\htdocs\manage_dev\application\libraries\google-cloud-php-master\vendor\google\gax\src\ApiCore\GapicClientTrait.php(425): Google\ApiCore\Transport\RestTransport->startServerStreamingCall(Object(Google\ApiCore\Call), Array) #2 C:\xampp\htdocs\manage_dev\application\libraries\google-cloud-php-master\vendor\google\gax\src\ApiCore\Middleware\CredentialsWrapperMiddleware.php(62): Google\Cloud\Bigtable\V2\Gapic\BigtableGapicClient->Google\ApiCore\{closure}(Object(Google\ApiCore\Call), Array) #3 C:\xampp\htdocs\manage_dev\applicat in C:\xampp\htdocs\manage_dev\application\libraries\google-cloud-php-master\vendor\google\gax\src\ApiCore\Transport\RestTransport.php on line 183

@jdpedrie
Copy link
Contributor

jdpedrie commented May 29, 2019

Hi @chintansureliya,

That error indicates that you need to install gRPC in order to use the readRows method. gRPC can be installed via PECL as follows:

$ pecl install grpc

For more information, check out Install gRPC for PHP.

If you're using AppEngine with PHP 7, gRPC can be enabled as well. Here is more information.

On Windows, you can download a pre-compiled version of the extension here (Click the link that says DLL under the latest version and choose the option which matches your PHP version). Once you've downloaded it, see the Loading an Extension section for information on enabling it.

@billyjacobson
Copy link
Contributor

We haven't heard back from you in over 7 days Chintan, so I am closing this issue. Please let us know if you have any further questions. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigtable Issues related to the Bigtable API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants