influxdata / influxdata/influxdb-client-python

Empty string in database becomes None value in Python

未关闭
#570 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug
主要语言
Python
星标
793
派生
186
平均合并
3 小时 2 分钟
30 天内合并 PR
1

描述

Specifications
  • Client Version: 1.34.0
  • InfluxDB Version: 2.6.1
  • Platform: Linux
Code sample to reproduce problem
import influxdb_client

with influxdb_client.InfluxDBClient(
    org = ...,
    token = ...,
    url = ...,
) as client:
    q = f"""
        from(bucket: ...)
        //|> filter(fn: (r) => exists r._value)
        //|> filter(fn: (r) => r._value != "")
        |> last()
    """
    res = [
        record_it.values
        for table_it in client.query_api().query(q)
        for record_it in table_it.records
    ]
    print(res)
Expected behavior

[{'result': '_result', 'table': 0, '_time': datetime.datetime(2023, 3, 2, 18, 47, 7, 547036, tzinfo=tzutc()), '_value': ''}]

Actual behavior

[{'result': '_result', 'table': 0, '_time': datetime.datetime(2023, 3, 2, 18, 47, 7, 547036, tzinfo=tzutc()), '_value': None}]

Additional info

last() function:

If [_value] column is null in the last record, last() returns the previous record with a non-null value.

My last record with a non-null _value has the empty string for _value.
So far, the row is correctly identified.
But by the time I read _value from the result returned in Python, the record does not hold the empty string "" but None.

I verified that the value of _value is really the empty string in the database and not None by experimenting with filters (see commented code).
I find it more intuitive to leave the empty string as empty string in Python.

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用所示的 Flux 查询运行 Python 复现代码,并比较预期的 _value 值和实际的 _value 值。跟踪 query_api().query(q) 如何解析返回的记录,然后验证空字符串在结果中仍保持为 "",而不是变成 None。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
database
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。