Repository navigation
fix(#7899): a TIMESERIES type whose TIMESTAMP column is not declared first reads and round-trips correctly - #8141
Conversation
…first reads and round-trips correctly An engine row is [timestamp, non-TIMESTAMP columns in schema order...] whatever position the TIMESTAMP column occupies in the declaration: TimeSeriesBucket.readRow writes position 0 from the row's own timestamp slot and then walks the schema SKIPPING that column. Four consumers mapped row position i onto getTsColumns().get(i) instead, which is the same thing only while the TIMESTAMP column is declared first - and issue #7702 made a later position spellable in CREATE TIMESERIES TYPE. - TimeSeriesGateway.selectedColumns: the null ("every column") branch answered the raw schema instead of the row order its own javadoc promises, so GET /ts/latest, POST /ts/query, the Grafana frames and both gRPC time-series RPCs named their response columns after the neighbouring column's values. - FetchFromTimeSeriesStep: SELECT * answered a TAG's value under the timestamp's name and back. - JsonlImporterFormat.loadTimeSeriesSamples: took the timestamp from the TIMESTAMP column's SCHEMA position, so a restore either died with a bare ClassCastException or silently exchanged the timestamp with the numeric column ahead of it. - PostPrometheusReadHandler: indexed labels, the series key and the sample value by schema position. JsonlExporterFormat is unchanged on the wire - it emitted the engine layout all along; only its javadoc, which called that "schema-column order", is corrected. No format-version bump: #7702 is not in any release (verified with git merge-base --is-ancestor against 26.9.1), so no released build could have written an export of a type whose TIMESTAMP column is not first, and every older export is byte-identical under both readings. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Tick the box to add this pull request to the merge queue (same as
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe change aligns time-series SQL, JSONL, and HTTP read paths with timestamp-first engine row ordering when the TIMESTAMP column is not first in the schema. Regression tests cover row mapping, JSONL round trips, and HTTP read surfaces. ChangesTime-series row ordering
Priority: ⬆️ High Estimated code review effort: 3 (Moderate) | ~30 minutes Change: Bug fix · Severity of issue fixed: High Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change corrects values and column names for time-series schemas where TIMESTAMP is declared later, while preserving JSONL round trips. The covered regression cases indicate no merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 11 |
🟢 Coverage 100.00% diff coverage · -6.19% coverage variation
Metric Results Coverage variation ✅ -6.19% coverage variation Diff coverage ✅ 100.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (642f431) 187386 155921 83.21% Head commit (ab0a257) 219944 (+32558) 169402 (+13481) 77.02% (-6.19%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#8141) 36 36 100.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
Review Reviewed the diff against the engine's actual row layout ( Code quality / correctness
Test coverage Scope Minor / non-blocking
Security / performance Overall: a well-scoped, well-tested fix that correctly traces the bug back to a single source-of-truth invariant and fixes all four affected consumers consistently. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #8141 +/- ##
============================================
+ Coverage 74.88% 74.90% +0.01%
- Complexity 2579 2582 +3
============================================
Files 2004 2004
Lines 187386 187399 +13
Branches 39184 39191 +7
============================================
+ Hits 140320 140367 +47
+ Misses 31504 31472 -32
+ Partials 15562 15560 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Closes #7899
An engine row is
[timestamp, non-TIMESTAMP columns in schema order...]whatever position the TIMESTAMP column occupies in the declaration:TimeSeriesBucket.readRowwrites position 0 from the row's own timestamp slot and then walks the schema skipping that column. Four consumers mapped row positioniontogetTsColumns().get(i)instead, which is the same thing only while the TIMESTAMP column is declared first - and #7702 made a later position spellable inCREATE TIMESERIES TYPE. This PR moves all four onto the engine's layout, reusing the projection helper (TimeSeriesGateway.selectedColumns) thatPromQLEvaluatorandGetPromQLSeriesHandleralready got right, so SQL, HTTP, gRPC and the JSONL round trip cannot disagree about what position 0 means.The invariant
Finding ledger
JsonlExporterFormat.exportTimeSeriesdocuments "schema-column order, timestamp first" but writes the engine layout - fixed (javadoc only; the bytes were already right)JsonlImporterFormat.loadTimeSeriesSamplesreads the sample by the TIMESTAMP column's schema position - fixedFetchFromTimeSeriesStep.next()mapsrow[i]ontocolumns.get(i)- fixedTimeSeriesGateway.selectedColumns(columns, null)answered the raw schema, against its own javadoc - fixed, which covers 6 wire call sites at oncePostPrometheusReadHandlerindexes labels, the series key and the sample value by schema position - fixedMultiColumnAggregationRequest.columnIndexas a row index in the mutable half and a schema index in the sealed half - filed as Aggregation push-down reads MultiColumnAggregationRequest.columnIndex as a row index in the mutable half and a schema index in the sealed half #8140, out of scope hereWhat changed
TimeSeriesGateway.selectedColumnsnull("every column") branch now returns timestamp-first row order, as its javadoc already promised. A fast path returns the schema list unchanged - no allocation - when the TIMESTAMP column is already first, which is every type written before #7702FetchFromTimeSeriesStepgetTsColumns(), resolved once per pull, not per rowJsonlImporterFormat.loadTimeSeriesSamplessample.get(0); value columns aresample.get(1 + k)in non-timestamp schema order, which is the orderappendBatchwants them in.timestampIdxis goneJsonlExporterFormat.exportTimeSeriesPostPrometheusReadHandlerbuildLabelKeyand the sample value index by1 + <non-timestamp ordinal>;findFieldColumnIndexbecomesfindFieldRowIndex. Also folds two stacked javadoc blocks into the one method that was leftWire-format compatibility
The exporter emits the engine layout and always did, so no format-version bump: an older export of a timestamp-first type is byte-identical under both readings, and no released build could have written an export of a type whose TIMESTAMP column is not first, because #7702 is unreleased -
Completeness
Commands run in this session; a path found by reading and not by a command is not listed as found.
Entry-point coverage
exportTimeSeriestheSampleArrayIsWrittenInEngineRowOrderTimestampFirstloadTimeSeriesSamples, STRING before tsaStringTagDeclaredBeforeTheTimestampRoundTripsloadTimeSeriesSamples, NUMERIC before ts (silent)aNumericFieldDeclaredBeforeTheTimestampRoundTripsWithoutSwappingTheTimestampSELECT *->FetchFromTimeSeriesStepTimeSeriesGateway.selectedColumns(cols, null)theFullRowProjectionListsTheTimestampFirstWhateverTheDeclarationSays(pins the projecting branch too)POST /ts/{db}/queryrawtheQueryEndpointNamesTheColumnsInTheOrderItReturnsTheirValuesGET /ts/{db}/latesttheLatestEndpointNamesTheColumnsInTheOrderItReturnsTheirValuesPOST /ts/{db}/grafana/queryrawtheGrafanaFrameNamesEachFieldAfterTheValueItCarriesTimeSeriesQuerystreamIssue7663GrpcTimeSeriesLimitFetchBoundIT,Issue7390...); no non-first-timestamp test - see residual riskTimeSeriesLatestthePrometheusRemoteReadLabelsAndSamplesComeFromTheirOwnColumnsTimeSeriesBucket.readRow)theEngineRowItselfCarriesTheTimestampInPositionZeropins itPromQLEvaluatorGetPromQLSeriesHandler,GetPromQLLabels*selectedColumnswith a NON-null projection (the already-correct branch);collectDistinctTagValuesresolves BY NAMESaveElementStep.saveToTimeSeries(write)TimeSeriesBatch/ pythonTimeSeriesBatcher(write)kindsis sized over non-TIMESTAMP columns (ObjectColumnsRowSource.kindsOf) and python passesenumerate(column_values), so both already use the non-ts ordinalTagFilter/resolveColumnIndicesresolveColumnIndicesGetGrafanaMetadataHandler,FetchFromSchemaTypesStep,RemoteTimeSeriesType,DatabaseCheckerMultiColumnAggregationRequest.columnIndex)Residual risk
FIELDS (v DOUBLE) TAGS (host STRING) TIMESTAMP tsand five samples,SELECT ts.timeBucket('1h', ts) AS b, sum(v) FROM A GROUP BY banswers8.50000001E12beforecompactAll()and15.0after it - the mutable half readscolumnIndexas a row index, the sealed half as a schema index, and all four producers supply the schema index. Fixing it means choosing one convention and movingSelectExecutionPlanner, both HTTP handlers, the gRPC service andTimeSeriesSealedStoreonto it, which is a bigger change than this one and would bury it.Adversarial pass
No isolated subagent was available in this environment (
Taskis not exposed), so the pass was run by me directly against the diff, with each finding checked by a command rather than by recollection.26.9.1tag (command above), so no released build can have exported a type whose TIMESTAMP column is not first, and for every other type the two readings produce identical bytes.columns.getFirst()on the new fast path throws for a type with no columns." Guarded by!columns.isEmpty(). A type with no TIMESTAMP column at all also still returns the same list it used to, in the same order.nonTsColumnNames()in the same file has the same bug." Checked, it does not: it skips the TIMESTAMP column and trims withArrays.copyOf.SaveElementStepresolves by name,TimeSeriesBatch.kindsis sized over non-TIMESTAMP columns, python passes positional value columns.Test plan
mvn -o -pl engine test -Dtest=Issue7899NonFirstTimestampRowMappingTest- 4 tests. 3 of 4 fail before the fix ("srv-1"vs1700000000000L;7Lvs1700000000000L;["host","ts","v"]vs["ts","host","v"]); the 4th pins the engine contract and passes both before and aftermvn -o -pl integration test -Dtest=Issue7899JsonlNonFirstTimestampRoundTripTest- 3 tests. Before the fix: oneClassCastException: String cannot be cast to Numberout ofloadTimeSeriesSamples:603and one silentexpected 1700000000000L but was 7Lmvn -o -pl server test -Dtest=Issue7899NonFirstTimestampReadSurfacesTest- 4 tests, all 4 fail before the fix, one per read surfacecom.arcadedb.engine.timeseries.**) + 89 (schema/SQL time-series, includingIssue7702InterleavedTagAndFieldOrderTest) - greenIssue7390...,Issue7663...,Issue7725...,Issue7699...- 25 tests greenIssue7663GrafanaPrometheusRowCeilingIT(11),Issue7371PromQLDiscoveryProjectionIT(8),Issue7660...(4),Issue7683...(3) + 25 unit tests - greenmvn -o -DskipTests installover the whole reactor - greenTwo IT classes are red, and are red on
maintoo.PrometheusRemoteWriteReadITandTimeSeriesPerTypeAclITbuild their URLs as"http://127.0.0.1:248" + serverIndex, and port 2480 was held by two foreign JVMs during this run (lsof -nP -iTCP:2480 -sTCP:LISTENshowed PIDs 41389 and 52771), so the requests reached another server and came back404/403. Re-run from a detached worktree atorigin/mainin the same environment: also red, with a different subset of methods failing - the signature of a port collision rather than of a code change. Neither class uses the free-port base accessor; that is the pre-existing gap #7983 was about. The new server test usesgetServerHttpPort().Coverage
Fixed here: the JSONL export/import round trip (both the loud and the silent shape),
SELECT *,TimeSeriesGateway.selectedColumnsfor the full row, and through itGET /ts/{db}/latest,POST /ts/{db}/query, the Grafana raw frame and both gRPC time-series RPCs, plus the Prometheus remote read's labels, series key and sample value.Known gaps: the aggregation push-down's row-vs-schema index confusion - #8140, reproduced, filed before this PR opened. No other gap.
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests