故障安全的recoverPartitions

时间:2018-09-09 05:19:58

标签: r apache-spark apache-spark-sql sparkr

我想在可能具有分区或没有分区的表上运行recoverPartitions

现在,我看到两个选项,两个选项都非常笨拙:

(1)在执行之前检查create table语句:

table_name = 'my_schema.my_table'
x = sql(sprintf('show create table %s', table_name))
if (grepl('PARTITIONED BY', collect(x), fixed = TRUE)) {
  recoverPartitions(table_name)
}

(2)tryCatch

tryCatch(recoverPartitions(table_name),
         error = function(e) {
  if (grepl('ALTER TABLE RECOVER PARTITIONS', e$message, fixed = TRUE)) 
    # expected error in case of non-partitioned table
    return(NULL)
  # else an unexpected error
  else stop(e$message, .call = FALSE)
})

这些是灵活恢复分区的真正“正确” /“规范”方法吗?在{{1}的[pP]artition的{​​{1}}中搜索formals时,在SparkR documentation中看不到任何其他提示}}。

如果是这样,是哪个(而不是效率)优先于另一个?

0 个答案:

没有答案