Failure on cursor.fetchall()

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

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
pandas, python, sql
领域
databases

调研方向

从第 89 行的 integration_test/utils/databricks/databricks_sql.py 开始,然后跟踪 cursor.fetchall 在 databricks/sql/client.py 中的调用流程,以及 traceback 中显示的 pandas 转换。复现该集成案例,并确定为什么包含 nullable Int64 数据的单行 COUNT 结果会引发 TypeError;当 fetchall 能够在不引发该异常的情况下返回计数时,即表示完成。

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

描述

Recently started having issues with the fetchall() method. This exact code was working fine last week, but now this same query statement is throwing the errors seen below.

def databricks_sql_count(column, catalog, schema, table, where=""):
    connection_cursor = open_connection()
    cursor = connection_cursor["cursor"]
    connection = connection_cursor["connection"]
    query = f'SELECT COUNT({column}) FROM `{catalog}`.`{schema}`.`{table}` WHERE  {where};'
    cursor.execute(query)
    response = cursor.fetchall()
    close_connection(cursor, connection)
    return response[0][0]

initial_count = databricks_sql_count('visitor_id',
                                               catalog,
                                               schema,
                                               table,
                                               f"created_at >= '{TEST_START_DATE}'")

integration_test/utils/databricks/databricks_sql.py:89: in databricks_sql_count
response = cursor.fetchall()
/usr/local/lib/python3.10/dist-packages/databricks/sql/client.py:670: in fetchall
return self.active_result_set.fetchall()
/usr/local/lib/python3.10/dist-packages/databricks/sql/client.py:944: in fetchall
return self._convert_arrow_table(self.fetchall_arrow())
/usr/local/lib/python3.10/dist-packages/databricks/sql/client.py:884: in _convert_arrow_table
res = df.to_numpy(na_value=None)
/usr/local/lib/python3.10/dist-packages/pandas/core/frame.py:1981: in to_numpy
result = self._mgr.as_array(dtype=dtype, copy=copy, na_value=na_value)


self = BlockManager
Items: Index(['0'], dtype='object')
Axis 1: RangeIndex(start=0, stop=1, step=1)
ExtensionBlock: slice(0, 1, 1), 1 x 1, dtype: Int64
dtype = None, copy = True, na_value = None

  def as_array(
      self,
      dtype: np.dtype | None = None,
      copy: bool = False,
      na_value: object = lib.no_default,
  ) -> np.ndarray:
      """
      Convert the blockmanager data into an numpy array.
  
      Parameters
      ----------
      dtype : np.dtype or None, default None
          Data type of the return array.
      copy : bool, default False
          If True then guarantee that a copy is returned. A value of
          False does not guarantee that the underlying data is not
          copied.
      na_value : object, default lib.no_default
          Value to be used as the missing value sentinel.
  
      Returns
      -------
      arr : ndarray
      """
      passed_nan = lib.is_float(na_value) and isna(na_value)
  
      if len(self.blocks) == 0:
          arr = np.empty(self.shape, dtype=float)
          return arr.transpose()
  
      if self.is_single_block:
          blk = self.blocks[0]
  
          if na_value is not lib.no_default:
              # We want to copy when na_value is provided to avoid
              # mutating the original object
              if lib.is_np_dtype(blk.dtype, "f") and passed_nan:
                  # We are already numpy-float and na_value=np.nan
                  pass
              else:
                  copy = True
  
          if blk.is_extension:
              # Avoid implicit conversion of extension blocks to object
  
              # error: Item "ndarray" of "Union[ndarray, ExtensionArray]" has no
              # attribute "to_numpy"
              arr = blk.values.to_numpy(  # type: ignore[union-attr]
                  dtype=dtype,
                  na_value=na_value,
                  copy=copy,
              ).reshape(blk.shape)
          else:
              arr = np.array(blk.values, dtype=dtype, copy=copy)
  
          if using_copy_on_write() and not copy:
              arr = arr.view()
              arr.flags.writeable = False
      else:
          arr = self._interleave(dtype=dtype, na_value=na_value)
          # The underlying data was copied within _interleave, so no need
          # to further copy if copy=True or setting na_value
  
      if na_value is lib.no_default:
          pass
      elif arr.dtype.kind == "f" and passed_nan:
          pass
      else:
          arr[isna(arr)] = na_value

E TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

/usr/local/lib/python3.10/dist-packages/pandas/core/internals/managers.py:1701: TypeError

主要语言
Python
星标
233
派生
152
平均合并
21 小时 5 分钟
30 天内合并 PR
10

贡献指南

打开贡献指南

从这里开始

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

databricks/databricks-sql-python 的其他 Issue

查看 databricks/databricks-sql-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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