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

[#4867] feat(core): Add storage support for columns in Gravitino #5078

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jerryshao
Copy link
Contributor

What changes were proposed in this pull request?

This PR aims to add storage support for columns in Gravitino.

Why are the changes needed?

With this, we can also support managing columns in Gravitno, like set tags, do column level privileges.

Fix: #4867

Does this PR introduce any user-facing change?

No.

How was this patch tested?

UTs added.

@jerryshao jerryshao self-assigned this Oct 9, 2024
scripts/postgresql/schema-0.7.0-postgresql.sql Outdated Show resolved Hide resolved
@@ -0,0 +1,290 @@
--
Copy link
Contributor

Choose a reason for hiding this comment

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

Once we are going to release a new version then a corresponding schema SQL file is needed, am I right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the meaning, can you please explain more?

.withDefaultValue(
columnEntity.defaultValue() == null
|| columnEntity.defaultValue().equals(Column.DEFAULT_VALUE_NOT_SET)
? null
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if the value of nullable is false, can we set the default value as null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use this DEFAULT_VALUE_NOT_SET to represent null, I think it is aligned with ColumnDTO's current implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

For column default value, we use DEFAULT_VALUE_NOT_SET and Literals.NULL to represent different default values:

  • For DEFAULT_VALUE_NOT_SET, it means that the user has not set a default value. If the column is nullable=false, then this default value will be entirely determined by the underlying catalog (for example, some engines set the default value of column int not null to 0).
  • For Literals.NULL, if the column nullable=true, we can use Literals.NULL to explicitly specify the default value as null. if we use DEFAULT_VALUE_NOT_SET, then this default value will be entirely determined by the underlying catalog

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For column default value, we use DEFAULT_VALUE_NOT_SET and Literals.NULL to represent different default values:

  • For DEFAULT_VALUE_NOT_SET, it means that the user has not set a default value. If the column is nullable=false, then this default value will be entirely determined by the underlying catalog (for example, some engines set the default value of column int not null to 0).
  • For Literals.NULL, if the column nullable=true, we can use Literals.NULL to explicitly specify the default value as null. if we use DEFAULT_VALUE_NOT_SET, then this default value will be entirely determined by the underlying catalog

I see, let me update the code.

mapper.insertTableMetaOnDuplicateKeyUpdate(po);
} else {
mapper.insertTableMeta(po);
TableColumnMetaService.getInstance()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a good way to judge if there has been a change in the table so that we don't need to drop all columns and create them if no changes have been made to them such as table renaming, or altering table comments?

Copy link
Contributor

Choose a reason for hiding this comment

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

TableColumnMetaService.getInstance().isColumnUpdated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't need to drop all columns and create them if no changes have been made to them such as table renaming, or altering table comments

If we don't want to update the columns, we have to fetch the old columns then do the comparison. The current overwrite doesn't fetch the old data, so we have to fetch again, the overhead is the same.

List<ColumnPO> columnPOsToInsert = Lists.newArrayList();
for (ColumnEntity newColumn : newColumns.values()) {
ColumnEntity oldColumn = oldColumns.get(newColumn.id());
if (oldColumn == null || !oldColumn.equals(newColumn)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if oldColumn == null, it means the newColumn is a newly created one, so the op type should not be update

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 depends on how we define the UPDATE or CREATE, here in my implementation, I only set the type to CREATE when table is created, UPDATE for table update, no matter it is adding new column or updating the existing column.

Actually, no matter it is UPDATE or CREATE, what we only care if DELETE, which is used to filter out deleted columns.

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.

[Subtask] Design and implement the column storage layout for columns.
3 participants