In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to implement union operation in Spark SQL. Many people may not know much about it. In order to let everyone know more, Xiaobian summarized the following contents for everyone. I hope you can gain something according to this article.
union all is a direct connection, get all values, records may have duplicates
union is a unique value, records are not duplicated
1. The syntax of UNION is as follows:
[SQL Statement 1]
UNION
[SQL Statement 2]
The syntax of UNION ALL is as follows:
[SQL Statement 1]
UNION ALL
[SQL Statement 2]
Comparative summary:
The UNION and UNION ALL keywords both combine two result sets into one, but both differ in terms of usage and efficiency.
1. Processing duplicate results: UNION filters out duplicate records after table linking, Union All does not remove duplicate records.
2, sorting processing: Union will sort according to the order of the fields;UNION ALL simply combines the two results and returns.
In terms of efficiency, UNION ALL is much faster than UNION, so if you can confirm that the two result sets merged do not contain duplicate data and do not need sorting, then use UNION ALL.
Spark SQL
In fact, the DataSet API of Spark SQL has no union all operation, only union operation, and its union operation is union all operation.
In this case, to implement the union operation, you need to add the distinct operation after union.
sales.union(sales).show()
The output is duplicate data
The action needs to be changed to:
sales.union(sales).distinct().show()
After reading the above, do you have any further understanding of how to implement union operations in Spark SQL? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.