You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2021/11/16 05:01:46 UTC

[GitHub] [hive] kasakrisz commented on a change in pull request #2777: HIVE-25652: Add constraints in result of “SHOW CREATE TABLE ”

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



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/metadata/CheckConstraint.java
##########
@@ -34,13 +34,40 @@
 @SuppressWarnings("serial")
 public class CheckConstraint implements Serializable {
 
-  public class CheckConstraintCol {
-    public String colName;
-    public String checkExpression;
-
-    public CheckConstraintCol(String colName, String checkExpression) {
+  public static class CheckConstraintCol {
+    private final String colName;
+    private final String checkExpression;
+    private final String enable;
+    private final String validate;
+    private final String rely;

Review comment:
       Should these be boolean?

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/DDLPlanUtils.java
##########
@@ -813,50 +838,52 @@ private String getColumns(Table table) {
     return StringUtils.join(columnDescs, ", \n");
   }
 
-  /** Struct fields are identifiers, need to be put between ``. */
+  /**
+   * Struct fields are identifiers, need to be put between ``.
+   */
   private String formatType(TypeInfo typeInfo) {
     switch (typeInfo.getCategory()) {
-    case PRIMITIVE:
-      return typeInfo.getTypeName();
-    case STRUCT:
-      StringBuilder structFormattedType = new StringBuilder();
-
-      StructTypeInfo structTypeInfo = (StructTypeInfo)typeInfo;
-      for (int i = 0; i < structTypeInfo.getAllStructFieldNames().size(); i++) {
-        if (structFormattedType.length() != 0) {
-          structFormattedType.append(", ");
-        }
+      case PRIMITIVE:
+        return typeInfo.getTypeName();
+      case STRUCT:
+        StringBuilder structFormattedType = new StringBuilder();
 
-        String structElementName = structTypeInfo.getAllStructFieldNames().get(i);
-        String structElementType = formatType(structTypeInfo.getAllStructFieldTypeInfos().get(i));
+        StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo;
+        for (int i = 0; i < structTypeInfo.getAllStructFieldNames().size(); i++) {
+          if (structFormattedType.length() != 0) {
+            structFormattedType.append(", ");
+          }
 
-        structFormattedType.append("`" + structElementName + "`:" + structElementType);
-      }
-      return "struct<" + structFormattedType.toString() + ">";
-    case LIST:
-      ListTypeInfo listTypeInfo = (ListTypeInfo)typeInfo;
-      String elementType = formatType(listTypeInfo.getListElementTypeInfo());
-      return "array<" + elementType + ">";
-    case MAP:
-      MapTypeInfo mapTypeInfo = (MapTypeInfo)typeInfo;
-      String keyTypeInfo = mapTypeInfo.getMapKeyTypeInfo().getTypeName();
-      String valueTypeInfo = formatType(mapTypeInfo.getMapValueTypeInfo());
-      return "map<" + keyTypeInfo + "," + valueTypeInfo + ">";
-    case UNION:
-      StringBuilder unionFormattedType = new StringBuilder();
-
-      UnionTypeInfo unionTypeInfo = (UnionTypeInfo)typeInfo;
-      for (TypeInfo unionElementTypeInfo : unionTypeInfo.getAllUnionObjectTypeInfos()) {
-        if (unionFormattedType.length() != 0) {
-          unionFormattedType.append(", ");
-        }
+          String structElementName = structTypeInfo.getAllStructFieldNames().get(i);

Review comment:
       Should this be escaped?
   ```
   HiveUtils.unparseIdentifier(structElementName)
   ```

##########
File path: ql/src/test/queries/clientpositive/show_create_table.q
##########
@@ -0,0 +1,44 @@
+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 CHECK (col3 + col4 > 1) enable novalidate rely,
+  col4 decimal NOT NULL,
+  col5 varchar(100),
+  primary key(col1, col2) disable novalidate rely,
+  constraint c3_c4_check CHECK((col3 + col4)/(col3 - col4) > 3),
+  constraint c4_unique UNIQUE(col4) disable novalidate rely)
+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';
+
+CREATE TABLE TEST2(
+ col varchar(100),
+ primary key(col) disable novalidate rely)
+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';
+
+CREATE TABLE TEST3(
+  col1 varchar(100) COMMENT "comment",
+  col2 timestamp,
+  col3 varchar(100),
+  foreign key(col1, col2) references TEST(col1, col2) disable novalidate rely,
+  foreign key(col3) references TEST2(col) disable novalidate rely)

Review comment:
       Please add a constraint with`enable validate norely` just to cover that case too.




-- 
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-unsubscribe@hive.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org