You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This proposal covers the binary data part of #137.
A blob is a non-streaming, reasonably small (< ~10MB), base64 encoded binary data type. The user can store a blob in a document.
For now, any time the document gets loaded, the blob gets loaded (this might change if we allow not loading fields if the user plucks them out). EDIT: It'd be really nice to optimize that right away, but I don't know how hard that is.
Any time the document gets copied, the blob gets copied.
Hopefully if only non-blob fields in a document get updated, the blob doesn't get rewritten.
For now, the only way to modify a blob is to rewrite it entirely.
I agree with this interface (although I might call the pseudotype "BINARY" or "BASE64" instead of "BLOB").
One question with this is what native types should be turned into binary pseudotypes. In Ruby, people generally just put binary data in strings (there's no separate type for it, although strings can have encodings).
If we go with turning binary strings in Ruby into binary pseudotypes (and vice-versa), we might also want to offer an r.binary(...) command to turn a non-binary string into a blob (e.g. r.binary("abc")).
One question with this is what native types should be turned into binary pseudotypes.
Embarrasingly, I don't know either of the three driver languages well enough to know this. @neumino@deontologician@larkost@Tryneus can speak about their respective languages.
we might also want to offer an r.binary(...) command
Python3 has a binary type (type(b'23') is <class 'bytes'>), but while Python2.x technically supports the b'23' format, it converts it into a string immediately. So such a thing would generally be needed for Python as well. There is a valid question about whether we should implicitly convert <class 'bytes'> objects, and what we should present on fetch.
The argument against natively supporting <class 'bytes'> is that some surprising (but correct) places return bytes objects in Python3 such as subprocess STDERR and STDOUT. If we natively bring those in as binary types then the same code in Python2.x would put it into the database as a binary type, while in Python3.x it would insert a binary.
The same arguments hold for what we present when fetching. In order to be consistent I think we should present r.binary objects rather than native items in Python3. One good option would be to have the r.binary class be a subclass of bytes (this maps to `<type 'str'> on Python2.x), which would "do the right thing" in most cases.
@srh For Python2.x we are pretty much stuck converting non-binary objects since even a read on a file in binary mode results in a plain string object. Probably the best approach would be to use the same format at the bytes instantiator uses in Python3.x:
class bytes(object)
| bytes(iterable_of_ints) -> bytes
| bytes(string, encoding[, errors]) -> bytes
| bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
| bytes(int) -> bytes object of size given by the parameter initialized with null bytes
| bytes() -> empty bytes object
Just subclassing the bytes object gets us this already on Python3. However, on Python2 bytes is just an alias to str, and so there we probably would have to call the encode methods ourselves.
Python2 str is the same as Python3 bytes. Neither holds any encoding information. The bytes() function and b"123" syntax are just dummy operations to make migrating to Python3 easier. I'd say only those two respective types should be base64'd in Python. Implicitly converting unicode strings to bytes is probably a bad idea since the user doesn't get to pick the encoding, and when you retrieve it again you need to know that to decode it.
r.binary would be a term on the server that takes a string and returns a binary pseudotype. (If passed a binary pseudotype, it just returns what it was passed.)
I think we should try hard to turn binary pseudotypes into a reasonable native type in the clients. In Ruby, if I have x = "a\0b".encode('binary'), I really want r(x).run to give me back that same string with a binary encoding.
@deontologician -- that makes sense. Converting str in Python 2 and bytes in Python 3 to binary pseudotypes automatically seems right. (And turning them back, obviously.)
I would love to do this, but it is a bad idea. It is a big break from the current behaviour, and will break in unexpected ways when the rethinkdb driver is used alongside other libraries that return str instead of unicode values.
@AtnNn Ah ok. I think I see the issue, I misunderstood that we were talking about what to coerce to a blob without the r.binary() wrapper. I agree that you can only really do that in Python3, since python2 strings are just overloaded with no way to discern the meaning.
I was talking more about r.binary() not coercing a unicode string to a byte array.
So you think we should automatically convert in Python 3, but not automatically convert anything in Python 2?
I sort of feel like r.binary should be able to turn any string into a binary blob. That feels like a common task. But if that seems crazy, I'll defer to the people who actually use Python regularly.
Please contemplate on how you would retrieve documents without the binary components. That is how would someone perform a query and get all the documents without the binary elements.
Pretend that I have a document with a handful of random metadata entries and 1 to 3 binary entries. for speed reasons I want to look at all the meta data and my binary elements are 20MiB images. clearly if I have 100k images I may want to look at all the metadata without the large images. Excluding a key in the document may not be enough. Those images might have different keys in each document. Clearly in that scenario exclusion via type would be useful.
I'd like to propose that we re-introduce slice since @Tryneus already implemented it in the CR . The use, meaning, and edge cases should be the same as array.slice.
Ok, r.binary has been approved and merged to next in commits b878582, d7730a5, b0285bc, a0f0973, and 9f7247b. Review was 1799. Will be in release 1.14.
A few notes about the final state of the feature:
base64 is only used on the wire; as soon as it is converted to a datum_t, the base64 is translated to a wire_string_t. The reverse applies when sending r.binary to a client.
We support the common subset of RFC 3548 and RFC 2045, but not base64url.
The r.binary term is client-only. There is no use case I could find for running r.binary on existing data that is not fulfilled by using coerce_to('binary').
count works on r.binary objects, similar to arrays.
slice works on r.binary objects, with the same semantics as when used on an array.
info, type_of, and coerce_to are all implemented (the type string is BINARY).
Drivers:
The python driver will implicitly convert bytes to r.binary unless bytes is the same as str (in python2).
The python driver will return r.binary objects as a thin wrapper of bytes (to allow implicit conversion when re-inserting in python2).
The javascript driver will implicitly convert Buffer to r.binary.
The javascript driver will return r.binary objects as Buffers.
The ruby driver does not implicitly convert data to r.binary, like python2.
The ruby driver will return r.binary objects as a thin wrapper of String (to allow implicit conversion when re-inserting).
The thin wrappers in Ruby and Python simply inherit from String and bytes, respectively, without redefining anything. They are functionally identical to a normal string, but we can tell if it was the result of r.binary in an earlier query.
Activity
mlucy commentedon Jun 26, 2014
I agree with this interface (although I might call the pseudotype "BINARY" or "BASE64" instead of "BLOB").
One question with this is what native types should be turned into binary pseudotypes. In Ruby, people generally just put binary data in strings (there's no separate type for it, although strings can have encodings).
If we go with turning binary strings in Ruby into binary pseudotypes (and vice-versa), we might also want to offer an
r.binary(...)command to turn a non-binary string into a blob (e.g.r.binary("abc")).coffeemug commentedon Jun 26, 2014
Embarrasingly, I don't know either of the three driver languages well enough to know this. @neumino @deontologician @larkost @Tryneus can speak about their respective languages.
👍
srh commentedon Jun 26, 2014
How would it do that?
larkost commentedon Jun 26, 2014
Python3 has a binary type (
type(b'23')is<class 'bytes'>), but while Python2.x technically supports theb'23'format, it converts it into a string immediately. So such a thing would generally be needed for Python as well. There is a valid question about whether we should implicitly convert<class 'bytes'>objects, and what we should present on fetch.The argument against natively supporting
<class 'bytes'>is that some surprising (but correct) places returnbytesobjects in Python3 such assubprocessSTDERR and STDOUT. If we natively bring those in as binary types then the same code in Python2.x would put it into the database as a binary type, while in Python3.x it would insert a binary.The same arguments hold for what we present when fetching. In order to be consistent I think we should present
r.binaryobjects rather than native items in Python3. One good option would be to have ther.binaryclass be a subclass ofbytes(this maps to `<type 'str'> on Python2.x), which would "do the right thing" in most cases.neumino commentedon Jun 26, 2014
Node has a buffer class, that should work fine.
The dataexplorer will probably drop the blobs and replace them with a string
<blob>or something like that.larkost commentedon Jun 26, 2014
@srh For Python2.x we are pretty much stuck converting non-binary objects since even a read on a file in binary mode results in a plain string object. Probably the best approach would be to use the same format at the
bytesinstantiator uses in Python3.x:Just subclassing the
bytesobject gets us this already on Python3. However, on Python2bytesis just an alias tostr, and so there we probably would have to call the encode methods ourselves.deontologician commentedon Jun 26, 2014
Python2
stris the same as Python3bytes. Neither holds any encoding information. Thebytes()function andb"123"syntax are just dummy operations to make migrating to Python3 easier. I'd say only those two respective types should be base64'd in Python. Implicitly converting unicode strings to bytes is probably a bad idea since the user doesn't get to pick the encoding, and when you retrieve it again you need to know that to decode it.mlucy commentedon Jun 26, 2014
r.binarywould be a term on the server that takes a string and returns abinarypseudotype. (If passed a binary pseudotype, it just returns what it was passed.)I think we should try hard to turn binary pseudotypes into a reasonable native type in the clients. In Ruby, if I have
x = "a\0b".encode('binary'), I really wantr(x).runto give me back that same string with a binary encoding.mlucy commentedon Jun 26, 2014
@deontologician -- that makes sense. Converting
strin Python 2 andbytesin Python 3 to binary pseudotypes automatically seems right. (And turning them back, obviously.)AtnNn commentedon Jun 26, 2014
I would love to do this, but it is a bad idea. It is a big break from the current behaviour, and will break in unexpected ways when the rethinkdb driver is used alongside other libraries that return
strinstead ofunicodevalues.deontologician commentedon Jun 26, 2014
@AtnNn Ah ok. I think I see the issue, I misunderstood that we were talking about what to coerce to a blob without the
r.binary()wrapper. I agree that you can only really do that in Python3, since python2 strings are just overloaded with no way to discern the meaning.I was talking more about r.binary() not coercing a unicode string to a byte array.
mlucy commentedon Jun 26, 2014
So you think we should automatically convert in Python 3, but not automatically convert anything in Python 2?
I sort of feel like
r.binaryshould be able to turn any string into a binary blob. That feels like a common task. But if that seems crazy, I'll defer to the people who actually use Python regularly.AtnNn commentedon Jun 26, 2014
In Python 2, strings are bytes by default. I think
r.binaryshould be required to convert them to blobs.In Python 3, strings are unicode by default. I think r.binary should be a no-op on bytes and should fail on unicode strings.
33 remaining items
srh commentedon Jul 7, 2014
Result sets are not ordered.
coffeemug commentedon Jul 8, 2014
Marking as settled. To clarify:
countto get the number of bytes and not add alengthcommandbinaryand the commandr.binarycount,info,type_of,coerce_toand the comparison operators to start withhardkrash commentedon Jul 11, 2014
Please contemplate on how you would retrieve documents without the binary components. That is how would someone perform a query and get all the documents without the binary elements.
Pretend that I have a document with a handful of random metadata entries and 1 to 3 binary entries. for speed reasons I want to look at all the meta data and my binary elements are 20MiB images. clearly if I have 100k images I may want to look at all the metadata without the large images. Excluding a key in the document may not be enough. Those images might have different keys in each document. Clearly in that scenario exclusion via type would be useful.
coffeemug commentedon Jul 11, 2014
You'd say
r.table('foo').without('blob_field_name').mlucy commentedon Jul 23, 2014
I'd like to propose that we re-introduce
slicesince @Tryneus already implemented it in the CR . The use, meaning, and edge cases should be the same asarray.slice.mlucy commentedon Jul 23, 2014
(From an administrative perspective, this issue is temporarily back in its discussion period for that one aspect.)
mlucy commentedon Jul 24, 2014
@coffeemug: any opinion on
slice?coffeemug commentedon Jul 24, 2014
Adding
slicewould be great. I talked to @Tryneus and I thought he already implemented it, but I'm not entirely sure.mlucy commentedon Jul 25, 2014
Alright, it's been 2-3 days with no objections and the code's already written, marking as settled once more.
Tryneus commentedon Jul 25, 2014
Ok,
r.binaryhas been approved and merged tonextin commits b878582, d7730a5, b0285bc, a0f0973, and 9f7247b. Review was 1799. Will be in release 1.14.A few notes about the final state of the feature:
datum_t, the base64 is translated to awire_string_t. The reverse applies when sendingr.binaryto a client.r.binaryterm is client-only. There is no use case I could find for runningr.binaryon existing data that is not fulfilled by usingcoerce_to('binary').countworks onr.binaryobjects, similar to arrays.sliceworks onr.binaryobjects, with the same semantics as when used on an array.info,type_of, andcoerce_toare all implemented (the type string isBINARY).Drivers:
bytestor.binaryunlessbytesis the same asstr(in python2).r.binaryobjects as a thin wrapper ofbytes(to allow implicit conversion when re-inserting in python2).Buffertor.binary.r.binaryobjects asBuffers.r.binary, like python2.r.binaryobjects as a thin wrapper ofString(to allow implicit conversion when re-inserting).coffeemug commentedon Jul 25, 2014
A few more questions.
binary_format='raw'to get the pseudotype in the driver? (if not, I think we should do that, both for clarity and consistency).r.binaryobject specified? What methods can I call on it/what can I do with it, etc.?Tryneus commentedon Jul 25, 2014
@coffeemug:
binary_format='raw'(I didn't see much of a use case), but that's a simple change - opened Addbinary_format='rawin the drivers. #2762 for this.Stringandbytes, respectively, without redefining anything. They are functionally identical to a normal string, but we can tell if it was the result ofr.binaryin an earlier query.