hvanhovell commented on code in PR #40651:
URL: https://github.com/apache/spark/pull/40651#discussion_r1156623809


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/PhysicalDataType.scala:
##########
@@ -17,53 +17,234 @@
 
 package org.apache.spark.sql.catalyst.types
 
-import org.apache.spark.sql.types._
-
+import scala.reflect.runtime.universe.TypeTag
+import scala.reflect.runtime.universe.typeTag
+import scala.util.control.NonFatal
+import org.apache.spark.sql.catalyst.util.SQLOrderingUtil
+import org.apache.spark.sql.errors.QueryExecutionErrors
+import org.apache.spark.sql.types.{AtomicType, BinaryType, BooleanType, 
ByteType, DataType, DateType, DayTimeIntervalType, Decimal, DecimalType, 
DoubleType, FloatType, IntegerType, LongType, NullType, NumericType, ShortType, 
StringType, StructField, TimestampNTZType, TimestampType}
+import org.apache.spark.unsafe.types.{ByteArray, UTF8String}
 
 sealed abstract class PhysicalDataType
 
-sealed abstract class PhysicalPrimitiveType extends PhysicalDataType
+object PhysicalDataType {
+  def apply(dt: DataType): PhysicalDataType = dt match {
+    case NullType => PhysicalNullType
+    case BooleanType => PhysicalBooleanType
+    case ByteType => PhysicalByteType
+    case ShortType => PhysicalShortType
+    case IntegerType => PhysicalIntegerType
+    case LongType => PhysicalLongType
+    case FloatType => PhysicalFloatType
+    case DoubleType => PhysicalDoubleType
+    case DecimalType.Fixed(p, s) => PhysicalDecimalType(p, s)
+    case BinaryType => PhysicalBinaryType
+    case _ => UninitializedPhysicalType
+  }
+}
+
+trait PhysicalPrimitiveType
+
+sealed abstract class TypedPhysicalDataType extends PhysicalDataType {
+  private[sql] type InternalType
+}
+
+sealed abstract class OrderedPhysicalDataType extends TypedPhysicalDataType {
+  private[sql] def ordering: Ordering[InternalType]
+}
+
+object OrderedPhysicalDataType {
+  def apply(dt: DataType): OrderedPhysicalDataType =
+    PhysicalDataType(dt).asInstanceOf[OrderedPhysicalDataType]
+
+  def ordering(dt: DataType): Ordering[Any] = {
+    try apply(dt).ordering.asInstanceOf[Ordering[Any]] catch {
+      case NonFatal(_) =>
+        throw QueryExecutionErrors.unsupportedTypeError(dt)
+    }
+  }
+}
+
+sealed abstract class PhysicalAtomicType extends OrderedPhysicalDataType {
+  private[sql] val tag: TypeTag[InternalType]
+}
+
+object PhysicalAtomicType extends PhysicalAtomicType {
+  def apply(dt: AtomicType): PhysicalAtomicType = dt match {
+    case ByteType => PhysicalByteType
+    case ShortType => PhysicalShortType
+    case IntegerType => PhysicalIntegerType
+    case LongType => PhysicalLongType
+    case StringType => PhysicalStringType
+    case FloatType => PhysicalFloatType
+    case DoubleType => PhysicalDoubleType
+    case DecimalType.Fixed(p, s) => PhysicalDecimalType(p, s)
+    case BooleanType => PhysicalBooleanType
+    case BinaryType => PhysicalBinaryType
+    case TimestampType => PhysicalLongType
+    case TimestampNTZType => PhysicalLongType
+    case DayTimeIntervalType(_, _) => PhysicalLongType
+    case DateType => PhysicalIntegerType
+    case _ => throw QueryExecutionErrors.unsupportedOperationExceptionError()
+  }
+
+  override private[sql] val tag = null
+  override private[sql] def ordering = null
+  override private[sql] type InternalType = Null
+}
+
+sealed abstract class PhysicalNumericType extends PhysicalAtomicType {
+}
+
+object PhysicalNumericType extends PhysicalNumericType {
+  def apply(nt: NumericType): PhysicalNumericType = {
+    PhysicalDataType(nt).asInstanceOf[PhysicalNumericType]
+  }
+
+  override private[sql] val tag = null
+  override private[sql] def ordering = null
+  override private[sql] type InternalType = Null
+}
+
+sealed abstract class PhysicalIntegralType extends PhysicalNumericType {
+}
+
+object PhysicalIntegralType extends PhysicalIntegralType {
+  def apply(dt: DataType): PhysicalIntegralType = dt match {
+    case IntegerType => PhysicalIntegerType
+    case ByteType => PhysicalByteType
+    case ShortType => PhysicalShortType
+    case LongType => PhysicalLongType
+    case _ => UninitializedPhysicalIntegralType

Review Comment:
   This should just throw. Please do the same as for `OrderedPhysicalDataType 
`, and friends.



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