更新时间:2023-10-26 GMT+08:00
分享

Hudi对接OBS文件系统

  1. 使用安装客户端用户登录客户端安装节点。
  2. 配置环境变量。

    source 客户端安装目录/bigdata_env

    source 客户端安装目录/Hudi/component_env

  3. 修改配置文件:

    vim 客户端安装目录/Hudi/hudi/conf/hdfs-site.xml

    <property>
    <name>dfs.namenode.acls.enabled</name>
    <value>false</value>
    </property>

  4. 如果是安全集群,使用以下命令用户进行用户认证,如果当前集群未启用Kerberos认证,则无需执行此命令。

    kinit 用户名

  5. 启动spark-shell,执行下面的命令创建COW表存储到OBS中:

    import org.apache.hudi.QuickstartUtils._

    import scala.collection.JavaConversions._

    import org.apache.spark.sql.SaveMode._

    import org.apache.hudi.DataSourceReadOptions._

    import org.apache.hudi.DataSourceWriteOptions._

    import org.apache.hudi.config.HoodieWriteConfig._

    val tableName = "hudi_cow_table"

    val basePath = "obs://testhudi/cow_table/"

    val dataGen = new DataGenerator

    val inserts = convertToStringList(dataGen.generateInserts(10))

    val df = spark.read.json(spark.sparkContext.parallelize(inserts, 2))

    df.write.format("org.apache.hudi").

    options(getQuickstartWriteConfigs).

    option(PRECOMBINE_FIELD_OPT_KEY, "ts").

    option(RECORDKEY_FIELD_OPT_KEY, "uuid").

    option(PARTITIONPATH_FIELD_OPT_KEY, "partitionpath").

    option(TABLE_NAME, tableName).

    mode(Overwrite).

    save(basePath);

    "obs://testhudi/cow_table/"是OBS路径,testhudi是桶名称,请根据实际情况修改。

  6. 使用datasource查看表建立成功,数据正常。

    val roViewDF = spark.

    read.

    format("org.apache.hudi").

    load(basePath + "/*/*/*/*")

    roViewDF.createOrReplaceTempView("hudi_ro_table")

    spark.sql("select * from hudi_ro_table").show()

  7. 执行:q退出spark-shell命令行。
分享:

    相关文档

    相关产品