[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3504: [CARBONDATA-3614] Support Alter table properties set/unset for longstring columns

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3504: [CARBONDATA-3614] Support Alter table properties set/unset for longstring columns

GitBox
ajantha-bhat commented on a change in pull request #3504: [CARBONDATA-3614] Support Alter table properties set/unset for longstring columns
URL: https://github.com/apache/carbondata/pull/3504#discussion_r356961874
 
 

 ##########
 File path: integration/spark2/src/main/scala/org/apache/spark/util/AlterTableUtil.scala
 ##########
 @@ -822,6 +846,57 @@ object AlterTableUtil {
     allColumnsMatch
   }
 
+  /**
+   * Validate LONG_STRING_COLUMNS property specified in Alter command
+   *
+   * @param longStringColumns
+   * @param carbonTable
+   */
+  def validateLongStringColumns(longStringColumns: String,
+      carbonTable: CarbonTable): Unit = {
+    // don't allow duplicate column names
+    val longStringCols = longStringColumns.split(",")
+    if (longStringCols.distinct.lengthCompare(longStringCols.size) != 0) {
+      val duplicateColumns = longStringCols
+        .diff(longStringCols.distinct).distinct
+      val errMsg =
+        "LONG_STRING_COLUMNS contains Duplicate Columns: " +
+        duplicateColumns.mkString(",") + ". Please check the DDL."
+      throw new MalformedCarbonCommandException(errMsg)
+    }
+    // check column exist && it is string type
+    val colSchemas = carbonTable.getTableInfo.getFactTable.getListOfColumns.asScala
+    // check if the column specified exists in table schema
+    longStringCols.foreach { col =>
+      if (!colSchemas.exists(x => x.getColumnName.equalsIgnoreCase(col.trim))) {
+        val errorMsg = "LONG_STRING_COLUMNS column: " + col.trim +
+                       " does not exist in table. Please check the DDL."
+        throw new MalformedCarbonCommandException(errorMsg)
+      }
+    }
+    // must be of string data type
+    longStringCols.foreach { longStringCol =>
+      if (colSchemas.exists(col => col.getColumnName.equalsIgnoreCase(longStringCol) &&
+                                   !col.getDataType.toString
+                                     .equalsIgnoreCase("STRING"))) {
+        val errMsg = "LONG_STRING_COLUMNS column: " + longStringCol.trim +
+                     " is not a string datatype column"
+        throw new MalformedCarbonCommandException(errMsg)
+      }
+    }
 
 Review comment:
   yes. done.

----------------------------------------------------------------
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:
[hidden email]


With regards,
Apache Git Services