Skip to content

chore(knowledge): enhance SQL date and time formatting rules#1431

Open
douenergy wants to merge 1 commit intoCanner:mainfrom
douenergy:time-sql-knowledge
Open

chore(knowledge): enhance SQL date and time formatting rules#1431
douenergy wants to merge 1 commit intoCanner:mainfrom
douenergy:time-sql-knowledge

Conversation

@douenergy
Copy link
Copy Markdown
Contributor

@douenergy douenergy commented Mar 6, 2026

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 DATE or TIMESTAMP values such as 2026-01-01 00:00:00.

Summary by CodeRabbit

  • Documentation
    • Added comprehensive formatting guidelines for date and time outputs when grouping data by year, month, or quarter. Includes step-by-step instructions for bucketing with DATE_TRUNC and formatting results, along with SQL examples and sample outputs for generating human-readable month and year labels.

@github-actions github-actions Bot added ibis python Pull requests that update Python code labels Mar 6, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 6, 2026

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Date/Time Documentation
ibis-server/resources/knowledge/instructions/date_and_time_functionality.txt
Adds 58 lines of guidance on formatting date/time output with DATE_TRUNC, including two-step approach, month/year formatting examples, SQL samples, and best practice notes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A whisper of wisdom, soft and clear,
How dates should dance throughout the year,
TRUNCATE and format, side by side,
Let readability be our guide! ✨📅

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: enhancing SQL date and time formatting rules in the knowledge documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6a5eb79 and a94b70f.

📒 Files selected for processing (1)
  • ibis-server/resources/knowledge/instructions/date_and_time_functionality.txt

Comment on lines +22 to +78
### 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
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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.

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

Labels

ibis python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant