influxdata / influxdb-java

Java client for InfluxDB
MIT License
1.18k stars 478 forks source link

Inconsistent handling of retention policies in single vs batch points #373

Open nebehr opened 7 years ago

nebehr commented 7 years ago

There is no way to write single points to a default retention policy in case it is not named "autogen". The following code will fail:

InfluxDB influxDB = influxDB.setDatabase("mydb");
influxDB.write(Point.measurement("msmt").tag("tag", "x").addField("field", 42).build());

Expected behaviour is to omit retention policy in the queries to InfluxDB if user did not explicitly specified it.

On the other hand, BatchPoints do support default retention policy but if any other RP is to be used, it has to be set on BatchPoints separately and the value set upon the client initialization is ignored:

InfluxDB influxDB = influxDB.setDatabase("mydb").setRetentionPolicy("non_default_rp");
influxDB.write(BatchPoints.database("mydb").tag("tag", "x").addField("field", 42).build());
fmachado commented 7 years ago

@nebehr be aware: you can write to a database using a non-default RP but you cannot easily query the same non-default RP. The only way to do it is providing the full qualified table name <retentionpolicy>.<tablename> in your query.

Something that new InfluxDB users are not aware is the "data visibility limitation" when you are using different retention policies: data written with a RP "A" can only be queried if you use the same RP "A" later.

With your example, the only way to query msmt using a retention policy named non_default_rp is:

Query query = new Query("SELECT * FROM non_default_rp.msmt", "mydb");

Regarding the inconsistency, an easy way to fix it IMO is by doing the following changes:

For more info about RP, check https://docs.influxdata.com/influxdb/v1.3/guides/downsampling_and_retention/ and https://docs.influxdata.com/influxdb/v1.3/query_language/database_management/#retention-policy-management

nebehr commented 7 years ago

@fmachado thanks for the explanation. I am aware of this limitation although I admit it did catch me unawares when I first discovered it.

I guess my main point is, the Java client cannot just assume the default retention policy is named "autogen". Its default value should be null (or, better still, Optional<String>), and if it is empty, the client should attempt to write/read to the default RP whatever its actual name is. Then there would be no need for another writePoints method.

As for BatchPoints, I agree that perhaps documentation update will be sufficient.

tafli commented 4 years ago

Just had the same issue as my default retention policy is not named autogen and I wondered, where my data is. When selection without any RP, there is nothing returned.

Any update on this?

bapBardas commented 4 years ago

Same issue here, my default retention policy is not named autogen and the write method causes unexpected troubles due to the fact that it doesn't try to write to the default RP but to the "autogen" one...

BrentonPoke commented 4 years ago

I started looking into the code for this one, and currently see no way for the client to know the default retention policy's name. Does the server react to "rp" by using a retention policy that it already knows is "default"?