Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CARBONDATA-4014] Support Change Column Comment #3960

Closed
wants to merge 1 commit into from

Conversation

marchpure
Copy link
Contributor

Why is this PR needed?

Now, we support add column comment in "CREATE TABLE" and "ADD COLUMN". but do not support alter comment of the column, which shall be support in 'CHANGE COLUMN'

What changes were proposed in this PR?

Support "ALTER TABLE table_name CHANGE [COLUMN] col_name col_name data_type [COMMENT col_comment]"

Does this PR introduce any user interface change?

  • Yes. add CHANGE COLUMN explaination in the ddl document.

Is any new testcase added?

  • Yes

@CarbonDataQA1
Copy link

Build Failed with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/4228/

@CarbonDataQA1
Copy link

Build Failed with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/2484/

@CarbonDataQA1
Copy link

Build Failed with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/4229/

@CarbonDataQA1
Copy link

Build Failed with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/2485/

@marchpure marchpure force-pushed the addcomment branch 2 times, most recently from 53ebd84 to 67d3789 Compare September 27, 2020 02:56
@CarbonDataQA1
Copy link

Build Success with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/4230/

@CarbonDataQA1
Copy link

Build Success with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/2486/

@CarbonDataQA1
Copy link

Build Success with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/4232/

@CarbonDataQA1
Copy link

Build Success with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/2488/

@klaus-xiong
Copy link

LGTM

@@ -366,7 +366,7 @@ class AlterTableValidationTestCase extends QueryTest with BeforeAndAfterAll {
sql("alter table default.restructure change decimalfield deciMalfield Decimal(11,3)")
sql("alter table default.restructure change decimalfield deciMalfield Decimal(12,3)")
intercept[ProcessMetaDataException] {
sql("alter table default.restructure change decimalfield deciMalfield Decimal(12,3)")
sql("alter table default.restructure change decimalfield deciMalfield Decimal(12,2)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this pr, we don't allow change dataype to same precision, which is actually allowed now for 2 reason:

  1. Be consistent with hive and spark;
  2. In 'CHANGE COLUMN' command. we support just change comment without renaming and changing datatype;

Copy link
Contributor

@QiangCai QiangCai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. do we support alter column without any change?
  2. how to remove comment from column

@@ -169,7 +169,8 @@ case class AlterTableDataTypeChangeModel(dataTypeInfo: DataTypeInfo,
tableName: String,
columnName: String,
newColumnName: String,
isColumnRename: Boolean)
isColumnRename: Boolean,
newColumnComment: Option[String])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to provide a default value: None.
it can avoid other unnecessary changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have modified code according to you suggestion.

if (col.getColumnName.equalsIgnoreCase(oldColumnName)) {
throw new MalformedCarbonCommandException(
s"Column Rename Operation failed. Renaming or ChangeType or " +
s"ChangeComment the partition column $newColumnName is not " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about to support changing comments of partition columns?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is really hard to support changing comments of partition columns, as spark and hive also don't support.
https://stackoverflow.com/questions/57871294/how-to-add-edit-the-comment-of-a-partitioned-column-in-hive-table

} else {
throw new MalformedCarbonCommandException("Data type provided is invalid.")
}
DataTypeInfo(DataTypeConverterUtil.convertToCarbonType(dataType).getName.toLowerCase)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the parameter isColumnRename of this method needed?

Copy link
Contributor Author

@marchpure marchpure Sep 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need. It is useless to throw MalformedCarbonCommandException("Data type provided is invalid.")
CarbonAlterTableColumnRenameCommand.validateColumnDataType will validate the given datatype.

I have delete the parameter isColumnRename. Please have a check

Comment on lines 235 to 239
if (changeColumnCommand.newColumn.metadata != null &&
changeColumnCommand.newColumn.metadata.contains(CarbonCommonConstants.COLUMN_COMMENT)) {
newColumnComment = Some(changeColumnCommand.
newColumn.metadata.getString(CarbonCommonConstants.COLUMN_COMMENT))
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is already a varibale "newColumn" that can be used above, or it is better to make "changeColumnCommand.newColumn.metadata" as a variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have modified code according to you suggestion.

@marchpure
Copy link
Contributor Author

  1. do we support alter column without any change?
  2. how to remove comment from column
  1. now, we support alter column without any change.
  2. now. we don't support remove comment.

@QiangCai
Copy link
Contributor

if alter column change nothing, the command should return directly without execution.

@CarbonDataQA1
Copy link

Build Success with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/4252/

@CarbonDataQA1
Copy link

Build Success with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/2507/

@marchpure
Copy link
Contributor Author

if alter column change nothing, the command should return directly without execution.

I have modified code according to you suggestion.

@CarbonDataQA1
Copy link

Build Success with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/2517/

@CarbonDataQA1
Copy link

Build Success with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/4262/

@@ -258,7 +262,7 @@ private[sql] case class CarbonAlterTableColRenameDataTypeChangeCommand(
}
} catch {
case e: Exception =>
if (carbonTable != null) {
if ( carbonTable != null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there has a blank between the '(' and carbonTable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have modified code according to you suggestion.

@CarbonDataQA1
Copy link

Build Success with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/2520/

@CarbonDataQA1
Copy link

Build Failed with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/4265/

@marchpure
Copy link
Contributor Author

retest this please

@CarbonDataQA1
Copy link

Build Success with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/4266/

@CarbonDataQA1
Copy link

Build Success with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/2521/

@Zhangshunyu
Copy link
Contributor

LGTM

col =>
if (col.getColumnName.equalsIgnoreCase(oldColumnName)) {
throw new MalformedCarbonCommandException(
s"Change Column Operation failed. Renaming or ChangeType or " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to

throw new InvalidOperationException("Alter on partition columns is not supported")

And add a test case for this

@CarbonDataQA1
Copy link

Build Failed with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/4268/

@CarbonDataQA1
Copy link

Build Failed with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/2523/

Why is this PR needed?
Now, we support add column comment in "CREATE TABLE" and "ADD COLUMN". but do not support alter comment of the column, which shall be support in 'CHANGE COLUMN'

What changes were proposed in this PR?
Support "ALTER TABLE table_name CHANGE [COLUMN] col_name col_name data_type [COMMENT col_comment]"

Does this PR introduce any user interface change?
Yes. add CHANGE COLUMN explaination in the ddl document.

Is any new testcase added?
Yes
@CarbonDataQA1
Copy link

Build Success with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/4269/

@CarbonDataQA1
Copy link

Build Success with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/2524/

@kunal642
Copy link
Contributor

LGTM

@asfgit asfgit closed this in 5e81796 Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants