ksqlDB流联接表出现聚合错误

时间:2020-07-09 13:19:53

标签: join ksqldb

当我执行以下带有错误的sql时,谁知道该如何解决?非常感谢。

错误消息: 无法将io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression类强制转换为io.confluent.ksql.execution.expression.tree.ComparisonExpression类(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression和io.confluent .ksql.execution.expression.tree.ComparisonExpression位于加载程序“ app”的未命名模块中)

select 
a.mo_order_id,
    a.mo_lot_no,
    b.tenant_id,
    a.line_id,
    substring((TIMESTAMPTOSTRING(a.creation_time, 'yyyy-MM-dd HH:mm:ss', 'GMT')),1,10) as produce_date,
    substring(substring((TIMESTAMPTOSTRING(a.creation_time, 'yyyy-MM-dd HH:mm:ss', 'GMT')),12,12),1,2) as produce_hour,
    (
    case 
    when a.result_code =1  then 1 
    when a.result_code =3  then 1 
    when a.result_code =8  then 1 
    when a.result_code =2 then 2 
    else 0 
    end) cause_type,
    SUM((
    case 
    when ((a.result_code =1) and is_reset = false) then sn_count
    when ((a.result_code =3) and is_reset = false) then sn_count 
    when ((a.result_code =8) and is_reset = false) then sn_count 
    when ((a.result_code =1) and is_reset = true)  then -1*sn_count 
    when (a.result_code = 2) then sn_count else 0 
    end)) stats
from
    STREAM_ORI_SACMES_INSPECTION a
inner join KSQL_TABLE_GP_MO_ORDER b on
    (a.mo_order_id = b.id and (a.result_code =1 or a.result_code =3 or a.result_code =8))
group by 
    a.mo_order_id,
    a.mo_lot_no,
    b.tenant_id,
    a.line_id,
    substring((TIMESTAMPTOSTRING(creation_time, 'yyyy-MM-dd HH:mm:ss', 'GMT')),1,10),
    substring(substring((TIMESTAMPTOSTRING(creation_time, 'yyyy-MM-dd HH:mm:ss', 'GMT')),12,12),1,2),
    (
    case 
    when a.result_code =1  then 1 
    when a.result_code =3  then 1 
    when a.result_code =8  then 1 
    when a.result_code =2 then 2 
    else 0 
    end)
    emit changes;

1 个答案:

答案 0 :(得分:0)

嗯...看起来像个虫子!

问题在于您的加入条件无效:(a.mo_order_id = b.id and (a.result_code =1 or a.result_code =3 or a.result_code =8))

看起来您的加入条件应该为a.mo_order_id = b.id,其他位应该移至WHERE子句中。

a.mo_order_id,
    a.mo_lot_no,
    b.tenant_id,
    a.line_id,
    substring((TIMESTAMPTOSTRING(a.creation_time, 'yyyy-MM-dd HH:mm:ss', 'GMT')),1,10) as produce_date,
    substring(substring((TIMESTAMPTOSTRING(a.creation_time, 'yyyy-MM-dd HH:mm:ss', 'GMT')),12,12),1,2) as produce_hour,
    (
    case 
    when a.result_code =1  then 1 
    when a.result_code =3  then 1 
    when a.result_code =8  then 1 
    when a.result_code =2 then 2 
    else 0 
    end) cause_type,
    SUM((
    case 
    when ((a.result_code =1) and is_reset = false) then sn_count
    when ((a.result_code =3) and is_reset = false) then sn_count 
    when ((a.result_code =8) and is_reset = false) then sn_count 
    when ((a.result_code =1) and is_reset = true)  then -1*sn_count 
    when (a.result_code = 2) then sn_count else 0 
    end)) stats
from
    STREAM_ORI_SACMES_INSPECTION a
inner join KSQL_TABLE_GP_MO_ORDER b on
    a.mo_order_id = b.id
where
    a.result_code =1 or a.result_code =3 or a.result_code =8
group by 
    a.mo_order_id,
    a.mo_lot_no,
    b.tenant_id,
    a.line_id,
    substring((TIMESTAMPTOSTRING(creation_time, 'yyyy-MM-dd HH:mm:ss', 'GMT')),1,10),
    substring(substring((TIMESTAMPTOSTRING(creation_time, 'yyyy-MM-dd HH:mm:ss', 'GMT')),12,12),1,2),
    (
    case 
    when a.result_code =1  then 1 
    when a.result_code =3  then 1 
    when a.result_code =8  then 1 
    when a.result_code =2 then 2 
    else 0 
    end)
    emit changes;
join ksqldb