influxdata / influxdb-client-python

InfluxDB 2.0 python client
https://influxdb-client.readthedocs.io/en/stable/
MIT License
706 stars 185 forks source link

string field gets inserted as integer :( #656

Closed rwader-swi closed 3 months ago

rwader-swi commented 3 months ago

Specifications

Code sample to reproduce problem


test1 = Point(measurement_name="pullrequest")
test1.tag("key1","value1")
**test1.field("status", "value2")**

test2 = Point(measurement_name="pullrequest")
test2.tag("key3","value3")
**test2.field("status", "value4")**

self._client = InfluxDBClient(
                    url=self._full_url, ssl=self._ssl, token=self._token, org=self._org, *args, **kwargs
                )
write_api = self._client.write_api(write_options=write_options)

write_api.write(bucket=self._bucket, **record=test1**, write_precision=time_precision, **kwargs)
write_api.write(bucket=self._bucket, **record=test2**, write_precision=time_precision, **kwargs)

Expected behavior

image

Actual behavior

Instead of "value2" string I get 0, and instead of "value4" string I get 1, and so on.

image

Additional info

No response

bednar commented 3 months ago

Hi @rwader-swi,

Thank you for using our client. Based on your description, it seems there might be an issue with the query you are using or the data you are querying. To help you achieve the correct response, I've prepared a working example specifically tailored to your data scenario:

from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS

with InfluxDBClient(url="http://localhost:8086", token="my-token", org="my-org", debug=False) as client:
    # Creating test points
    test1 = Point("pullrequest").tag("key1", "value1").field("status", "value2")
    test2 = Point("pullrequest").tag("key3", "value3").field("status", "value4")

    # Writing points to the database
    write_api = client.write_api(write_options=SYNCHRONOUS)
    write_api.write(bucket="my-bucket", record=[test1, test2])

    # Querying written data and printing the results
    query_api = client.query_api()
    tables = query_api.query('from(bucket:"my-bucket") |> range(start: -10m) |> filter(fn: (r) => r._measurement == "pullrequest")')
    for table in tables:
        for record in table.records:
            print(record.values)

This example demonstrates how to correctly structure data points using Point objects, write them to InfluxDB, and retrieve them with a query that filters based on the measurement name. Please make sure your bucket name, token, and organization details are correctly set up as per your environment.

Try running this example in your setup, and see if it resolves the issues you are experiencing. If you continue to face problems or have any other questions, feel free to reach out.

Best Regards.