如果foo存在,则spark [dataframe] .write.option(“ mode”,“ overwrite”)。saveAsTable(“ foo”)失败,并显示“ already exist”

时间:2019-08-06 04:01:30

标签: sql scala apache-spark overwrite

我认为我正在火花中发现一个错误,该错误不尊重模式“ overwrite”,而是试图将saveAsTable放入已经存在的表中(使用模式“ overwrite”)。

下面是一个重现问题的小脚本。最后一条语句导致堆栈跟踪读取:

private Handler broadcastReceiverHandler = null;
private HandlerThread broadcastReceiverThread = null;
private Looper broadcastReceiverThreadLooper = null;

private BroadcastReceiver broadcastReceiverReadScans = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

    }
}

private void registerForIntents() {
    broadcastReceiverThread = new HandlerThread("THREAD_NAME");//Create a thread for BroadcastReceiver
    broadcastReceiverThread.start();

    broadcastReceiverThreadLooper = broadcastReceiverThread.getLooper();
    broadcastReceiverHandler = new Handler(broadcastReceiverThreadLooper);

    IntentFilter filterScanReads = new IntentFilter();
    filterScanReads.addAction("ACTION_SCAN_READ");
    filterScanReads.addCategory("CATEGORY_SCAN");

    context.registerReceiver(broadcastReceiverReadScans, filterScanReads, null, broadcastReceiverHandler);
}

private void unregisterIntents() {
    context.unregisterReceiver(broadcastReceiverReadScans);
    broadcastReceiverThreadLooper.quit();//Don't forget
}

任何建议,不胜感激。

 org.apache.spark.sql.AnalysisException: Table `example` already exists.;

1 个答案:

答案 0 :(得分:1)

saveAsTable不检查其他选项,请直接使用mode

df3.write.mode(SaveMode.Overwrite).saveAsTable("example")

df3.write.mode("overwrite").saveAsTable("example")