anishshri-db commented on code in PR #47104: URL: https://github.com/apache/spark/pull/47104#discussion_r1662978196
########## sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/ColumnFamilySchemaFactory.scala: ########## @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.sql.execution.streaming + +import org.apache.spark.sql.Encoder +import org.apache.spark.sql.execution.streaming.TransformWithStateKeyValueRowSchema.{COMPOSITE_KEY_ROW_SCHEMA, KEY_ROW_SCHEMA, VALUE_ROW_SCHEMA, VALUE_ROW_SCHEMA_WITH_TTL} +import org.apache.spark.sql.execution.streaming.state.{ColumnFamilySchema, ColumnFamilySchemaV1, NoPrefixKeyStateEncoderSpec, PrefixKeyScanStateEncoderSpec} + +/** + * Singleton class to fetch the ColumnFamilySchema for each state type + */ +private[sql] object ColumnFamilySchemaFactory { + + def getFactory(version: Int): ColumnFamilySchemaFactory = { + version match { + case 1 => ColumnFamilySchemaFactoryV1 + case _ => throw new IllegalArgumentException(s"Unsupported version: $version") + } + } +} +private[sql] trait ColumnFamilySchemaFactory { + def getValueStateSchema[T]( + stateName: String, + valueEncoder: Encoder[T]): ColumnFamilySchema + + def getValueStateTtlSchema[T]( + stateName: String, + valueEncoder: Encoder[T]): ColumnFamilySchema + + def getListStateSchema[T]( + stateName: String, + valueEncoder: Encoder[T]): ColumnFamilySchema + + def getListStateTtlSchema[T]( + stateName: String, + valueEncoder: Encoder[T]): ColumnFamilySchema + + def getMapStateSchema[K, V]( + stateName: String, + userKeyEnc: Encoder[K], + valueEncoder: Encoder[V]): ColumnFamilySchema + + def getMapStateTtlSchema[K, V]( + stateName: String, + userKeyEnc: Encoder[K], + valueEncoder: Encoder[V]): ColumnFamilySchema +} + +private[sql] object ColumnFamilySchemaFactoryV1 extends ColumnFamilySchemaFactory { + + def getValueStateSchema[T]( + stateName: String, + valueEncoder: Encoder[T]): ColumnFamilySchemaV1 = { + new ColumnFamilySchemaV1( + stateName, + KEY_ROW_SCHEMA, + VALUE_ROW_SCHEMA, + NoPrefixKeyStateEncoderSpec(KEY_ROW_SCHEMA), + false, + valueEncoder.schema) + } + + def getValueStateTtlSchema[T]( + stateName: String, + valueEncoder: Encoder[T]): ColumnFamilySchemaV1 = { + new ColumnFamilySchemaV1( + stateName, + KEY_ROW_SCHEMA, + VALUE_ROW_SCHEMA_WITH_TTL, + NoPrefixKeyStateEncoderSpec(KEY_ROW_SCHEMA), + false, + valueEncoder.schema) + } + + def getListStateSchema[T]( + stateName: String, + valueEncoder: Encoder[T]): ColumnFamilySchemaV1 = { + new ColumnFamilySchemaV1( + stateName, + KEY_ROW_SCHEMA, + VALUE_ROW_SCHEMA, + NoPrefixKeyStateEncoderSpec(KEY_ROW_SCHEMA), + true, + valueEncoder.schema) + } + + def getListStateTtlSchema[T]( + stateName: String, + valueEncoder: Encoder[T]): ColumnFamilySchemaV1 = { + new ColumnFamilySchemaV1( + stateName, + KEY_ROW_SCHEMA, + VALUE_ROW_SCHEMA_WITH_TTL, + NoPrefixKeyStateEncoderSpec(KEY_ROW_SCHEMA), + true, + valueEncoder.schema) + } + + def getMapStateSchema[K, V]( + stateName: String, + userKeyEnc: Encoder[K], + valueEncoder: Encoder[V]): ColumnFamilySchemaV1 = { + new ColumnFamilySchemaV1( + stateName, + COMPOSITE_KEY_ROW_SCHEMA, + VALUE_ROW_SCHEMA, Review Comment: Same here -- 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]
