Skip to content

Instantly share code, notes, and snippets.

@jklukas
jklukas / add-wire-prefix.bash
Last active August 29, 2015 14:20
Break long compound imports to multiple lines (Scala)
for x in $(gsed -n -E -e 's/.*(class|object|trait) ([[:alnum:]]*).*/\2/p' nacho-wire/src/main/scala/com/simple/nacho/wire/Json.scala); do
find nacho-service -name "*.scala" | \
xargs sed -i '' '/^import/! s/\([^.[:alnum:]]\)\('$x'[[:punct:][:space:]]\)/\1wire.\2/g';
done
WITH
-- Distinct document_ids and their minimum submission_timestamp today
-- not including document_ids that only occur on or after @end_time
distinct_document_ids AS (
SELECT
document_id,
MIN(submission_timestamp) AS submission_timestamp
FROM
`moz-fx-data-shared-prod.telemetry_live.main_v4`
WHERE
CREATE TEMP FUNCTION
replace_compact_use_counters(h ANY type) AS ((
SELECT
AS STRUCT h.* REPLACE(
COALESCE(JSON_EXTRACT_SCALAR(h.use_counter2_appearance_nonwidget_button_document,"$.sum"),h.use_counter2_appearance_nonwidget_button_document) AS use_counter2_appearance_nonwidget_button_document,
COALESCE(JSON_EXTRACT_SCALAR(h.use_counter2_appearance_nonwidget_button_page,"$.sum"),h.use_counter2_appearance_nonwidget_button_page) AS use_counter2_appearance_nonwidget_button_page,
COALESCE(JSON_EXTRACT_SCALAR(h.use_counter2_appearance_nonwidget_checkbox_document,"$.sum"),h.use_counter2_appearance_nonwidget_checkbox_document) AS use_counter2_appearance_nonwidget_checkbox_document,
COALESCE(JSON_EXTRACT_SCALAR(h.use_counter2_appearance_nonwidget_checkbox_page,"$.sum"),h.use_counter2_appearance_nonwidget_checkbox_page) AS use_counter2_appearance_nonwidget_checkbox_page,
COALESCE(JSON_EXTRACT_SCALAR(h.use_counter2_appearance_nonwidget_innerspinbutton_document,"$.sum"),h.use_counter2_appearance_nonwidget_inn
/* Example of a custom class with automatically generated Coder */
@DefaultSchema(AutoValueSchema.class)
@AutoValue
abstract static class MyMessage {
public static MyMessage of(byte[] payload, Map<String, String> attributes) {
return new AutoValue_MyMessage(paylod, attributes);
}
public abstract byte[] getPayload();
public abstract Map<String, String> getAttributes();
}
WITH base AS (
SELECT
*,
ARRAY(
SELECT AS STRUCT
mozfun.map.get_key(mozfun.hist.extract(histogram).values, 0) AS histogram
FROM
UNNEST(
[
payload.histograms.devtools_aboutdebugging_opened_count,
WITH base AS (
SELECT
*,
ARRAY(
SELECT AS STRUCT
mozfun.map.get_key(mozfun.hist.extract(histogram).values, 0) AS histogram
FROM
UNNEST(
[
payload.histograms.devtools_aboutdebugging_opened_count,
@jklukas
jklukas / README.md
Last active March 19, 2021 20:10
Prototype of ios baseline+metrics ETL