Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between com.google.datastore.v1 and com.google.cloud.datastore / Missing option to disable index

I'm currently building a Google Cloud Dataflow job which parses XML files and saves the entries using Google Datastore, bu the different Java libraries seem to be very confusing.

First I found com.google.datastore.v1, which works great with Dataflow, but later on I realized that the option to excludes fields from being indexed is missing. (Most of my fields do not need an index and will never be used in a query.)

Then I found com.google.cloud.datastore, which has a method named "setExcludeFromIndexes" to achieve exactly what I was looking for, but Dataflow is not able to save entities generated using this library.

Is one of the libraries the newer one or what is the difference at all? And is there a way to disable indexes for single fields using the v1-library?

like image 597
Tobias K. Avatar asked Jan 04 '17 18:01

Tobias K.


People also ask

What is the difference between native mode and Datastore mode?

Datastore mode can automatically scale to millions of writes per second. Use Firestore in Native mode for new mobile and web apps. Firestore offers mobile and web client libraries with real-time and offline features. Native mode can automatically scale to millions of concurrent clients.

How do I delete an index in Datastore?

Deleting unused indexes When you are sure that old indexes are no longer needed, you can delete them by using the datastore indexes cleanup command. This command deletes all indexes for the production Datastore mode instance that are not mentioned in the local version of index.

What are indexes in Datastore?

Datastore has two types of indexes, built-in and composite indexes. By default, in ascending and descending index is predefined for each property of each entity kind. These are called built-in indexes.

How do I create an index configuration in Datastore?

To do this, Datastore needs to know in advance which queries the application will make. You specify which indexes your app needs in a index. yaml configuration file. You can use the Datastore emulator to generate the file automatically as you test your app, or write the file yourself.


2 Answers

v1-library is a thin layer that provides generated proto sources and some helper functions.
google-cloud-datastore is a wrapper that uses v1-library aimed to be more user friendly.
To allow different Datastore client libraries to interface with Dataflow, we use the v1 library as it is the least common denominator.

Ideally you would use the google-cloud-datastore library, but depending on the versions, v1-library and google-cloud-datastore might have conflicting dependencies (protobuf 3.0.0 v 3.0.0-beta-1 in particular) in which case you either have to pick the compatible versions or use v1-library directly.

The v1-library helper functions might not be enough to exclude fields from indexing but you could always create your own helpers by dealing with proto messages directly. In this particular case, you would be creating your own Value and setting exclude_from_indexes explicitly.

like image 90
Vikas Kedigehalli Avatar answered Sep 21 '22 00:09

Vikas Kedigehalli


These two libraries are not currently compatible with each other (you cannot convert between the two data representations), but you can exclude values from indexes in com.google.datastore.v1:

Value value = Value.newBuilder()
    .setStringValue("foo")
    .setExcludeFromIndexes(true)
    .build();
like image 37
Ed Davisson Avatar answered Sep 18 '22 00:09

Ed Davisson