Skip to content

data transformation : bronze -> silver data cleaning and standardization in store table #72

Merged
Ritik574-coder merged 1 commit into
mainfrom
dbt_branch
May 23, 2026
Merged

data transformation : bronze -> silver data cleaning and standardization in store table #72
Ritik574-coder merged 1 commit into
mainfrom
dbt_branch

Conversation

@Ritik574-coder

@Ritik574-coder Ritik574-coder commented May 23, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Refactor

    • Enhanced data cleaning and standardization across multiple database fields including city, country, region, district, and manager information
    • Improved data validation logic for handling missing and invalid values with consistent normalization to standardized formats
    • Added comprehensive profiling and transformation logic for date, boolean, and text fields to ensure data quality and consistency
  • Chores

    • Minor query formatting adjustments

Review Change Stack

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR refines two SQL data-cleaning scripts: minor formatting adjustments to review channel and title selection in the reviews script, and comprehensive data profiling and standardization additions to the stores script, including new normalization for geographic, text, date, numeric, and boolean fields with consistent Unknown mapping.

Changes

Reviews Script Formatting

Layer / File(s) Summary
Review channel and title formatting refinement
explore_database/reviews/reviews.sql
Line structure and indentation updated in the review_channel CTE aggregation and review_title selection without changing CASE logic or output values.

Stores Script Data Cleaning Expansion

Layer / File(s) Summary
Address probe removal and city/country profiling
explore_database/stores/stores.sql
Removed a single address length filter and added new profiling and normalization sections for city and country, including dbo.TitleCase and mapping US synonyms to United States.
Region and district profiling and normalization
explore_database/stores/stores.sql
Extended profiling and distribution analysis for region and district fields with Unknown handling and dbo.TitleCase normalization.
Manager name and opened date cleaning
explore_database/stores/stores.sql
Added profiling and cleanup for manager_name with Unknown mapping and dbo.TitleCase, plus comprehensive opened_date validation using TRANSLATE structural analysis and multi-pattern TRY_CONVERT(DATE, ...) conversion.
Numeric field and boolean standardization
explore_database/stores/stores.sql
Added cleanup for numeric fields (sq_footage, num_employees, annual_rent_usd) with null/negative handling, and standardized boolean-like columns (is_active, has_parking, has_cafe) to 'True'/'False'/'Unknown'.
Final cleaned data projection
explore_database/stores/stores.sql
Applied CASE-based cleaned expressions to the final output for all newly standardized columns (geographic, text, date, numeric, boolean) with consistent Unknown mapping and formatting adjustment to the SELECT header.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • Ritik574-coder/dbt_learning_project#71: Both PRs heavily modify the explore_database/stores/stores.sql ETL by expanding/adjusting the "STORES DATA" and "STORES CLEAN DATA" profiling/normalization logic (e.g., new CASE/dbo.TitleCase/Unknown standardization), so the changes overlap at the core cleaning code level.
  • Ritik574-coder/dbt_learning_project#69: Both PRs modify explore_database/reviews/reviews.sql specifically around the review_channel cleaning/aggregation logic (same CTE/query area), even though the main PR's changes are mostly reformatting.
  • Ritik574-coder/dbt_learning_project#65: Both PRs extend/adjust SQL data-cleaning standardization logic for location/text fields (e.g., city/country via dbo.TitleCase/TRIM and mapping to Unknown) and boolean-like fields (e.g., True/False) across their respective tables, so the changes are code-level related.

Poem

🐰 Through stores and reviews, a tidying spree,
With TitleCase whispers and Unknown we see—
Each channel aligned, each date in its place,
SQL cleaned up with careful grace!
nose twitch

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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: data transformation and cleaning/standardization in the store table, with bronze-to-silver layer progression being the primary focus.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dbt_branch

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

@github-actions

Copy link
Copy Markdown

Failed to generate code suggestions for PR

@Ritik574-coder Ritik574-coder left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

data transformation and cleaning and standardization in store table

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 92a5d03403

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +836 to +840
WHEN opened_date LIKE '__/__/____' AND TRY_CONVERT(INT, SUBSTRING(opened_date, 4, 2)) > 12 THEN TRY_CONVERT(DATE, opened_date, 101)
WHEN opened_date LIKE '__/__/____' AND TRY_CONVERT(INT, LEFT(opened_date, 2)) > 12 THEN TRY_CONVERT(DATE, opened_date, 103)
WHEN opened_date LIKE '__-__-____' AND TRY_CONVERT(INT, SUBSTRING(opened_date, 4, 2)) > 12 THEN TRY_CONVERT(DATE, opened_date, 110)
WHEN opened_date LIKE '__-__-____' AND TRY_CONVERT(INT, LEFT(opened_date, 2)) > 12 THEN TRY_CONVERT(DATE, opened_date, 105)
ELSE TRY_CONVERT(DATE, opened_date)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Parse ambiguous dd/mm and mm/dd dates explicitly

