anishshri-db commented on code in PR #48401:
URL: https://github.com/apache/spark/pull/48401#discussion_r1837387348
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/StateStoreColumnFamilySchemaUtils.scala:
##########
@@ -16,36 +16,132 @@
*/
package org.apache.spark.sql.execution.streaming
+import org.apache.spark.internal.Logging
import org.apache.spark.sql.Encoder
+import org.apache.spark.sql.avro.{AvroDeserializer, AvroOptions,
AvroSerializer, SchemaConverters}
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
import
org.apache.spark.sql.execution.streaming.TransformWithStateKeyValueRowSchemaUtils._
-import
org.apache.spark.sql.execution.streaming.state.{NoPrefixKeyStateEncoderSpec,
PrefixKeyScanStateEncoderSpec, StateStoreColFamilySchema}
-import org.apache.spark.sql.types.StructType
+import org.apache.spark.sql.execution.streaming.state.{AvroEncoder,
NoPrefixKeyStateEncoderSpec, PrefixKeyScanStateEncoderSpec,
RangeKeyScanStateEncoderSpec, StateStoreColFamilySchema}
+import org.apache.spark.sql.types.{BinaryType, BooleanType, ByteType,
DataType, DoubleType, FloatType, IntegerType, LongType, NullType, ShortType,
StructField, StructType}
-object StateStoreColumnFamilySchemaUtils {
+object StateStoreColumnFamilySchemaUtils extends Serializable {
+
+ def apply(initializeAvroSerde: Boolean): StateStoreColumnFamilySchemaUtils =
+ new StateStoreColumnFamilySchemaUtils(initializeAvroSerde)
+
+ /**
+ * Avro uses zig-zag encoding for some fixed-length types, like Longs and
Ints. For range scans
+ * we want to use big-endian encoding, so we need to convert the source
schema to replace these
+ * types with BinaryType.
+ *
+ * @param schema The schema to convert
+ * @param ordinals If non-empty, only convert fields at these ordinals.
+ * If empty, convert all fields.
+ */
+ def convertForRangeScan(schema: StructType, ordinals: Seq[Int] = Seq.empty):
StructType = {
+ val ordinalSet = ordinals.toSet
+
+ StructType(schema.fields.zipWithIndex.flatMap { case (field, idx) =>
+ if ((ordinals.isEmpty || ordinalSet.contains(idx)) &&
isFixedSize(field.dataType)) {
+ // For each numeric field, create two fields:
+ // 1. A boolean for sign (positive = true, negative = false)
Review Comment:
nit: lets update the comment ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]