Skip to main content
Bird & Bear
Menu
← All articles

BigQuery Working Examples Dataset Update

bigquery ai analytics sql
BigQuery Working Examples Dataset Update

Our AI.AGG article needed something the rest of the BigQuery Working Examples series doesn’t: free text. The shared bq_ai_demo.ecommerce_orders table behind AI.KEY_DRIVERS, AI.FORECAST, AI.CAUSAL_EFFECT, ML.CORRELATION, and ML.METRICS is all numbers and categories, channel, device, region, revenue. AI.AGG reads text and summarises it, so it needed a text column to read.

Rather than build a separate dataset for one article, we added a single column, customer_note, to the same table. If you’ve already loaded ecommerce_orders to follow along with any of the earlier articles, this is the update to run so the AI.AGG article works too. If you’re setting the dataset up for the first time, follow the main setup guide first, then come back here.

The GitHub containing everything you need can be found here.

What’s new

customer_note is a short, optional note on each order. About 40% of rows get no note at all (NULL), the way most online orders never get a comment. The other 60% get one of six varied notes per product category, so the text isn’t identical across a whole category, mixing positive, neutral, and negative feedback. Electronics has a deliberate recurring pattern built in on purpose: roughly a third of its notes mention the companion app losing its Bluetooth connection, a specific, repeated complaint for the AI.AGG article’s worked examples to find.

No CSV re-upload is needed. Both steps below are plain SQL against the table you already have.

Step 1: Add the column

ALTER TABLE `bq_ai_demo.ecommerce_orders` ADD COLUMN customer_note STRING;

Step 2: Populate it

BigQuery’s UPDATE statement requires a WHERE clause, as a safeguard against accidentally rewriting an entire table with no filter. Since every row genuinely needs updating here, the clause is just WHERE TRUE, that’s deliberate, rather than something to remove:

UPDATE `bq_ai_demo.ecommerce_orders`
SET customer_note = CASE
  WHEN MOD(ABS(FARM_FINGERPRINT(CONCAT(order_id, '-note'))), 10) < 4 THEN NULL
  WHEN product_category = 'Footwear' THEN [
    'Shoes run a bit small, ordered a size up next time.',
    'Really comfortable, true to size, would buy again.',
    'Sole started coming away from the upper after a few weeks.',
    'Fit was perfect and delivery was quick.',
    'Wish this style came in more colours.',
    'Box arrived a bit crushed but the shoes were fine.'
  ][OFFSET(MOD(ABS(FARM_FINGERPRINT(order_id)), 6))]
  WHEN product_category = 'Outerwear' THEN [
    'Warm and well made, exactly what I needed for winter.',
    'Zip on the left pocket broke within a month.',
    'Runs a little large, had to size down.',
    'Great value for the price, happy with this.',
    'Colour was more faded than shown online.',
    'Good quality but took over a week longer to arrive than expected.'
  ][OFFSET(MOD(ABS(FARM_FINGERPRINT(order_id)), 6))]
  WHEN product_category = 'Electronics' THEN [
    'Works well, setup was straightforward.',
    'Companion app keeps losing its Bluetooth connection, had to reset it twice.',
    'Battery life is shorter than advertised.',
    'Good value, does exactly what it says.',
    'Pairing over Bluetooth dropped out constantly until I updated the app.',
    'No issues, arrived quickly and works as described.'
  ][OFFSET(MOD(ABS(FARM_FINGERPRINT(order_id)), 6))]
  WHEN product_category = 'Homeware' THEN [
    'Looks great, nicely packaged, no damage on arrival.',
    'One corner was chipped when it arrived.',
    'Smaller than I pictured but good quality.',
    'Exactly as described, very happy with this.',
    'Packaging was flimsy for something this fragile.',
    'Good price for the quality, would recommend.'
  ][OFFSET(MOD(ABS(FARM_FINGERPRINT(order_id)), 6))]
  WHEN product_category = 'Accessories' THEN [
    'Nice finish, feels well made for the price.',
    'Colour was slightly different to the product photo.',
    'Great gift, arrived well packaged.',
    'Clasp is a bit stiff but otherwise fine.',
    'Exactly what I was looking for.',
    'Smaller than expected, check the dimensions first.'
  ][OFFSET(MOD(ABS(FARM_FINGERPRINT(order_id)), 6))]
END
WHERE TRUE;

Step 3: Check it worked

SELECT
  product_category,
  COUNT(*) AS order_count,
  COUNTIF(customer_note IS NULL) AS no_note_count,
  COUNTIF(customer_note LIKE '%Bluetooth%') AS bluetooth_mentions
FROM `bq_ai_demo.ecommerce_orders`
GROUP BY product_category
ORDER BY product_category;

Expect roughly 40% no_note_count in every category, and bluetooth_mentions concentrated in Electronics only.

Once this is done, every query in the AI.AGG article will run as written. Nothing else changes, and the other five articles in the series don’t touch customer_note and aren’t affected by adding it.


All articles in this series

Newsletter

Occasional notes on data, tracking & AI-readiness

No spam, no growth-hacking. Just an email when there's something worth reading.