Kế Hoạch Thực Thi Spark

Giới Thiệu

Sử dụng hàm explain() trên bất kỳ đối tượng DataFrame nào để xem dòng dữ liệu của DataFrame (hoặc cách Spark sẽ thực thi truy vấn này). Kế hoạch thực thi được đọc từ trên xuống dưới, phần trên là kết quả cuối cùng và phần dưới là nguồn (hoặc các bước xử lý) của dữ liệu.

Trong ví dụ dưới đây, hãy xem từ khóa đầu tiên của mỗi dòng: FileScan, Exchange, Sort. Việc sắp xếp dữ liệu thực sự là một biến đổi rộng vì các hàng sẽ cần được so sánh với nhau.

pythonSao chép mãflight_df = spark\
.read\
.option("inferSchema", "true")\ # suy đoán schema, có nghĩa là chúng ta muốn Spark đoán schema tốt nhất cho DataFrame của chúng ta
.option("header", "true")\
.csv("/data/flight-data/csv/2015-summary.csv")
flight_df.sort("count").explain()

Kế Hoạch Thực Thi (Physical Plan)

plaintextSao chép mã== Kế Hoạch Thực Thi ==
* Sắp Xếp [count#195 ASC NULLS FIRST], true, 0
+- Trao Đổi rangepartitioning(count#195 ASC NULLS FIRST, 200)
   +- *FileScan csv [DEST_COUNTRY_NAME#193,ORIGIN_COUNTRY_NAME#194,count#195]

Dòng thứ nhất là kế hoạch thực thi của Spark, nó hiển thị các bước mà Spark sẽ thực hiện để thực hiện truy vấn này. Trong ví dụ này, chúng ta thấy một Sort và một Exchange. Sorting thực sự là một biến đổi rộng, vì các hàng sẽ cần được so sánh với nhau để sắp xếp. Exchange cũng là một bước rộng, vì nó liên quan đến việc tráo đổi dữ liệu giữa các phân vùng. Dưới đó là một FileScan, cho biết dữ liệu sẽ được đọc từ một tệp CSV.

DataFrame trong Spark

Tạo DataFrame

createDataFrame

Khi schema là một danh sách các tên cột, loại của mỗi cột sẽ được suy đoán từ dữ liệu.

Khi schema là None, nó sẽ cố gắng suy đoán schema (tên cột và loại) từ dữ liệu, dữ liệu này phải là một RDD của Row, namedtuple hoặc dict.

pythonSao chép mã# Tạo Spark Session
spark = SparkSession.builder\
        .getOrCreate()

# Tạo Spark Context
sc = spark.sparkContext

# Định nghĩa schema
schema = StructType([
   StructField("name", StringType(), True), # True - Có thể là null
   StructField("age", IntegerType(), True)
])

# Tạo DataFrame Spark từ RDD của Row, namedtuple hoặc dict
rdd = sc.parallelize([('Alice', 1)]) # Spark context -> để tạo một phiên làm việc song song
spark_df = spark.createDataFrame(rdd, schema)
spark_df.collect()
# [Row(name='Alice', age=1)]

# Tạo DataFrame Spark từ DataFrame Pandas
spark_df = spark.createDataFrame(pandas_df, schema)

Đây là cách tạo DataFrame trong Spark từ một loạt các nguồn dữ liệu khác nhau. Bạn có thể sử dụng RDD của Row, namedtuple hoặc dict để tạo DataFrame, hoặc tạo từ DataFrame Pandas. Điều này cho phép bạn làm việc với các loại dữ liệu khác nhau trong môi trường Spark một cách linh hoạt.

154 thoughts on “Kế Hoạch Thực Thi Spark

  1. Howdy, I think your web site could be having browser compatibility problems. When I take a look at your blog in Safari, it looks fine however, when opening in I.E., it’s got some overlapping issues. I just wanted to give you a quick heads up! Besides that, excellent website.

  2. Aw, this was an extremely nice post. Taking a few minutes and actual effort to generate a top notch article… but what can I say… I procrastinate a lot and don’t seem to get anything done.

  3. Can I just say what a relief to find an individual who genuinely knows what they are discussing on the internet. You certainly understand how to bring a problem to light and make it important. More people really need to read this and understand this side of your story. I can’t believe you aren’t more popular because you surely have the gift.

  4. Hello there, I do believe your website might be having web browser compatibility issues. When I look at your website in Safari, it looks fine however, when opening in Internet Explorer, it’s got some overlapping issues. I simply wanted to give you a quick heads up! Other than that, wonderful site!

  5. sugar defender Official website I have
    actually dealt with blood sugar level fluctuations
    for many years, and it really impacted my power degrees throughout the day.
    Given that starting Sugar Protector, I really feel a lot more well balanced and
    sharp, and I do not experience those mid-day slumps any longer!
    I like that it’s an all-natural solution that functions without any harsh
    negative effects. It’s genuinely been a game-changer for me

  6. you’re really a good webmaster. The website loading speed is incredible. It seems that you are doing any distinctive trick. Furthermore, The contents are masterwork. you have performed a great process on this topic!

  7. Lots of people were enthusiastic sportsmen or enjoyed music and dancing. It’s possible you’ll remember that you were most joyful on the operating track. Even so, with increasing obligations you might have found almost no time to indulge in any of the interests. Are you affected by depression and want to get free from its abysmal depths without lifelong antidepresants? You could attempt and help yourself to overcome depression naturally.

  8. A lot of thanks for all your labor on this web page. Ellie really loves doing internet research and it’s really obvious why. My partner and i notice all relating to the powerful means you present efficient information via the web blog and therefore improve contribution from others on the subject and our simple princess is really understanding a great deal. Take advantage of the remaining portion of the year. You have been carrying out a great job.

  9. Thanks a lot for giving everyone an extraordinarily memorable chance to read in detail from this site. It is often so brilliant and packed with a lot of fun for me and my office acquaintances to search your site nearly thrice in a week to read through the latest items you will have. And definitely, I’m certainly astounded considering the exceptional ideas you serve. Certain two points in this post are really the most beneficial we’ve ever had.

  10. Attractive element of content. I just stumbled upon your blog and in accession capital to say that I get in fact enjoyed account your weblog posts. Any way I’ll be subscribing in your feeds and even I success you get admission to consistently rapidly.

  11. My husband and i got now thrilled Edward managed to finish off his researching while using the ideas he gained out of the web site. It’s not at all simplistic to just continually be giving out ideas which usually some people have been selling. And we consider we now have you to give thanks to because of that. The type of explanations you’ve made, the easy blog menu, the friendships you aid to instill – it’s everything powerful, and it is helping our son in addition to our family imagine that the situation is excellent, and that is incredibly pressing. Thanks for all!

  12. I have noticed that over the course of developing a relationship with real estate homeowners, you’ll be able to get them to understand that, in every single real estate transaction, a commission is paid. In the long run, FSBO sellers will not “save” the commission. Rather, they fight to win the commission by means of doing a great agent’s job. In completing this task, they invest their money along with time to conduct, as best they will, the assignments of an broker. Those duties include getting known the home by means of marketing, representing the home to all buyers, constructing a sense of buyer desperation in order to prompt an offer, making arrangement for home inspections, taking on qualification checks with the loan company, supervising fixes, and aiding the closing of the deal.

  13. We’re a group of volunteers and starting a new scheme in our community. Your site provided us with valuable information to work on. You’ve done a formidable job and our whole community will be thankful to you.

  14. As far as me being a member here, I didnt even know that I was a member here. When the article was published I received a notification, so that I could participate in Comments, so perhaps that is it. But we’re certainly all members in the world of ideas.

  15. Great ¡V I should certainly pronounce, impressed with your site. I had no trouble navigating through all tabs as well as related info ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or anything, website theme . a tones way for your client to communicate. Excellent task..

  16. I blog frequently and I seriously thank you for your content. Your article has truly peaked my interest. I am going to book mark your website and keep checking for new information about once a week. I opted in for your Feed as well.

  17. I think youve made some actually helpful factors. Not as well lots of people would actually feel about this the best way you simply did. Im genuinely impressed that theres so much about this matter thats been uncovered and you also did it so nicely, with so considerably class. Fantastic one you, man! Definitely terrific things correct here.

  18. I would like to thnkx stiforp for the efforts you have put in writing this site. I am hoping the same high-grade blog post from you in the future too. Stiforp In fact your creative writing abilities has encouraged me to get my own web site going now. Really blogging is spreading its wings and growing fast. Your Stiforp write up is a great example.

  19. I’m really loving the theme/design of your blog. Do you ever run into any web browser compatibility problems? A few of my blog audience have complained about my site not operating correctly in Explorer but looks great in Opera. Do you have any recommendations to help fix this issue?

  20. For that reason times repeatedly pretty much everything, this life definitely is ended up saving a little bit more. The program in fact saves currently the And also carbon actually motivated in to planet during these development activities. dc free mommy blog giveaways family trip home gardening house power wash baby laundry detergent

  21. Hello! I could have sworn I’ve visited this site before but after browsing through many of the posts I realized it’s new to me. Anyhow, I’m definitely happy I discovered it and I’ll be book-marking it and checking back frequently.

  22. I have to thank you for the efforts you have put in writing this blog. I really hope to view the same high-grade blog posts by you later on as well. In fact, your creative writing abilities has inspired me to get my very own blog now 😉

  23. When I originally left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and from now on each time a comment is added I receive four emails with the exact same comment. Is there a way you are able to remove me from that service? Thanks a lot.

  24. Oh my goodness! Amazing article dude! Thank you, However I am having problems with your RSS. I don’t know why I am unable to join it. Is there anybody else getting the same RSS problems? Anyone that knows the solution can you kindly respond? Thanks.

  25. An impressive share! I’ve just forwarded this onto a co-worker who was doing a little homework on this. And he actually ordered me dinner simply because I found it for him… lol. So allow me to reword this…. Thanks for the meal!! But yeah, thanks for spending some time to talk about this topic here on your blog.

  26. An outstanding share! I’ve just forwarded this onto a friend who had been conducting a little homework on this. And he in fact ordered me dinner simply because I found it for him… lol. So allow me to reword this…. Thank YOU for the meal!! But yeah, thanks for spending the time to talk about this matter here on your web page.

  27. Hello there! This blog post could not be written any better! Going through this article reminds me of my previous roommate! He continually kept preaching about this. I will forward this article to him. Pretty sure he’s going to have a good read. Thank you for sharing!

  28. I truly love your site.. Very nice colors & theme. Did you make this web site yourself? Please reply back as I’m trying to create my own personal blog and want to know where you got this from or what the theme is named. Thank you.

  29. Oh my goodness! Amazing article dude! Many thanks, However I am experiencing issues with your RSS. I don’t know the reason why I am unable to subscribe to it. Is there anybody else getting similar RSS issues? Anybody who knows the answer will you kindly respond? Thanks!

  30. I have to thank you for the efforts you’ve put in penning this blog. I really hope to check out the same high-grade content by you in the future as well. In truth, your creative writing abilities has motivated me to get my own website now 😉

  31. Good post. I learn something totally new and challenging on sites I stumbleupon on a daily basis. It’s always helpful to read through content from other authors and use something from their web sites.

  32. Nice post. I learn something new and challenging on websites I stumbleupon everyday. It will always be exciting to read through content from other authors and practice a little something from their websites.

  33. I blog often and I really thank you for your information. The article has really peaked my interest. I’m going to bookmark your website and keep checking for new information about once a week. I opted in for your RSS feed too.

  34. When I initially left a comment I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on every time a comment is added I recieve 4 emails with the exact same comment. There has to be an easy method you are able to remove me from that service? Thanks.

  35. Spot on with this write-up, I honestly believe that this website needs a lot more attention. I’ll probably be back again to read more, thanks for the info.

  36. I would like to thank you for the efforts you’ve put in writing this blog. I really hope to check out the same high-grade content from you later on as well. In fact, your creative writing abilities has inspired me to get my own website now 😉

  37. I would like to thank you for the efforts you have put in penning this website. I’m hoping to view the same high-grade blog posts from you in the future as well. In truth, your creative writing abilities has motivated me to get my own blog now 😉

Để lại một bình luận

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *