hive - 如何在 Jython Evaluator 中获取 StreamSets 记录字段类型
问题描述
我有一个 StreamSets 管道,我使用 JDBC 组件作为源从远程 SQL Server 数据库中读取数据,并将数据放入 Hive 和 Kudu 数据湖。
我在使用 Binary Columns 类型时遇到了一些问题,因为 Impala 中没有 Binary 类型支持,我用它来访问 Hive 和 Kudu。
我决定将 Binary 类型列(在管道中作为 Byte_Array 类型流动)转换为 String 并像这样插入它。
我尝试使用字段类型转换器元素将所有 Byte_Array 类型转换为字符串,但它不起作用。所以我使用了一个 Jython 组件将所有 arr.arr 类型转换为 String。它工作正常,直到我在该字段上获得 Null 值,因此 Jython 类型为 None.type 并且我无法检测到 Byte_Array 类型并且无法将其转换为 String。所以我无法将它插入 Kudu。
任何帮助如何在 Jython Evaluator 中获取 StreamSets 记录字段类型?或者针对我面临的问题有什么建议的解决方法?
解决方案
您需要使用sdcFunctions.getFieldNull()
来测试该字段是否为NULL_BYTE_ARRAY
. 例如:
import array
def convert(item):
return ':-)'
def is_byte_array(record, k, v):
# getFieldNull expect a field path, so we need to prepend the '/'
return (sdcFunctions.getFieldNull(record, '/'+k) == NULL_BYTE_ARRAY
or (type(v) == array.array and v.typecode == 'b'))
for record in records:
try:
record.value = {k: convert(v) if is_byte_array(record, k, v) else v
for k, v in record.value.items()}
output.write(record)
except Exception as e:
error.write(record, str(e))
推荐阅读
- python - JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- postgresql - 如何在使用 Jenkins 将 Postgresql 映像部署到 openshift 后执行数据库脚本?
- mysql - 查询超过 1800 万行的 mysql 数据库的替代解决方案
- css - 是否可以通过编辑 CSS 文件在 Bootstrap 4 中设置自定义断点?
- windows - Windows 上文件映射重叠视图的物理 RAM 消耗
- razor - Insight into inheriting from a base controller class
- html - 遇到麻烦
在 CSS 中 - javascript - URL 编码正在破坏 ExtJS 中的路由
- mysql - 在 mysql 中更新表后触发错误 1054
- performance - clflush 是否也会删除 TLB 条目?