主頁 >  其他 > 實踐資料湖iceberg 第二十四課 iceberg元資料詳細決議

實踐資料湖iceberg 第二十四課 iceberg元資料詳細決議

2022-02-25 07:58:09 其他

系列文章目錄

實踐資料湖iceberg 第一課 入門
實踐資料湖iceberg 第二課 iceberg基于hadoop的底層資料格式
實踐資料湖iceberg 第三課 在sqlclient中,以sql方式從kafka讀資料到iceberg
實踐資料湖iceberg 第四課 在sqlclient中,以sql方式從kafka讀資料到iceberg(升級版本到flink1.12.7)
實踐資料湖iceberg 第五課 hive catalog特點
實踐資料湖iceberg 第六課 從kafka寫入到iceberg失敗問題 解決
實踐資料湖iceberg 第七課 實時寫入到iceberg
實踐資料湖iceberg 第八課 hive與iceberg集成
實踐資料湖iceberg 第九課 合并小檔案
實踐資料湖iceberg 第十課 快照洗掉
實踐資料湖iceberg 第十一課 測驗磁區表完整流程(造數、建表、合并、刪快照)
實踐資料湖iceberg 第十二課 catalog是什么
實踐資料湖iceberg 第十三課 metadata比資料檔案大很多倍的問題
實踐資料湖iceberg 第十四課 元資料合并(解決元資料隨時間增加而元資料膨脹的問題)
實踐資料湖iceberg 第十五課 spark安裝與集成iceberg(jersey包沖突)
實踐資料湖iceberg 第十六課 通過spark3打開iceberg的認知之門
實踐資料湖iceberg 第十七課 hadoop2.7,spark3 on yarn運行iceberg配置
實踐資料湖iceberg 第十八課 多種客戶端與iceberg互動啟動命令(常用命令)
實踐資料湖iceberg 第十九課 flink count iceberg,無結果問題
實踐資料湖iceberg 第二十課 flink + iceberg CDC場景(版本問題,測驗失敗)
實踐資料湖iceberg 第二十一課 flink1.13.5 + iceberg0.131 CDC(測驗成功INSERT,變更操作失敗)
實踐資料湖iceberg 第二十二課 flink1.13.5 + iceberg0.131 CDC(CRUD測驗成功)
實踐資料湖iceberg 第二十三課 flink-sql從checkpoint重啟
實踐資料湖iceberg 第二十四課 iceberg元資料詳細決議


3

文章目錄

  • 系列文章目錄
  • 前言
  • 一、元資料管理概要
    • 1.每次寫入都會成一個snapshot
    • 2 讀寫并發原理
    • 3 精準完善的元資料資訊:
  • 二、測驗CRUD在iceberg中是如何記錄的
  • 三、hdfs的影響
    • 1.create表
    • 2. insert
    • 3.再insert
    • 4.update
  • 四、元資料分析
    • 1.從簡單入手,看看看 version-hint.text
    • 2.metadata.json檔案分析
      • 2.1 v1.metadata.json (insert)
      • 2.2 v2.metadata.json (insert)
      • 2.3 v3.metadata.json (insert)
      • 2.4 v4.metadata.json (update)
      • 2.5 metadata.json特點總結
    • 3. snapshot檔案分析
      • 3.1 分析第一個快照
      • 3.2 分析第二個snapshot
      • 3.3 分析第三個快照(update)
  • 四、資料變更圖解
  • 總結


前言


一、元資料管理概要

1.每次寫入都會成一個snapshot

每次寫入都會成一個snapshot, 每個snapshot包含著一系列的檔案串列
在這里插入圖片描述

2 讀寫并發原理

基于MVCC(Multi Version Concurrency Control)的機制,默認讀取檔案會從最新的的版本, 每次寫入都會產生一個新的snapshot, 讀寫相互不干擾
在這里插入圖片描述

3 精準完善的元資料資訊:

在這里插入圖片描述
如上圖所示, snapshot資訊、manifest資訊以及檔案資訊, 一個snapshot包含一系列的manifest資訊, 每個manifest存盤了一系列的檔案串列

snapshot串列資訊:包含了詳細的manifest串列,產生snapshot的操作,以及詳細記錄數、檔案數、甚至任務資訊,充分考慮到了資料血緣的追蹤

manifest串列資訊:保存了每個manifest包含的磁區資訊

檔案串列資訊:保存了每個檔案欄位級別的統計資訊,以及磁區資訊

如此完善的統計資訊,利用查詢引擎層的條件下推,可以快速的過濾掉不必要檔案,提高查詢效率,熟悉了Iceberg 的機制,在寫入Iceberg 的表時按照需求以及欄位的分布,合理的寫入有序的資料,能夠達到非常好的過濾效果,

二、測驗CRUD在iceberg中是如何記錄的

CREATE TABLE local.db.table1 (id bigint, data string) USING iceberg;
INSERT INTO local.db.table1 VALUES (1, 'a'), (2, 'b'), (3, 'c');
INSERT INTO local.db.table1 VALUES (4, 'd'), (5, 'e'), (6, 'f');
update local.db.table1 set data='apple' where id=1;
delete from local.db.table1;

[root@hadoop103 spark-3.2.0-bin-hadoop2.7]# bin/spark-sql --packages org.apache.iceberg:iceberg-spark-runtime-3.2_2.12:0.13.1 --conf spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions --conf spark.sql.catalog.spark_catalog=org.apache.iceberg.spark.SparkSessionCatalog --conf spark.sql.catalog.spark_catalog.type=hive --conf spark.sql.catalog.local=org.apache.iceberg.spark.SparkCatalog --conf spark.sql.catalog.local.type=hadoop --conf spark.sql.catalog.local.warehouse=/tmp/iceberg/warehouse

三、hdfs的影響

1.create表

執行:

CREATE TABLE local.db.table1 (id bigint, data string) USING iceberg;

查hdfs檔案:

[root@hadoop103 spark-3.2.0-bin-hadoop2.7]# hadoop fs -ls -R  /tmp/iceberg/warehouse/db/table1   
drwxrwx---   - root supergroup          0 2022-02-23 17:44 /tmp/iceberg/warehouse/db/table1/metadata
-rw-r--r--   2 root supergroup       1169 2022-02-23 17:44 /tmp/iceberg/warehouse/db/table1/metadata/v1.metadata.json
-rw-r--r--   2 root supergroup          1 2022-02-23 17:44 /tmp/iceberg/warehouse/db/table1/metadata/version-hint.text

2. insert

INSERT INTO local.db.table1 VALUES (1, ‘a’), (2, ‘b’), (3, ‘c’);
查詢:

