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

Updating or Deleting a property from an entity by name (Java) #128

Closed
caioiglesias opened this issue Jun 15, 2016 · 2 comments
Closed

Updating or Deleting a property from an entity by name (Java) #128

caioiglesias opened this issue Jun 15, 2016 · 2 comments

Comments

@caioiglesias
Copy link

caioiglesias commented Jun 15, 2016

On Google Cloud Dataflow when adding a property to an entity the process would be

Entity oldEntity = c.element();
Entity.Builder entityBuilder = Entity.newBuilder(oldEntity);
entityBuilder.addProperty(
        DatastoreHelper.makeProperty("newProperty",
                DatastoreHelper.makeValue("Value")
        )
);
  c.output(entityBuilder.build());

The only foreign elements from the datastore API here are:

  • DatastoreHelper: returning a property field and a value
  • c: getting the entity as an input and then outputting another entity.

Shouldn't there be a method to remove, get or set a property by name instead of an int? Adding an existing property produces no error, but saving it to the Datastore service produces an error complaining about a duplicate name for a property.

@eddavisson
Copy link
Contributor

eddavisson commented Jun 15, 2016

In the v1beta3 API, the properties are exposed as an actual map, so this will get a lot simpler once Google Cloud Dataflow is updated to use that API version.

In the meantime, once option is to use DatastoreHelper.getPropertyMap to get the properties as a Map<String, Value>, modify that map as needed, clear the original property list on the Entity.Builder, and then add back the values from the map.

@caioiglesias
Copy link
Author

That's what I'm currently doing, but I felt like it could use some improvements. I'll keep following the Dataflow/Beam project as they switch to v1beta3. Thank you very much for the prompt reply @eddavisson .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants