Interface TypeApiOps
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
TimeTypeApiOps
This trait consolidates all client-side operations that a data type must implement to be usable in the Spark SQL API layer. Mandatory methods (format, toSQLValue, getEncoder) must be implemented by every type. Optional methods (Arrow, Python, Hive, Thrift) return Option and default to None - types implement them as they expand their integration coverage.
RELATIONSHIP TO TypeOps: - TypeOps (catalyst): Server-side operations - physical types, literals, conversions - TypeApiOps (spark-api): Client-side operations - formatting, encoding
The split exists because sql/api cannot depend on sql/catalyst. For TimeType, TimeTypeOps (catalyst) extends TimeTypeApiOps (sql-api) to inherit both sets of operations.
- Since:
- 4.2.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondataType()The DataType this Ops instance handles.Formats an internal value as a display string.scala.Option<String>formatExternal(Object value) Formats an external-type value for Hive output.scala.Option<String>formatExternal(Object value, boolean nested) Formats with nesting context.org.apache.spark.unsafe.types.UTF8StringformatUTF8(Object v) Formats an internal value as a UTF8String.org.apache.spark.sql.catalyst.encoders.AgnosticEncoder<?>Returns the AgnosticEncoder for this type.Creates a converter function for Python/Py4J interop.scala.Option<Object>Returns true if values of this type need conversion when passed to/from Python.nullSafeConvert(Object input, scala.PartialFunction<Object, Object> f) Null-safe conversion helper.scala.Option<String>Returns the Thrift TTypeId name for this type (e.g., "STRING_TYPE").scala.Option<org.apache.arrow.vector.types.pojo.ArrowType>toArrowType(String timeZoneId) Converts this DataType to its Arrow representation.toSQLValue(Object v) Formats an internal value as a SQL literal string.
-
Method Details
-
dataType
DataType dataType()The DataType this Ops instance handles. -
format
Formats an internal value as a display string.Used by CAST to STRING, EXPLAIN output, SHOW commands.
- Parameters:
v- the internal value (e.g., Long nanoseconds for TimeType)- Returns:
- formatted string (e.g., "10:30:45.123456")
-
formatUTF8
Formats an internal value as a UTF8String.Default implementation wraps format(). Override for performance if needed.
- Parameters:
v- (undocumented)- Returns:
- (undocumented)
-
toSQLValue
Formats an internal value as a SQL literal string.- Parameters:
v- the internal value- Returns:
- SQL literal string (e.g., "TIME '10:30:00'")
-
getEncoder
org.apache.spark.sql.catalyst.encoders.AgnosticEncoder<?> getEncoder()Returns the AgnosticEncoder for this type.Used by RowEncoder for Dataset[T] operations.
- Returns:
- AgnosticEncoder instance (e.g., LocalTimeEncoder for TimeType)
-
nullSafeConvert
Null-safe conversion helper. Returns null for null input, applies the partial function for non-null input, and returns null for unmatched values.- Parameters:
input- (undocumented)f- (undocumented)- Returns:
- (undocumented)
-
toArrowType
Converts this DataType to its Arrow representation. Returns None if not supported. -
needConversionInPython
scala.Option<Object> needConversionInPython()Returns true if values of this type need conversion when passed to/from Python. -
makeFromJava
Creates a converter function for Python/Py4J interop. -
formatExternal
Formats an external-type value for Hive output. Most types override this simple version. Types that need different formatting when nested should override the 2-param overload.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
formatExternal
Formats with nesting context. Default delegates to the simple version. -
thriftTypeName
scala.Option<String> thriftTypeName()Returns the Thrift TTypeId name for this type (e.g., "STRING_TYPE").
-