【问题标题】:Will Spark cache the data twice if we cache a DataSet and then cache the same DataSet as a table如果我们缓存一个DataSet,然后将同一个DataSet缓存为一张表,Spark会缓存两次数据吗
【发布时间】:2018-04-23 06:29:06
【问题描述】:
DataSet<Row> dataSet = sqlContext.sql("some query");
dataSet.registerTempTable("temp_table");
dataset.cache(); // cache 1
sqlContext.cacheTable("temp_table"); // cache 2

所以,我的问题是只触发一次缓存数据集,或者会有两个相同数据集的副本,一个作为数据集(缓存 1),另一个作为表(缓存 2)

【问题讨论】:

    标签: java apache-spark rdd apache-spark-dataset


    【解决方案1】:

    不会,或者至少在任何最新版本中都不会:

    scala> val df = spark.range(1)
    df: org.apache.spark.sql.Dataset[Long] = [id: bigint]
    
    scala> df.cache
    res0: df.type = [id: bigint]
    
    scala> df.createOrReplaceTempView("df")
    
    scala> spark.catalog.cacheTable("df")
    2018-01-23 12:33:48 WARN  CacheManager:66 - Asked to cache already cached data.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-25
      • 2012-01-29
      • 2019-03-28
      相关资源
      最近更新 更多