在上一篇文章中我们主要讲解了iceberg各个元数据文件中的数据组织形式,那么这些元数据是怎么生成的呢?如何通过spark写入iceberg?本文将带大家简单了解一下使用spark 2.4.7 batch写入iceberg的整体流程。
spark写入示例
本文主要演示如何使用iceberg hadoopTable写入数据,hadoopCatalog和hiveCatalog在使用上大同小异。
import org.apache.iceberg.hadoop.HadoopTables
import org.apache.hadoop.conf.Configuration
import org.apache.iceberg.catalog.TableIdentifier
import org.apache.iceberg.Schema
import org.apache.iceberg.types._
import org.apache.spark.sql.types._
import org.apache.iceberg.PartitionSpec
import org.apache.iceberg.spark.SparkSchemaUtil
import org.apache.spark.sql._
import spark.implicits._
val order_item_schema = StructType(List(
StructField("id", LongType, true),
StructField("order_id", LongType, true),
StructField("product_id", LongType, true),
StructField("product_price", DecimalType(7,2), true),
StructField("pro