risingwavelabs/risingwave · error · ValueEncodingError

invalid Timestamp value encoding: secs: {0} nsecs: {1}

Error message

invalid Timestamp value encoding: secs: {0} nsecs: {1}

What it means

`ValueEncodingError::InvalidTimestampEncoding` is raised when decoding a value-encoded TIMESTAMP/Timestamptz: the pair (secs: i64, nsecs: u32) read from the buffer cannot be converted to a valid `NaiveDateTime` (e.g. seconds or nanoseconds outside the representable range). The message reports both components.

Source

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

//     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}")]
    InvalidListEncoding(
        #[source]

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Verify the decoded (secs, nsecs) values: nsecs must be < 1_000_000_000 and secs within NaiveDateTime's range
  2. If your writer emits epoch millis/micros, convert to (secs, nanos) before value-encoding
  3. Check byte offsets and endianness so the correct 12 bytes are read as the timestamp
  4. Re-encode the data with RisingWave's value-encoding APIs

Example fix

// before
let (secs, nsecs) = (1_700_000_000_000i64, 0u32); // millis mistakenly in secs
// after
let (secs, nsecs) = (1_700_000_000i64, 0u32); // secs + nanos pair
Defensive patterns

Strategy: validation

Validate before calling

// validate the (secs, nsecs) pair before encoding a timestamp
fn is_valid_timestamp(secs: i64, nsecs: u32) -> bool {
    nsecs < 1_000_000_000
        && chrono::NaiveDateTime::from_timestamp_opt(secs, nsecs).is_some()
}

Try / catch

match NaiveDateTime::try_from_value_encoding(bytes) {
    Ok(ts) => ts,
    Err(ValueEncodingError::InvalidTimestampEncoding(secs, nsecs)) => {
        return Err(anyhow!("bad timestamp secs={secs} nsecs={nsecs}"));
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: Decoding a timestamp whose stored secs exceed chrono's valid range for NaiveDateTime, or whose nsecs exceed 999_999_999; wrong-offset reads that reinterpret unrelated bytes as (secs, nsecs); external writers using a different epoch or unit (e.g. millis written as secs).

Common situations: Hand-rolled serializers writing epoch-millis into the secs field, corrupt/truncated payloads, endian mismatch, offset errors when manually slicing value-encoded rows.

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/07d370fb7f600400. Report an issue: GitHub.