kasakrisz commented on a change in pull request #2752:
URL: https://github.com/apache/hive/pull/2752#discussion_r738996497



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/DDLPlanUtils.java
##########
@@ -800,19 +804,59 @@ private String getExternal(Table table) {
     return table.getTableType() == TableType.EXTERNAL_TABLE ? "EXTERNAL " : "";
   }
 
-  private String getColumns(Table table) {
-    List<String> columnDescs = new ArrayList<String>();
+  private String getColumns(Table table) throws HiveException{
+    List<String> columnDescs = new ArrayList<>();
+    Set<String> notNullColumns = null;
+    if 
(NotNullConstraint.isNotNullConstraintNotEmpty(table.getNotNullConstraint())) {
+      notNullColumns = new 
HashSet<>(table.getNotNullConstraint().getNotNullConstraints().values());
+    }
+
+    Map<String, String> columnDefaultValueMap = null;
+    if 
(DefaultConstraint.isCheckConstraintNotEmpty(table.getDefaultConstraint())) {

Review comment:
       `DefaultConstraint.isCheckConstraintNotEmpty` can be renamed to 
`DefaultConstraint.isDefaultConstraintNotEmpty`. What is your opinion?

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/DDLPlanUtils.java
##########
@@ -800,19 +804,59 @@ private String getExternal(Table table) {
     return table.getTableType() == TableType.EXTERNAL_TABLE ? "EXTERNAL " : "";
   }
 
-  private String getColumns(Table table) {
-    List<String> columnDescs = new ArrayList<String>();
+  private String getColumns(Table table) throws HiveException{
+    List<String> columnDescs = new ArrayList<>();
+    Set<String> notNullColumns = null;
+    if 
(NotNullConstraint.isNotNullConstraintNotEmpty(table.getNotNullConstraint())) {
+      notNullColumns = new 
HashSet<>(table.getNotNullConstraint().getNotNullConstraints().values());
+    }
+
+    Map<String, String> columnDefaultValueMap = null;
+    if 
(DefaultConstraint.isCheckConstraintNotEmpty(table.getDefaultConstraint())) {
+      columnDefaultValueMap = 
table.getDefaultConstraint().getColNameToDefaultValueMap();
+    }
     for (FieldSchema column : table.getCols()) {
       String columnType = 
formatType(TypeInfoUtils.getTypeInfoFromTypeString(column.getType()));
-      String columnDesc = "  `" + column.getName() + "` " + columnType;
+      String columnName = column.getName();
+      StringBuilder columnDesc = new StringBuilder();
+      columnDesc.append("  `").append(columnName).append("` 
").append(columnType);

Review comment:
       Should backticks in `columnName` be escaped here?
   please see `HiveUtils.unparseIdentifier(fieldSchema.getName(), conf)`
   
   This this is out of the scope here it can be fixed in a follow-up jira.
   The reason why I mentioning this is because I'm not sure about that the 
command generated by `show create table` can actually be executed if a column 
and/or table name has special characters.
   
https://github.com/apache/hive/blob/918e4e3bb535be095f336bb7742e92471357ec05/ql/src/test/queries/clientpositive/quotedid_basic.q#L18
   

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/DDLPlanUtils.java
##########
@@ -800,19 +804,59 @@ private String getExternal(Table table) {
     return table.getTableType() == TableType.EXTERNAL_TABLE ? "EXTERNAL " : "";
   }
 
-  private String getColumns(Table table) {
-    List<String> columnDescs = new ArrayList<String>();
+  private String getColumns(Table table) throws HiveException{
+    List<String> columnDescs = new ArrayList<>();
+    Set<String> notNullColumns = null;
+    if 
(NotNullConstraint.isNotNullConstraintNotEmpty(table.getNotNullConstraint())) {
+      notNullColumns = new 
HashSet<>(table.getNotNullConstraint().getNotNullConstraints().values());
+    }
+
+    Map<String, String> columnDefaultValueMap = null;
+    if 
(DefaultConstraint.isCheckConstraintNotEmpty(table.getDefaultConstraint())) {
+      columnDefaultValueMap = 
table.getDefaultConstraint().getColNameToDefaultValueMap();
+    }
     for (FieldSchema column : table.getCols()) {
       String columnType = 
formatType(TypeInfoUtils.getTypeInfoFromTypeString(column.getType()));
-      String columnDesc = "  `" + column.getName() + "` " + columnType;
+      String columnName = column.getName();
+      StringBuilder columnDesc = new StringBuilder();
+      columnDesc.append("  `").append(columnName).append("` 
").append(columnType);
+      if (notNullColumns != null && notNullColumns.contains(columnName)) {

Review comment:
       nit: this if statement can be simplified by removing the null check 
`notNullColumns != null`
   When notNullColumns is defined let's assign the empty set as default value
   ```
       Set<String> notNullColumns = Collections.emptySet();
       if 
(NotNullConstraint.isNotNullConstraintNotEmpty(table.getNotNullConstraint())) {
         notNullColumns = new 
HashSet<>(table.getNotNullConstraint().getNotNullConstraints().values());
       }
   ```
   or it can be assigned in an else branch like
   ```
       Set<String> notNullColumns;
       if 
(NotNullConstraint.isNotNullConstraintNotEmpty(table.getNotNullConstraint())) {
         notNullColumns = new 
HashSet<>(table.getNotNullConstraint().getNotNullConstraints().values());
       } else {
         notNullColumns = Collections.emptySet();
       }
   ```
   
   Same for `columnDefaultValueMap` (`Collections.emptyMap()`)




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