cube icon indicating copy to clipboard operation
cube copied to clipboard

Invalid or out-of-range datetime '9999-12-31 00:00:00'

Open Larissa-Rocha opened this issue 3 years ago • 11 comments

Describe the bug We are experiencing an odd behavior when a timestamp column has a value equals '9999-12-31 00:00:00'. This is error in cube server:

thread 'tokio-runtime-worker' panicked at 'invalid or out-of-range datetime', /github/home/.cargo/registry/src/github.com-1ecc6299db9ec823/chrono-0.4.19/src/naive/datetime.rs:117:18

To Reproduce Steps to reproduce the behavior:

  1. Run SELECT TIMESTAMP '1999-12-31 00:00:00' and see that it works
  2. Run SELECT TIMESTAMP '9999-12-31 00:00:00' and see the error

Expected behavior Return the value '9999-12-31 00:00:00' when I run the query SELECT TIMESTAMP '9999-12-31 00:00:00'

Version: 0.30.47

Larissa-Rocha avatar Aug 17 '22 19:08 Larissa-Rocha

@Larissa-Rocha, does it works for you with previous versions?

buntarb avatar Aug 18 '22 10:08 buntarb

Hi @Larissa-Rocha , Could you please share exact steps to reproduce that? We need more info to be able to help here.

ivan-vdovin avatar Aug 18 '22 11:08 ivan-vdovin

@Larissa-Rocha, does it works for you with previous versions?

@buntarb I haven't used any previous versions, just 0.30.47

Larissa-Rocha avatar Aug 18 '22 14:08 Larissa-Rocha

Hi @Larissa-Rocha , Could you please share exact steps to reproduce that? We need more info to be able to help here.

Hi @ivan-vdovin, I think I forgot to mention that I'm using the Cube SQL API, so to reproduce that you just need run query number 2, in my case I have used Apache Superset as BI tool

Larissa-Rocha avatar Aug 18 '22 14:08 Larissa-Rocha

@Larissa-Rocha, is it a query over the pre-aggregations, or are you querying the data source?

buntarb avatar Aug 18 '22 15:08 buntarb

@buntarb I'm querying the data source, there's a 'end date column' where the value is '9999-12-31 00:00:00' by default when there's no end date

Larissa-Rocha avatar Aug 18 '22 18:08 Larissa-Rocha

This bug is related to the SQL API bug, not to the Cube (js) part, I will prepare a fix for that.

Expected behavior Return the value '9999-12-31 00:00:00' when I run the query SELECT TIMESTAMP '9999-12-31 00:00:00'

Instead of silent panic, it will return an error to the client.

ovr avatar Aug 18 '22 21:08 ovr

I've prepared the PR https://github.com/cube-js/cube.js/pull/5122 which will handle panics as errors back to the client instead of panicking and closing the connection.

The same issue will be with Cube Store.

Related to this error. It cannot be stored and I there are no plans to implement it, because there are limitions in:

  1. Apache Arrow stores Timestamp as i64
  2. Rust's Chrono library uses i64.

Why it panics:

    #[inline]
    pub fn timestamp_nanos(&self) -> i64 {
        let as_ns = self.timestamp() * 1_000_000_000;
        as_ns + i64::from(self.timestamp_subsec_nanos())
    }

As another way it can be possible to store such a big timestamp with Second units. Right now, we use Nanosecond units. But I don't think that we will use Second units because it can be another limitation.

end date column' where the value is '9999-12-31 00:00:00' by default

As workaround you can:

  1. Use custom SQL in your Cube with CASE my_date WHEN 9999-12-31 00:00:00 THEN NULL (another, smaller date) ELSE my_date inside sql field.
  2. https://cube.dev/docs/schema/reference/dimensions#parameters-case (I am not sure that it will work)

WDYT about this workaround? Will it work for you?

Thanks

ovr avatar Aug 18 '22 22:08 ovr

@Larissa-Rocha Could you please share the place where superset introduces this date? Which version of superset do you use?

paveltiunov avatar Aug 20 '22 15:08 paveltiunov

Hi @ovr, thank you for your quick reply, that workaround did work for me!

Larissa-Rocha avatar Aug 26 '22 12:08 Larissa-Rocha

@Larissa-Rocha Could you please share the place where superset introduces this date? Which version of superset do you use?

Hi @paveltiunov, I'm sorry if I wasn't clear, Superset does not introduce this date, this date is stored in my database, I'm using Superset just to run the query in SQL Lab.

Larissa-Rocha avatar Aug 26 '22 12:08 Larissa-Rocha

I am going to close this issue because it looks solved by the workaround.

Thanks

ovr avatar Oct 18 '22 19:10 ovr