Skip to content

fix: parse timestamp-without-time-zone partition bounds#56

Open
vyruss wants to merge 1 commit into
mainfrom
fix/parse-ntz-partition-bounds
Open

fix: parse timestamp-without-time-zone partition bounds#56
vyruss wants to merge 1 commit into
mainfrom
fix/parse-ntz-partition-bounds

Conversation

@vyruss

@vyruss vyruss commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

The archiver failed on timestamp without time zone partition columns: pg_get_expr renders their bounds with no timezone offset, which parseTimestamp rejected. The archiver and partitioner now pin the session to DateStyle='ISO, YMD' and TimeZone='UTC' so bounds render deterministically, and parseTimestamp parses them via stdlib layouts.

Closes #49.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Partition bounds

Layer / File(s) Summary
Bound parsing and session settings
internal/partition/partition.go, internal/partition/partition_test.go
Timestamp parsing now accepts timezone-less and offset formats, while Connect configures PostgreSQL with DateStyle and TimeZone; tests cover parsing and runtime parameters.
Startup connection integration
cmd/archiver/main.go, cmd/partitioner/main.go
Both applications now establish PostgreSQL connections through partition.Connect before continuing their existing ping and processing flows.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main fix: parsing timestamp-without-time-zone partition bounds.
Description check ✅ Passed The description matches the changes and explains the parsing and session pinning fix.
Linked Issues check ✅ Passed The changes address #49 by supporting no-offset timestamp bounds and pinning session rendering.
Out of Scope Changes check ✅ Passed The connection helper and call-site updates are directly tied to the bound-rendering fix and not out of scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/parse-ntz-partition-bounds

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
internal/partition/partition_test.go (1)

154-163: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the exact session commands.

Substring checks would allow incorrect values such as ISO, MDY to pass. Assert the complete SQL strings instead.

Proposed assertion fix
-	assert.Contains(t, db.execSQL[0], "DateStyle")
-	assert.Contains(t, db.execSQL[0], "ISO")
-	assert.Contains(t, db.execSQL[1], "TimeZone")
-	assert.Contains(t, db.execSQL[1], "UTC")
+	assert.Equal(t, "SET DateStyle = 'ISO, YMD'", db.execSQL[0])
+	assert.Equal(t, "SET TimeZone = 'UTC'", db.execSQL[1])
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/partition/partition_test.go` around lines 154 - 163, Update
TestPinSessionForBounds to assert the complete SQL strings in db.execSQL[0] and
db.execSQL[1], replacing the individual assert.Contains checks. Preserve the
existing command ordering while validating the exact DateStyle and TimeZone
session commands and values.
cmd/partitioner/main.go (1)

69-71: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the duplicate local session-pinning helper.

This path now calls partition.PinSessionForBounds, but cmd/partitioner/main.go:108-116 still contains another implementation. Delete the duplicate so future SQL or error-handling changes cannot diverge.

As per coding guidelines: “Follow DRY, extracting shared logic only when there are at least two real callers.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/partitioner/main.go` around lines 69 - 71, Remove the duplicate local
session-pinning helper in main.go around the referenced helper definition,
retaining partition.PinSessionForBounds as the sole implementation used by the
partitioner path. Delete only the redundant function and any now-unused imports
or references required for a clean build.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/partitioner/main.go`:
- Around line 69-71: Remove the duplicate local session-pinning helper in
main.go around the referenced helper definition, retaining
partition.PinSessionForBounds as the sole implementation used by the partitioner
path. Delete only the redundant function and any now-unused imports or
references required for a clean build.

In `@internal/partition/partition_test.go`:
- Around line 154-163: Update TestPinSessionForBounds to assert the complete SQL
strings in db.execSQL[0] and db.execSQL[1], replacing the individual
assert.Contains checks. Preserve the existing command ordering while validating
the exact DateStyle and TimeZone session commands and values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 27d51c59-a904-48db-b005-11100816b2b8

📥 Commits

Reviewing files that changed from the base of the PR and between 99c79b6 and 582e8b9.

📒 Files selected for processing (4)
  • cmd/archiver/main.go
  • cmd/partitioner/main.go
  • internal/partition/partition.go
  • internal/partition/partition_test.go

@vyruss
vyruss force-pushed the fix/parse-ntz-partition-bounds branch from 582e8b9 to a71bea5 Compare July 22, 2026 15:37
@vyruss

vyruss commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai recheck

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== PR diff ==='
git diff --find-renames origin/main...HEAD -- \
  cmd/archiver/main.go \
  cmd/partitioner/main.go \
  internal/partition/partition.go \
  internal/partition/partition_test.go

echo '=== Partition package outline ==='
ast-grep outline internal/partition/partition.go --items all --view expanded

echo '=== Startup call contexts ==='
rg -n -C 10 'PinSessionForBounds|func setupConnection|func main' \
  cmd/archiver/main.go cmd/partitioner/main.go

echo '=== Relevant parser and DB interfaces ==='
rg -n -C 12 'func parseTimestamp|func parseBoundExpr|func PinSessionForBounds|type DBTX|pg_get_expr|relpartbound' \
  internal/partition

Length of output: 31642


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== pgx connection call sites ==='
rg -n -C 5 '\bpgx\.(Connect|ConnectConfig|ParseConfig)\s*\(' --type go .

echo '=== Command import blocks and connection lifecycle ==='
sed -n '1,135p' cmd/archiver/main.go
printf '\n--- partitioner ---\n'
sed -n '1,105p' cmd/partitioner/main.go

echo '=== TimeBoundary parser delegation ==='
ast-grep outline internal/partition/boundary.go --items all --view expanded
rg -n -C 8 'func \(TimeBoundary\) (Literal|Parse)|parseTimestamp' internal/partition/boundary.go

echo '=== Declared pgx dependency ==='
rg -n -C 2 'jackc/pgx' go.mod go.sum

Length of output: 15930


@vyruss Rechecked the updated implementation. I found no new issues in the bound parsing or connection setup.

The archiver and partitioner now consistently use the pinned connection configuration, and the parser covers the reported timezone-less timestamp format (including fractional seconds). Static verification only; tests were not executed in this sandbox.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/partition/partition_test.go`:
- Around line 154-159: Add a unit test alongside TestBoundConnConfig that
directly exercises the exported Connect function with a malformed DSN and
asserts the returned error. Keep the test focused on the error path; leave
successful connection coverage to integration tests if required.

