首页 > 解决方案 > 故障保护恢复分区

问题描述

我想recoverPartitions在可能有也可能没有分区的表上运行。

现在我看到两个选项,这两个选项都感觉很hacky:

(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)
})

这些真的是灵活恢复分区的“正确”/“规范”方法吗?SparkR我在文档中没有看到任何其他内容,并且在搜索 of[pP]artition中没有看到任何暗示formals性的Namespace内容SparkR

如果是这样,一个优先于另一个(例如效率)吗?

标签: rapache-sparkapache-spark-sqlsparkr

解决方案


推荐阅读