gpt4 book ai didi

jdbc - java.sql.SQLException:的验证失败: 'null'无法强制转换为double类型

转载 作者:行者123 更新时间:2023-12-03 01:00:16 27 4
gpt4 key购买 nike

我正在使用logstash创建从elasticsearch到crate.io的管道。下面是配置。

input{
elasticsearch {
hosts => "<host_name>:9200"
index => "index1"
query => '{ "size":10,"query": {"match_all": {} } }'
}
}
filter{
if!([bench_pose][M_Body_t]) {
mutate{
add_field => {"[bench_pose][M_Body_t]" => null}
}
}
if!([bench_pose][M_Jaw_t]) {
mutate{
add_field => {"[bench_pose][M_Jaw_t]" => null}
}
}
}
output{
jdbc {
driver_class => "io.crate.client.jdbc.CrateDriver"
driver_auto_commit => false
driver_jar_path => "/etc/crate/crate-jdbc-standalone-1.12.3.jar"
connection_string => "crate://<host_ip>:4300"
statement => ["INSERT INTO table_name(path,bench_pose_m_Body_t,bench_pose_m_jaw_t) VALUES(?,?,?)",'path','%{[bench_pose][M_Body_t]}','%{[bench_pose][M_Jaw_t]}']
}
}

源具有字段OBJECT数据类型的“bench_pose”字段,并且Bench_pose下的M_Body_t和M_Jaw_t字段为DOUBLE类型。这些字段在源和目标中可以为NULL。在源中的少数文档中,该字段具有空值。即使目标表具有NULLable字段,当insert语句遇到具有空值的文档时,也会引发以下错误。
JDBC - Exception. Not retrying. {:exception=>java.sql.SQLException: Validation failed for bench_pose_m_body_t: 'null' cannot be cast to type double  

如果删除过滤器插件,则会引发如下错误。
JDBC - Exception. Not retrying. {:exception=>java.sql.SQLException: Validation failed for bench_pose_m_body_t: '%{[bench_pose][M_Body_t]}' cannot be cast to type double

如果我在插入中硬编码null值并在crate sql上运行查询,它将正确执行。
如何在Logstash中解析这些字段中的空值?

最佳答案

您需要将INSERT语句更改为此:

   statement => ["INSERT INTO table_name(path,benc‌​h_pose_m_Body_t,bench‌​_pose_m_jaw_t) VALUES(?,TRY_CAST(? as double),TRY_CAST(? as double))",'path','%{[bench_pose][M_Body_t]}','%{[bench_pose][M_Jaw_t]}']

如果类型转换不兼容, TRY_CAST 将返回null而不是抛出错误。

关于jdbc - java.sql.SQLException:<field_name>的验证失败: 'null'无法强制转换为double类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38981546/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com