[root@hadoop103 spark-3.2.0-bin-hadoop2.7]# hadoop fs -ls -R  /tmp/iceberg/warehouse/db/table1   
drwxrwx---   - root supergroup          0 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/data
-rw-r--r--   2 root supergroup        643 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/data/00000-0-59d54827-c03f-47f6-a6a1-fc74e6861dcf-00001.parquet
-rw-r--r--   2 root supergroup        643 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/data/00001-1-3445ca12-3b21-4795-8fd7-5124ecc16c85-00001.parquet
-rw-r--r--   2 root supergroup        643 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/data/00002-2-6659369d-638d-432a-83e8-0da1b0abce4f-00001.parquet
drwxrwx---   - root supergroup          0 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/metadata
-rw-r--r--   2 root supergroup       5860 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/metadata/e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7-m0.avro
-rw-r--r--   2 root supergroup       3754 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/metadata/snap-1233304278810386445-1-e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7.avro
-rw-r--r--   2 root supergroup       1169 2022-02-23 17:44 /tmp/iceberg/warehouse/db/table1/metadata/v1.metadata.json
-rw-r--r--   2 root supergroup       2073 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/metadata/v2.metadata.json
-rw-r--r--   2 root supergroup          1 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/metadata/version-hint.text

生成了三個資料檔案,猜一下應該是spark的并行度是3

在這里插入圖片描述

3.再insert

[root@hadoop103 spark-3.2.0-bin-hadoop2.7]#  hadoop fs -ls -R  /tmp/iceberg/warehouse/db/table1   
drwxrwx---   - root supergroup          0 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/data
-rw-r--r--   2 root supergroup        643 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/data/00000-0-59d54827-c03f-47f6-a6a1-fc74e6861dcf-00001.parquet
-rw-r--r--   2 root supergroup        642 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/data/00000-3-746396e4-6e79-4609-9933-867d1af62900-00001.parquet
-rw-r--r--   2 root supergroup        643 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/data/00001-1-3445ca12-3b21-4795-8fd7-5124ecc16c85-00001.parquet
-rw-r--r--   2 root supergroup        643 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/data/00001-4-1a16a1dc-b8f8-4897-8e4b-d4482618f50a-00001.parquet
-rw-r--r--   2 root supergroup        643 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/data/00002-2-6659369d-638d-432a-83e8-0da1b0abce4f-00001.parquet
-rw-r--r--   2 root supergroup        643 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/data/00002-5-e444dccc-e722-4bd6-8271-66875ab8ce01-00001.parquet
drwxrwx---   - root supergroup          0 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/metadata
-rw-r--r--   2 root supergroup       5869 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/metadata/0336be7d-9a6c-45a9-af77-036cb4379b9a-m0.avro
-rw-r--r--   2 root supergroup       5860 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/metadata/e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7-m0.avro
-rw-r--r--   2 root supergroup       3754 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/metadata/snap-1233304278810386445-1-e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7.avro
-rw-r--r--   2 root supergroup       3827 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/metadata/snap-9179203419030846107-1-0336be7d-9a6c-45a9-af77-036cb4379b9a.avro
-rw-r--r--   2 root supergroup       1169 2022-02-23 17:44 /tmp/iceberg/warehouse/db/table1/metadata/v1.metadata.json
-rw-r--r--   2 root supergroup       2073 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/metadata/v2.metadata.json
-rw-r--r--   2 root supergroup       3011 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/metadata/v3.metadata.json
-rw-r--r--   2 root supergroup          1 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/metadata/version-hint.text

4.update

spark-sql (default)> select * from local.db.table1;
id      data
1       a
2       b
3       c
4       d
5       e
6       f
Time taken: 0.159 seconds, Fetched 6 row(s)
spark-sql (default)> update local.db.table1 set data='apple' where id=1;
Response code
Time taken: 2.394 seconds
spark-sql (default)> select * from local.db.table1;
id      data
1       apple
4       d
5       e
6       f
2       b
3       c
Time taken: 0.165 seconds, Fetched 6 row(s)

看日期,最新的時間,就是剛剛執行的效果,

[root@hadoop103 spark-3.2.0-bin-hadoop2.7]#   hadoop fs -ls -R  /tmp/iceberg/warehouse/db/table1   
drwxrwx---   - root supergroup          0 2022-02-23 17:50 /tmp/iceberg/warehouse/db/table1/data
-rw-r--r--   2 root supergroup        643 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/data/00000-0-59d54827-c03f-47f6-a6a1-fc74e6861dcf-00001.parquet
-rw-r--r--   2 root supergroup        642 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/data/00000-3-746396e4-6e79-4609-9933-867d1af62900-00001.parquet
-rw-r--r--   2 root supergroup        643 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/data/00001-1-3445ca12-3b21-4795-8fd7-5124ecc16c85-00001.parquet
-rw-r--r--   2 root supergroup        643 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/data/00001-4-1a16a1dc-b8f8-4897-8e4b-d4482618f50a-00001.parquet
-rw-r--r--   2 root supergroup        643 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/data/00002-2-6659369d-638d-432a-83e8-0da1b0abce4f-00001.parquet
-rw-r--r--   2 root supergroup        643 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/data/00002-5-e444dccc-e722-4bd6-8271-66875ab8ce01-00001.parquet
-rw-r--r--   2 root supergroup        686 2022-02-23 17:50 /tmp/iceberg/warehouse/db/table1/data/00112-11-2d333752-b387-43ff-ac6e-30fea75cb791-00001.parquet
drwxrwx---   - root supergroup          0 2022-02-23 17:50 /tmp/iceberg/warehouse/db/table1/metadata
-rw-r--r--   2 root supergroup       5869 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/metadata/0336be7d-9a6c-45a9-af77-036cb4379b9a-m0.avro
-rw-r--r--   2 root supergroup       5876 2022-02-23 17:50 /tmp/iceberg/warehouse/db/table1/metadata/c41a3e4d-1dae-4635-97af-fe57e2765335-m0.avro
-rw-r--r--   2 root supergroup       5780 2022-02-23 17:50 /tmp/iceberg/warehouse/db/table1/metadata/c41a3e4d-1dae-4635-97af-fe57e2765335-m1.avro
-rw-r--r--   2 root supergroup       5860 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/metadata/e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7-m0.avro
-rw-r--r--   2 root supergroup       3754 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/metadata/snap-1233304278810386445-1-e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7.avro
-rw-r--r--   2 root supergroup       3827 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/metadata/snap-9179203419030846107-1-0336be7d-9a6c-45a9-af77-036cb4379b9a.avro
-rw-r--r--   2 root supergroup       3848 2022-02-23 17:50 /tmp/iceberg/warehouse/db/table1/metadata/snap-941010551389488871-1-c41a3e4d-1dae-4635-97af-fe57e2765335.avro
-rw-r--r--   2 root supergroup       1169 2022-02-23 17:44 /tmp/iceberg/warehouse/db/table1/metadata/v1.metadata.json
-rw-r--r--   2 root supergroup       2073 2022-02-23 17:45 /tmp/iceberg/warehouse/db/table1/metadata/v2.metadata.json
-rw-r--r--   2 root supergroup       3011 2022-02-23 17:48 /tmp/iceberg/warehouse/db/table1/metadata/v3.metadata.json
-rw-r--r--   2 root supergroup       4048 2022-02-23 17:50 /tmp/iceberg/warehouse/db/table1/metadata/v4.metadata.json
-rw-r--r--   2 root supergroup          1 2022-02-23 17:50 /tmp/iceberg/warehouse/db/table1/metadata/version-hint.text

