Write to BigQuery using Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 พ.ย. 2024

ความคิดเห็น • 98

  • @로봇-y8n
    @로봇-y8n 3 ปีที่แล้ว +6

    For me, this lecture was very helpful. thank you!!

    • @d-i-ry
      @d-i-ry  3 ปีที่แล้ว

      I’m really glad, thanks for letting me know!

  • @SagarKN-12
    @SagarKN-12 2 ปีที่แล้ว +2

    Short and sweet, just the way it should be. Perfect explanation.

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Hey Sagar, glad you liked it!

  • @omarlx
    @omarlx 3 ปีที่แล้ว +1

    You saved me, replacing the colon with the period, that trick is not in the official documentation!, your videos in sections and short length are the best

    • @d-i-ry
      @d-i-ry  3 ปีที่แล้ว

      Hey Andres, I'm really glad it helped! That period trick took me ages to figure out (I found it hidden away in a Python example in some Google Cloud source code), so I'm glad it worked for you, too!

  • @Baba_kasih
    @Baba_kasih 2 ปีที่แล้ว +1

    Thank you, now I can read and write data using python script

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Great! I'm glad it helped! :)

  • @isragaytanmistico
    @isragaytanmistico ปีที่แล้ว +1

    Thank to you very much!....You saved a lot of innecesary documentation! Best!

    • @d-i-ry
      @d-i-ry  ปีที่แล้ว

      I’m glad it helped!

  • @mbhekenisidu2082
    @mbhekenisidu2082 2 ปีที่แล้ว +1

    Hi Ryan, your tutorials are very helpful, and much appreciated. I was wondering if you have written data to BigQuery using pubsub and BigQuery subscription? Instead of using pubsub to dataflow to bigquery?

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Hi Mbhekeni, I’ve only recently started working with DataFlow. This tutorial is just with pushes and pulls, no dataflow :)

  • @Draco-pu4ro
    @Draco-pu4ro 3 ปีที่แล้ว +2

    Great Explanation. In Production environment how should i schedule my python script and i want to run my code daily.

    • @d-i-ry
      @d-i-ry  3 ปีที่แล้ว +1

      Thanks! That's going to depend on your production environment. Really all you need to do is modify your "cron jobs" if you're in Linux. Guessing that you're using Linux, just type "crontab -e" on your terminal to edit what code runs on a schedule, and you can use this to add your script www.geeksforgeeks.org/crontab-in-linux-with-examples/

  • @imdadood5705
    @imdadood5705 2 ปีที่แล้ว +1

    Wow. Simple. Thank for this!

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      You're welcome!

  • @SCVincentLiu
    @SCVincentLiu 2 ปีที่แล้ว +1

    Great video, short but lots of useful information.

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Thanks Sunchi!

  • @honggolangromanlang2393
    @honggolangromanlang2393 2 ปีที่แล้ว

    it's very good explanation, your voice clear, thank you

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Thanks Honggolang! I’m glad it was helpful :)

  • @MessiFCBisseM
    @MessiFCBisseM ปีที่แล้ว +1

    Thanks so much, this is what's called right to the point

    • @d-i-ry
      @d-i-ry  ปีที่แล้ว

      That’s been my goal, glad you like it!

  • @lucasparallada4991
    @lucasparallada4991 3 ปีที่แล้ว +1

    Hi!! because it may take me 2 hours to get the information to the database?
    Great video

    • @d-i-ry
      @d-i-ry  3 ปีที่แล้ว

      thanks a lot!

  • @rrafaelpaz
    @rrafaelpaz 2 ปีที่แล้ว +1

    Awesome video mate, but couldn't find the pubsub -> cloud funcions -> big query video :(

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว +1

      Thanks a lot, Rafael!!

    • @rrafaelpaz
      @rrafaelpaz 2 ปีที่แล้ว

      @@d-i-ry thank you, great teaching skills you have!

  • @diatribes
    @diatribes 2 ปีที่แล้ว +1

    Exactly what I was looking for!!! Thanks:)

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว +1

      Glad I could help!

  • @AdityaKumar-bj5qz
    @AdityaKumar-bj5qz 2 ปีที่แล้ว +1

    superb, really usefull

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Thanks Aditya!

  • @victorvidal9444
    @victorvidal9444 3 ปีที่แล้ว +2

    Great explanation!, thank you very much, you have a lot of experience, and you teach very well, God bless you.

    • @d-i-ry
      @d-i-ry  3 ปีที่แล้ว +1

      That makes my day, Victor! Thank you!!

    • @victorvidal9444
      @victorvidal9444 3 ปีที่แล้ว

      @@d-i-ry Nice to know that!, thank you!, excuse me, do you know any way to upload another kind of files such as .txt or .prn to bigquery using python?

    • @d-i-ry
      @d-i-ry  3 ปีที่แล้ว +1

      @@victorvidal9444 hi Victor, I’d actually use Cloud Storage for the uploads and just use BigQuery to store a direct link to the Cloud Storage bucket with your files

    • @d-i-ry
      @d-i-ry  3 ปีที่แล้ว +1

      th-cam.com/video/w7vKcUJld-U/w-d-xo.html&ab_channel=D-I-Ry check this tutorial out.. it's not exactly what you're asking for, but it'll give you an idea of what it takes to upload files :)

    • @victorvidal9444
      @victorvidal9444 3 ปีที่แล้ว +1

      Great!!, thank you very much, I will check it!, God bless you!

  • @andrewbateman2282
    @andrewbateman2282 3 ปีที่แล้ว +1

    Thanks. Very useful tutorial and it all worked perfectly.

    • @d-i-ry
      @d-i-ry  3 ปีที่แล้ว

      Hey Andrew, glad it helped!

  • @UdiSabach
    @UdiSabach 2 ปีที่แล้ว

    Thank you for this lecture. Say instead of inserting hard coded data I am inserting data loaded via API call, how do you recommend I schedule the python script to run on a schedule?

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Hi Udi, I’m glad you like it!
      Will your data be coming in at regular intervals? Or at random times? Let’s hear a little more about your project

    • @UdiSabach
      @UdiSabach 2 ปีที่แล้ว

      @@d-i-ry Hi! I currently have a cron job that runs every 1hr. However, eventually I'd like to move that into a Cloud Schedule. does that help?

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      @@UdiSabach Hi, yeah that helps. I really don't see much change to the writer.py file. As a cron job script, you just change the 'rows_to_insert' variable. As a Cloud Schedule (or perhaps as a Cloud Function), you do the same. And if this was a stand-alone script that had your API code it in as well, you would set up the 'client' and 'table_id' at the start of your script, then your callback functions for the API populate the 'rows_to_insert' var and call the 'insert_rows_json' function.
      You could start building out your project with hardcoded values in 'rows_to_insert'. Have a few API calls ("endpoints"), each of which writes a different hardcoded set of values to BigQuery. Once that works, you can substitute the actual data from the API calls into the write.
      I hope that helps :)

    • @UdiSabach
      @UdiSabach 2 ปีที่แล้ว +1

      @@d-i-ry It does help, thank you very much.

  • @enesteymir
    @enesteymir 3 ปีที่แล้ว +1

    thanks a lot, short and useful video

    • @d-i-ry
      @d-i-ry  3 ปีที่แล้ว

      Glad it was helpful!

  • @Gabriel198765432
    @Gabriel198765432 ปีที่แล้ว

    I'm a bit lost... what are the pre requisites to understand all the operations you are performing? I don't understand much about objects, so that might be why i dont understand the os library

    • @d-i-ry
      @d-i-ry  ปีที่แล้ว

      Hi Gabriel, let’s see if I can explain an object…
      We have our basic variable types: integer, string, Boolean, float, and so on.
      Then we have types that you and I create, and those are objects. The difference is that we don’t create a new basic (or “fundamental”) type. An object is a collection of items.
      When I want to create a new variable type (a new object type) that’ll describe a cat, I’ll make an object (a collection of variables) with the following:
      class Cat:
      def __init__(self, name, age, indoor, num_paws):
      self.name = name
      self.age = age
      self.indoor = indoor
      self.num_paws = num_paws
      And to make a variable of type Cat, I’d do this:
      my_pet = Cat(name='Oatie', age=9, indoor=True, num_paws=4)
      Let me know if this made sense and helped, and then what your next question is :)

  • @valentinaelizondo6024
    @valentinaelizondo6024 2 ปีที่แล้ว +1

    Great Video, thank you

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Thanks! I'm glad you liked it!

  • @luiseduardoobandobonilla37
    @luiseduardoobandobonilla37 2 ปีที่แล้ว +1

    Tenga su like y suscripción buen hombre!!
    Mil gracias!!

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว +1

      ¡de nada!

  • @vigneshkrish4742
    @vigneshkrish4742 3 ปีที่แล้ว

    Thank you for the Wonderful video, I have a doubt here u have added two rows to the table what if if I want to insert a dataset to the table

    • @d-i-ry
      @d-i-ry  3 ปีที่แล้ว +1

      Hi Vignesh, you're welcome, I'm glad you liked it! When you need to insert intricate data, you can nest your data very deep (like JSON data), like this example stackoverflow.com/questions/36673456/bigquery-insert-new-data-row-into-table-by-python/36849400 ...but it's still just adding a row at a time, which is not a bad approach at all

  • @linpershey
    @linpershey 2 ปีที่แล้ว +1

    Great! succinct and helpful.

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Glad it was helpful!

  • @hizokadarkwolf
    @hizokadarkwolf 2 ปีที่แล้ว +1

    Thanks! It's better to see it than read it from the book. I see that your JSON is separated by commas which is different from other examples where they use NDJSON (new line delimited Json) files.
    I will test both formats and see the outcome. Have a good day!
    - Alex

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Hey Alex, would you mind pasting the NDJSON example? :)

  • @ramakantsingh2262
    @ramakantsingh2262 ปีที่แล้ว +1

    Hi Ryan, very nice, can you write code to using jason data into bigquery using cloud functions

    • @d-i-ry
      @d-i-ry  ปีที่แล้ว

      Hi Ramakant, yes, and if you check out my video list, I have 2 videos on that topic :)

  • @mansipandya1733
    @mansipandya1733 2 ปีที่แล้ว +1

    A big thank you.

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      You're welcome!

  • @francomarcialferrer2232
    @francomarcialferrer2232 2 ปีที่แล้ว +1

    Great! thank you

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Hey Franco, glad it helped!

  • @rumasingh638
    @rumasingh638 2 ปีที่แล้ว

    How can I load csv files from cloud storage to bigquery table? Can you help me on this.

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Hi Ruma, this page will show you the steps for that :) cloud.google.com/bigquery/docs/loading-data-cloud-storage-csv

  • @travorhouse503
    @travorhouse503 ปีที่แล้ว

    Is there a way to get all rows into the dataset rather than defining individual rows?

    • @d-i-ry
      @d-i-ry  ปีที่แล้ว

      Hi Travor, I’m not certain what you mean. Can you give me an example?

  • @sridharkm1711
    @sridharkm1711 2 ปีที่แล้ว

    how we can create a new table in a existing dataset, using create table option and import csv file using python

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Hi Sridhar, here's the API for running a BigQuery statement in Python. If you scroll down, you'll see the exact statement for adding a table :)
      cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language

  • @aymanejarah7064
    @aymanejarah7064 2 ปีที่แล้ว

    Great video, I was wondering how I can update rows in existing table using python

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว +1

      Hi Aymane, this should do it for you cloud.google.com/bigquery/docs/updating-data#python
      With a simpler example here (scroll down to the answer with about 14 votes): stackoverflow.com/questions/48684613/how-to-update-delete-rows-in-bigquery-from-the-python-api

    • @aymanejarah7064
      @aymanejarah7064 2 ปีที่แล้ว +1

      @@d-i-ry Thanks for the response, very useful ressource. (y)

  • @fivel6436
    @fivel6436 ปีที่แล้ว +1

    Thanks a lot

    • @d-i-ry
      @d-i-ry  ปีที่แล้ว

      Welcome :)

  • @jasonconcepcion3948
    @jasonconcepcion3948 2 ปีที่แล้ว +1

    nicee...

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Thanks

  • @hansparson2583
    @hansparson2583 2 ปีที่แล้ว

    Hy. I get problem when runing python scripts.. It say unable stream data in free tier.. Is that bigquery need to pay to upload data?

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Hi Hans, what's the exact error?

    • @hansparson2583
      @hansparson2583 2 ปีที่แล้ว

      @@d-i-ry it say "unable stream data in free tier" When i search the problem.. It say that i need to enable biling acount.. It need credits card. 😭😭 i dont have any credit cards😭😭

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      @@hansparson2583 Ooooh, yes, you will need the paid account, but it gives you a $300 credit when you sign up, so it'll be free to use. Can you maybe use a debit card?

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว +1

      When I started on Google Cloud, I think I used $56 of services in my first year, nooooo where near the $300 credit they gave me :)

  • @yigitcanarin4156
    @yigitcanarin4156 2 ปีที่แล้ว +1

    no seconds wasted 👍

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Thanks, Yigit!

  • @thebujoco9381
    @thebujoco9381 3 ปีที่แล้ว

    Hi, how do we write the data from a csv or excel file to Bigquery?

    • @d-i-ry
      @d-i-ry  3 ปีที่แล้ว

      Just search for example code that uses “import csv”, and you’ll be able to use my project with that. Let me know if you get stuck!

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Hi @Bhaskar Pawar , though the problem is easy to state, it's far too complicated... so what should you do instead? Change the problem just a little so it becomes approachable and easy.
      First, the reason why it's hard --- no one else needs to do this, so you'll end up solving every bit of it yourself. The ultimate goal in programming is to reuse code, and not just your own code, but to reuse everyone's code! And since the original problem is so different from a normal, every-day problem, you'll have to write the entire thing yourself.
      Now how should you change the problem so it becomes easy?
      Don't compare apples to oranges (or CSV files to database entries). Either download your BigQuery tables into CSV files, or upload your CSV files into new BigQuery entires. That way, you're comparing CSV to CSV or DB to DB.
      I hope this helps :)

  • @kurniaanwarraif3688
    @kurniaanwarraif3688 ปีที่แล้ว

    mantaps bosq !

    • @d-i-ry
      @d-i-ry  ปีที่แล้ว

      haha senang kamu menyukainya

  • @j2jj248
    @j2jj248 2 ปีที่แล้ว +1

    Thank you

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      You're welcome!

  • @rajatsahu7024
    @rajatsahu7024 3 ปีที่แล้ว +1

    Thanks

    • @d-i-ry
      @d-i-ry  3 ปีที่แล้ว

      Welcome :)

  • @mohammadmoinuddin5477
    @mohammadmoinuddin5477 2 ปีที่แล้ว

    Error: streaming insert is not allowed in free tier,
    Any solution please

    • @d-i-ry
      @d-i-ry  2 ปีที่แล้ว

      Hi Mohammad, you need to sign up to the paid tier. It comes with $300 of free credits

    • @mohammadmoinuddin5477
      @mohammadmoinuddin5477 2 ปีที่แล้ว

      @@d-i-ry oh I see, thank you so much

  • @nikolasiwanus4009
    @nikolasiwanus4009 2 ปีที่แล้ว

    How do I add arrays from jsons?

    • @d-i-ry
      @d-i-ry  ปีที่แล้ว

      Hi Nikolas, here you go! cloud.google.com/bigquery/docs/loading-data-cloud-storage-json there's an example with json arrays just a little way down on that (very long) page