Package org.apache.spark.sql.columnar
Interface CachedBatchSerializer
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
SimpleMetricsCachedBatchSerializer
Provides APIs that handle transformations of SQL data associated with the cache/persist APIs.
-
Method Summary
Modifier and TypeMethodDescriptionscala.Function2<Object,
scala.collection.Iterator<CachedBatch>, scala.collection.Iterator<CachedBatch>> buildFilter
(scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Expression> predicates, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> cachedAttributes) Builds a function that can be used to filter batches prior to being decompressed.convertCachedBatchToColumnarBatch
(RDD<CachedBatch> input, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> cacheAttributes, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> selectedAttributes, org.apache.spark.sql.internal.SQLConf conf) Convert the cached data into a ColumnarBatch.RDD<org.apache.spark.sql.catalyst.InternalRow>
convertCachedBatchToInternalRow
(RDD<CachedBatch> input, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> cacheAttributes, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> selectedAttributes, org.apache.spark.sql.internal.SQLConf conf) Convert the cached batch intoInternalRow
s.convertColumnarBatchToCachedBatch
(RDD<ColumnarBatch> input, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> schema, StorageLevel storageLevel, org.apache.spark.sql.internal.SQLConf conf) Convert anRDD[ColumnarBatch]
into anRDD[CachedBatch]
in preparation for caching the data.convertInternalRowToCachedBatch
(RDD<org.apache.spark.sql.catalyst.InternalRow> input, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> schema, StorageLevel storageLevel, org.apache.spark.sql.internal.SQLConf conf) Convert anRDD[InternalRow]
into anRDD[CachedBatch]
in preparation for caching the data.boolean
supportsColumnarInput
(scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> schema) CanconvertColumnarBatchToCachedBatch()
be called instead ofconvertInternalRowToCachedBatch()
for this given schema? True if it can and false if it cannot.boolean
supportsColumnarOutput
(StructType schema) CanconvertCachedBatchToColumnarBatch()
be called instead ofconvertCachedBatchToInternalRow()
for this given schema? True if it can and false if it cannot.scala.Option<scala.collection.immutable.Seq<String>>
vectorTypes
(scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> attributes, org.apache.spark.sql.internal.SQLConf conf) The exact java types of the columns that are output in columnar processing mode.
-
Method Details
-
buildFilter
scala.Function2<Object,scala.collection.Iterator<CachedBatch>, buildFilterscala.collection.Iterator<CachedBatch>> (scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Expression> predicates, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> cachedAttributes) Builds a function that can be used to filter batches prior to being decompressed. In most cases extendingSimpleMetricsCachedBatchSerializer
will provide the filter logic necessary. You will need to provide metrics for this to work.SimpleMetricsCachedBatch
provides the APIs to hold those metrics and explains the metrics used, really just min and max. Note that this is intended to skip batches that are not needed, and the actual filtering of individual rows is handled later.- Parameters:
predicates
- the set of expressions to use for filtering.cachedAttributes
- the schema/attributes of the data that is cached. This can be helpful if you don't store it with the data.- Returns:
- a function that takes the partition id and the iterator of batches in the partition. It returns an iterator of batches that should be decompressed.
-
convertCachedBatchToColumnarBatch
RDD<ColumnarBatch> convertCachedBatchToColumnarBatch(RDD<CachedBatch> input, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> cacheAttributes, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> selectedAttributes, org.apache.spark.sql.internal.SQLConf conf) Convert the cached data into a ColumnarBatch. This currently is only used ifsupportsColumnarOutput()
returns true for the associated schema, but there are other checks that can force row based output. One of the main advantages of doing columnar output over row based output is that the code generation is more standard and can be combined with code generation for downstream operations.- Parameters:
input
- the cached batches that should be converted.cacheAttributes
- the attributes of the data in the batch.selectedAttributes
- the fields that should be loaded from the data and the order they should appear in the output batch.conf
- the configuration for the job.- Returns:
- an RDD of the input cached batches transformed into the ColumnarBatch format.
-
convertCachedBatchToInternalRow
RDD<org.apache.spark.sql.catalyst.InternalRow> convertCachedBatchToInternalRow(RDD<CachedBatch> input, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> cacheAttributes, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> selectedAttributes, org.apache.spark.sql.internal.SQLConf conf) Convert the cached batch intoInternalRow
s. If you want this to be performant, code generation is advised.- Parameters:
input
- the cached batches that should be converted.cacheAttributes
- the attributes of the data in the batch.selectedAttributes
- the field that should be loaded from the data and the order they should appear in the output rows.conf
- the configuration for the job.- Returns:
- RDD of the rows that were stored in the cached batches.
-
convertColumnarBatchToCachedBatch
RDD<CachedBatch> convertColumnarBatchToCachedBatch(RDD<ColumnarBatch> input, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> schema, StorageLevel storageLevel, org.apache.spark.sql.internal.SQLConf conf) Convert anRDD[ColumnarBatch]
into anRDD[CachedBatch]
in preparation for caching the data. This will only be called ifsupportsColumnarInput()
returned true for the given schema and the plan up to this point would could produce columnar output without modifying it.- Parameters:
input
- the inputRDD
to be converted.schema
- the schema of the data being stored.storageLevel
- where the data will be stored.conf
- the config for the query.- Returns:
- The data converted into a format more suitable for caching.
-
convertInternalRowToCachedBatch
RDD<CachedBatch> convertInternalRowToCachedBatch(RDD<org.apache.spark.sql.catalyst.InternalRow> input, scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> schema, StorageLevel storageLevel, org.apache.spark.sql.internal.SQLConf conf) Convert anRDD[InternalRow]
into anRDD[CachedBatch]
in preparation for caching the data.- Parameters:
input
- the inputRDD
to be converted.schema
- the schema of the data being stored.storageLevel
- where the data will be stored.conf
- the config for the query.- Returns:
- The data converted into a format more suitable for caching.
-
supportsColumnarInput
boolean supportsColumnarInput(scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> schema) CanconvertColumnarBatchToCachedBatch()
be called instead ofconvertInternalRowToCachedBatch()
for this given schema? True if it can and false if it cannot. Columnar input is only supported if the plan could produce columnar output. Currently this is mostly supported by input formats like parquet and orc, but more operations are likely to be supported soon.- Parameters:
schema
- the schema of the data being stored.- Returns:
- True if columnar input can be supported, else false.
-
supportsColumnarOutput
CanconvertCachedBatchToColumnarBatch()
be called instead ofconvertCachedBatchToInternalRow()
for this given schema? True if it can and false if it cannot. Columnar output is typically preferred because it is more efficient. Note thatconvertCachedBatchToInternalRow()
must always be supported as there are other checks that can force row based output.- Parameters:
schema
- the schema of the data being checked.- Returns:
- true if columnar output should be used for this schema, else false.
-
vectorTypes
scala.Option<scala.collection.immutable.Seq<String>> vectorTypes(scala.collection.immutable.Seq<org.apache.spark.sql.catalyst.expressions.Attribute> attributes, org.apache.spark.sql.internal.SQLConf conf) The exact java types of the columns that are output in columnar processing mode. This is a performance optimization for code generation and is optional.- Parameters:
attributes
- the attributes to be output.conf
- the config for the query that will read the data.- Returns:
- (undocumented)
-