四、元資料分析

1.從簡單入手,看看看 version-hint.text

每次修改時,version-hint.text的日期都變更,

[root@hadoop103 spark-3.2.0-bin-hadoop2.7]# hadoop fs -cat /tmp/iceberg/warehouse/db/table1/metadata/version-hint.text
4[root@hadoop103 spark-3.2.0-bin-hadoop2.7]# 

結合version-hint的名字, 猜一下就知道是獲取當前是第幾個版本

2.metadata.json檔案分析

2.1 v1.metadata.json (insert)

建表的元資訊

[root@hadoop103 spark-3.2.0-bin-hadoop2.7]# hadoop fs -text /tmp/iceberg/warehouse/db/table1/metadata/v1.metadata.json
{
  "format-version" : 1,
  "table-uuid" : "756090df-d197-4881-9d8d-aea0b9354077",
  "location" : "/tmp/iceberg/warehouse/db/table1",
  "last-updated-ms" : 1645609485795,
  "last-column-id" : 2,
  "schema" : {
    "type" : "struct",
    "schema-id" : 0,
    "fields" : [ {
      "id" : 1,
      "name" : "id",
      "required" : false,
      "type" : "long"
    }, {
      "id" : 2,
      "name" : "data",
      "required" : false,
      "type" : "string"
    } ]
  },
  "current-schema-id" : 0,
  "schemas" : [ {
    "type" : "struct",
    "schema-id" : 0,
    "fields" : [ {
      "id" : 1,
      "name" : "id",
      "required" : false,
      "type" : "long"
    }, {
      "id" : 2,
      "name" : "data",
      "required" : false,
      "type" : "string"
    } ]
  } ],
  "partition-spec" : [ ],
  "default-spec-id" : 0,
  "partition-specs" : [ {
    "spec-id" : 0,
    "fields" : [ ]
  } ],
  "last-partition-id" : 999,
  "default-sort-order-id" : 0,
  "sort-orders" : [ {
    "order-id" : 0,
    "fields" : [ ]
  } ],
  "properties" : {
    "owner" : "root"
  },
  "current-snapshot-id" : -1,
  "snapshots" : [ ],
  "snapshot-log" : [ ],
  "metadata-log" : [ ]

2.2 v2.metadata.json (insert)

這個檔案:manifest-list, snapshot-log,metadata-log 都有資料了

[root@hadoop103 spark-3.2.0-bin-hadoop2.7]#  hadoop fs -text /tmp/iceberg/warehouse/db/table1/metadata/v2.metadata.json
{
  "format-version" : 1,
  "table-uuid" : "756090df-d197-4881-9d8d-aea0b9354077",
  "location" : "/tmp/iceberg/warehouse/db/table1",
  "last-updated-ms" : 1645609519412,
  "last-column-id" : 2,
  "schema" : {
    "type" : "struct",
    "schema-id" : 0,
    "fields" : [ {
      "id" : 1,
      "name" : "id",
      "required" : false,
      "type" : "long"
    }, {
      "id" : 2,
      "name" : "data",
      "required" : false,
      "type" : "string"
    } ]
  },
  "current-schema-id" : 0,
  "schemas" : [ {
    "type" : "struct",
    "schema-id" : 0,
    "fields" : [ {
      "id" : 1,
      "name" : "id",
      "required" : false,
      "type" : "long"
    }, {
      "id" : 2,
      "name" : "data",
      "required" : false,
      "type" : "string"
    } ]
  } ],
  "partition-spec" : [ ],
  "default-spec-id" : 0,
  "partition-specs" : [ {
    "spec-id" : 0,
    "fields" : [ ]
  } ],
  "last-partition-id" : 999,
  "default-sort-order-id" : 0,
  "sort-orders" : [ {
    "order-id" : 0,
    "fields" : [ ]
  } ],
  "properties" : {
    "owner" : "root"
  },
  "current-snapshot-id" : 1233304278810386445,
  "snapshots" : [ {
    "snapshot-id" : 1233304278810386445,
    "timestamp-ms" : 1645609519412,
    "summary" : {
      "operation" : "append",
      "spark.app.id" : "local-1645609363060",
      "added-data-files" : "3",
      "added-records" : "3",
      "added-files-size" : "1929",
      "changed-partition-count" : "1",
      "total-records" : "3",
      "total-files-size" : "1929",
      "total-data-files" : "3",
      "total-delete-files" : "0",
      "total-position-deletes" : "0",
      "total-equality-deletes" : "0"
    },
    "manifest-list" : "/tmp/iceberg/warehouse/db/table1/metadata/snap-1233304278810386445-1-e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7.avro",
    "schema-id" : 0
  } ],
  "snapshot-log" : [ {
    "timestamp-ms" : 1645609519412,
    "snapshot-id" : 1233304278810386445
  } ],
  "metadata-log" : [ {
    "timestamp-ms" : 1645609485795,
    "metadata-file" : "/tmp/iceberg/warehouse/db/table1/metadata/v1.metadata.json"
  } ]
}

2.3 v3.metadata.json (insert)

[root@hadoop103 spark-3.2.0-bin-hadoop2.7]# hadoop fs -text /tmp/iceberg/warehouse/db/table1/metadata/v3.metadata.json
{
  "format-version" : 1,
  "table-uuid" : "756090df-d197-4881-9d8d-aea0b9354077",
  "location" : "/tmp/iceberg/warehouse/db/table1",
  "last-updated-ms" : 1645609708761,
  "last-column-id" : 2,
  "schema" : {
    "type" : "struct",
    "schema-id" : 0,
    "fields" : [ {
      "id" : 1,
      "name" : "id",
      "required" : false,
      "type" : "long"
    }, {
      "id" : 2,
      "name" : "data",
      "required" : false,
      "type" : "string"
    } ]
  },
  "current-schema-id" : 0,
  "schemas" : [ {
    "type" : "struct",
    "schema-id" : 0,
    "fields" : [ {
      "id" : 1,
      "name" : "id",
      "required" : false,
      "type" : "long"
    }, {
      "id" : 2,
      "name" : "data",
      "required" : false,
      "type" : "string"
    } ]
  } ],
  "partition-spec" : [ ],
  "default-spec-id" : 0,
  "partition-specs" : [ {
    "spec-id" : 0,
    "fields" : [ ]
  } ],
  "last-partition-id" : 999,
  "default-sort-order-id" : 0,
  "sort-orders" : [ {
    "order-id" : 0,
    "fields" : [ ]
  } ],
  "properties" : {
    "owner" : "root"
  },
  "current-snapshot-id" : 9179203419030846107,
  "snapshots" : [ {
    "snapshot-id" : 1233304278810386445,
    "timestamp-ms" : 1645609519412,
    "summary" : {
      "operation" : "append",
      "spark.app.id" : "local-1645609363060",
      "added-data-files" : "3",
      "added-records" : "3",
      "added-files-size" : "1929",
      "changed-partition-count" : "1",
      "total-records" : "3",
      "total-files-size" : "1929",
      "total-data-files" : "3",
      "total-delete-files" : "0",
      "total-position-deletes" : "0",
      "total-equality-deletes" : "0"
    },
    "manifest-list" : "/tmp/iceberg/warehouse/db/table1/metadata/snap-1233304278810386445-1-e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7.avro",
    "schema-id" : 0
  }, {
    "snapshot-id" : 9179203419030846107,
    "parent-snapshot-id" : 1233304278810386445,
    "timestamp-ms" : 1645609708761,
    "summary" : {
      "operation" : "append",
      "spark.app.id" : "local-1645609363060",
      "added-data-files" : "3",
      "added-records" : "3",
      "added-files-size" : "1928",
      "changed-partition-count" : "1",
      "total-records" : "6",
      "total-files-size" : "3857",
      "total-data-files" : "6",
      "total-delete-files" : "0",
      "total-position-deletes" : "0",
      "total-equality-deletes" : "0"
    },
    "manifest-list" : "/tmp/iceberg/warehouse/db/table1/metadata/snap-9179203419030846107-1-0336be7d-9a6c-45a9-af77-036cb4379b9a.avro",
    "schema-id" : 0
  } ],
  "snapshot-log" : [ {
    "timestamp-ms" : 1645609519412,
    "snapshot-id" : 1233304278810386445
  }, {
    "timestamp-ms" : 1645609708761,
    "snapshot-id" : 9179203419030846107
  } ],
  "metadata-log" : [ {
    "timestamp-ms" : 1645609485795,
    "metadata-file" : "/tmp/iceberg/warehouse/db/table1/metadata/v1.metadata.json"
  }, {
    "timestamp-ms" : 1645609519412,
    "metadata-file" : "/tmp/iceberg/warehouse/db/table1/metadata/v2.metadata.json"
  } ]
}

2.4 v4.metadata.json (update)

[root@hadoop103 spark-3.2.0-bin-hadoop2.7]# hadoop fs -text /tmp/iceberg/warehouse/db/table1/metadata/v4.metadata.json
{
  "format-version" : 1,
  "table-uuid" : "756090df-d197-4881-9d8d-aea0b9354077",
  "location" : "/tmp/iceberg/warehouse/db/table1",
  "last-updated-ms" : 1645609828216,
  "last-column-id" : 2,
  "schema" : {
    "type" : "struct",
    "schema-id" : 0,
    "fields" : [ {
      "id" : 1,
      "name" : "id",
      "required" : false,
      "type" : "long"
    }, {
      "id" : 2,
      "name" : "data",
      "required" : false,
      "type" : "string"
    } ]
  },
  "current-schema-id" : 0,
  "schemas" : [ {
    "type" : "struct",
    "schema-id" : 0,
    "fields" : [ {
      "id" : 1,
      "name" : "id",
      "required" : false,
      "type" : "long"
    }, {
      "id" : 2,
      "name" : "data",
      "required" : false,
      "type" : "string"
    } ]
  } ],
  "partition-spec" : [ ],
  "default-spec-id" : 0,
  "partition-specs" : [ {
    "spec-id" : 0,
    "fields" : [ ]
  } ],
  "last-partition-id" : 999,
  "default-sort-order-id" : 0,
  "sort-orders" : [ {
    "order-id" : 0,
    "fields" : [ ]
  } ],
  "properties" : {
    "owner" : "root"
  },
  "current-snapshot-id" : 941010551389488871,
  "snapshots" : [ {
    "snapshot-id" : 1233304278810386445,
    "timestamp-ms" : 1645609519412,
    "summary" : {
      "operation" : "append",
      "spark.app.id" : "local-1645609363060",
      "added-data-files" : "3",
      "added-records" : "3",
      "added-files-size" : "1929",
      "changed-partition-count" : "1",
      "total-records" : "3",
      "total-files-size" : "1929",
      "total-data-files" : "3",
      "total-delete-files" : "0",
      "total-position-deletes" : "0",
      "total-equality-deletes" : "0"
    },
    "manifest-list" : "/tmp/iceberg/warehouse/db/table1/metadata/snap-1233304278810386445-1-e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7.avro",
    "schema-id" : 0
  }, {
    "snapshot-id" : 9179203419030846107,
    "parent-snapshot-id" : 1233304278810386445,
    "timestamp-ms" : 1645609708761,
    "summary" : {
      "operation" : "append",
      "spark.app.id" : "local-1645609363060",
      "added-data-files" : "3",
      "added-records" : "3",
      "added-files-size" : "1928",
      "changed-partition-count" : "1",
      "total-records" : "6",
      "total-files-size" : "3857",
      "total-data-files" : "6",
      "total-delete-files" : "0",
      "total-position-deletes" : "0",
      "total-equality-deletes" : "0"
    },
    "manifest-list" : "/tmp/iceberg/warehouse/db/table1/metadata/snap-9179203419030846107-1-0336be7d-9a6c-45a9-af77-036cb4379b9a.avro",
    "schema-id" : 0
  }, {
    "snapshot-id" : 941010551389488871,
    "parent-snapshot-id" : 9179203419030846107,
    "timestamp-ms" : 1645609828216,
    "summary" : {
      "operation" : "overwrite",
      "spark.app.id" : "local-1645609363060",
      "added-data-files" : "1",
      "deleted-data-files" : "1",
      "added-records" : "1",
      "deleted-records" : "1",
      "added-files-size" : "686",
      "removed-files-size" : "643",
      "changed-partition-count" : "1",
      "total-records" : "6",
      "total-files-size" : "3900",
      "total-data-files" : "6",
      "total-delete-files" : "0",
      "total-position-deletes" : "0",
      "total-equality-deletes" : "0"
    },
    "manifest-list" : "/tmp/iceberg/warehouse/db/table1/metadata/snap-941010551389488871-1-c41a3e4d-1dae-4635-97af-fe57e2765335.avro",
    "schema-id" : 0
  } ],
  "snapshot-log" : [ {
    "timestamp-ms" : 1645609519412,
    "snapshot-id" : 1233304278810386445
  }, {
    "timestamp-ms" : 1645609708761,
    "snapshot-id" : 9179203419030846107
  }, {
    "timestamp-ms" : 1645609828216,
    "snapshot-id" : 941010551389488871
  } ],
  "metadata-log" : [ {
    "timestamp-ms" : 1645609485795,
    "metadata-file" : "/tmp/iceberg/warehouse/db/table1/metadata/v1.metadata.json"
  }, {
    "timestamp-ms" : 1645609519412,
    "metadata-file" : "/tmp/iceberg/warehouse/db/table1/metadata/v2.metadata.json"
  }, {
    "timestamp-ms" : 1645609708761,
    "metadata-file" : "/tmp/iceberg/warehouse/db/table1/metadata/v3.metadata.json"
  } ]
}

2.5 metadata.json特點總結

  • 新的metadata.json包含前面修改的全部資訊
  • table1.snapshots 查的就是metadata檔案
spark-sql (default)> select * from local.db.table1.snapshots;
committed_at    snapshot_id     parent_id       operation       manifest_list   summary
2022-02-23 17:45:19.412 1233304278810386445     NULL    append  /tmp/iceberg/warehouse/db/table1/metadata/snap-1233304278810386445-1-e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7.avro  {"added-data-files":"3","added-files-size":"1929","added-records":"3","changed-partition-count":"1","spark.app.id":"local-1645609363060","total-data-files":"3","total-delete-files":"0","total-equality-deletes":"0","total-files-size":"1929","total-position-deletes":"0","total-records":"3"}
2022-02-23 17:48:28.761 9179203419030846107     1233304278810386445     append  /tmp/iceberg/warehouse/db/table1/metadata/snap-9179203419030846107-1-0336be7d-9a6c-45a9-af77-036cb4379b9a.avro  {"added-data-files":"3","added-files-size":"1928","added-records":"3","changed-partition-count":"1","spark.app.id":"local-1645609363060","total-data-files":"6","total-delete-files":"0","total-equality-deletes":"0","total-files-size":"3857","total-position-deletes":"0","total-records":"6"}
2022-02-23 17:50:28.216 941010551389488871      9179203419030846107     overwrite       /tmp/iceberg/warehouse/db/table1/metadata/snap-941010551389488871-1-c41a3e4d-1dae-4635-97af-fe57e2765335.avro   {"added-data-files":"1","added-files-size":"686","added-records":"1","changed-partition-count":"1","deleted-data-files":"1","deleted-records":"1","removed-files-size":"643","spark.app.id":"local-1645609363060","total-data-files":"6","total-delete-files":"0","total-equality-deletes":"0","total-files-size":"3900","total-position-deletes":"0","total-records":"6"}
Time taken: 0.179 seconds, Fetched 3 row(s)

3. snapshot檔案分析

3.1 分析第一個快照

把表檔案down會本地
[root@hadoop101 software]# hadoop fs -get /tmp/iceberg/warehouse/db/table1 .
分析第一個 snap

[root@hadoop101 metadata]# java -jar /opt/software/avro-tools-1.11.0.jar  tojson --pretty  snap-1233304278810386445-1-e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7.avro 
22/02/23 20:09:11 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
{
  "manifest_path" : "/tmp/iceberg/warehouse/db/table1/metadata/e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7-m0.avro",
  "manifest_length" : 5860,
  "partition_spec_id" : 0,
  "added_snapshot_id" : {
    "long" : 1233304278810386445
  },
  "added_data_files_count" : {
    "int" : 3
  },
  "existing_data_files_count" : {
    "int" : 0
  },
  "deleted_data_files_count" : {
    "int" : 0
  },
  "partitions" : {
    "array" : [ ]
  },
  "added_rows_count" : {
    "long" : 3
  },
  "existing_rows_count" : {
    "long" : 0
  },
  "deleted_rows_count" : {
    "long" : 0
  }
}

分析這個manifest檔案
“manifest_path” : “/tmp/iceberg/warehouse/db/table1/metadata/e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7-m0.avro”,

[root@hadoop101 metadata]# java -jar /opt/software/avro-tools-1.11.0.jar  tojson --pretty  e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7-m0.avro
22/02/23 20:12:15 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
{
  "status" : 1,
  "snapshot_id" : {
    "long" : 1233304278810386445
  },
  "data_file" : {
    "file_path" : "/tmp/iceberg/warehouse/db/table1/data/00000-0-59d54827-c03f-47f6-a6a1-fc74e6861dcf-00001.parquet",
    "file_format" : "PARQUET",
    "partition" : { },
    "record_count" : 1,
    "file_size_in_bytes" : 643,
    "block_size_in_bytes" : 67108864,
    "column_sizes" : {
      "array" : [ {
        "key" : 1,
        "value" : 46
      }, {
        "key" : 2,
        "value" : 48
      } ]
    },
    "value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 1
      }, {
        "key" : 2,
        "value" : 1
      } ]
    },
    "null_value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 0
      }, {
        "key" : 2,
        "value" : 0
      } ]
    },
    "nan_value_counts" : {
      "array" : [ ]
    },
    "lower_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "a"
      } ]
    },
    "upper_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "a"
      } ]
    },
    "key_metadata" : null,
    "split_offsets" : {
      "array" : [ 4 ]
    },
    "sort_order_id" : {
      "int" : 0
    }
  }
}
{
  "status" : 1,
  "snapshot_id" : {
    "long" : 1233304278810386445
  },
  "data_file" : {
    "file_path" : "/tmp/iceberg/warehouse/db/table1/data/00001-1-3445ca12-3b21-4795-8fd7-5124ecc16c85-00001.parquet",
    "file_format" : "PARQUET",
    "partition" : { },
    "record_count" : 1,
    "file_size_in_bytes" : 643,
    "block_size_in_bytes" : 67108864,
    "column_sizes" : {
      "array" : [ {
        "key" : 1,
        "value" : 46
      }, {
        "key" : 2,
        "value" : 48
      } ]
    },
    "value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 1
      }, {
        "key" : 2,
        "value" : 1
      } ]
    },
    "null_value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 0
      }, {
        "key" : 2,
        "value" : 0
      } ]
    },
    "nan_value_counts" : {
      "array" : [ ]
    },
    "lower_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "b"
      } ]
    },
    "upper_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "b"
      } ]
    },
    "key_metadata" : null,
    "split_offsets" : {
      "array" : [ 4 ]
    },
    "sort_order_id" : {
      "int" : 0
    }
  }
}
{
  "status" : 1,
  "snapshot_id" : {
    "long" : 1233304278810386445
  },
  "data_file" : {
    "file_path" : "/tmp/iceberg/warehouse/db/table1/data/00002-2-6659369d-638d-432a-83e8-0da1b0abce4f-00001.parquet",
    "file_format" : "PARQUET",
    "partition" : { },
    "record_count" : 1,
    "file_size_in_bytes" : 643,
    "block_size_in_bytes" : 67108864,
    "column_sizes" : {
      "array" : [ {
        "key" : 1,
        "value" : 46
      }, {
        "key" : 2,
        "value" : 48
      } ]
    },
    "value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 1
      }, {
        "key" : 2,
        "value" : 1
      } ]
    },
    "null_value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 0
      }, {
        "key" : 2,
        "value" : 0
      } ]
    },
    "nan_value_counts" : {
      "array" : [ ]
    },
    "lower_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0003\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "c"
      } ]
    },
    "upper_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0003\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "c"
      } ]
    },
    "key_metadata" : null,
    "split_offsets" : {
      "array" : [ 4 ]
    },
    "sort_order_id" : {
      "int" : 0
    }
  }
}

