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

Binary data in BigTable column #1526

Closed
arbesfeld opened this issue Aug 25, 2016 · 5 comments
Closed

Binary data in BigTable column #1526

arbesfeld opened this issue Aug 25, 2016 · 5 comments
Assignees
Labels
api: bigtable Issues related to the Bigtable API.

Comments

@arbesfeld
Copy link
Contributor

arbesfeld commented Aug 25, 2016

Hi, I am trying to store an encode protobuf in BigTable and I'm not able to insert binary data (represented as a Buffer) into a BigTable column. I have tried the following ways:

this.table.insert([
  key: `foo`,
  data: {
    event: new Buffer(),
  },
]);

this.table.insert([
  key: `foo`,
  data: {
    event: {
     data: new Buffer(),
    }
  },
]);

It seems to get stringified somewhere in the client library, which is making the data invalid.

@callmehiphop callmehiphop added the api: bigtable Issues related to the Bigtable API. label Aug 25, 2016
@callmehiphop
Copy link
Contributor

callmehiphop commented Aug 25, 2016

Hi @arbesfeld, we don't stringify any data before trying to insert it. However, we do transform any data you pass in into Buffers. Have you tried passing your data in as a string/number?

e.g.

this.table.insert([
  {
    key: 'foo',
    data: {
      familyName: {
        columnName: 'data'
      }
    }
  }
]);

@callmehiphop
Copy link
Contributor

callmehiphop commented Aug 25, 2016

@arbesfeld can you give me an example of what kind of data you're trying to save? (Aside from Node buffers)

@callmehiphop
Copy link
Contributor

@arbesfeld we've just merged some changes for the Bigtable API. Assuming what you're passing in is a Buffer, then it should pass through just fine to the API. When retrieving the data, if you want a Buffer returned to you, you'll need to set the decode: false option like so

table.getRows({ decode: false }, function(err, rows) {});

@arbesfeld
Copy link
Contributor Author

Hey @callmehiphop, I'm setting decode: false and getting seemingly all base64 encoded buffers when I call .getRows(). I passed in a binary-encoded Buffer. Is this the expected behavior?

@stephenplusplus
Copy link
Contributor

@callmehiphop I think we should always create the Buffer from the response base64 value: https://github.com/GoogleCloudPlatform/google-cloud-node/blob/3cbc93b9d770dd25aa5c6ed1f215e01518e42a03/packages/bigtable/src/row.js#L163

    if (qualifier && chunk.value) {
      var value = Mutation.convertFromBytes(chunk.value, options);

      qualifier.push({
        value: value,
        labels: chunk.labels,
        timestamp: chunk.timestampMicros,
        size: chunk.valueSize
      });
    }

and do something like this in Mutation.convertFromBytes:

  var buf = new Buffer(bytes, 'base64');
  var num = new Int64(buf).toNumber();

  if (!isNaN(num) && isFinite(num)) {
    return num;
  }

  if (options && options.decode === false) {
    return buf;
  }

  return buf.toString();

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.
Projects
None yet
Development

No branches or pull requests

3 participants