The opened_date normalizer falls back to TRY_CONVERT(DATE, opened_date) when both day and month are <= 12, so values like 11/07/2015 and 03-12-2019 are interpreted according to the SQL Server session LANGUAGE/DATEFORMAT instead of a fixed rule. This makes the cleaned date output environment-dependent and can silently swap month/day across runs, which corrupts downstream analytics that treat opened_date as standardized.

Useful? React with 👍 / 👎.

@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: 3

🧹 Nitpick comments (2)
explore_database/stores/stores.sql (2)

650-652: ⚡ Quick win

Inconsistent CR/LF handling across boolean columns.

has_cafe cleaning (lines 739-740) strips CHAR(13) and CHAR(10) before comparison, but is_active and has_parking do not. If any boolean column data contains embedded newlines, the latter two would incorrectly map to 'Unknown'. Consider applying consistent normalization.

Proposed fix: Apply consistent CR/LF handling
 -- is_active column cleaning and standardization
 WITH clean_is_active AS 
 (
     SELECT 
         CASE 
-            WHEN TRIM(LOWER(is_active)) IN ('true', 'yes', 'y', '1', 'active')     THEN 'True'
-            WHEN TRIM(LOWER(is_active)) IN ('false', 'no', 'n', '0', 'not active') THEN 'False'
+            WHEN REPLACE(REPLACE(TRIM(LOWER(is_active)), CHAR(13), ''),CHAR(10), '') IN ('true', 'yes', 'y', '1', 'active')     THEN 'True'
+            WHEN REPLACE(REPLACE(TRIM(LOWER(is_active)), CHAR(13), ''),CHAR(10), '') IN ('false', 'no', 'n', '0', 'not active') THEN 'False'
         ELSE 'Unknown'
     END as is_active
     FROM bronze.stores 
 )

Apply the same pattern to has_parking.

Also applies to: 694-697

🤖 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 `@explore_database/stores/stores.sql` around lines 650 - 652, The boolean
normalization for columns is inconsistent: has_cafe uses TRIM(REPLACE(...,
CHAR(13), ''))/CHAR(10) before LOWER but is_active and has_parking do not, so
embedded CR/LF can cause wrong 'Unknown' mapping; update the CASE/WHEN blocks
that normalize is_active and has_parking (and the other boolean normalization
occurrences around the referenced area) to apply the same CR/LF stripping and
trimming pattern used by has_cafe before LOWER and comparison so all boolean
columns use consistent normalization.

479-483: 💤 Low value

Ambiguous date format falls through to server default.

When both date components are ≤ 12 (e.g., 05/06/2020), neither disambiguation condition matches and TRY_CONVERT(DATE, opened_date) uses server locale settings. Consider adding a comment documenting the assumed default format or explicitly choosing a style for the ambiguous case.

🤖 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 `@explore_database/stores/stores.sql` around lines 479 - 483, The CASE that
normalizes opened_date can fall back to server-default parsing for ambiguous
values (e.g., "05/06/2020") because the ELSE uses TRY_CONVERT(DATE, opened_date)
without a style; update the ELSE branch to explicitly convert using a chosen
style (e.g., CONVERT/TRY_CONVERT with style 101/103/110/105) or implement a
deterministic disambiguation rule, and add a short comment above the CASE noting
which format is being assumed for ambiguous MM/DD vs DD/MM inputs so future
readers know the chosen behavior; reference the opened_date field and the
TRY_CONVERT calls in this CASE when making the change.
🤖 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 `@explore_database/stores/stores.sql`:
- Line 426: The profiling check uses LEN(TRIM(manager_name)) < 3 while the
cleaning rule uses LEN(TRIM(manager_name)) < 2, causing 2-character names to be
profiled as bad but not cleaned; update one of these to match the other so both
profiling and cleaning use the same minimum length threshold for manager_name
(e.g., change the profiling condition or the cleaning condition so both use
LEN(TRIM(manager_name)) < 3 or both use < 2), and ensure any related conditions
referencing manager_name in this file are adjusted to the same threshold for
consistency.
- Line 875: The SQL has an invalid table reference ".[bronze].[stores]" (also
duplicated at the earlier occurrence) — remove the leading dot and use a valid
qualifier such as "[bronze].[stores]" or supply the full three-part name
"[DatabaseName].[bronze].[stores]" (or "[DatabaseName].[Schema].[stores]" /
"dbo.[stores]" as appropriate); update both occurrences to a properly-qualified
table reference so the FROM clause is syntactically correct.
- Around line 395-401: Remove the duplicated "district column cleaning" block:
delete the repeated comment header lines starting with
"--===================================== district column cleaning
==============================" and the redundant query "SELECT district FROM
bronze.stores;" (the duplicate section shown in the diff). Keep only the
original district cleaning section (the earlier block between the first matching
headers) to avoid repeated headers/queries.

---

