influxdata / influxdata/influxdb-java

Query with different time format does not work if database is not specified.

Open
#599 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.2k
Forks
469
PR merge metrics
No merged PRs in 30d

Description

If you do not specify database in query (even thou you have specified database on the client level) method InfluxDBl#query(Query, TimeUnit) will not return any result because it will not send database information.

Steps to reproduce:

InfluxDB influxDB = InfluxDBFactory.connect(host + ":" + port);
influxDB.setDatabase(database);
// queryResult will be empty.
QueryResult queryResult = influxDB.query(new Query("..."),  TimeUnit.NANOSECONDS)

Quick fix:

InfluxDB influxDB = InfluxDBFactory.connect(host + ":" + port);
influxDB.setDatabase(database);
// queryResult will be empty.
QueryResult queryResult = influxDB.query(new Query("...", "database"),  TimeUnit.NANOSECONDS)

Permanent fix:
Change into "InfluxDBImpl#query(Query, TimeUnit)" into:

public QueryResult query(final Query query, final TimeUnit timeUnit) {
   String db = query.getDatabase();
    if (db == null) {
        db = this.database;
    }
    Call<QueryResult> call = null;
    if (query instanceof BoundParameterQuery) {
        BoundParameterQuery boundParameterQuery = (BoundParameterQuery) query;
        call = this.influxDBService.query(db,
                TimeUtil.toTimePrecision(timeUnit), query.getCommandWithUrlEncoded(),
                boundParameterQuery.getParameterJsonWithUrlEncoded());
    } else {
        call = this.influxDBService.query(db,
                TimeUtil.toTimePrecision(timeUnit), query.getCommandWithUrlEncoded());
    }
    return executeQuery(call);
  }

Here database information is taken from client level if not given in query object.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at InfluxDBImpl#query(Query, TimeUnit) and inspect how Query.getDatabase() and the client-level database are passed to influxDBService.query. Verify both regular Query and BoundParameterQuery behavior. Done means a query without its own database uses the database configured on the client and returns results with the requested time precision.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.