【问题标题】:How to write streaming dataset into Hive? [duplicate]如何将流数据集写入 Hive? [复制]
【发布时间】:2018-06-24 00:19:53
【问题描述】:

使用 Apache Spark 2.2:结构化流,我正在创建一个从 Kafka 读取数据并将其写入 Hive 的程序。 我正在寻找以 100 条记录/秒的速度写入 Kafka 主题中传入的批量数据。

已创建 Hive 表:

CREATE TABLE demo_user( timeaa BIGINT, numberbb INT, decimalcc DOUBLE, stringdd STRING, booleanee BOOLEAN ) STORED AS ORC ;

通过手动 Hive 查询插入:

INSERT INTO TABLE demo_user (1514133139123, 14, 26.4, 'pravin', true);

通过 Spark 结构化流代码插入:

SparkConf conf = new SparkConf();
conf.setAppName("testing");
conf.setMaster("local[2]");
conf.set("hive.metastore.uris", "thrift://localhost:9083");
SparkSession session = 
SparkSession.builder().config(conf).enableHiveSupport().getOrCreate();

// workaround START: code to insert static data into hive
String insertQuery = "INSERT INTO TABLE demo_user (1514133139123, 14, 26.4, 'pravin', true)";
session.sql(insertQuery);
// workaround END:

// Solution START
Dataset<Row> dataset = readFromKafka(sparkSession); // private method reading data from Kafka's 'xyz' topic

// **My question here:**
// some code which writes dataset into hive table demo_user
// Solution END

【问题讨论】:

    标签: apache-spark hive apache-spark-sql spark-structured-streaming


    【解决方案1】:

    使用下面的时候不需要创建hive表,这是自动创建的

    dataset.write.jdbc(String url, String table, java.util.Properties connectionProperties)

    或使用

    dataset.write.saveAsTable(String tableName)

    【讨论】:

    • 感谢您的回复。但在结构流数据集中不适用于 write() 函数。它适用于 .writeStream() 函数。
    • @pravin .. 你找到解决办法了吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-17
    • 2017-12-20
    • 1970-01-01
    • 1970-01-01
    • 2017-05-16
    • 2018-09-03
    • 2022-07-07
    相关资源
    最近更新 更多