-
Notifications
You must be signed in to change notification settings - Fork 1
store table data cleaning and standardization #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,13 @@ | ||
| SELECT TOP (1000) [store_id] | ||
| --############################################################################################# | ||
| --#################################### STORES DATA ############################################ | ||
| --############################################################################################# | ||
|
|
||
| --============================================================================================= | ||
| --================================== stores table overview ==================================== | ||
| --============================================================================================= | ||
|
|
||
| SELECT TOP (1000) | ||
| [store_id] | ||
| ,[store_name] | ||
| ,[store_type] | ||
| ,[address] | ||
|
|
@@ -18,4 +27,234 @@ SELECT TOP (1000) [store_id] | |
| ,[is_active] | ||
| ,[has_parking] | ||
| ,[has_cafe] | ||
| FROM .[bronze].[stores] | ||
| FROM .[bronze].[stores] | ||
|
|
||
| --============================================================================================= | ||
| --================================== store_id column cleaning ================================= | ||
| --============================================================================================= | ||
| -- store_id data overview | ||
| SELECT | ||
| store_id | ||
| FROM bronze.stores ; | ||
|
|
||
| -- store_id data type check | ||
| SELECT | ||
| store_id | ||
| FROM bronze.stores | ||
| WHERE TRY_CONVERT(INT, store_id) IS NULL ; | ||
|
|
||
| -- store_id data profiling | ||
| SELECT | ||
| store_id | ||
| FROM bronze.stores | ||
| WHERE store_id IS NULL | ||
| OR store_id < 1 ; | ||
|
|
||
| -- store_id duplicate chck | ||
| SELECT | ||
| * | ||
| FROM | ||
| ( | ||
| SELECT | ||
| store_id, | ||
| ROW_NUMBER() OVER(PARTITION BY store_id ORDER BY store_id DESC) as flag | ||
| FROM bronze.stores | ||
| )t WHERE flag != 1 ; | ||
|
|
||
| --============================================================================================= | ||
| --================================== store_name column cleaning =============================== | ||
| --============================================================================================= | ||
| -- store_name data overview | ||
| SELECT | ||
| store_name | ||
| FROM bronze.stores ; | ||
|
|
||
| -- store_name data profiling | ||
| SELECT | ||
| store_name | ||
| FROM bronze.stores | ||
| WHERE store_name IS NULL | ||
| OR store_name != store_name | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace self-comparison predicates in profiling filters.
Proposed fix-WHERE store_name IS NULL
- OR store_name != store_name
+WHERE store_name IS NULL
+ OR store_name != TRIM(store_name)
OR store_name != dbo.TitleCase(store_name)
OR TRIM(store_name) = ''
OR LEN(TRIM(store_name)) < 3 ;
-WHERE store_type IS NULL
- OR store_type != store_type
+WHERE store_type IS NULL
+ OR store_type != TRIM(store_type)
OR store_type != dbo.TitleCase(store_type)
OR TRIM(store_type) = ''
OR LEN(TRIM(store_type)) < 3 ;Also applies to: 121-121 🤖 Prompt for AI Agents |
||
| OR store_name != dbo.TitleCase(store_name) | ||
| OR TRIM(store_name) = '' | ||
| OR LEN(TRIM(store_name)) < 3 ; | ||
|
|
||
| -- duplicate check in store_name | ||
| SELECT | ||
| * | ||
| FROM | ||
| ( | ||
| SELECT | ||
| store_name, | ||
| ROW_NUMBER() OVER(PARTITION BY store_name ORDER BY store_name DESC) as flag | ||
| FROM bronze.stores | ||
| )t WHERE flag != 1 ; | ||
|
|
||
| -- store_name cleaning and standardization | ||
| WITH clean_store_name AS | ||
| ( | ||
| SELECT | ||
| CASE | ||
| WHEN store_name IS NULL OR LEN(TRIM(store_name)) < 3 THEN 'Unknown' | ||
| ELSE TRIM(dbo.TitleCase(store_name)) | ||
| END as store_name | ||
| FROM bronze.stores | ||
| ) | ||
| SELECT | ||
| * | ||
| FROM clean_store_name | ||
| WHERE store_name = 'Unknown'; | ||
|
|
||
| --============================================================================================= | ||
| --================================== store_type column cleaning =============================== | ||
| --============================================================================================= | ||
| -- store_type data overview | ||
| SELECT | ||
| store_type | ||
| FROM bronze.stores ; | ||
|
|
||
| -- store_type data profiling | ||
| SELECT | ||
| store_type | ||
| FROM bronze.stores | ||
| WHERE store_type IS NULL | ||
| OR store_type != store_type | ||
| OR store_type != dbo.TitleCase(store_type) | ||
| OR TRIM(store_type) = '' | ||
| OR LEN(TRIM(store_type)) < 3 ; | ||
|
|
||
| -- store type count | ||
| SELECT | ||
| store_type , | ||
| COUNT(*) type_count, | ||
| CAST(ROUND(COUNT(*)*100/SUM(COUNT(*)) OVER(), 2)as nvarchar) + '%' as percentages | ||
| FROM bronze.stores | ||
| GROUP BY store_type | ||
| ORDER BY type_count DESC ; | ||
|
|
||
| -- store_type cleaning and standardization | ||
| WITH clean_store_type AS | ||
| ( | ||
| SELECT | ||
| CASE | ||
| WHEN store_type IS NULL OR LEN(TRIM(store_type)) < 3 THEN 'Unknown' | ||
| ELSE TRIM(dbo.TitleCase(store_type)) | ||
| END as store_type | ||
| FROM bronze.stores | ||
| ) | ||
| SELECT | ||
| * | ||
| FROM clean_store_type | ||
| WHERE store_type = 'Unknown'; | ||
|
|
||
| --============================================================================================= | ||
| --================================== address column cleaning ================================== | ||
| --============================================================================================= | ||
| -- address data overview | ||
| SELECT | ||
| address | ||
| FROM bronze.stores ; | ||
|
|
||
| -- address column data profiling | ||
| SELECT | ||
| address | ||
| FROM bronze.stores | ||
| WHERE address IS NULL | ||
| OR address != TRIM(address) | ||
| OR address != TRIM(dbo.TitleCase(address)) | ||
| OR TRIM(address) = '' | ||
| OR LEN(address) < 5 ; | ||
|
|
||
|
|
||
| SELECT | ||
| address | ||
| from bronze.stores | ||
| where len(address) = 12 | ||
|
|
||
|
|
||
| -- address cleaning and standardization | ||
| WITH clean_address AS | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Add a statement terminator before this CTE. The preceding debug query ( Useful? React with 👍 / 👎. |
||
| ( | ||
| SELECT | ||
| CASE | ||
| WHEN address IS NULL OR TRIM(address) = '' OR LEN(address) < 5 THEN 'Unknown' | ||
| ELSE TRIM(dbo.TitleCase(address)) | ||
| END address | ||
| FROM bronze.stores | ||
| ) | ||
| SELECT | ||
| * | ||
| FROM clean_address | ||
| WHERE address = 'Unknown' ; | ||
|
|
||
| --============================================================================================= | ||
| --===================================== city column cleaning ================================== | ||
| --============================================================================================= | ||
| -- city data overview | ||
| SELECT | ||
| city | ||
| FROM bronze.stores ; | ||
|
|
||
| --############################################################################################# | ||
| --############################## STORES CLEAN DATA ############################################ | ||
| --############################################################################################# | ||
|
|
||
| SELECT | ||
| store_id | ||
| ,store_name | ||
| ,store_type | ||
| ,address | ||
| ,city | ||
| ,state | ||
| ,state_full | ||
| ,zip_code | ||
| ,country | ||
| ,region | ||
| ,district | ||
| ,phone | ||
| ,manager_name | ||
| ,opened_date | ||
| ,sq_footage | ||
| ,num_employees | ||
| ,annual_rent_usd | ||
| ,is_active | ||
| ,has_parking | ||
| ,has_cafe | ||
| FROM | ||
| ( | ||
| SELECT | ||
| store_id | ||
|
|
||
| ,CASE | ||
| WHEN store_name IS NULL OR LEN(TRIM(store_name)) < 3 THEN 'Unknown' | ||
| ELSE TRIM(dbo.TitleCase(store_name)) | ||
| END as store_name | ||
|
|
||
| ,CASE | ||
| WHEN store_type IS NULL OR LEN(TRIM(store_type)) < 3 THEN 'Unknown' | ||
| ELSE TRIM(dbo.TitleCase(store_type)) | ||
| END as store_type | ||
|
|
||
| ,CASE | ||
| WHEN address IS NULL OR TRIM(address) = '' OR LEN(address) < 5 THEN 'Unknown' | ||
| ELSE TRIM(dbo.TitleCase(address)) | ||
| END address | ||
|
|
||
| ,[city] | ||
| ,[state] | ||
| ,[state_full] | ||
| ,[zip_code] | ||
| ,[country] | ||
| ,[region] | ||
| ,[district] | ||
| ,[phone] | ||
| ,[manager_name] | ||
| ,[opened_date] | ||
| ,[sq_footage] | ||
| ,[num_employees] | ||
| ,[annual_rent_usd] | ||
| ,[is_active] | ||
| ,[has_parking] | ||
| ,[has_cafe] | ||
| FROM .[bronze].[stores] | ||
| )t ; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: Ritik574-coder/dbt_learning_project
Length of output: 292
Fix invalid T-SQL table reference syntax (
FROM .[bronze].[stores]).The leading dot before
[bronze]inFROM .[bronze].[stores]is not valid multipart identifier syntax for SQL Server and can fail execution.Also present in:
explore_database/stores/stores.sql:259(FROM .[bronze].[stores])explore_database/transactions/transactions.sql:62(FROM .[bronze].[sales_transactions])Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents