[ 
https://issues.apache.org/jira/browse/HIVE-25652?focusedWorklogId=672258&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-672258
 ]

ASF GitHub Bot logged work on HIVE-25652:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 29/Oct/21 23:54
            Start Date: 29/Oct/21 23:54
    Worklog Time Spent: 10m 
      Work Description: soumyakanti3578 commented on a change in pull request 
#2752:
URL: https://github.com/apache/hive/pull/2752#discussion_r739579722



##########
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:
       Do we really need the backticks? Removing them will make check 
constraints very easy, as we can directly use the check expression. Let's say 
the check expression is `col3 + col4 > 3`, and we don't get backticks here. If 
we don't use backticks anywhere, we can use this directly, otherwise we'll have 
to somehow figure out the column names and add backticks around it, which will 
make it a bit more complex.




-- 
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: gitbox-unsubscr...@hive.apache.org

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 672258)
    Time Spent: 40m  (was: 0.5h)

> Add constraints in result of “SHOW CREATE TABLE ”
> -------------------------------------------------
>
>                 Key: HIVE-25652
>                 URL: https://issues.apache.org/jira/browse/HIVE-25652
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: Soumyakanti Das
>            Assignee: Soumyakanti Das
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> Currently show create table doesn’t pull any constraint info like not null, 
> defaults, primary key.
> Example:
> Create table
>  
> {code:java}
> CREATE TABLE TEST(
>   col1 varchar(100) NOT NULL COMMENT "comment for column 1",
>   col2 timestamp DEFAULT CURRENT_TIMESTAMP() COMMENT "comment for column 2",
>   col3 decimal,
>   col4 varchar(512) NOT NULL,
>   col5 varchar(100),
>   primary key(col1, col2) disable novalidate)
> ROW FORMAT SERDE
>   'org.apache.hadoop.hive.ql.io.orc.OrcSerde'
> STORED AS INPUTFORMAT
>   'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
> OUTPUTFORMAT
>   'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat';
> {code}
> Currently {{SHOW CREATE TABLE TEST}} doesn't show the column constraints.
> {code:java}
> CREATE TABLE `test`(
>   `col1` varchar(100) COMMENT 'comment for column 1', 
>   `col2` timestamp COMMENT 'comment for column 2', 
>   `col3` decimal(10,0), 
>   `col4` varchar(512), 
>   `col5` varchar(100))
> ROW FORMAT SERDE 
>   'org.apache.hadoop.hive.ql.io.orc.OrcSerde' 
> STORED AS INPUTFORMAT 
>   'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' 
> OUTPUTFORMAT 
>   'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to