提到的這個三個data檔案,去查一下:

/tmp/iceberg/warehouse/db/table1/data/00000-0-59d54827-c03f-47f6-a6a1-fc74e6861dcf-00001.parquet
/tmp/iceberg/warehouse/db/table1/data/00001-1-3445ca12-3b21-4795-8fd7-5124ecc16c85-00001.parquet
/tmp/iceberg/warehouse/db/table1/data/00002-2-6659369d-638d-432a-83e8-0da1b0abce4f-00001.parquet


scala> spark.read.parquet("/tmp/iceberg/warehouse/db/table1/data/00000-0-59d54827-c03f-47f6-a6a1-fc74e6861dcf-00001.parquet").show
+---+----+                                                                      
| id|data|
+---+----+
|  1|   a|
+---+----+

scala> spark.read.parquet("/tmp/iceberg/warehouse/db/table1/data/00001-1-3445ca12-3b21-4795-8fd7-5124ecc16c85-00001.parquet").show
+---+----+
| id|data|
+---+----+
|  2|   b|
+---+----+

scala> spark.read.parquet("/tmp/iceberg/warehouse/db/table1/data/00002-2-6659369d-638d-432a-83e8-0da1b0abce4f-00001.parquet").show
+---+----+
| id|data|
+---+----+
|  3|   c|
+---+----+

