Upgrade to Pro — share decks privately, control downloads, hide ads and more …

1年分のデータが見たいと言われてやったこと/yearly_data_with_note

fromkk
March 11, 2022

 1年分のデータが見たいと言われてやったこと/yearly_data_with_note

note tech meetup #1 エンジニアLT大会で発表したきた内容です。
Redashだとデータ容量の制限があり1年見たいな大規模なデータは扱えないのですが別の手段を試してみました。
https://pieceofcake.connpass.com/event/240575/

fromkk

March 11, 2022
Tweet

More Decks by fromkk

Other Decks in Programming

Transcript

  1. ΫΤϦͷ࣮ߦ const request = { query: query, useLegacySql: false }

    const result = BigQuery.Jobs.query(request, projectId) ઌ΄Ͳ߇͓͍͑ͯͨϓϩδΣΫτ൪߸
  2. ݄ؒͷ17Λूܭ͢Δαϯϓϧίʔυ function countMonthlyUser(year, month) { const from = `${zeroFill(year, 4)}${zeroFill(month,

    2)}01` const toDate = new Date(year, month, 0) const to = `${zeroFill(year, 4)}${zeroFill(month, 2)}${zeroFill(toDate.getDate(), 2)}` const query = `SELECT FORMAT_TIMESTAMP("%Y-%m", TIMESTAMP_MICROS(event_timestamp), "Asia/Tokyo") AS date , COUNT(distinct if(user_id IS NOT NULL, user_id, user_pseudo_id)) AS count_user FROM \`${tableName}.events_*\` WHERE _TABLE_SUFFIX BETWEEN '${from}' AND '${to}' GROUP BY date ` const request = { query: query, useLegacySql: false } const result = BigQuery.Jobs.query(request, projectId) if (!result || !result.rows) { return 0 } else if (result.rows.length == 0) { return 0 } else { if (result.rows[0].f.length == 0) { return 0 } else { return result.rows[0].f[1].v } } } IUUQTHJUIVCDPNGSPNLL4BNQMF#JH2VFSZ8JUI4QSFBETIFFU