Nitpick comments:
In `@explore_database/stores/stores.sql`:
- Around line 650-652: The boolean normalization for columns is inconsistent:
has_cafe uses TRIM(REPLACE(..., CHAR(13), ''))/CHAR(10) before LOWER but
is_active and has_parking do not, so embedded CR/LF can cause wrong 'Unknown'
mapping; update the CASE/WHEN blocks that normalize is_active and has_parking
(and the other boolean normalization occurrences around the referenced area) to
apply the same CR/LF stripping and trimming pattern used by has_cafe before
LOWER and comparison so all boolean columns use consistent normalization.
- Around line 479-483: The CASE that normalizes opened_date can fall back to
server-default parsing for ambiguous values (e.g., "05/06/2020") because the
ELSE uses TRY_CONVERT(DATE, opened_date) without a style; update the ELSE branch
to explicitly convert using a chosen style (e.g., CONVERT/TRY_CONVERT with style
101/103/110/105) or implement a deterministic disambiguation rule, and add a
short comment above the CASE noting which format is being assumed for ambiguous
MM/DD vs DD/MM inputs so future readers know the chosen behavior; reference the
opened_date field and the TRY_CONVERT calls in this CASE when making the change.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 05f007ea-01b7-4e71-a899-d431ccb81207

📥 Commits

Reviewing files that changed from the base of the PR and between a5b8dd1 and 92a5d03.

📒 Files selected for processing (2)
  • explore_database/reviews/reviews.sql
  • explore_database/stores/stores.sql

Comment on lines +395 to +401
--=============================================================================================
--===================================== district column cleaning ==============================
--=============================================================================================
-- district column data overview
SELECT
district
FROM bronze.stores;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Duplicate section header and query for district.

Lines 351-393 already contain the complete district column cleaning section. This appears to be a copy-paste artifact that should be removed.

Proposed fix: Remove duplicate section
---=============================================================================================
---===================================== district column cleaning ==============================
---=============================================================================================
--- district column data overview 
-SELECT 
-    district
-FROM bronze.stores;
-
📝 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
--=============================================================================================
--===================================== district column cleaning ==============================
--=============================================================================================
-- district column data overview
SELECT
district
FROM bronze.stores;
🤖 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 `@explore_database/stores/stores.sql` around lines 395 - 401, Remove the
duplicated "district column cleaning" block: delete the repeated comment header
lines starting with "--===================================== district column
cleaning ==============================" and the redundant query "SELECT
district FROM bronze.stores;" (the duplicate section shown in the diff). Keep
only the original district cleaning section (the earlier block between the first
matching headers) to avoid repeated headers/queries.

WHERE manager_name IS NULL
OR manager_name != TRIM(manager_name)
OR TRIM(manager_name) = ''
OR LEN(TRIM(manager_name)) < 3 ;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Inconsistent minimum length threshold for manager_name.

The profiling query (line 426) uses LEN(TRIM(manager_name)) < 3 while the cleaning logic (line 433) uses LEN(TRIM(manager_name)) < 2. This inconsistency means 2-character names would be flagged during profiling but not cleaned to 'Unknown'.

Proposed fix: Align thresholds
 -- manager_name column data profiling
 SELECT 
       manager_name
 FROM  bronze.stores 
 WHERE manager_name IS NULL 
    OR manager_name != TRIM(manager_name)
    OR TRIM(manager_name) = ''
-   OR LEN(TRIM(manager_name)) < 3 ;
+   OR LEN(TRIM(manager_name)) < 2 ;

Also applies to: 433-433

🤖 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 `@explore_database/stores/stores.sql` at line 426, The profiling check uses
LEN(TRIM(manager_name)) < 3 while the cleaning rule uses LEN(TRIM(manager_name))
< 2, causing 2-character names to be profiled as bad but not cleaned; update one
of these to match the other so both profiling and cleaning use the same minimum
length threshold for manager_name (e.g., change the profiling condition or the
cleaning condition so both use LEN(TRIM(manager_name)) < 3 or both use < 2), and
ensure any related conditions referencing manager_name in this file are adjusted
to the same threshold for consistency.

WHEN REPLACE(REPLACE(TRIM(LOWER(has_cafe)), CHAR(13), ''),CHAR(10), '') IN ('0', 'no', 'n','false') THEN 'False'
ELSE 'Unknown'
END as has_cafe
FROM .[bronze].[stores]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Syntax error: Invalid leading dot in table reference.

.[bronze].[stores] is invalid SQL Server syntax. The leading dot suggests a database qualifier that is missing. The same issue exists in line 30.

Proposed fix
-    FROM .[bronze].[stores]
+    FROM [bronze].[stores]
📝 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
FROM .[bronze].[stores]
FROM [bronze].[stores]
🤖 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 `@explore_database/stores/stores.sql` at line 875, The SQL has an invalid table
reference ".[bronze].[stores]" (also duplicated at the earlier occurrence) —
remove the leading dot and use a valid qualifier such as "[bronze].[stores]" or
supply the full three-part name "[DatabaseName].[bronze].[stores]" (or
"[DatabaseName].[Schema].[stores]" / "dbo.[stores]" as appropriate); update both
occurrences to a properly-qualified table reference so the FROM clause is
syntactically correct.

@Ritik574-coder Ritik574-coder merged commit 044418b into main May 23, 2026
2 checks passed
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.

1 participant