In `@internal/partition/partition.go`:
- Around line 83-89: Update the parseTimestamp comment’s session-pinning
reference to describe the current Connect/boundConnConfig connection path
instead of naming PinSessionForBounds. Keep the existing explanation of
supported PostgreSQL timestamp renderings unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bed3a896-2358-4dd6-a064-2d96a785bf72

📥 Commits

Reviewing files that changed from the base of the PR and between 582e8b9 and a71bea5.

📒 Files selected for processing (4)
  • cmd/archiver/main.go
  • cmd/partitioner/main.go
  • internal/partition/partition.go
  • internal/partition/partition_test.go

Comment on lines +154 to +159
func TestBoundConnConfig(t *testing.T) {
cfg, err := boundConnConfig("postgres://u@localhost:5432/db")
require.NoError(t, err)
assert.Equal(t, "ISO, YMD", cfg.RuntimeParams["datestyle"])
assert.Equal(t, "UTC", cfg.RuntimeParams["timezone"])
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add a unit test for exported Connect.

TestBoundConnConfig covers only the private helper. The exported Connect function in internal/partition/partition.go, Lines 121-126, has no direct unit test in the supplied changes. Add at least an error-path unit test for malformed DSNs, with any successful connection behavior covered by an integration test if needed.

As per coding guidelines, every public Go function should have a unit test.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/partition/partition_test.go` around lines 154 - 159, Add a unit test
alongside TestBoundConnConfig that directly exercises the exported Connect
function with a malformed DSN and asserts the returned error. Keep the test
focused on the error path; leave successful connection coverage to integration
tests if required.

Source: Coding guidelines

Comment on lines +83 to +89
// parseTimestamp parses a pg_get_expr bound value (the quoted string inside
// FOR VALUES FROM/TO) into a UTC time. PostgreSQL renders bounds ISO-style but
// not as strict ISO 8601 (space separator, bare +00 offset), so time.RFC3339
// does not apply. The layouts are the stdlib time.DateTime (timestamp without
// time zone) and time.DateOnly (date), plus a numeric-offset layout for
// timestamptz; time.Parse consumes any trailing fractional second on its own.
// Callers pin the session (PinSessionForBounds) so the render stays in this set.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update the stale session-pinning reference.

Line 89 names PinSessionForBounds, while the current implementation and call sites use Connect/boundConnConfig. Update the comment so it describes the actual current connection path.

Proposed fix
-// Callers pin the session (PinSessionForBounds) so the render stays in this set.
+// Connections created by Connect pin the session so the render stays in this set.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// parseTimestamp parses a pg_get_expr bound value (the quoted string inside
// FOR VALUES FROM/TO) into a UTC time. PostgreSQL renders bounds ISO-style but
// not as strict ISO 8601 (space separator, bare +00 offset), so time.RFC3339
// does not apply. The layouts are the stdlib time.DateTime (timestamp without
// time zone) and time.DateOnly (date), plus a numeric-offset layout for
// timestamptz; time.Parse consumes any trailing fractional second on its own.
// Callers pin the session (PinSessionForBounds) so the render stays in this set.
// parseTimestamp parses a pg_get_expr bound value (the quoted string inside
// FOR VALUES FROM/TO) into a UTC time. PostgreSQL renders bounds ISO-style but
// not as strict ISO 8601 (space separator, bare +00 offset), so time.RFC3339
// does not apply. The layouts are the stdlib time.DateTime (timestamp without
// time zone) and time.DateOnly (date), plus a numeric-offset layout for
// timestamptz; time.Parse consumes any trailing fractional second on its own.
// Connections created by Connect pin the session so the render stays in this set.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/partition/partition.go` around lines 83 - 89, Update the
parseTimestamp comment’s session-pinning reference to describe the current
Connect/boundConnConfig connection path instead of naming PinSessionForBounds.
Keep the existing explanation of supported PostgreSQL timestamp renderings
unchanged.

Source: Coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Archiver fails on timestamp without time zone partition column — unrecognized timestamp format

1 participant