其實記錄有哪幾個資料檔案,以及他們的位置,

3.2 分析第二個snapshot

查內容:
發現:它存盤了所有snapshot資訊(目前是2個),

[root@hadoop101 metadata]# java -jar /opt/software/avro-tools-1.11.0.jar  tojson --pretty   snap-9179203419030846107-1-0336be7d-9a6c-45a9-af77-036cb4379b9a.avro
22/02/23 20:24:42 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
{
  "manifest_path" : "/tmp/iceberg/warehouse/db/table1/metadata/0336be7d-9a6c-45a9-af77-036cb4379b9a-m0.avro",
  "manifest_length" : 5869,
  "partition_spec_id" : 0,
  "added_snapshot_id" : {
    "long" : 9179203419030846107
  },
  "added_data_files_count" : {
    "int" : 3
  },
  "existing_data_files_count" : {
    "int" : 0
  },
  "deleted_data_files_count" : {
    "int" : 0
  },
  "partitions" : {
    "array" : [ ]
  },
  "added_rows_count" : {
    "long" : 3
  },
  "existing_rows_count" : {
    "long" : 0
  },
  "deleted_rows_count" : {
    "long" : 0
  }
}
{
  "manifest_path" : "/tmp/iceberg/warehouse/db/table1/metadata/e66a1dcc-15bd-43d8-bba2-5b8a5b2726a7-m0.avro",
  "manifest_length" : 5860,
  "partition_spec_id" : 0,
  "added_snapshot_id" : {
    "long" : 1233304278810386445
  },
  "added_data_files_count" : {
    "int" : 3
  },
  "existing_data_files_count" : {
    "int" : 0
  },
  "deleted_data_files_count" : {
    "int" : 0
  },
  "partitions" : {
    "array" : [ ]
  },
  "added_rows_count" : {
    "long" : 3
  },
  "existing_rows_count" : {
    "long" : 0
  },
  "deleted_rows_count" : {
    "long" : 0
  }
}

