我想返回sql计数结果,如果计数大于0,我想诱导一个失败函数。
然而,我得到一个错误。我认为这是因为id_of_zero_count是一个字符串,它不能与整数比较?
id_of_zero_count = sql(""" SELECT count(*) cnt FROM schema.table where ID = 0 """.format(val))
#BU.collect[0][0] returns the value of the first row & first column
display(id_of_zero_count)
if id_of_zero_count > 0:
print("Quality check not passed")
induce_fail_func()
这是返回的错误:
TypeError: '>' not supported between instances of 'DataFrame' and 'int'
TypeError Traceback (most recent call last)
<command-873419207778593> in <module>
----> 1 if id_of_zero_count > 0:
2 print("Quality check not passed")
3 induce_fail_func()
TypeError: '>' not supported between instances of 'DataFrame' and 'int'
sql查询返回一个数据框,您应该在显示调用中看到它。
您可以获取第一行的第一个元素:
if id_of_zero_count.first()[0] > 0:
print("Quality check not passed")
induce_fail_func()