davidm-db commented on code in PR #54905:
URL: https://github.com/apache/spark/pull/54905#discussion_r3136339845


##########
sql/connect/common/src/main/scala/org/apache/spark/sql/connect/common/types/ops/ConnectTypeOps.scala:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.connect.common.types.ops
+
+import org.apache.arrow.vector.FieldVector
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.encoders.AgnosticEncoder
+import org.apache.spark.sql.catalyst.encoders.AgnosticEncoders.LocalTimeEncoder
+import org.apache.spark.sql.connect.client.arrow.{ArrowDeserializers, 
ArrowSerializer, ArrowVectorReader}
+import org.apache.spark.sql.connect.client.arrow.types.ops.TimeTypeConnectOps
+import org.apache.spark.sql.internal.SqlApiConf
+import org.apache.spark.sql.types.{DataType, TimeType}
+
+/**
+ * Optional type operations for Spark Connect infrastructure.
+ *
+ * Consolidates both proto conversions (DataTypeProtoConverter, 
LiteralValueProtoConverter) and
+ * Arrow serialization/deserialization (ArrowSerializer, ArrowDeserializer, 
ArrowVectorReader) for
+ * framework-managed types.
+ *
+ * @since 4.2.0
+ */
+trait ConnectTypeOps extends Serializable {
+
+  def dataType: DataType
+
+  def encoder: AgnosticEncoder[_]
+
+  // ==================== Proto Conversions ====================
+
+  /** Converts this DataType to its Connect proto representation. */
+  def toConnectProtoType: proto.DataType
+
+  /** Converts a value to a proto literal builder (generic, no DataType 
context). */
+  def toLiteralProto(
+      value: Any,
+      builder: proto.Expression.Literal.Builder): 
proto.Expression.Literal.Builder
+
+  /** Converts a value to a proto literal builder (with DataType context). */
+  def toLiteralProtoWithType(
+      value: Any,
+      dt: DataType,
+      builder: proto.Expression.Literal.Builder): 
proto.Expression.Literal.Builder
+
+  /**
+   * Returns a converter from proto literal to Scala value. The returned 
converter assumes
+   * non-null input - null handling is done by the caller 
(LiteralValueProtoConverter wraps with
+   * `if (v.hasNull) null`).
+   */
+  def getScalaConverter: proto.Expression.Literal => Any
+
+  /** Returns a proto DataType inferred from a proto literal (for type 
inference). */
+  def getProtoDataTypeFromLiteral(literal: proto.Expression.Literal): 
proto.DataType
+
+  /** Converts a proto DataType to a Spark DataType (reverse of 
toConnectProtoType). */
+  def toCatalystTypeFromProto(t: proto.DataType): DataType
+
+  // ==================== Arrow Serialization ====================
+
+  /** Creates an Arrow serializer for writing values to a vector. */
+  def createArrowSerializer(vector: AnyRef): ArrowSerializer.Serializer
+
+  /** Creates an Arrow deserializer for reading values from a vector. */
+  def createArrowDeserializer(
+      enc: AgnosticEncoder[_],
+      data: AnyRef,
+      timeZoneId: String): ArrowDeserializers.Deserializer[Any]
+
+  /** Creates an ArrowVectorReader for this type's vector. */
+  def createArrowVectorReader(vector: FieldVector): ArrowVectorReader
+}
+
+/**
+ * Factory object for ConnectTypeOps lookup.
+ *
+ * Provides separate factory methods for proto (server-side, 
feature-flag-gated) and Arrow
+ * (client-side, no flag) dispatch.
+ */
+object ConnectTypeOps {
+
+  // ==================== Proto Dispatch (server-side, flag-gated) 
====================
+
+  /** DataType-keyed dispatch for proto conversions. Checks feature flag. */
+  def apply(dt: DataType): Option[ConnectTypeOps] = {
+    if (!SqlApiConf.get.typesFrameworkEnabled) return None

Review Comment:
   same reply as in 
https://github.com/apache/spark/pull/54905#discussion_r3136338496



##########
sql/connect/common/src/main/scala/org/apache/spark/sql/connect/common/types/ops/ConnectTypeOps.scala:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.connect.common.types.ops
+
+import org.apache.arrow.vector.FieldVector
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.catalyst.encoders.AgnosticEncoder
+import org.apache.spark.sql.catalyst.encoders.AgnosticEncoders.LocalTimeEncoder
+import org.apache.spark.sql.connect.client.arrow.{ArrowDeserializers, 
ArrowSerializer, ArrowVectorReader}
+import org.apache.spark.sql.connect.client.arrow.types.ops.TimeTypeConnectOps
+import org.apache.spark.sql.internal.SqlApiConf
+import org.apache.spark.sql.types.{DataType, TimeType}
+
+/**
+ * Optional type operations for Spark Connect infrastructure.
+ *
+ * Consolidates both proto conversions (DataTypeProtoConverter, 
LiteralValueProtoConverter) and
+ * Arrow serialization/deserialization (ArrowSerializer, ArrowDeserializer, 
ArrowVectorReader) for
+ * framework-managed types.
+ *
+ * @since 4.2.0
+ */
+trait ConnectTypeOps extends Serializable {
+
+  def dataType: DataType
+
+  def encoder: AgnosticEncoder[_]
+
+  // ==================== Proto Conversions ====================
+
+  /** Converts this DataType to its Connect proto representation. */
+  def toConnectProtoType: proto.DataType
+
+  /** Converts a value to a proto literal builder (generic, no DataType 
context). */
+  def toLiteralProto(
+      value: Any,
+      builder: proto.Expression.Literal.Builder): 
proto.Expression.Literal.Builder
+
+  /** Converts a value to a proto literal builder (with DataType context). */
+  def toLiteralProtoWithType(
+      value: Any,
+      dt: DataType,
+      builder: proto.Expression.Literal.Builder): 
proto.Expression.Literal.Builder
+
+  /**
+   * Returns a converter from proto literal to Scala value. The returned 
converter assumes
+   * non-null input - null handling is done by the caller 
(LiteralValueProtoConverter wraps with
+   * `if (v.hasNull) null`).
+   */
+  def getScalaConverter: proto.Expression.Literal => Any
+
+  /** Returns a proto DataType inferred from a proto literal (for type 
inference). */
+  def getProtoDataTypeFromLiteral(literal: proto.Expression.Literal): 
proto.DataType
+
+  /** Converts a proto DataType to a Spark DataType (reverse of 
toConnectProtoType). */
+  def toCatalystTypeFromProto(t: proto.DataType): DataType
+
+  // ==================== Arrow Serialization ====================
+
+  /** Creates an Arrow serializer for writing values to a vector. */
+  def createArrowSerializer(vector: AnyRef): ArrowSerializer.Serializer
+
+  /** Creates an Arrow deserializer for reading values from a vector. */
+  def createArrowDeserializer(
+      enc: AgnosticEncoder[_],
+      data: AnyRef,
+      timeZoneId: String): ArrowDeserializers.Deserializer[Any]
+
+  /** Creates an ArrowVectorReader for this type's vector. */
+  def createArrowVectorReader(vector: FieldVector): ArrowVectorReader
+}
+
+/**
+ * Factory object for ConnectTypeOps lookup.
+ *
+ * Provides separate factory methods for proto (server-side, 
feature-flag-gated) and Arrow
+ * (client-side, no flag) dispatch.
+ */
+object ConnectTypeOps {
+
+  // ==================== Proto Dispatch (server-side, flag-gated) 
====================
+
+  /** DataType-keyed dispatch for proto conversions. Checks feature flag. */
+  def apply(dt: DataType): Option[ConnectTypeOps] = {
+    if (!SqlApiConf.get.typesFrameworkEnabled) return None
+    dt match {
+      case tt: TimeType => Some(new TimeTypeConnectOps(tt))
+      // Add new framework types here
+      case _ => None
+    }
+  }
+
+  /** Reverse lookup by value class for the generic literal builder. Checks 
feature flag. */
+  def toLiteralProtoForValue(
+      value: Any,
+      builder: proto.Expression.Literal.Builder): 
Option[proto.Expression.Literal.Builder] = {
+    if (!SqlApiConf.get.typesFrameworkEnabled) return None

Review Comment:
   https://github.com/apache/spark/pull/54905#discussion_r3136338496



-- 
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]

Reply via email to