查本manifest檔案的內容

[root@hadoop101 metadata]# java -jar /opt/software/avro-tools-1.11.0.jar  tojson --pretty  0336be7d-9a6c-45a9-af77-036cb4379b9a-m0.avro
22/02/23 20:29:50 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
{
  "status" : 1,
  "snapshot_id" : {
    "long" : 9179203419030846107
  },
  "data_file" : {
    "file_path" : "/tmp/iceberg/warehouse/db/table1/data/00000-3-746396e4-6e79-4609-9933-867d1af62900-00001.parquet",
    "file_format" : "PARQUET",
    "partition" : { },
    "record_count" : 1,
    "file_size_in_bytes" : 642,
    "block_size_in_bytes" : 67108864,
    "column_sizes" : {
      "array" : [ {
        "key" : 1,
        "value" : 45
      }, {
        "key" : 2,
        "value" : 48
      } ]
    },
    "value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 1
      }, {
        "key" : 2,
        "value" : 1
      } ]
    },
    "null_value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 0
      }, {
        "key" : 2,
        "value" : 0
      } ]
    },
    "nan_value_counts" : {
      "array" : [ ]
    },
    "lower_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0004\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "d"
      } ]
    },
    "upper_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0004\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "d"
      } ]
    },
    "key_metadata" : null,
    "split_offsets" : {
      "array" : [ 4 ]
    },
    "sort_order_id" : {
      "int" : 0
    }
  }
}
{
  "status" : 1,
  "snapshot_id" : {
    "long" : 9179203419030846107
  },
  "data_file" : {
    "file_path" : "/tmp/iceberg/warehouse/db/table1/data/00001-4-1a16a1dc-b8f8-4897-8e4b-d4482618f50a-00001.parquet",
    "file_format" : "PARQUET",
    "partition" : { },
    "record_count" : 1,
    "file_size_in_bytes" : 643,
    "block_size_in_bytes" : 67108864,
    "column_sizes" : {
      "array" : [ {
        "key" : 1,
        "value" : 46
      }, {
        "key" : 2,
        "value" : 48
      } ]
    },
    "value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 1
      }, {
        "key" : 2,
        "value" : 1
      } ]
    },
    "null_value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 0
      }, {
        "key" : 2,
        "value" : 0
      } ]
    },
    "nan_value_counts" : {
      "array" : [ ]
    },
    "lower_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0005\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "e"
      } ]
    },
    "upper_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0005\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "e"
      } ]
    },
    "key_metadata" : null,
    "split_offsets" : {
      "array" : [ 4 ]
    },
    "sort_order_id" : {
      "int" : 0
    }
  }
}
{
  "status" : 1,
  "snapshot_id" : {
    "long" : 9179203419030846107
  },
  "data_file" : {
    "file_path" : "/tmp/iceberg/warehouse/db/table1/data/00002-5-e444dccc-e722-4bd6-8271-66875ab8ce01-00001.parquet",
    "file_format" : "PARQUET",
    "partition" : { },
    "record_count" : 1,
    "file_size_in_bytes" : 643,
    "block_size_in_bytes" : 67108864,
    "column_sizes" : {
      "array" : [ {
        "key" : 1,
        "value" : 46
      }, {
        "key" : 2,
        "value" : 48
      } ]
    },
    "value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 1
      }, {
        "key" : 2,
        "value" : 1
      } ]
    },
    "null_value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 0
      }, {
        "key" : 2,
        "value" : 0
      } ]
    },
    "nan_value_counts" : {
      "array" : [ ]
    },
    "lower_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0006\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "f"
      } ]
    },
    "upper_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0006\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "f"
      } ]
    },
    "key_metadata" : null,
    "split_offsets" : {
      "array" : [ 4 ]
    },
    "sort_order_id" : {
      "int" : 0
    }
  }
}

