Membuat kueri set data publik dan memvisualisasikan hasilnya

Pelajari cara membuat kueri set data publik dan memvisualisasikan hasilnya di BigQuery.


Untuk mengikuti panduan langkah demi langkah tugas ini langsung di Google Cloud konsol, klik Pandu saya:

Pandu saya


Sebelum memulai

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that you have the following role or roles on the project: BigQuery Job User, Service Usage Admin

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      Buka IAM
    2. Pilih project.
    3. Klik Grant access.
    4. Di kolom New principals, masukkan ID pengguna Anda. Biasanya berupa alamat email untuk Akun Google.

    5. Di daftar Select a role, pilih peran.
    6. Untuk memberikan peran tambahan, klik Tambahkan peran lain, lalu tambahkan setiap peran tambahan.
    7. Klik Simpan.
  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that you have the following role or roles on the project: BigQuery Job User, Service Usage Admin

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      Buka IAM
    2. Pilih project.
    3. Klik Grant access.
    4. Di kolom New principals, masukkan ID pengguna Anda. Biasanya berupa alamat email untuk Akun Google.

    5. Di daftar Select a role, pilih peran.
    6. Untuk memberikan peran tambahan, klik Tambahkan peran lain, lalu tambahkan setiap peran tambahan.
    7. Klik Simpan.
  6. Verify that billing is enabled for your Google Cloud project.

  7. Jika Anda tidak mengaktifkan penagihan untuk Google Cloud project yang digunakan dalam tutorial ini, Anda harus membuat kueri data publik di sandbox BigQuery. Sandbox BigQuery memungkinkan Anda mempelajari BigQuery dengan sekumpulan fitur BigQuery terbatas tanpa biaya.

  8. Pastikan BigQuery API diaktifkan.

    Mengaktifkan API

    Jika Anda membuat project baru, BigQuery API akan otomatis diaktifkan.

  9. Melihat set data publik

    Set data publik BigQuery tersedia secara default di BigQuery Studio dalam project bernama bigquery-public-data. Dalam tutorial ini, Anda akan membuat kueri set data Perjalanan NYC Citi Bike. Citi Bike adalah program berbagi sepeda besar, dengan 10.000 sepeda dan 600 stasiun di Manhattan, Brooklyn, Queens, dan Jersey City. Set data ini mencakup perjalanan Citi Bike sejak Citi Bike diluncurkan pada September 2013.

    1. Di konsol Google Cloud , buka halaman BigQuery.

      Buka BigQuery

    2. Di BigQuery Studio, di panel Penjelajah, klik Tambahkan data.

    3. Dalam dialog Tambahkan data, di panel Filter Menurut, klik Ikon set data publik di halaman Filter menurut Set data publik.

    4. Di halaman Marketplace, di kolom Search Marketplace, ketik NYC Citi Bike Trips untuk mempersempit penelusuran Anda.

    5. Di hasil penelusuran, klik NYC Citi Bike Trips.

    6. Di halaman Detail produk, klik Lihat set data. Anda dapat melihat informasi tentang set data di tab Detail.

    Mengkueri set data publik

    Pada langkah-langkah berikut, Anda akan membuat kueri tabel citibike_trips untuk menentukan 100 stasiun Citi Bike paling populer dalam set data publik Perjalanan NYC Citi Bike. Kueri mengambil nama dan lokasi stasiun, serta jumlah perjalanan yang dimulai di stasiun tersebut.

    Kueri menggunakan fungsi ST_GEOGPOINT untuk membuat titik dari parameter bujur dan lintang setiap stasiun dan menampilkan titik tersebut dalam kolom GEOGRAPHY. Kolom GEOGRAPHY digunakan untuk membuat peta panas di penampil data geografi terintegrasi.

    1. Di konsol Google Cloud , buka halaman BigQuery.

      Buka BigQuery

    2. Klik SQL query.

    3. Di query editor, masukkan kueri berikut:

      SELECT
        start_station_name,
        start_station_latitude,
        start_station_longitude,
        ST_GEOGPOINT(start_station_longitude, start_station_latitude) AS geo_location,
        COUNT(*) AS num_trips
      FROM
        `bigquery-public-data.new_york.citibike_trips`
      GROUP BY
        1,
        2,
        3
      ORDER BY
        num_trips DESC
      LIMIT
        100;
      

      Jika kueri valid, tanda centang akan muncul bersama dengan jumlah data yang diproses kueri. Jika kueri tidak valid, tanda seru akan muncul bersama dengan pesan error.

      Validator kueri

    4. Klik Jalankan. Stasiun paling populer tercantum di bagian Hasil kueri.

      Hasil kueri di konsol Google Cloud

    5. Opsional: Untuk menampilkan durasi tugas dan jumlah data yang diproses tugas kueri, klik tab Informasi tugas di bagian Hasil kueri.

    6. Beralihlah ke tab Visualisasi. Tab ini membuat peta untuk memvisualisasikan hasil Anda dengan cepat.

    7. Di panel Konfigurasi visualisasi:

      1. Pastikan Jenis visualisasi disetel ke Peta.
      2. Pastikan Kolom geografi disetel ke geo_location.
      3. Untuk Kolom data, pilih num_trips.
      4. Gunakan opsi Perbesar untuk menampilkan peta Manhattan.

      Peta panas yang dihasilkan di tab Visualisasi

    Pembersihan

    Agar akun Google Cloud Anda tidak dikenai biaya untuk resource yang digunakan pada halaman ini, ikuti langkah-langkah berikut.

    Menghapus project

    Jika Anda menggunakan sandbox BigQuery untuk mengkueri set data publik, penagihan tidak akan diaktifkan untuk project Anda, dan Anda tidak perlu menghapus project.

    Cara termudah untuk menghilangkan penagihan adalah dengan menghapus project yang Anda buat untuk tutorial.

    Untuk menghapus project:

    1. In the Google Cloud console, go to the Manage resources page.

      Go to Manage resources

    2. In the project list, select the project that you want to delete, and then click Delete.
    3. In the dialog, type the project ID, and then click Shut down to delete the project.

    Langkah berikutnya