[
https://issues.apache.org/jira/browse/HIVE-25652?focusedWorklogId=672562&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-672562
]
ASF GitHub Bot logged work on HIVE-25652:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 01/Nov/21 07:16
Start Date: 01/Nov/21 07:16
Worklog Time Spent: 10m
Work Description: 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 672562)
Time Spent: 50m (was: 40m)
> 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: 50m
> 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)