資料檔案對應的內容:

scala> spark.read.parquet("/tmp/iceberg/warehouse/db/table1/data/00000-3-746396e4-6e79-4609-9933-867d1af62900-00001.parquet").show
+---+----+                                                                      
| id|data|
+---+----+
|  4|   d|
+---+----+


scala> spark.read.parquet("/tmp/iceberg/warehouse/db/table1/data/00001-4-1a16a1dc-b8f8-4897-8e4b-d4482618f50a-00001.parquet").show
+---+----+
| id|data|
+---+----+
|  5|   e|
+---+----+


scala> spark.read.parquet("/tmp/iceberg/warehouse/db/table1/data/00002-5-e444dccc-e722-4bd6-8271-66875ab8ce01-00001.parquet").show
+---+----+
| id|data|
+---+----+
|  6|   f|
+---+----+

3.3 分析第三個快照(update)

分析發現:包含三個快照的內容,也就可以推出,這個檔案是存盤所有快照資訊的元資料
update分為delete和insert,觀察snap檔案如何記錄

記錄洗掉:/tmp/iceberg/warehouse/db/table1/metadata/c41a3e4d-1dae-4635-97af-fe57e2765335-m0.avro
記錄新增:/tmp/iceberg/warehouse/db/table1/metadata/c41a3e4d-1dae-4635-97af-fe57e2765335-m1.avro
上一個snapshot的manifest: /tmp/iceberg/warehouse/db/table1/metadata/0336be7d-9a6c-45a9-af77-036cb4379b9a-m0.avro

[root@hadoop101 metadata]# java -jar /opt/software/avro-tools-1.11.0.jar  tojson --pretty snap-941010551389488871-1-c41a3e4d-1dae-4635-97af-fe57e2765335.avro
22/02/23 20:35:28 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
{
  "manifest_path" : "/tmp/iceberg/warehouse/db/table1/metadata/c41a3e4d-1dae-4635-97af-fe57e2765335-m1.avro",
  "manifest_length" : 5780,
  "partition_spec_id" : 0,
  "added_snapshot_id" : {
    "long" : 941010551389488871
  },
  "added_data_files_count" : {
    "int" : 1
  },
  "existing_data_files_count" : {
    "int" : 0
  },
  "deleted_data_files_count" : {
    "int" : 0
  },
  "partitions" : {
    "array" : [ ]
  },
  "added_rows_count" : {
    "long" : 1
  },
  "existing_rows_count" : {
    "long" : 0
  },
  "deleted_rows_count" : {
    "long" : 0
  }
}
{
  "manifest_path" : "/tmp/iceberg/warehouse/db/table1/metadata/0336be7d-9a6c-45a9-af77-036cb4379b9a-m0.avro",
  "manifest_length" : 5869,
  "partition_spec_id" : 0,
  "added_snapshot_id" : {
    "long" : 9179203419030846107
  },
  "added_data_files_count" : {
    "int" : 3
  },
  "existing_data_files_count" : {
    "int" : 0
  },
  "deleted_data_files_count" : {
    "int" : 0
  },
  "partitions" : {
    "array" : [ ]
  },
  "added_rows_count" : {
    "long" : 3
  },
  "existing_rows_count" : {
    "long" : 0
  },
  "deleted_rows_count" : {
    "long" : 0
  }
}
{
  "manifest_path" : "/tmp/iceberg/warehouse/db/table1/metadata/c41a3e4d-1dae-4635-97af-fe57e2765335-m0.avro",
  "manifest_length" : 5876,
  "partition_spec_id" : 0,
  "added_snapshot_id" : {
    "long" : 941010551389488871
  },
  "added_data_files_count" : {
    "int" : 0
  },
  "existing_data_files_count" : {
    "int" : 2
  },
  "deleted_data_files_count" : {
    "int" : 1
  },
  "partitions" : {
    "array" : [ ]
  },
  "added_rows_count" : {
    "long" : 0
  },
  "existing_rows_count" : {
    "long" : 2
  },
  "deleted_rows_count" : {
    "long" : 1
  }
}

manifest內容:

[root@hadoop101 metadata]# java -jar /opt/software/avro-tools-1.11.0.jar  tojson --pretty  c41a3e4d-1dae-4635-97af-fe57e2765335-m1.avro
22/02/23 20:37:36 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
{
  "status" : 1,
  "snapshot_id" : {
    "long" : 941010551389488871
  },
  "data_file" : {
    "file_path" : "/tmp/iceberg/warehouse/db/table1/data/00112-11-2d333752-b387-43ff-ac6e-30fea75cb791-00001.parquet",
    "file_format" : "PARQUET",
    "partition" : { },
    "record_count" : 1,
    "file_size_in_bytes" : 686,
    "block_size_in_bytes" : 67108864,
    "column_sizes" : {
      "array" : [ {
        "key" : 1,
        "value" : 52
      }, {
        "key" : 2,
        "value" : 56
      } ]
    },
    "value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 1
      }, {
        "key" : 2,
        "value" : 1
      } ]
    },
    "null_value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 0
      }, {
        "key" : 2,
        "value" : 0
      } ]
    },
    "nan_value_counts" : {
      "array" : [ ]
    },
    "lower_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "apple"
      } ]
    },
    "upper_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "apple"
      } ]
    },
    "key_metadata" : null,
    "split_offsets" : {
      "array" : [ 4 ]
    },
    "sort_order_id" : {
      "int" : 0
    }
  }
}

