Preserve time of day when converting TIME storage units

perfloop-oss/parquet-go · Inefficient Algorithm

https://perfloop.ai/t/oss/case_v4b59g8qma

Verdict

VERIFIED · settled 2026-11-24 · merged as parquet-go/parquet-go#744

What happened: The check fails before this change and passes with it.

Hypothesis

Reading a TIME column through a schema with different storage precision changes the represented time of day. One stored millisecond becomes one microsecond instead of remaining one millisecond. This is a correctness claim; no runtime saving is asserted.

The cited `timeType` owns `ConvertValue` at type_time.go:283-305. It recognizes string and timestamp sources, but TIME sources fall through to the destination physical integer type. `int32Type.ConvertValue` and `int64Type.ConvertValue` then cast or retain the raw count without rescaling (type_int32.go:74-100; type_int64.go:74-100). Generic schema conversion calls the logical destination's `ConvertValue` for every converted value (convert.go:98-109). Both millisecond INT32 and microsecond/nanosecond INT64 representations are supported. The claim covers unit changes with equal UTC-adjustment annotations; it does not invent semantics for changing that annotation.

`go test . -run '^TestHuntTimeUnitConversion(Search|Replay)$' -count=1 -v` searched all nine unit pairs in both equal annotation modes. Each combination used ten boundary durations and 1,024 seeded durations in the valid [0,24h) domain. All six same-unit controls passed. Every unequal-unit combination changed nonzero times rather than merely discarding sub-unit precision. For example, a source count of 1 in milliseconds converted to INT64 1 microsecond instead of 1,000.

The reduced replay writes a typed INT32 field annotated TIME(millisecond) with physical count 1. It first reads the same schema back and verifies that count, then reads into a time.Duration field annotated TIME(microsecond). `go test . -run '^TestHuntTimeUnitConversionReplay$' -count=1 -v` fails with `read duration = 1µs, want 1ms`. This validates an ordinary supported file/schema-conversion route, not just the direct type API. An earlier duration-valued writer fixture produced 1 second instead; that fixture also exercised duration encoding and is not used to attribute this local conversion defect. The corrected source and both observations remain under `/tmp/perfloop/work/type-scope-time-units/`.

The Case should establish preservation of the represented time across supported unit conversions, with correct physical kinds and expected truncation for coarser precision. The smallest useful next check is the attached physical-count-verified replay and the bounded unit-pair oracle. The native test layout is provisional. Usage frequency and incident counts remain unknown.

The upstream audit found no implementation of this repair. https://github.com/parquet-go/parquet-go/pull/696 handles unsupported logical/physical combinations; this replay uses supported TIME(millisecond)/INT32 and TIME(microsecond)/INT64 combinations. Targeted prior searches for time unit conversion and timeType ConvertValue found no overlapping repair. The available local history is shallow, so older decisions remain an evidence gap.

Change to test: Rescale supported TIME-to-TIME conversions according to both source and destination units, returning the destination physical kind and truncating only the precision being discarded. Preserve existing annotation handling and non-TIME conversion behavior.

Where it lives

perfloop-oss/parquet-go

Evidence

The check fails before this change and passes with it: `For TIME values in [0,24h), conversion among millisecond INT32, microsecond INT64 and nanosecond INT64 rescales storage counts for every source/destination UTC-adjustment annotation, discards only sub-unit precision at coarser destinations, treats unset units as nanoseconds, preserves nulls, and retains value levels.`

The check fails before this change and passes with it: `Reading a stored TIME(millisecond) INT32 count of 1 through a TIME(microsecond) schema into time.Duration returns 1ms, after a same-schema read confirms the physical source count.`

Checks: 3 of 3 passed. Verification: no defect found.

Timeline