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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/PhysicalDataType.scala:
##########
@@ -17,53 +17,237 @@
 
 package org.apache.spark.sql.catalyst.types
 
-import org.apache.spark.sql.types._
-
-
-sealed abstract class PhysicalDataType
-
-sealed abstract class PhysicalPrimitiveType extends PhysicalDataType
-
-case class PhysicalArrayType(elementType: DataType, containsNull: Boolean) 
extends PhysicalDataType
-
-class PhysicalBinaryType() extends PhysicalDataType
+import scala.reflect.runtime.universe.TypeTag
+import scala.reflect.runtime.universe.typeTag
+
+import org.apache.spark.sql.catalyst.expressions.{Ascending, BoundReference, 
InterpretedOrdering, SortOrder}
+import org.apache.spark.sql.catalyst.util.{ArrayData, SQLOrderingUtil}
+import org.apache.spark.sql.errors.QueryExecutionErrors
+import org.apache.spark.sql.types.{ArrayType, BinaryType, BooleanType, 
ByteType, DataType, DateType, DayTimeIntervalType, Decimal, DecimalType, 
DoubleType, FloatType, IntegerType, LongType, MapType, NullType, ShortType, 
StringType, StructField, StructType, TimestampNTZType, TimestampType, 
YearMonthIntervalType}
+import org.apache.spark.unsafe.types.{ByteArray, UTF8String}
+
+sealed abstract class PhysicalDataType {
+  private[sql] type InternalType
+  private[sql] def ordering: Ordering[InternalType]
+  private[sql] val tag: TypeTag[InternalType]
+}
+
+object PhysicalDataType {
+  def apply(dt: DataType): PhysicalDataType = dt match {
+    case NullType => PhysicalNullType
+    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 YearMonthIntervalType(_, _) => PhysicalIntegerType
+    case DateType => PhysicalIntegerType
+    case ArrayType(elementType, containsNull) => 
PhysicalArrayType(elementType, containsNull)
+    case StructType(fields) => PhysicalStructType(fields)
+    case MapType(keyType, valueType, valueContainsNull) =>
+      PhysicalMapType(keyType, valueType, valueContainsNull)
+    case _ => UninitializedPhysicalType
+  }
+
+  def ordering(dt: DataType): Ordering[Any] = 
apply(dt).ordering.asInstanceOf[Ordering[Any]]
+}
+
+trait PhysicalPrimitiveType
+
+class PhysicalBinaryType() extends PhysicalDataType {
+  private[sql] val ordering =
+    (x: Array[Byte], y: Array[Byte]) => ByteArray.compareBinary(x, y)
+
+  private[sql] type InternalType = Array[Byte]
+  @transient private[sql] lazy val tag = typeTag[InternalType]
+}
 case object PhysicalBinaryType extends PhysicalBinaryType
 
-class PhysicalBooleanType() extends PhysicalPrimitiveType
-case object PhysicalBooleanType extends PhysicalBooleanType
-
-class PhysicalByteType() extends PhysicalPrimitiveType
-case object PhysicalByteType extends PhysicalByteType
-
-class PhysicalCalendarIntervalType() extends PhysicalDataType
+class PhysicalBooleanType extends PhysicalDataType {
+  // The companion object and this class is separated so the companion object 
also subclasses
+  // this type. Otherwise, the companion object would be of type 
"BooleanType$" in byte code.
+  // Defined with a private constructor so the companion object is the only 
possible instantiation.
+  private[sql] type InternalType = Boolean
+  private[sql] val ordering = implicitly[Ordering[InternalType]]
+  @transient private[sql] lazy val tag = typeTag[InternalType]
+}
+case object PhysicalBooleanType extends PhysicalBooleanType with 
PhysicalPrimitiveType

Review Comment:
   I believe there is no primitive type in logical data type? 
   
   For example `class BooleanType private() extends AtomicType {`



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