資料檔案內容(update操作: 把id=1改為 apple)

scala> spark.read.parquet("/tmp/iceberg/warehouse/db/table1/data/00112-11-2d333752-b387-43ff-ac6e-30fea75cb791-00001.parquet").show
+---+-----+                                                                     
| id| data|
+---+-----+
|  1|apple|
+---+-----+

哪還有個delete操作,回去看看delete是怎樣存盤的
原來在snap檔案中,記錄各個manifest_path,manaifest檔案增加,洗掉的資訊,
c41a3e4d-1dae-4635-97af-fe57e2765335-m0.avro
“deleted_rows_count” : {
“long” : 1
}
但洗掉具體哪一行,是怎樣記錄呢?
查一下這個檔案內容:

[root@hadoop101 metadata]#   java -jar /opt/software/avro-tools-1.11.0.jar  tojson --pretty   c41a3e4d-1dae-4635-97af-fe57e2765335-m0.avro 
22/02/24 10:37:36 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
{
  "status" : 2,
  "snapshot_id" : {
    "long" : 941010551389488871
  },
  "data_file" : {
    "file_path" : "/tmp/iceberg/warehouse/db/table1/data/00000-0-59d54827-c03f-47f6-a6a1-fc74e6861dcf-00001.parquet",
    "file_format" : "PARQUET",
    "partition" : { },
    "record_count" : 1,
    "file_size_in_bytes" : 643,
    "block_size_in_bytes" : 67108864,
    "column_sizes" : {
      "array" : [ {
        "key" : 1,
        "value" : 46
      }, {
        "key" : 2,
        "value" : 48
      } ]
    },
    "value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 1
      }, {
        "key" : 2,
        "value" : 1
      } ]
    },
    "null_value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 0
      }, {
        "key" : 2,
        "value" : 0
      } ]
    },
    "nan_value_counts" : {
      "array" : [ ]
    },
    "lower_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "a"
      } ]
    },
    "upper_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "a"
      } ]
    },
    "key_metadata" : null,
    "split_offsets" : {
      "array" : [ 4 ]
    },
    "sort_order_id" : {
      "int" : 0
    }
  }
}
{
  "status" : 0,
  "snapshot_id" : {
    "long" : 1233304278810386445
  },
  "data_file" : {
    "file_path" : "/tmp/iceberg/warehouse/db/table1/data/00001-1-3445ca12-3b21-4795-8fd7-5124ecc16c85-00001.parquet",
    "file_format" : "PARQUET",
    "partition" : { },
    "record_count" : 1,
    "file_size_in_bytes" : 643,
    "block_size_in_bytes" : 67108864,
    "column_sizes" : {
      "array" : [ {
        "key" : 1,
        "value" : 46
      }, {
        "key" : 2,
        "value" : 48
      } ]
    },
    "value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 1
      }, {
        "key" : 2,
        "value" : 1
      } ]
    },
    "null_value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 0
      }, {
        "key" : 2,
        "value" : 0
      } ]
    },
    "nan_value_counts" : {
      "array" : [ ]
    },
    "lower_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "b"
      } ]
    },
    "upper_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0002\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "b"
      } ]
    },
    "key_metadata" : null,
    "split_offsets" : {
      "array" : [ 4 ]
    },
    "sort_order_id" : {
      "int" : 0
    }
  }
}
{
  "status" : 0,
  "snapshot_id" : {
    "long" : 1233304278810386445
  },
  "data_file" : {
    "file_path" : "/tmp/iceberg/warehouse/db/table1/data/00002-2-6659369d-638d-432a-83e8-0da1b0abce4f-00001.parquet",
    "file_format" : "PARQUET",
    "partition" : { },
    "record_count" : 1,
    "file_size_in_bytes" : 643,
    "block_size_in_bytes" : 67108864,
    "column_sizes" : {
      "array" : [ {
        "key" : 1,
        "value" : 46
      }, {
        "key" : 2,
        "value" : 48
      } ]
    },
    "value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 1
      }, {
        "key" : 2,
        "value" : 1
      } ]
    },
    "null_value_counts" : {
      "array" : [ {
        "key" : 1,
        "value" : 0
      }, {
        "key" : 2,
        "value" : 0
      } ]
    },
    "nan_value_counts" : {
      "array" : [ ]
    },
    "lower_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0003\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "c"
      } ]
    },
    "upper_bounds" : {
      "array" : [ {
        "key" : 1,
        "value" : "\u0003\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
      }, {
        "key" : 2,
        "value" : "c"
      } ]
    },
    "key_metadata" : null,
    "split_offsets" : {
      "array" : [ 4 ]
    },
    "sort_order_id" : {
      "int" : 0
    }
  }
}

看它指向的檔案名:一看就是第一次insert對應的檔案

00000-0-59d54827-c03f-47f6-a6a1-fc74e6861dcf-00001.parquet
00001-1-3445ca12-3b21-4795-8fd7-5124ecc16c85-00001.parquet
00002-2-6659369d-638d-432a-83e8-0da1b0abce4f-00001.parquet

讀出來看看:

scala> spark.read.parquet("/tmp/iceberg/warehouse/db/table1/data/00000-0-59d54827-c03f-47f6-a6a1-fc74e6861dcf-00001.parquet").show
+---+----+                                                                      
| id|data|
+---+----+
|  1|   a|
+---+----+


scala> spark.read.parquet("/tmp/iceberg/warehouse/db/table1/data/00001-1-3445ca12-3b21-4795-8fd7-5124ecc16c85-00001.parquet").show
+---+----+
| id|data|
+---+----+
|  2|   b|
+---+----+


scala> spark.read.parquet("/tmp/iceberg/warehouse/db/table1/data/00002-2-6659369d-638d-432a-83e8-0da1b0abce4f-00001.parquet").show
+---+----+
| id|data|
+---+----+
|  3|   c|
+---+----+

四、資料變更圖解

下圖下載后,打開,放大,能夠看清的,
請添加圖片描述

分析結論

  1. 把涉及到洗掉快照對應的所有檔案(不僅僅是update的,沒變更的也記錄),進行記錄
  2. 沒有說明哪個記錄被改,也沒有直接改原來資料
  3. 重復insert也是可以寫入,怎么知道需要合并呢?

總結

manifest-list 對應一個snap檔案,這個snap檔案下記錄多個manifest檔案(本次新增、本次修改、上一次snap 新增的manifest檔案),一個manifest檔案記錄多個資料檔案,

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/432153.html

標籤:其他

上一篇:Flink查詢關聯Hbase輸出

下一篇:【MQ我可以講一個小時】

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more