ShivamSharma43 opened a new pull request, #1710:
URL: https://github.com/apache/arrow-go/pull/1710

   ### Rationale for this change
   
   `csv.NewInferringReader` infers `time32[s]` for `12:34:56`, but a column 
like `12:34:56.789` is inferred as `utf8`. Inference tries `time32[s]`, which 
rejects fractional seconds, and then moves on to the timestamp types, which 
need a date, so it ends up at string.
   
   @zeroshade pointed this out as a possible follow-up while reviewing #1706 
([review 
comment](https://github.com/apache/arrow-go/pull/1706#pullrequestreview-6117352989)).
 Thanks for the suggestion.
   
   ### What changes are included in this PR?
   
   In `conversionColumn.inferType`, when `time32[s]` fails, inference now tries 
`time32[ms]` before `timestamp[s]`. That accepts `HH:MM:SS` with 1 to 3 
fractional digits, which is what `arrow.Time32FromString` already parses for 
milliseconds. The reader already uses that function for `time32` columns, so no 
reader changes are needed. The rest of the inference order is unchanged.
   
   Values with 4 or more fractional digits still end up as `utf8`. I didn't add 
`time64[us]`/`time64[ns]` inference. Arrow C++ doesn't do it: 
`inference_internal.h` has a single `InferKind::Time`, which maps to 
`time32(TimeUnit::SECOND)`. Also, `csv.Reader` doesn't parse `time64` columns 
yet.
   
   Note that Arrow C++ doesn't infer `time32[ms]` either, so pyarrow still 
reads `12:34:56.789` as a string. This change makes the Go reader infer more 
than C++ does here. It works the same way as the existing timestamp inference, 
which tries a coarser unit first and then a finer one.
   
   This doesn't depend on #1706 and is based on `main`. The two PRs touch 
different files and merge cleanly. Once #1706 is in, `csv.Writer` can write the 
inferred `time32[ms]` column back out too.
   
   ### Are these changes tested?
   
   Yes. `TestInferringReaderTimeOfDay` reads a single column through 
`NewInferringReader` with a checked allocator and checks both the inferred type 
and the values:
   
   - `12:34:56`: `time32[s]` (unchanged)
   - `12:34:56.789`: `time32[ms]`
   - `12:34:56.7` and `00:00:01.05`: `time32[ms]` (fewer than 3 fractional 
digits)
   - `12:34:56.789` followed by `12:34:57`: `time32[ms]`, and the later row 
without fractional seconds also parses
   - `12:34:56.789123`: `utf8` (unchanged, since there is no `time64` inference)
   
   Without the change, the three `time32[ms]` cases fail because the column is 
inferred as `utf8`.
   
   On Windows amd64 with Go 1.26.11, `go test -tags assert ./arrow/csv/ -run 
'^Test'` and `go test -tags assert,test ./arrow/csv/ -run '^Test'` pass, `go 
vet` is clean, gofmt reports nothing, and `golangci-lint run ./arrow/csv/` 
reports 0 issues. `Example_reader` was skipped because it needs the 
`arrow-testing` submodule, which isn't checked out locally.
   
   ### Are there any user-facing changes?
   
   No API changes. `NewInferringReader` now infers `time32[ms]` instead of 
`utf8` for time-of-day columns whose first value has 1 to 3 fractional digits. 
Code that relied on these columns being strings will now get `time32[ms]`.
   
   This PR was prepared with AI assistance (Claude Code).
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to