risingwave icon indicating copy to clipboard operation
risingwave copied to clipboard

Bug: panic when decimal use special value('NaN', 'Infinity', '-Infinity')

Open Li0k opened this issue 3 years ago • 3 comments

Describe the bug

risingwave panic when we insert a decimal with special value ('NaN', 'Infinity', '-Infinity')

image

To Reproduce


create table t (d decimal);
create materialized view mv as select count(*) as count, d from t group by d;
CREATE_MATERIALIZED_VIEW
insert into t values ('NaN'::decimal);
insert into t values ('Infinity'::decimal);
insert into t values ('-Infinity'::decimal);
dev=> select * from mv;

Expected behavior statement ok

Additional context

  • case 1
ERROR:  RPC error: Status { code: Internal, message: "internal error: broken fifo_channel", metadata: MetadataMap { headers: {"risingwave-error-bin": "CAESI2ludGVybmFsIGVycm9yOiBicm9rZW4gZmlmb19jaGFubmVs"} }, source: None }
  • case 2
 test error at e2e_test/streaming/basic.slt:28: statement failed: db error: ERROR: RPC error: Status { code: Internal, message: "Expr error: Cast(\"str\", \"risingwave_common::types::decimal::Decimal\")", metadata: MetadataMap { headers: {"risingwave-error-bin": "CBwSRUV4cHIgZXJyb3I6IENhc3QoInN0ciIsICJyaXNpbmd3YXZlX2NvbW1vbjo6dHlwZXM6OmRlY2ltYWw6OkRlY2ltYWwiKQ"} }, source: None }

Li0k avatar Jul 13 '22 03:07 Li0k

case 2 Conculusion

Decimal from_str 1.5
Decimal from_str 2.5
Decimal from_str +Inf
fn from_str(s: &str) -> Result<Self, Self::Err> {
        println!("Decimal from_str {}", s);
        match s {
            "nan" | "NaN" | "NAN" => Ok(Decimal::NaN),
            "inf" | "INF" | "+inf" | "+INF" => Ok(Decimal::PositiveINF),
            "-inf" | "-INF" => Ok(Decimal::NegativeINF),
            s => RustDecimal::from_str(s).map(Decimal::Normalized),
        }
    }

pattern match not conver the "Inf" and "-Inf"

Li0k avatar Jul 13 '22 03:07 Li0k

Converting inf to decimal is disallowed in PG. For example, the query select 'inf'::decimal; has syntax error. However,select 'inf'::real; is acceptable in PG. We may need to rethink RW's bahavior......

likg227 avatar Jul 13 '22 04:07 likg227

Converting inf to decimal is disallowed in PG. For example, the query select 'inf'::decimal; has syntax error. However,select 'inf'::real; is acceptable in PG. We may need to rethink RW's bahavior......

Tested locally on my side and select 'inf'::decimal; works well on PostgreSQL. In addition, some error cases in #3823 are also supported: 'nAN'::decimal, '-iNF'::decimal.

As of PostgreSQL 14.0 (86a4dc1), it actually matches the strings in a case-insensitive manner (pg_strncasecmp): https://github.com/postgres/postgres/blob/86a4dc1e6f29d1992a2afa3fac1a0b0a6e84568c/src/backend/utils/adt/numeric.c#L613

xiangjinwu avatar Jul 13 '22 07:07 xiangjinwu