【问题标题】:Spark Insert Operation with postgres and java使用 postgres 和 java 进行 Spark 插入操作
【发布时间】:2016-09-08 09:55:43
【问题描述】:

我想使用 Spark SQLContext 在表中插入一条记录。

这是我为检索数据所做的示例代码

        Class.forName(dbDriver);

        Map<String, String> options = new HashMap<String, String>();
        options.put("url", dbUrl);
        options.put("dbtable", dbTable);
        options.put("driver", dbDriver);

        SparkConf conf = new SparkConf().setAppName("JAVA_SPARK")
                .setMaster("local[2]").set("spark.ui.port‌​", "7077");

        JavaSparkContext jsc = new JavaSparkContext(conf);

        SQLContext sqlContext = new SQLContext(jsc);

        DataFrame dframe = sqlContext.read().format("jdbc")
                .options(options).load();

        dframe.show();

如何在表中插入新记录? dframe.show() 操作对我来说工作正常。

【问题讨论】:

    标签: java postgresql apache-spark


    【解决方案1】:

    我想Spark-Sql目前还没有提供这样的功能,你可以自己实现该方法,然后在foreach之类的动作中调用它来实现当前场景的解决方案,

    有关实施此功能的更多信息和最佳实践,请参阅此处:Inserting Analytic data from Spark to Postgres

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2021-12-14
      • 2016-01-01
      • 1970-01-01
      • 2021-09-06
      • 2017-07-17
      相关资源
      最近更新 更多