-
Notifications
You must be signed in to change notification settings - Fork 627
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
CASSGO-36 could map scan get nil instead of zero value for null value #1834
base: trunk
Are you sure you want to change the base?
Conversation
Based on this being possible outside of the package I'm hesitant to approve this. See my comment on the original issue: #1699 (comment) |
@jameshartig I believe we should consider implementing features directly within gocql rather than requiring external solutions. It would be much more convenient to have these features available out of the box. Furthermore, it seems like this behavior should be the default since Cassandra can return nullable values. Currently, gocql represents these as default Go values, which alters the original data. To address this, we should at least provide an alternative functionality that preserves the original data and aligns with Cassandra's behavior. |
So it looks like @jameshartig is proposing a change to the behavior of |
Or is #1856 just limited to byte slices and we still can't read nullable values for other types? |
Yes, that's just for byte slices. The reason being that nil slices are equivalent to empty slices and there's no need to make an empty slice if we don't need to.
This is maybe something we can consider for 2.0 but there's no way we could make that change in the existing version.
You can use pointers if you which to get the "original data". I've seen places that utilize the default Go values as a feature because they don't have to check for nil and can rely on the default value. I also provided a code example in the original issue with how you can do this quite easily without any changes to gocql. |
The release that we're working on atm ( |
So it looks like there's no consensus on whether CASSGO-36 should actually be considered, maybe this needs a [discuss] thread on the C* dev mailing list? |
It seems like misbehavior that MapScan doesn't get the original data from the database. Sure, we can use Scan and make a custom "MapScan" as suggested in #1699 (comment), but it looks like overhead, and as mentioned in the issue, it's confusing, but it is still confusing, especially for new users, and imo MapScan doc is not clear enough when we're talking about null values. I think there is no issue with backward compatibility because this functionality will be added to 2.0. |
I agree with @joao-r-reis, I think we need more consensus that "original data" is not the default go values and is actually
We can definitely clarify the docs.
You're changing a public interface which means anything implementing
I can appreciate your frustration but we want to decrease the surface area of the API and not increase it. We're stuck with |
I think I misunderstood this issue because reading this comment #1785 (comment) made me believe that we actually have no way of differentiating between a NULL and empty value from the database. It looks like there is indeed a way of doing this even if it requires a bit of extra code, correct? If this is the case then I'm starting to lean with @jameshartig here and CASSGO-36 (+ this PR) should probably just be closed |
I think I found a way of achieving this without any changes to public interfaces. That said, I'm concerned about breaking existing code. My goal is that users can upgrade to 2.0 easily and anything that's broken the compiler will complain about (method changes, new arguments, etc). If we changed |
Yeah that doesn't sound good, I'd prefer to add a new method and deprecate the current one (while keeping it around for backwards compatibility) to make it clearer for users (which is kind of what this PR is currently doing already). Either add a new method for map scan that properly returns nil values and deprecate the current one until people have the chance to transition or just keep both methods long term (I'd prefer deprecating the current one) |
@jameshartig @joao-r-reis So what did we come up with? I like Joao's Idea to add a new method and sign the old one as deprecated. It will eliminate the backward compatibility issue and provide the proper behavior. |
@OleksiienkoMykyta I've been busy with #1855 and I completely changed how map scan works. I'd like to get that in a good place and then get back to this as it should be significantly easier now. I also haven't had enough time to think through the best way for this and I've been looking at other DB libraries for inspiration. |
I'd like to deprecate |
@jameshartig so, are we just waiting for #1855 to be merged for now? |
I wonder if some users prefer passing in an existing map so it can be reused (GC/mem optimization). |
Maybe but would we need to delete keys from the map that didn't match any results? Maybe not, but it still seems like a weird API.
Yes, and sorry for taking so long on that. |
Closes #1699
This PR adds a new feature (MapScanWithNullableValues) that allows users to receive nullable values from Cassandra.