2.5 KiB
2.5 KiB
Task 2 Report: Candidate Mileage Schema And Writer
Outcome
- Implemented Task 2 in
go/vehicle-gateway/internal/stats. - Added candidate mileage schema, sample-to-candidate mapping, and the upsert writer.
RED Evidence
The focused candidate tests failed before implementation because the new symbols did not exist:
cd /Users/lingniu/project/ai-coding/lingniu-vehicle-ingest/go/vehicle-gateway
go test ./internal/stats -run 'TestSourceKey|TestUpsertSourceMileage' -count=1
Result:
undefined: SourceKeyundefined: SourceMileageSampleundefined: QualityOKundefined: UpsertSourceMileage
GREEN Evidence
After implementation, the focused candidate tests passed:
cd /Users/lingniu/project/ai-coding/lingniu-vehicle-ingest/go/vehicle-gateway
go test ./internal/stats -run 'TestSourceKey|TestUpsertSourceMileage' -count=1
Result:
ok lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats 0.556s
Package verification also passed:
cd /Users/lingniu/project/ai-coding/lingniu-vehicle-ingest/go/vehicle-gateway
go test ./internal/stats -count=1
Result:
ok lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats 0.235s
Files Changed
go/vehicle-gateway/internal/stats/schema.gogo/vehicle-gateway/internal/stats/daily_metric.gogo/vehicle-gateway/internal/stats/source_mileage.gogo/vehicle-gateway/internal/stats/source_mileage_test.go
Self-Review
- The candidate schema matches the brief's table shape and indexes.
SamplesFromEnvelopenow carriesEventTimeandDeviceID, which the new candidate mapping needs.- The upsert SQL is focused on the candidate table and reuses the shared
Execerinterface. - No unrelated stats files were modified.
Review Fix Addendum
- Preserved manual
platform_namevalues when the candidate upsert receives blank runtime input by switching toCOALESCE(NULLIF(TRIM(VALUES(platform_name)), ''), platform_name). - Bootstrapped
vehicle_data_source,vehicle_daily_mileage_source, andvehicle_daily_mileagebefore running alter statements inWriter.EnsureSchema. - Added a defensive blank
SourceIPguard inUpsertSourceMileageso malformed candidate rows are skipped instead of written. - Removed the SQL comment that existed only to satisfy a string-match test and updated the focused assertions to check the real
daily_mileage_kmandplatform_nameSQL expressions. - Verification run:
go test ./internal/stats -run 'TestUpsertSourceMileage|TestWriterEnsuresSchema' -count=1go test ./internal/stats -count=1- Both passed.