如何刷新表并同时进行? [英] How to refresh a table and do it concurrently?

查看:21
本文介绍了如何刷新表并同时进行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Spark Streaming 2.1.我想定期刷新一些缓存表(由 spark 提供的数据源加载,如 parquet、MySQL 或用户定义的数据源).

I'm using Spark Streaming 2.1. I'd like to refresh some cached table (loaded by spark provided DataSource like parquet, MySQL or user-defined data sources) periodically.

  1. 如何刷新表格?

  1. how to refresh the table?

假设我加载了一些表

spark.read.format("").load().createTempView("my_table")

并且它也被缓存

spark.sql("缓存表 my_table")

使用以下代码刷新表格是否足够,以及何时接下来加载表,会自动缓存

is it enough with following code to refresh the table, and when the table is loaded next, it will automatically be cached

spark.sql("刷新表 my_table")

还是我必须手动执行

spark.table("my_table").unpersistspark.read.format("").load().createOrReplaceTempView("my_table")spark.sql("缓存表 my_table")

同时刷新表是否安全?

并发是指使用 ScheduledThreadPoolExecutor 来完成主线程之外的刷新工作.

By concurrent I mean using ScheduledThreadPoolExecutor to do the refresh work apart from the main thread.

当我对表调用刷新时,如果 Spark 正在使用缓存的表会发生什么?

What will happen if the Spark is using the cached table when I call refresh on the table?

推荐答案

在 Spark 2.2.0 中,他们引入了刷新表元数据的功能,如果它被 hive 或一些外部工具更新.

In Spark 2.2.0 they have introduced feature of refreshing the metadata of a table if it was updated by hive or some external tools.

您可以通过使用 API 来实现,

You can achieve it by using the API,

spark.catalog.refreshTable("my_table")

此 API 将更新该表的元数据以保持一致.

This API will update the metadata for that table to keep it consistent.

这篇关于如何刷新表并同时进行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