Github user jackylk commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/2800#discussion_r223205791
  
    --- Diff: 
integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/table/CarbonDescribeFormattedCommand.scala
 ---
    @@ -44,89 +42,121 @@ private[sql] case class CarbonDescribeFormattedCommand(
       override def processMetadata(sparkSession: SparkSession): Seq[Row] = {
         val relation = CarbonEnv.getInstance(sparkSession).carbonMetastore
           
.lookupRelation(tblIdentifier)(sparkSession).asInstanceOf[CarbonRelation]
    -    val mapper = new ObjectMapper()
    -    val colProps = StringBuilder.newBuilder
    -    val dims = relation.metaData.dims.map(x => x.toLowerCase)
    -    var results: Seq[(String, String, String)] = child.schema.fields.map { 
field =>
    -      val fieldName = field.name.toLowerCase
    -      val colComment = field.getComment().getOrElse("null")
    -      val comment = if (dims.contains(fieldName)) {
    -        val dimension = relation.metaData.carbonTable.getDimensionByName(
    -          relation.carbonTable.getTableName, fieldName)
    -        if (null != dimension.getColumnProperties && 
!dimension.getColumnProperties.isEmpty) {
    -          colProps.append(fieldName).append(".")
    -            
.append(mapper.writeValueAsString(dimension.getColumnProperties))
    -            .append(",")
    -        }
    -        if (dimension.hasEncoding(Encoding.DICTIONARY) &&
    -            !dimension.hasEncoding(Encoding.DIRECT_DICTIONARY)) {
    -          "DICTIONARY, KEY COLUMN" + (if 
(dimension.hasEncoding(Encoding.INVERTED_INDEX)) {
    -            "".concat(",").concat(colComment)
    -          } else {
    -            ",NOINVERTEDINDEX".concat(",").concat(colComment)
    -          })
    -        } else {
    -          "KEY COLUMN" + (if 
(dimension.hasEncoding(Encoding.INVERTED_INDEX)) {
    -            "".concat(",").concat(colComment)
    -          } else {
    -            ",NOINVERTEDINDEX".concat(",").concat(colComment)
    -          })
    -        }
    -      } else {
    -        "MEASURE".concat(",").concat(colComment)
    -      }
    +    val carbonTable = relation.carbonTable
    +    val tblProps = carbonTable.getTableInfo.getFactTable.getTableProperties
     
    -      (field.name, field.dataType.simpleString, comment)
    -    }
    -    val colPropStr = if (colProps.toString().trim().length() > 0) {
    -      // drops additional comma at end
    -      colProps.toString().dropRight(1)
    -    } else {
    -      colProps.toString()
    +    // Table Schema Information
    +    var results: Seq[(String, String, String)] = child.schema.fields.map { 
field =>
    +      (field.name, field.dataType.simpleString, 
field.getComment().getOrElse(""))
         }
    -    val carbonTable = relation.carbonTable
    -    results ++= Seq(("", "", ""), ("##Detailed Table Information", "", ""))
    -    results ++= Seq(("Database Name", 
relation.carbonTable.getDatabaseName, "")
    -    )
    -    results ++= Seq(("Table Name", relation.carbonTable.getTableName, ""))
    -    results ++= Seq(("CARBON Store Path ", carbonTable.getTablePath, ""))
     
    -    val tblProps = carbonTable.getTableInfo.getFactTable.getTableProperties
    +    results ++= Seq(("", "", ""), ("### PROPERTY", "VALUE", 
"DEFAULT_VALUE"))
    +
    +    // Table Basic Information
    +    results ++= Seq(("", "", ""), ("## Table Basic Information", "", ""))
    +    results ++= Seq(("Database Name", carbonTable.getDatabaseName, ""))
    +    results ++= Seq(("Table Name", carbonTable.getTableName, ""))
    +    results ++= Seq(("Table Path", carbonTable.getTablePath, ""))
     
         // Carbon table support table comment
    -    val tableComment = 
tblProps.asScala.getOrElse(CarbonCommonConstants.TABLE_COMMENT, "")
    -    results ++= Seq(("Comment", tableComment, ""))
    -    results ++= Seq(("Table Block Size ", carbonTable.getBlockSizeInMB + " 
MB", ""))
    +    results ++= Seq(("Comment",
    +        tblProps.asScala.getOrElse(CarbonCommonConstants.TABLE_COMMENT, 
""), ""))
    +
         val dataIndexSize = CarbonUtil.calculateDataIndexSize(carbonTable, 
false)
    +    var tableDataSizeStr = "0B"
    +    var tableIndexSizeStr = "0B"
    +    var lastUpdateTimeStr = "NA"
         if (!dataIndexSize.isEmpty) {
    -      results ++= Seq((CarbonCommonConstants.TABLE_DATA_SIZE,
    -        
dataIndexSize.get(CarbonCommonConstants.CARBON_TOTAL_DATA_SIZE).toString, ""))
    -      results ++= Seq((CarbonCommonConstants.TABLE_INDEX_SIZE,
    -        
dataIndexSize.get(CarbonCommonConstants.CARBON_TOTAL_INDEX_SIZE).toString, ""))
    -      results ++= Seq((CarbonCommonConstants.LAST_UPDATE_TIME,
    -        
dataIndexSize.get(CarbonCommonConstants.LAST_UPDATE_TIME).toString, ""))
    +      val tableDataSize =
    +        
dataIndexSize.get(CarbonCommonConstants.CARBON_TOTAL_DATA_SIZE).toLong
    +      tableDataSizeStr = Strings.formatSize(tableDataSize)
    +      val tableIndexSize =
    +        
dataIndexSize.get(CarbonCommonConstants.CARBON_TOTAL_INDEX_SIZE).toLong
    +      tableIndexSizeStr = Strings.formatSize(tableIndexSize)
    +      val lastUpdateTime = 
dataIndexSize.get(CarbonCommonConstants.LAST_UPDATE_TIME).toLong
    +      lastUpdateTimeStr = if (lastUpdateTime > 0L) {
    +        new java.sql.Timestamp(lastUpdateTime).toString()
    +      } else {
    +        "NA"
    +      }
         }
    +    results ++= Seq((CarbonCommonConstants.TABLE_DATA_SIZE, 
tableDataSizeStr, ""))
    +    results ++= Seq((CarbonCommonConstants.TABLE_INDEX_SIZE, 
tableIndexSizeStr, ""))
    +    results ++= Seq((CarbonCommonConstants.LAST_UPDATE_TIME, 
lastUpdateTimeStr, ""))
     
    +    // Detailed Table Properties Information
    +    results ++= Seq(("", "", ""), ("## Detailed Table Properties 
Information", "", ""))
    +    results ++= Seq(("Table Block Size", carbonTable.getBlockSizeInMB + " 
MB",
    +        CarbonCommonConstants.BLOCK_SIZE_DEFAULT_VAL + " MB"))
         results ++= Seq(("SORT_SCOPE", 
tblProps.asScala.getOrElse("sort_scope", CarbonCommonConstants
    --- End diff --
    
    For these table properties, I think it is not very good to print the 
default value if the user does not specify. Because the default value may 
change from version to version, I think it is better to write the value to 
table property when loading the table. Then in DESC table, we can always get 
the table properties from the schema file


---

Reply via email to