Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ object SQLConf {
.booleanConf
.createWithDefault(true)

val CACHE_STORAGE_LEVEL = buildConf("spark.sql.inMemoryColumnarStorage.level")
.internal()
.doc("Configures the storage level of the cached tables.")
.stringConf
.createWithDefault("MEMORY_AND_DISK")

val COLUMN_BATCH_SIZE = buildConf("spark.sql.inMemoryColumnarStorage.batchSize")
.internal()
.doc("Controls the size of batches for columnar caching. Larger batch sizes can improve " +
Expand Down Expand Up @@ -930,6 +936,8 @@ class SQLConf extends Serializable with Logging {

def columnBatchSize: Int = getConf(COLUMN_BATCH_SIZE)

def cacheStorageLevel: String = getConf(CACHE_STORAGE_LEVEL)

def numShufflePartitions: Int = getConf(SHUFFLE_PARTITIONS)

def targetPostShuffleInputSize: Long =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import org.apache.spark.sql.execution.columnar.InMemoryRelation
import org.apache.spark.sql.execution.datasources.{HadoopFsRelation, LogicalRelation}
import org.apache.spark.sql.SparkSession
import org.apache.spark.storage.StorageLevel
import org.apache.spark.storage.StorageLevel.MEMORY_AND_DISK

/** Holds a cached logical plan and its data */
case class CachedData(plan: LogicalPlan, cachedRepresentation: InMemoryRelation)
Expand Down Expand Up @@ -88,8 +87,8 @@ class CacheManager extends Logging {
*/
def cacheQuery(
query: Dataset[_],
tableName: Option[String] = None,
storageLevel: StorageLevel = MEMORY_AND_DISK): Unit = writeLock {
tableName: Option[String],
storageLevel: StorageLevel): Unit = writeLock {
val planToCache = query.logicalPlan
if (lookupCachedData(planToCache).nonEmpty) {
logWarning("Asked to cache already cached data.")
Expand All @@ -106,6 +105,11 @@ class CacheManager extends Logging {
}
}

def cacheQuery(query: Dataset[_], tableName: Option[String] = None): Unit = writeLock {
cacheQuery(query, tableName, StorageLevel.fromString(
query.sparkSession.sessionState.conf.cacheStorageLevel))
Copy link
Member

@felixcheung felixcheung Jun 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, this is a bit odd to roundtrip to string <-> storagelevel...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain your question in a bit more details?

}

/**
* Un-cache all the cache entries that refer to the given plan.
*/
Expand Down