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

string values parse as boolean #39

Closed
mukatee opened this issue Jun 24, 2015 · 12 comments
Closed

string values parse as boolean #39

mukatee opened this issue Jun 24, 2015 · 12 comments

Comments

@mukatee
Copy link

mukatee commented Jun 24, 2015

Hello,

There seems to be a problem with the Point.Builder class and using String values. Example:

db = InfluxDBFactory.connect(dbUrl, dbUser, dbPass);
BatchPoints batchPoints = BatchPoints
              .database("my_db")
              .time(time, TimeUnit.MILLISECONDS)
              .tag("async", "true")
              .retentionPolicy("default")
              .consistency(InfluxDB.ConsistencyLevel.ALL)
              .build();
Point.Builder builder = Point.measurement("my_type");
builder.field("my_field", "string_value");
Point point = builder.build();
db.write(batchPoints);

This results in a field of type "boolean" typically set to false in the DB.

Influxd console shows errors such as
unable to parse bool value 'string_value': strconv.ParseBool: parsing "string_value": invalid syntax

I can repeat this with curl using

$ curl -i -XPOST 'http://localhost:8086/write?db=test1&precision=ms' -d 'cpu_load_short,host=server01,region=us-west value=string_value 1435148346112'

the above creates a field called "value" with boolean type and value of false, with the matching parse error.

$ curl -i -XPOST 'http://localhost:8086/write?db=test1&precision=ms' -d 'cpu_load_short,host=server01,region=us-west value2="string_value" 1435148346112'

the above with the double quotes creates a string field with the given string_value.

The problem seems to be in Point.java file in the method "public String lineProtocol()", where you do

sb.append(field.getKey()).append("=").append(field.getValue());

I would suggest checking if the value is of type String and add the double quotes to fix.

This is using the 2.0 version built from the repository.

Cheers,
T

@majst01
Copy link
Collaborator

majst01 commented Jun 24, 2015

Hi,

in your example you forgot to add the point to the batchPoints:

Point point = builder.build();
batchPoints.point(point);
db.write(batchPoints);

But even with that modification i cannot reproduce, nor understand your bug report.
"string_value" is not a boolean, in no way.
To further nail down this problem, please give me the exact version of influxdb and add the logs of your code generated with:

db.setLogLevel(LogLevel.FULL);

before you write anything.

thanks
Stefan

@majst01
Copy link
Collaborator

majst01 commented Jun 24, 2015

@mukatee
Copy link
Author

mukatee commented Jun 24, 2015

Hi,

Thanks for the quick response. Here is the log and some clarification.

The code I ran this time (modified from your test):

public class Test39 {
  public static void main(String[] args) {
    String ip = "192.168.2.79";
    InfluxDB influxDB = InfluxDBFactory.connect("http://" + ip + ":8086", "root", "root");;
    influxDB.setLogLevel(InfluxDB.LogLevel.FULL);
    String dbName = "ticket39_" + System.currentTimeMillis();
    influxDB.createDatabase(dbName);
    BatchPoints batchPoints = BatchPoints
            .database(dbName)
            .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
            .tag("async", "true")
            .retentionPolicy("default")
            .consistency(InfluxDB.ConsistencyLevel.ALL)
            .build();
    Point.Builder builder = Point.measurement("my_type");
    builder.field("my_field", "string_value");
    Point point = builder.build();
    batchPoints.point(point);
    influxDB.write(batchPoints);
//    influxDB.deleteDatabase(dbName);
  }
}

The log

---> HTTP GET http://192.168.2.79:8086/query?u=root&p=root&q=CREATE+DATABASE+ticket39_1435158439935
---> END HTTP (no body)
<--- HTTP 200 http://192.168.2.79:8086/query?u=root&p=root&q=CREATE+DATABASE+ticket39_1435158439935 (467ms)
Content-Type: application/json
Request-Id: b38b8071-1a82-11e5-94f8-000000000000
X-Influxdb-Version: FIXME
Date: Wed, 24 Jun 2015 15:07:16 GMT
OkHttp-Selected-Protocol: http/1.1
OkHttp-Sent-Millis: 1435158440435
OkHttp-Received-Millis: 1435158440443

