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/01 07:16:54 UTC
[GitHub] [hive] kasakrisz commented on a change in pull request #2752: HIVE-25652: Add constraints in result of “SHOW CREATE TABLE ”
kasakrisz commented on a change in pull request #2752:
URL: https://github.com/apache/hive/pull/2752#discussion_r739999468
##########
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:
Without backticks identifiers contains special characters like space can not be handled. See the create table example from `quotedid_basic.q` Those characters can be used in column names too.
Yes, it requires a more complex solution but in the end we can print `CREATE TABLE` statements which can be executed by just copy-pasting.
Probably the expression in the check constraint must be parsed to AST to collect the identifiers and replace them with the escaped versions.
1. Example how to build the AST:
https://github.com/apache/hive/blob/8a8e03d02003aa3543f46f595b4425fd8c156ad9/ql/src/java/org/apache/hadoop/hive/ql/parse/type/ConstraintExprGenerator.java#L180
2. The AST need to be traversed to replace the identifiers.
3. Print the altered expression from AST. You need a TokenRewriteStream to do this and currently `parseExpression` doesn't return it. So more code need to be changed 🙂 https://github.com/apache/hive/blob/8a8e03d02003aa3543f46f595b4425fd8c156ad9/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java#L15010
This seems to be a bigger change feel free to tackle this in a separate jira.
--
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