risingwavelabs/risingwave · error · ValueEncodingError

Invalid Date value encoding: days

Error message

Invalid Date value encoding: days: {0}

What it means

`ValueEncodingError::InvalidDateEncoding` is raised when decoding a value-encoded DATE: the day count is stored as an i32 (days since 1970-01-01) and reconstruction via `NaiveDate::from_num_days_from_ce`-style conversion fails when the value is out of the representable date range. The message reports the offending day count.

Solutions

  1. Ensure the encoded i32 day count falls within RisingWave's supported DATE range before decoding
  2. Fix read offsets so the correct 4 bytes are interpreted as the day count
  3. Check the reported `days` value against your writer's output to locate corruption
  4. Regenerate the data with RisingWave's own value-encoding `memcomparable`/value encode APIs instead of hand-rolling

Example fix

// before
let days = i32::MAX; // out of representable date range
let d = NaiveDate::try_from_value_encoding(&days.to_be_bytes())?;
// after
let days = 19_000i32; // valid day count (≈2022)
let d = NaiveDate::try_from_value_encoding(&days.to_be_bytes())?;
Defensive patterns

Strategy: validation

Validate before calling

// range-check day count before encoding/decoding a DATE
fn is_valid_date_days(days: i32) -> bool {
    chrono::NaiveDate::from_num_days_from_ce_opt(days).is_some()
}

Try / catch

match NaiveDate::try_from_value_encoding(bytes) {
    Ok(d) => d,
    Err(ValueEncodingError::InvalidDateEncoding(days)) => {
        return Err(anyhow!("DATE days={days} out of supported calendar range"));
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: Decoding a DATE from bytes whose i32 day value is out of range (e.g. i32::MIN/MAX, negative extremes, or a value produced by a different format), reading at a wrong offset so arbitrary bytes are interpreted as the day count.

Common situations: Hand-crafted encoders writing raw integers outside the supported calendar range, corrupt/truncated storage or Kafka payloads, endian/format mismatches between writer and reader when users serialize externally.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/d8d3eee0c9b94bc2. Report an issue: GitHub.

Appendix: source

Thrown at src/common/src/util/value_encoding/error.rs:23

// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use thiserror::Error;

#[derive(Error, Debug)]
pub enum ValueEncodingError {
    #[error("Invalid bool value encoding: {0}")]
    InvalidBoolEncoding(u8),
    #[error("Invalid UTF8 value encoding: {0}")]
    InvalidUtf8(#[from] std::string::FromUtf8Error),
    #[error("Invalid Date value encoding: days: {0}")]
    InvalidDateEncoding(i32),
    #[error("invalid Timestamp value encoding: secs: {0} nsecs: {1}")]
    InvalidTimestampEncoding(i64, u32),
    #[error("invalid Time value encoding: secs: {0} nano: {1}")]
    InvalidTimeEncoding(u32, u32),
    #[error("Invalid null tag value encoding: {0}")]
    InvalidTagEncoding(u8),
    #[error("Invalid jsonb encoding")]
    InvalidJsonbEncoding,
    #[error("Invalid variant encoding")]
    InvalidVariantEncoding,
    #[error("Invalid struct encoding: {0}")]
    InvalidStructEncoding(
        #[source]
        #[backtrace]
        crate::array::ArrayError,
    ),
    #[error("Invalid list encoding: {0}")]

View on GitHub (pinned to 6469eb736d)