[GitHub] [carbondata] zzcclp 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] zzcclp commented on a change in pull request #3504: [CARBONDATA-3614] Support Alter table properties set/unset for longstring columns

GitBox
zzcclp 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_r356715276
 
 

 ##########
 File path: core/src/main/java/org/apache/carbondata/core/util/CarbonUtil.java
 ##########
 @@ -3396,4 +3398,105 @@ public static CarbonFile createTempFolderForIndexServer(String tablePath, String
       return file;
     }
   }
+
+  /**
+   * For alter table tableProperties of long string, modify ColumnSchema
+   * set operation:
+   * a. reset the current varchar datatype to string
+   * b. reorder back to original order (consider sort column and original schema ordinal)
+   * c. set the new columns to varchar
+   * d. reorder new varchar columns to be after dimensions
+   * <p>
+   * unset operation:
+   * a. reset the current varchar datatype to string
+   * b. reorder back to original order (consider sort column and original schema ordinal)
+   *
+   * @param columns                 list of column schema from thrift
+   * @param longStringColumnsString comma separated long string columns to be set, empty for unset
+   * @return updated columnSchema list
+   */
+  public static List<org.apache.carbondata.format.ColumnSchema> reorderColumnsForLongString(
+      List<org.apache.carbondata.format.ColumnSchema> columns, String longStringColumnsString) {
+    // find the end of the dimension index [which can be start of complex or measure columns or end]
+    // if doesn't find any complex are measure column, last element is the dimension end.
+    int dimensionEnd = columns.size() - 1;
+    int sortColumnEnd = -1;
+    for (int i = 0; i < columns.size(); i++) {
+      // if it is complex or measure, then previous index is dimension end
+      if ((columns.get(i).getData_type() == org.apache.carbondata.format.DataType.ARRAY
+          || columns.get(i).getData_type() == org.apache.carbondata.format.DataType.STRUCT
+          || columns.get(i).getData_type() == org.apache.carbondata.format.DataType.MAP || (!columns
+          .get(i).isDimension()))) {
+        dimensionEnd = i - 1;
+        break;
+      } else {
+        // update sort columns end
+        if (columns.get(i).getColumnProperties() != null) {
+          String isSortColumn =
+              columns.get(i).getColumnProperties().get(CarbonCommonConstants.SORT_COLUMNS);
+          if ((isSortColumn != null) && (isSortColumn.equalsIgnoreCase("true"))) {
+            sortColumnEnd = i;
+          }
+        }
+      }
+    }
+    List<org.apache.carbondata.format.ColumnSchema> sortColumns = null;
+    List<org.apache.carbondata.format.ColumnSchema> dimColumns = null;
+    List<org.apache.carbondata.format.ColumnSchema> otherColumns = null;
+    if (sortColumnEnd != -1) {
+      // sort columns will always be present first
+      sortColumns = columns.subList(0, sortColumnEnd + 1);
+      dimColumns = columns.subList(sortColumnEnd + 1, dimensionEnd + 1);
+    } else {
+      dimColumns = columns.subList(0, dimensionEnd + 1);
+    }
+    otherColumns = columns.subList(dimensionEnd + 1, columns.size());
+    // clear the varchar type in dims
+    boolean isResetDone = false;
+    for (org.apache.carbondata.format.ColumnSchema col : dimColumns) {
+      if (col.data_type == org.apache.carbondata.format.DataType.VARCHAR) {
+        col.data_type = org.apache.carbondata.format.DataType.STRING;
+        isResetDone = true;
+      }
+    }
 
 Review comment:
   get these three ColumnSchema list in the 'for' loop which starts from line 3424.
   and also set DataType.STRING in that loop.

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