chore(knowledge): enhance SQL date and time formatting rules#1431
chore(knowledge): enhance SQL date and time formatting rules#1431douenergy wants to merge 1 commit intoCanner:mainfrom
Conversation
📝 WalkthroughWalkthroughAdds documentation guidelines for date/time formatting when grouping by year, month, or quarter. Instructions include using DATE_TRUNC for bucketing followed by human-readable label formatting. Examples cover month output (yyyy-mm format) and year output (4-digit labels) with sample SQL and results. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@ibis-server/resources/knowledge/instructions/date_and_time_functionality.txt`:
- Around line 22-78: Add a quarter formatting rule similar to the month/year
sections: require bucketing with DATE_TRUNC('quarter', ...) and formatting the
bucket into a stable label like "yyyy-Qn" (e.g., 2026-Q1); reference the
existing patterns using DATE_TRUNC, EXTRACT, CONCAT, and LPAD (and CAST where
used for year) and provide a short example SQL that shows DATE_TRUNC('quarter',
created_at) being formatted into "2026-Q1" as the output label along with
example output lines; ensure the note "Always bucket with DATE_TRUNC('quarter',
...)" is added and mirror the grouping/GROUP BY 1 and ORDER BY 1 conventions
from the month/year examples.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9305f9b6-9743-4dd9-89a3-9c17455471bb
📒 Files selected for processing (1)
ibis-server/resources/knowledge/instructions/date_and_time_functionality.txt
| ### DATE AND TIME OUTPUT FORMATTING ### | ||
| When grouping results by year, month, or quarter, the output column should be formatted as a human-readable label, not a raw DATE or TIMESTAMP. | ||
|
|
||
| Always follow two steps: | ||
|
|
||
| 1. Bucket the timestamp using DATE_TRUNC | ||
| 2. Format the bucket into a readable string | ||
|
|
||
| #### Month Output #### | ||
| Monthly results must be formatted as **yyyy-mm** | ||
|
|
||
| Example: | ||
| ```sql | ||
| SELECT | ||
| CONCAT( | ||
| EXTRACT(year FROM DATE_TRUNC('month', created_at)), | ||
| '-', | ||
| LPAD(EXTRACT(month FROM DATE_TRUNC('month', created_at)), 2, '0') | ||
| ) AS txn_month, | ||
| COUNT(*) AS order_count | ||
| FROM orders | ||
| GROUP BY 1 | ||
| ORDER BY 1 | ||
| ``` | ||
| Example output: | ||
| ``` | ||
| txn_month | ||
| 2026-01 | ||
| 2026-02 | ||
| 2026-03 | ||
| ``` | ||
|
|
||
| Notes: | ||
| Always bucket with DATE_TRUNC('month', ...) before formatting. | ||
| Do not extract year/month directly from the raw timestamp when grouping. | ||
|
|
||
|
|
||
| #### Year Output #### | ||
| Year values should appear as a 4-digit label. | ||
|
|
||
| Example: | ||
| ```sql | ||
| SELECT | ||
| CAST(EXTRACT(year FROM DATE_TRUNC('year', created_at)) AS VARCHAR) AS txn_year, | ||
| COUNT(*) AS order_count | ||
| FROM orders | ||
| GROUP BY 1 | ||
| ORDER BY 1 | ||
| ``` | ||
|
|
||
| Example output: | ||
| ```sql | ||
| txn_year | ||
| 2024 | ||
| 2025 | ||
| 2026 | ||
| ``` |
There was a problem hiding this comment.
Add the missing quarter formatting rule.
This section says the guidance covers year, month, and quarter, but only month and year are actually specified. That leaves quarter groupings under-defined, so the model can still fall back to raw timestamps or inconsistent labels for one of the PR’s target cases. Please add a concrete quarter rule and example output as well, e.g. a stable label like 2026-Q1.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@ibis-server/resources/knowledge/instructions/date_and_time_functionality.txt`
around lines 22 - 78, Add a quarter formatting rule similar to the month/year
sections: require bucketing with DATE_TRUNC('quarter', ...) and formatting the
bucket into a stable label like "yyyy-Qn" (e.g., 2026-Q1); reference the
existing patterns using DATE_TRUNC, EXTRACT, CONCAT, and LPAD (and CAST where
used for year) and provide a short example SQL that shows DATE_TRUNC('quarter',
created_at) being formatted into "2026-Q1" as the output label along with
example output lines; ensure the note "Always bucket with DATE_TRUNC('quarter',
...)" is added and mirror the grouping/GROUP BY 1 and ORDER BY 1 conventions
from the month/year examples.
Improve the SQL knowledge rules for year, month, and quarter outputs to produce human-readable time bucket labels (e.g. 2026-01, 2026) instead of raw
DATEorTIMESTAMPvalues such as 2026-01-01 00:00:00.Summary by CodeRabbit