tutorials on cli vibe-coding tools
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
PRAGMA disable_progress_bar;
|
||||
|
||||
CREATE TABLE products_raw AS
|
||||
SELECT *
|
||||
FROM read_json(
|
||||
getenv('BEAUTY_INPUT'),
|
||||
format = 'newline_delimited',
|
||||
columns = {
|
||||
main_category: 'VARCHAR',
|
||||
title: 'VARCHAR',
|
||||
average_rating: 'DOUBLE',
|
||||
rating_number: 'BIGINT',
|
||||
features: 'VARCHAR[]',
|
||||
description: 'VARCHAR[]',
|
||||
price: 'DOUBLE',
|
||||
images: 'STRUCT(thumb VARCHAR, large VARCHAR, variant VARCHAR, hi_res VARCHAR)[]',
|
||||
videos: 'STRUCT(title VARCHAR, url VARCHAR, user_id VARCHAR)[]',
|
||||
store: 'VARCHAR',
|
||||
categories: 'JSON[]',
|
||||
details: 'MAP(VARCHAR, VARCHAR)',
|
||||
parent_asin: 'VARCHAR',
|
||||
bought_together: 'VARCHAR'
|
||||
}
|
||||
);
|
||||
|
||||
CREATE TABLE products AS
|
||||
SELECT
|
||||
parent_asin,
|
||||
title,
|
||||
store,
|
||||
main_category,
|
||||
average_rating,
|
||||
rating_number,
|
||||
price,
|
||||
details['UPC'] AS upc,
|
||||
(list_filter(images, lambda image: image.variant = 'MAIN'))[1].large AS main_image_url,
|
||||
len(features) AS feature_count,
|
||||
array_to_string(description, ' ') AS description_text
|
||||
FROM products_raw;
|
||||
|
||||
CREATE INDEX products_parent_asin_idx ON products(parent_asin);
|
||||
CREATE INDEX products_store_idx ON products(store);
|
||||
|
||||
CREATE VIEW store_summary AS
|
||||
SELECT
|
||||
store,
|
||||
count(*) AS product_count,
|
||||
round(avg(average_rating), 3) AS mean_product_rating,
|
||||
sum(rating_number) AS rating_count,
|
||||
count(price) AS products_with_price,
|
||||
round(avg(price), 2) AS mean_price
|
||||
FROM products
|
||||
WHERE store IS NOT NULL
|
||||
GROUP BY store;
|
||||
|
||||
CREATE VIEW data_quality AS
|
||||
SELECT
|
||||
count(*) AS records,
|
||||
count(parent_asin) AS records_with_parent_asin,
|
||||
count(DISTINCT parent_asin) AS distinct_parent_asins,
|
||||
count(*) FILTER (WHERE title IS NULL) AS missing_titles,
|
||||
count(*) FILTER (WHERE price IS NULL) AS missing_prices,
|
||||
count(*) FILTER (WHERE average_rating < 0 OR average_rating > 5) AS invalid_ratings,
|
||||
count(*) FILTER (WHERE rating_number < 0) AS negative_rating_numbers,
|
||||
count(*) FILTER (WHERE price < 0) AS negative_prices
|
||||
FROM products;
|
||||
|
||||
CREATE VIEW duplicate_parent_asins AS
|
||||
SELECT parent_asin, count(*) AS records
|
||||
FROM products
|
||||
WHERE parent_asin IS NOT NULL
|
||||
GROUP BY parent_asin
|
||||
HAVING count(*) > 1;
|
||||
|
||||
CHECKPOINT;
|
||||
Reference in New Issue
Block a user