ShreelekhyaG commented on a change in pull request #4113:
URL: https://github.com/apache/carbondata/pull/4113#discussion_r608343704



##########
File path: 
integration/spark/src/main/scala/org/apache/spark/sql/execution/command/table/CarbonDescribeFormattedCommand.scala
##########
@@ -370,3 +373,134 @@ private[sql] case class CarbonDescribeFormattedCommand(
 
   override protected def opName: String = "DESC FORMATTED"
 }
+
+case class CarbonDescribeColumnCommand(
+    carbonTable: CarbonTable,
+    inputFieldNames: java.util.List[String],
+    field: StructField)
+  extends MetadataCommand {
+
+  override val output: Seq[Attribute] = Seq(
+    // Column names are based on Hive.
+    AttributeReference("col_name", StringType, nullable = false,
+      new MetadataBuilder().putString("comment", "name of the 
column").build())(),
+    AttributeReference("data_type", StringType, nullable = false,
+      new MetadataBuilder().putString("comment", "data type of the 
column").build())(),
+    AttributeReference("comment", StringType, nullable = true,
+      new MetadataBuilder().putString("comment", "comment of the 
column").build())()
+  )
+
+  override def processMetadata(sparkSession: SparkSession): Seq[Row] = {
+    setAuditTable(carbonTable)
+    var results = Seq[(String, String, String)]()
+    var currField = field
+    val inputFieldsIterator = inputFieldNames.iterator()
+    var inputColumn = inputFieldsIterator.next()
+    while (results.size == 0) {
+      breakable {
+        if 
(currField.dataType.typeName.equalsIgnoreCase(CarbonCommonConstants.ARRAY)) {
+          if (inputFieldsIterator.hasNext) {
+            val nextField = inputFieldsIterator.next()
+            if (!nextField.equalsIgnoreCase("item")) {
+              throw handleException(nextField, currField.name, 
carbonTable.getTableName)
+            }
+            currField = StructField("item", 
currField.dataType.asInstanceOf[ArrayType].elementType)
+            inputColumn += "." + currField.name
+            break()
+          }
+          val colComment = currField.getComment().getOrElse("null")
+          results = Seq((inputColumn,
+            currField.dataType.typeName, 
currField.getComment().getOrElse("null")),
+            ("## Children of " + inputColumn + ":  ", "", ""))
+          results ++= Seq(("item", currField.dataType.asInstanceOf[ArrayType]
+            .elementType.simpleString, colComment))

Review comment:
       no. modified so that child columns don't display parent column's comment.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to