2

我是 Apache Iceberg 的新手。我想使用 Apache Iceberg 执行读写操作。我正在使用 Spark 3.0.0。

代码:

    System.setProperty("hadoop.home.dir","C:\\hadoop" )
    val conf = new SparkConf()
    conf.set("spark.sql.extensions","org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions")
    conf.set("spark.sql.catalog.spark_catalog","org.apache.iceberg.spark.SparkSessionCatalog")
    conf.set("spark.sql.catalog.spark_catalog.type","hive")
    conf.set("spark.sql.catalog.local","org.apache.iceberg.spark.SparkCatalog")
    conf.set("spark.sql.catalog.local.type","hadoop")
    conf.set("spark.sql.catalog.local.warehouse","warehouse")

    val spark = SparkSession.builder().master("local").config(conf).getOrCreate()
    
    spark.sql("CREATE TABLE local.db.table (id bigint, data string) USING iceberg")
    spark.sql("INSERT INTO local.db.table VALUES (1, 'a'), (2, 'b'), (3, 'c')")

依赖列表:

    compile group: 'org.scala-lang', name: 'scala-library', version: '2.12.0'

    compile group: 'org.apache.spark', name: 'spark-core_2.12', version: '3.0.0'
    compile group: 'org.apache.spark', name: 'spark-sql_2.12', version: '3.0.0'

    compile group: 'org.apache.iceberg', name: 'iceberg-spark', version: '0.11.1'
    compile group: 'org.apache.iceberg', name: 'iceberg-spark3-runtime', version: '0.11.1'

    compile group:  'org.apache.hive', name: 'hive-metastore', version: '2.0.1'

异常消息:

java.lang.ClassCastException: org.apache.iceberg.shaded.org.apache.parquet.schema.MessageType cannot be cast to org.apache.parquet.schema.MessageType
    at org.apache.iceberg.parquet.ParquetWriter.<init>(ParquetWriter.java:96)
    at org.apache.iceberg.parquet.Parquet$WriteBuilder.build(Parquet.java:250)
    at org.apache.iceberg.spark.source.SparkAppenderFactory.newAppender(SparkAppenderFactory.java:110)

我是否需要任何其他依赖项来启用 MessageType 强制转换。

4

1 回答 1

0

使用 Spark 和 Iceberg 时,您只想使用iceberg-spark3-runtimejar。这是一个带阴影的 jar,可防止与 Spark 依赖项发生依赖项冲突。如果你也包含iceberg-spark了,你最终会遇到冲突,因为这是 Spark 2 的未着色 jar,并且将包含与 Spark3 和 Iceberg-Spark3-Runtime 冲突的未着色依赖项。

所以总而言之,你应该删除

    compile group: 'org.apache.iceberg', name: 'iceberg-spark', version: '0.11.1'

和这个

    compile group: 'org.apache.iceberg', name: 'iceberg-spark3-runtime', version: '0.11.1'

应标记为提供的(或运行时)依赖项

于 2021-09-24T20:03:42.597 回答