Cassandra unset int在Scala中转换为Option时变为0
Cassandra unset int becomes 0 when converted to Option in Scala
我有一个 cassandra 行
slug | logo | name | priority
------+------+------+----------
test | null | Test | null
我正在使用 datastax java 驱动程序查询此结果,然后将 Row
映射到 Scala 案例 class :
Brand(r.getString("slug"), r.getString("name"), Option( r.getInt("priority") ) ,Option( r.getString("logo")))
结果应该是:
Brand(test,Test,None,None)
但我明白了:
Brand(test,Test,Some(0),None)
插入时未设置 priority
和 logo
字段。如果我简单地打印该行,我会得到正确的结果:
[Row[test, NULL, Test, NULL]]
有什么想法吗?
谢谢@Lukasz,我现在明白问题所在了。
由于我无法更改数据模型,所以我最终在映射时进行了 isNull
检查。
Brand(r.getString("slug"), r.getString("name"),(if( r.isNull("priority") ) None else Some(r.getInt("priority")) ), Option( r.getString("logo")))
我有一个 cassandra 行
slug | logo | name | priority
------+------+------+----------
test | null | Test | null
我正在使用 datastax java 驱动程序查询此结果,然后将 Row
映射到 Scala 案例 class :
Brand(r.getString("slug"), r.getString("name"), Option( r.getInt("priority") ) ,Option( r.getString("logo")))
结果应该是:
Brand(test,Test,None,None)
但我明白了:
Brand(test,Test,Some(0),None)
插入时未设置 priority
和 logo
字段。如果我简单地打印该行,我会得到正确的结果:
[Row[test, NULL, Test, NULL]]
有什么想法吗?
谢谢@Lukasz,我现在明白问题所在了。
由于我无法更改数据模型,所以我最终在映射时进行了 isNull
检查。
Brand(r.getString("slug"), r.getString("name"),(if( r.isNull("priority") ) None else Some(r.getInt("priority")) ), Option( r.getString("logo")))