{"results":[{}]}
<--- END HTTP (16-byte body)
---> HTTP POST http://192.168.2.79:8086/write?u=root&p=root&db=ticket39_1435158439935&rp=default&precision=ms&consistency=all
Content-Type: text/plain
Content-Length: 55
my_type,async=true my_field=string_value 1435158440495

---> END HTTP (55-byte body)
<--- HTTP 204 http://192.168.2.79:8086/write?u=root&p=root&db=ticket39_1435158439935&rp=default&precision=ms&consistency=all (1016ms)
Content-Encoding: gzip
Request-Id: b39700b5-1a82-11e5-94f9-000000000000
X-Influxdb-Version: FIXME
Date: Wed, 24 Jun 2015 15:07:17 GMT
OkHttp-Selected-Protocol: http/1.1
OkHttp-Sent-Millis: 1435158440510
OkHttp-Received-Millis: 1435158441523


<--- END HTTP (0-byte body)

And console log from influxdb server showing the issue

show databases
name: databases
---------------
name
test1
ticket39_1435158367500
ticket39_1435158439935

> use ticket39_1435158439935
Using database ticket39_1435158439935
> show measurements
name: measurements
------------------
name
my_type

> select * from my_type
name: my_type
tags: async=true
time                my_field
----                --------
2015-06-24T15:07:20.495Z    false

> 

As you can see, the server response is OK, but the value has been converted to boolean. The error I mentioned earlier is visible in the "influxd" server console log, referring to the shell where i start the "influxd" on the host running it.

The database server version should be the latest (think I installed it yesterday from brew). It is running on OSX 10.10.3. When I run influx -version I get the info below.

influx -version
InfluxDB shell 0.9.0

@majst01
Copy link
Collaborator

majst01 commented Jun 24, 2015

Ok i see,

but influxdb-java writes the right content in the lineprotocol, so this seems to be a problem with influxdb itself. I still does not know how exactly tags,fields and their values have to be escaped. Would you please raise a ticket with this example , in curl, to the influxdb directly ?
thanks
Stefan

@mukatee
Copy link
Author

mukatee commented Jun 24, 2015

OK, I will do that.

If you look at my curl examples from above, you can also see that if the POST data was

my_type,async=true my_field="string_value" 1435158440495

and not

my_type,async=true my_field=string_value 1435158440495

that might fix it. At least with curl it worked that way. But I have no idea what is the correct intended way to escape data types so I will post a question in their issue tracker..

@majst01
Copy link
Collaborator

majst01 commented Jun 24, 2015

fine,

im also not sure if it is correct to surround string values with quotes, so i wait for their explanation.

@mukatee
Copy link
Author

mukatee commented Jun 24, 2015

There was an issue already for the same behaviour in the db console. I put my comment there influxdata/influxdb#3063

@jwilder
Copy link

jwilder commented Jun 24, 2015

String field values should be surrounded by double-quotes and any double-quotes in the string need to be escaped with \".

See https://github.com/influxdb/influxdb/blob/master/tsdb/README.md

@majst01
Copy link
Collaborator

majst01 commented Jun 28, 2015

I close this issue again, if this happens again please reopen.

@majst01 majst01 closed this as completed Jun 28, 2015
@hMechkouri
Copy link

Hi mukatee,

We are using the same version of influxdb 0.9, and I encountred the same issue. All strings values are converted to boolean.

Can we have please the link for the ticket ?

Thanks

@andrewdodd
Copy link
Contributor

@hMechkouri is this the ticket you mean? influxdata/influxdb#3063

@mukatee
Copy link
Author

mukatee commented Mar 11, 2016

Hi,

I think Andrew already linked the ticket if you were referring to the one on InfluxDB itself (also should be visible in above comments). Anyway, I think it is also handled better by the driver now..

T

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

5 participants