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
Hi
Im trying to use Timestamp when set'ing the Entity that im saving.
But if the code send in null then i only get an exception back.
I can manually say that the Key should be null but then i need to know beforehand that the value im sending in is null....
I think this needs to be fixed. Timestamp timestampThatCanBeNull = getTimestampOrNull(); Entity.newBuilder(keyFactory.newKey()).set("TimestampThatCanSometimesBeNull", consumableFormatId)
I think this is true for not only Timestamp but the other types, instead of return a exception it should use NullValue
i solved it by creating a convinience method to take builder property key/value and then do a lookup.
But feels weird that it's not supported in the framework.
It's the BaseEntity and it's builder that I'm talking about.
My solution to the issue is as follows. private void setTimestampOrNull(BaseEntity.Builder builder, String key, Timestamp timestamp) { if (timestamp != null) { builder.set(key, timestamp); } else { builder.setNull(key); } }
Because a value can be Null in datastore it feels normal to have the option to pass in null while setting the value and not having to do this if null type of check.
Thanks for the clarification! Your setTimestampOrNull() example looks like a simple, clean workaround :)
The javadoc for the set(String name, Timestamp value) function, and others like it, say that it "sets a property of type TimestampValue, which "must be associated with non-null content" (see com.google.cloud.datastore.Value javadoc). If a null timestamp was passed in, there would be no way for the set() function to fulfill its contract, because TimestampValue cannot be null, and NullValue is not the same type as TimestampValue.
I am biased towards requiring that the property values in set() be non-null, and explicitly calling the setNull() function for null values, so that the client isn't surprised when a get() returns a null value, because the client must have explicitly called the setNull() previously for that to happen.
Would it be possible to something like builder.orElseSetNull(key).set(key, timestamp);
It will catch the nullpoint exception and then set the key to be null.
So that the developer can easily solve this without having to create their own solution to this problem?
Activity
Nosfert commentedon Sep 8, 2017
i solved it by creating a convinience method to take builder property key/value and then do a lookup.
But feels weird that it's not supported in the framework.
andreamlin commentedon Sep 26, 2017
Is this for the com.google.cloud.datastore.Entity class?
If so, that neither the Entity class nor its Builder has a .set() method.
Can you provide a valid code snippet to clarify the issue?
Nosfert commentedon Sep 28, 2017
Sorry for not providing enough info.
It's the BaseEntity and it's builder that I'm talking about.
My solution to the issue is as follows.
private void setTimestampOrNull(BaseEntity.Builder builder, String key, Timestamp timestamp) { if (timestamp != null) { builder.set(key, timestamp); } else { builder.setNull(key); } }Because a value can be Null in datastore it feels normal to have the option to pass in null while setting the value and not having to do this if null type of check.
andreamlin commentedon Sep 29, 2017
Thanks for the clarification! Your
setTimestampOrNull()example looks like a simple, clean workaround :)The javadoc for the
set(String name, Timestamp value)function, and others like it, say that it "sets a property of type TimestampValue, which "must be associated with non-null content" (see com.google.cloud.datastore.Value javadoc). If a null timestamp was passed in, there would be no way for theset()function to fulfill its contract, because TimestampValue cannot be null, and NullValue is not the same type as TimestampValue.I am biased towards requiring that the property values in
set()be non-null, and explicitly calling the setNull() function for null values, so that the client isn't surprised when a get() returns a null value, because the client must have explicitly called thesetNull()previously for that to happen.@vam-google, any thoughts?
Nosfert commentedon Oct 4, 2017
Would it be possible to something like
builder.orElseSetNull(key).set(key, timestamp);It will catch the nullpoint exception and then set the key to be null.
So that the developer can easily solve this without having to create their own solution to this problem?
yihanzhen commentedon Jan 29, 2018
Move this issue to feature request backlog and close it here. This place can continue to be used for discussion.
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
chore(main): release 3.3.0 (#2415)
chore(main): release 1.139.4-SNAPSHOT (#2417)
chore(main): release 1.139.4-SNAPSHOT (#2417)