-
Notifications
You must be signed in to change notification settings - Fork 286
"skip" method to generate a null value in prepared queries #30
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
Conversation
// As per CQL bytes representation, if len is negative, no byte | ||
// should follow and the represented value is 'null' | ||
cql::cql_int_t len = -1; | ||
output.write(reinterpret_cast<char*>(&len), sizeof(len)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without using the hton* function, this won't be portable, will it?
Also, how would this be different from encode_int(output, -1)? If you're trying to encode a NULL string, then encode_short(output, -1) might do what you want, if you're right about negative length values having special significance. If you're trying to encode a NULL integer (or floating point), then how do you distinguish NULL from any valid value? I don't know the binary spec, but based on this implementation, there is no room in the representation for NULL integer values.
Definitely right about the hton, I have just missed it. (initially I though len was a cql_byte_t) Please consider that I'm just trying to speculate about the binary protocol, that I just don't know well enough. However, my point is based, besides the lines already quoted, on the following ones too (4.1.4)
If I get this correctly, values are always encoded as [bytes]. So, I guess the server takes care of correctly interpreting the byte stream, by casting the appropriate amount of bytes to the right data type based on the corresponding type of the bound variable. In that case, a 'null' byte should always lead to a 'null' value for any possible type (if that is taken care of on the server side!). For the purpose of what I'm trying to do, yes, I could have used any other encode_* method that leads to encoding a negative cql_int_t value. I thought it was just more clear to add a new one, given the specific purpose. |
A similar feature has been correctly added on #32 |
- Per-commit, scheduling, deploy release artifacts, and adhoc testing - Scheduling uses branch validation to determine if it should execute - Deploy uses Jenkins credentials and secrets to upload to Artifactory - Adhoc testing adds the ability to run one or all server versions - Documents can be generated with documentor (adhoc and monthly) - Adds parameters for adhoc building, testing, and deployment - Uses HTML descriptions for external users - Descriptive builds for Jenkins UI - Log rotation is used to minimize server storage - Timeouts are used for entire pipeline and per particular stage - Retry logic is used for false positive failures in unit tests - Artifacts are archived in Jenkins for per-commit builds - Artifacts force into OS specific directories; avoids overwrite - Error logic to archive logs for evaluating issues - Clean workspace logic for static MacOS node - Allow AppVeyor to ignore Jenkins pipeline changes - Rename configure_environment; was only used for testing - Add Slack notifications for start and end of runs - Per-Commit, scheduled, and release runs only - Works for both OSS and DSE drivers Note: All Server versions for scheduled/adhoc are available. This required a workaround due to the following Jenkins issue, https://issues.jenkins-ci.org/browse/JENKINS-37984. Co-authored-by: Michael Fero <michael.fero@datastax.com>
…ax#30) - Per-commit, scheduling, deploy release artifacts, and adhoc testing - Scheduling uses branch validation to determine if it should execute - Deploy uses Jenkins credentials and secrets to upload to Artifactory - Adhoc testing adds the ability to run one or all server versions - Documents can be generated with documentor (adhoc and monthly) - Adds parameters for adhoc building, testing, and deployment - Uses HTML descriptions for external users - Descriptive builds for Jenkins UI - Log rotation is used to minimize server storage - Timeouts are used for entire pipeline and per particular stage - Retry logic is used for false positive failures in unit tests - Artifacts are archived in Jenkins for per-commit builds - Artifacts force into OS specific directories; avoids overwrite - Error logic to archive logs for evaluating issues - Clean workspace logic for static MacOS node - Allow AppVeyor to ignore Jenkins pipeline changes - Rename configure_environment; was only used for testing - Add Slack notifications for start and end of runs - Per-Commit, scheduled, and release runs only - Works for both OSS and DSE drivers Note: All Server versions for scheduled/adhoc are available. This required a workaround due to the following Jenkins issue, https://issues.jenkins-ci.org/browse/JENKINS-37984. Co-authored-by: Michael Fero <michael.fero@datastax.com>
…datastax#30)" This reverts commit 72cbc13.
Hi
as stated in this discussion, I think prepared queries with unnamed variables are very limited.
In my use case, I have a CQL table with many fields and a massive amount of INSERT to perform, where only some fields per query will be present. I want to do this with prepared queries for performance reasons.
At present, prepared queries with '?' bound variables are not usable in real life. Best solution would be to have named bound variables, but I understand this is not immediate to accomplish (also, very new feature in cassandra and CQL).
So, temporarily, I would just love to have a "skip" method that I could use instead of a "push_back" every time I do not have a value to push to a given field.
This is my attempt to implement this. It is based on the following description of a "null" byte in binary protocol specifications. I'm not sure this is the correct way to do it, however it was quick enough to implement that I just tried it
I have tested this with a simple table.
Notice that the entry for key4 is generated manually by a cqlsh query where I just insert a value for v3. I correctly see "null" for v2 field.
key2 and key3 entries are generated by a prepared query using the "skip" method. I don't see the "null" representation so I guess my method is not correct
Any pointers about this? Is this even possible at all with my (simple) approach?
Thanks
Giacomo
P.S. i just realized I committed also the exposure of "str()" method from cql_message_execute_impl_t. That is unrelated to the "skip" method