0

I am using sprigboot and influx client :https://github.com/influxdata/influxdb-java

I am facing a problem where i am trying to get specif column from the influx db but i am not able to get any record when i am putting column name in the query .But, when i am trying to use select * then i am getting the data.

@Data
@Measurement(name = "layout")
public class LayoutMapper {

    @Column(name = "id", tag=true)
    private String id;

    @Column(name = "linename", tag=true)
    private String lineName;

    @Column(name = "tenantid")
    private String tenantName;

    @Column(name = "layout")
    private String layout;



}

To save POJO to database:

Point point = Point.measurementByPOJO(clazz.getClass()).addFieldsFromPOJO(pojoObject).build();
            connection.query(new Query("CREATE RETENTION POLICY " + retentionPolicyName + " ON " + dbProperties.getDatabase() DURATION 1h  REPLICATION 1 DEFAULT"));
            connection.write(dbProperties.getDatabase(), retentionPolicyName, point);

Working:

  select * from layout;
  select layout from layout;

Not Working (Giving empty records):

select linename from layout;

Can anyone suggest what i am doing wrong ?

NOTE: Observation its weird that we cannot do select query for the string column any suggestion ?

Rohitesh
  • 1,514
  • 7
  • 28
  • 51

1 Answers1

1

I think influxdb-java client library's approach to create an abstraction for accessing data is a little confusing. First of all, none of those are actually columns. In InfluxDB, your data is stored using the following data model (aka, the line protocol): measurement-name,tag-set field-set timestamp

The measurement” is a high level of grouping of data and it is string, “the tag set” is a collection of key/value pairs which can be considered as metadata where all values are indexed and strings, and “the field set” is a collection of key/value pairs where the values can be int64, float64, bool, or string. In contrast to tags, fields are not indexed.

In the LayoutMapper class, you set tag=true for the id and linename, that means these two are members of the tag-set in your measurement. Tags are used to query fields in a high performance way. For that reason, they are usually located in WHERE clause, not SELECT alone.

In InfluxDB, if you want to return a specific tag, the SELECT clause must include at least one field. That's why you only get result from the queries including * and layout field. All in all, give the following a try:

SELECT layout, linename FROM layout;
kahveci
  • 1,429
  • 9
  • 23