Giới Thiệu
Apache Hive là một hệ thống lưu trữ dữ liệu được xây dựng trên nền tảng của Hadoop, hỗ trợ phân tích các tập dữ liệu lớn được lưu trữ trong các hệ thống tệp phân tán của Hadoop (HDFS) hoặc S3 bằng cách sử dụng các truy vấn tương tự SQL.
Nó lưu trữ siêu dữ liệu (metadata) của schema trong một cơ sở dữ liệu (như Apache Derby, MySQL, Postgres hoặc MariaDB) và xử lý dữ liệu từ lưu trữ kết nối (như HDFS hoặc S3).
Nó cung cấp ngôn ngữ truy vấn giống SQL, HiveQL.
Hive Metastore
Hive metastore ghi lại tất cả thông tin cấu trúc (metadata) của một bảng Hive và các phân vùng của nó trong kho lưu trữ:
- Thông tin cột và định nghĩa kiểu dữ liệu
- Các serializer và de-serializer cần thiết để đọc và ghi dữ liệu
- Vị trí của dữ liệu liên quan trong HDFS hoặc S3
Các siêu dữ liệu trong Hive metastore được lưu trữ trong một hệ quản trị cơ sở dữ liệu mã nguồn mở là Apache Derby (MySQL/Postgres/MariaDB cũng có thể được sử dụng).
Hive metastore có thể có nhiều schema (cơ sở dữ liệu), và mỗi schema (cơ sở dữ liệu) có thể chứa nhiều siêu dữ liệu bảng Hive.
Bảng Hive
Loại bảng Hive
Hive hỗ trợ hai loại bảng: Bảng Quản lý (Bảng Nội bộ) & Bảng Ngoại bộ
Bảng Quản lý (Bảng Nội bộ)
Bảng Quản lý: còn được gọi là bảng nội bộ, các bảng này quản lý cả dữ liệu và siêu dữ liệu trong thư mục kho lưu trữ mặc định của Hive (được chỉ định bởi hive.metastore.warehouse.dir).
Bảng Ngoại bộ
Bảng Ngoại bộ: các bảng này tham chiếu đến các tệp dữ liệu được lưu trữ bên ngoài Hive, thường là trong HDFS hoặc S3.
Vì các tệp dữ liệu không được quản lý bởi Hive, nên việc thay đổi hoặc xóa một bảng Hive ngoại bộ không xóa dữ liệu ở dạng dưới lying. Bạn có thể cần xóa dữ liệu từ vị trí HDSF hoặc S3 phía dưới.
Cách Tạo Bảng Hive
Bước 1: Tạo SparkSession với cấu hình Hive
pythonSao chép mãspark = SparkSession.builder \
.appName("Hive Table Example") \
.config("spark.sql.warehouse.dir", "/user/hive/warehouse") \
.enableHiveSupport() \
.getOrCreate()
Bước 2: Có hai phương pháp để tạo bảng Hive
Phương pháp 1: Tạo bảng Hive bằng cách sử dụng API DataFrame với write.saveAsTable
pythonSao chép mã# Bảng Quản lý (Bảng Nội bộ)
df.write \
.mode("overwrite") \
.option("database", "your_database_name") \
.partitionBy("partition_col1", "partition_col2") \
.saveAsTable("hive_table_name")
# Bảng Ngoại bộ
df.write \
.mode("overwrite") \
.option("database", "your_database_name") \
.option("path", "s3a://your_bucket_name/your_folder_path/your_external_table_name") \
.partitionBy("partition_col1", "partition_col2") \
.format("parquet") \
.saveAsTable("hive_table_name")
Phương pháp 2: Tạo Bảng Hive bằng cách sử dụng Truy vấn SQL với spark.sql
pythonSao chép mã# Bảng Quản lý (Bảng Nội bộ)
spark.sql("""
CREATE TABLE IF NOT EXISTS your_database_name.your_managed_table_name (
id INT, name STRING, age INT
)
PARTITIONED BY (country STRING, city STRING)
USING PARQUET
""")
# Bảng Ngoại bộ
spark.sql("""
CREATE TABLE IF NOT EXISTS your_database_name.your_external_table_name (
id INT, name STRING, age INT
)
PARTITIONED BY (country STRING, city STRING)
STORED AS PARQUET
LOCATION 'hdfs://your_hdfs_path/your_external_table_name/'
""")
Cách chèn dữ liệu vào Bảng Hive
Phương pháp 1: Ghi trực tiếp thông qua write.saveAsTable vào Bảng Hive
pythonSao chép mãdf.write \
.mode("overwrite") \
.partitionBy("partition_col1", "partition_col2") \
.format("parquet") \
.saveAsTable("your_database_name.your_hive_table_name")
Phương pháp 2: Ghi vào vị trí lưu trữ dưới lying & cập nhật lại siêu dữ liệu Hive
pythonSao chép mãtable_path = "s3a://your_bucket_name/your_folder_path/your_hive_table_name"
df.write \
.mode("overwrite") \
.partitionBy("partition_col1", "partition_col2") \
.parquet(table_path)
spark.sql("REFRESH TABLE your_database_name.your_hive_table_name")
spark.sql("MSCK REPAIR your_database_name.your_hive_table_name")
Cách Xem Chi Tiết Bảng Hive
Lấy thông tin chi tiết về bảng
pythonSao chép mãtable_metadata = spark.sql("DESCRIBE FORMATTED db.table_name")
table_metadata.show(truncate=False)
Lấy thông tin về phân vùng của bảng
pythonSao chép mãpartitions = spark.sql("SHOW PARTITIONS db.table_name")
partitions.show(truncate=False)
Đây là một cách sơ bộ để làm việc với Hive trong Spark. Có nhiều khía cạnh và tính năng hơn mà bạn có thể khám phá!
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Your article helped me a lot, is there any more related content? Thanks!
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your article helped me a lot, is there any more related content? Thanks!
Your article helped me a lot, is there any more related content? Thanks!
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://accounts.binance.com/ru-UA/register-person?ref=OMM3XK51
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your article helped me a lot, is there any more related content? Thanks! https://accounts.binance.com/register?ref=P9L9FQKY
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://accounts.binance.com/ur/register?ref=WTOZ531Y
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Your article helped me a lot, is there any more related content? Thanks!
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
покупка аккаунтов купить аккаунт
маркетплейс для реселлеров безопасная сделка аккаунтов
магазин аккаунтов маркетплейс для реселлеров
профиль с подписчиками заработок на аккаунтах
продажа аккаунтов купить аккаунт с прокачкой
площадка для продажи аккаунтов биржа аккаунтов
аккаунты с балансом покупка аккаунтов
продажа аккаунтов соцсетей маркетплейс аккаунтов
продажа аккаунтов соцсетей маркетплейс аккаунтов соцсетей
заработок на аккаунтах перепродажа аккаунтов
маркетплейс аккаунтов https://marketplace-akkauntov-top.ru/
маркетплейс аккаунтов соцсетей https://magazin-akkauntov-online.ru
маркетплейс аккаунтов перепродажа аккаунтов
платформа для покупки аккаунтов https://prodat-akkaunt-online.ru
купить аккаунт kupit-akkaunt-top.ru/
маркетплейс аккаунтов соцсетей магазин аккаунтов
Find Accounts for Sale Secure Account Sales
Accounts for Sale Database of Accounts for Sale
Account Trading Platform Account Catalog
Account Sale Ready-Made Accounts for Sale
Ready-Made Accounts for Sale Find Accounts for Sale
Find Accounts for Sale Database of Accounts for Sale
Buy Pre-made Account https://buyagedaccounts001.com
Ready-Made Accounts for Sale https://accountsmarketplaceonline.com/
Verified Accounts for Sale https://buyaccounts001.com
Sell accounts Account Buying Platform
account buying platform account exchange
ready-made accounts for sale account sale
account trading verified accounts for sale
find accounts for sale account trading platform
website for selling accounts account trading platform
account marketplace account selling service
account trading platform account buying service
account exchange sell account
database of accounts for sale account exchange service
account trading buy pre-made account
account acquisition account selling platform
secure account sales guaranteed accounts
buy pre-made account account market
guaranteed accounts accounts for sale
profitable account sales social media account marketplace
account buying service sell pre-made account
buy accounts secure account purchasing platform
account sale secure account purchasing platform
online account store account selling service
account store secure account purchasing platform
social media account marketplace account trading platform
account catalog account selling platform
sell account buy and sell accounts
database of accounts for sale account exchange
account exchange service https://top-social-accounts.org
buy accounts account exchange
account trading service https://accounts-offer.org
account selling service https://accounts-marketplace.xyz
marketplace for ready-made accounts buy accounts
account acquisition https://accounts-marketplace.live/
sell pre-made account https://social-accounts-marketplace.xyz
buy and sell accounts https://buy-accounts.space
secure account sales https://buy-accounts-shop.pro/
website for selling accounts account marketplace
sell pre-made account https://accounts-marketplace.online
accounts market https://social-accounts-marketplace.live
account buying service https://accounts-marketplace-best.pro
маркетплейс аккаунтов соцсетей https://akkaunty-na-prodazhu.pro/
магазин аккаунтов https://rynok-akkauntov.top
магазин аккаунтов kupit-akkaunt.xyz
маркетплейс аккаунтов https://akkaunt-magazin.online/
площадка для продажи аккаунтов https://akkaunty-market.live/
маркетплейс аккаунтов https://kupit-akkaunty-market.xyz
биржа аккаунтов маркетплейсов аккаунтов
биржа аккаунтов online-akkaunty-magazin.xyz
маркетплейс аккаунтов akkaunty-dlya-prodazhi.pro
биржа аккаунтов kupit-akkaunt.online
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
buy facebook profile buy facebook advertising
buy fb ad account https://buy-ad-accounts.click
buy aged facebook ads accounts https://buy-ad-account.top/
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
buy facebook advertising accounts https://buy-ads-account.click
buy fb account https://ad-account-buy.top
buy aged facebook ads account https://buy-ads-account.work
buy facebook profile buy facebook accounts
В этой информационной статье вы найдете интересное содержание, которое поможет вам расширить свои знания. Мы предлагаем увлекательный подход и уникальные взгляды на обсуждаемые темы, побуждая пользователей к активному мышлению и критическому анализу!
Получить дополнительные сведения – https://medalkoblog.ru/
buy facebook account https://buy-ad-account.click
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
buy facebook old accounts https://ad-accounts-for-sale.work
buy google ads invoice account buy google adwords accounts
adwords account for sale buy google adwords accounts
cheap facebook accounts https://buy-accounts.click/
buy google ads verified account https://ads-account-for-sale.top
buy google ads threshold account https://ads-account-buy.work
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
buy aged google ads accounts https://buy-ads-invoice-account.top/
buy google ads threshold accounts https://buy-account-ads.work
buy google ads agency account https://buy-ads-agency-account.top
buy google ads threshold accounts buy verified google ads accounts
Your article helped me a lot, is there any more related content? Thanks!
verified bm for sale buy fb business manager
sell google ads account https://buy-verified-ads-account.work/
verified bm for sale https://buy-bm-account.org/
facebook bm account buy https://buy-verified-business-manager-account.org
facebook verified business manager for sale https://buy-verified-business-manager.org/
buy business manager facebook https://buy-business-manager-acc.org
facebook verified business manager for sale buy bm facebook
facebook business manager buy https://buy-business-manager-verified.org
buy verified bm https://buy-bm.org/
facebook business manager account buy https://buy-business-manager-accounts.org/
buy verified business manager https://verified-business-manager-for-sale.org
tiktok agency account for sale https://buy-tiktok-ads-account.org
buy tiktok business account https://tiktok-ads-account-buy.org
tiktok ad accounts https://tiktok-ads-account-for-sale.org
tiktok agency account for sale https://tiktok-agency-account-for-sale.org
buy tiktok ads account https://buy-tiktok-ad-account.org
buy tiktok ads account https://buy-tiktok-ads-accounts.org
buy tiktok ads accounts https://tiktok-ads-agency-account.org
buy tiktok ads account https://buy-tiktok-business-account.org
tiktok agency account for sale https://buy-tiktok-ads.org