-
Notifications
You must be signed in to change notification settings - Fork 409
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
[#1661] feat(core): introduce catalog capability framework #2819
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...talog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveCatalogCapability.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.catalog.hive; | ||
|
||
import com.datastrato.gravitino.connector.capability.Capability; | ||
import com.datastrato.gravitino.connector.capability.CapabilityResult; | ||
|
||
public class HiveCatalogCapability implements Capability { | ||
@Override | ||
public CapabilityResult columnNotNull() { | ||
// The NOT NULL constraint for column is supported since Hive3.0, see | ||
// https://issues.apache.org/jira/browse/HIVE-16575 | ||
return CapabilityResult.unsupported( | ||
"The NOT NULL constraint for column is only supported since Hive 3.0, " | ||
+ "but the current Gravitino Hive catalog only supports Hive 2.x."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
core/src/main/java/com/datastrato/gravitino/catalog/CapabilityHelpers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.catalog; | ||
|
||
import static com.datastrato.gravitino.rel.Column.DEFAULT_VALUE_NOT_SET; | ||
|
||
import com.datastrato.gravitino.connector.capability.Capability; | ||
import com.datastrato.gravitino.rel.Column; | ||
import com.datastrato.gravitino.rel.TableChange; | ||
import com.google.common.base.Preconditions; | ||
import java.util.Arrays; | ||
|
||
public class CapabilityHelpers { | ||
|
||
public static Column[] applyCapabilities(Column[] columns, Capability capabilities) { | ||
return Arrays.stream(columns) | ||
.map(c -> applyCapabilities(c, capabilities)) | ||
.toArray(Column[]::new); | ||
} | ||
|
||
public static TableChange[] applyCapabilities(Capability capabilities, TableChange... changes) { | ||
return Arrays.stream(changes) | ||
.map( | ||
change -> { | ||
if (change instanceof TableChange.AddColumn) { | ||
return applyCapabilities((TableChange.AddColumn) change, capabilities); | ||
|
||
} else if (change instanceof TableChange.UpdateColumnNullability) { | ||
return applyCapabilities( | ||
(TableChange.UpdateColumnNullability) change, capabilities); | ||
} | ||
return change; | ||
}) | ||
.toArray(TableChange[]::new); | ||
} | ||
|
||
private static TableChange applyCapabilities( | ||
TableChange.AddColumn addColumn, Capability capabilities) { | ||
Column appliedColumn = | ||
applyCapabilities( | ||
Column.of( | ||
addColumn.fieldName()[0], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why getting the first element of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because the first name is the column name, and the others are just nested fields in columns. |
||
addColumn.getDataType(), | ||
addColumn.getComment(), | ||
addColumn.isNullable(), | ||
addColumn.isAutoIncrement(), | ||
addColumn.getDefaultValue()), | ||
capabilities); | ||
|
||
return TableChange.addColumn( | ||
applyCaseSensitiveOnColumnName(addColumn.fieldName(), capabilities), | ||
appliedColumn.dataType(), | ||
appliedColumn.comment(), | ||
addColumn.getPosition(), | ||
appliedColumn.nullable(), | ||
appliedColumn.autoIncrement(), | ||
appliedColumn.defaultValue()); | ||
} | ||
|
||
private static TableChange applyCapabilities( | ||
TableChange.UpdateColumnNullability updateColumnNullability, Capability capabilities) { | ||
|
||
applyColumnNotNull( | ||
String.join(".", updateColumnNullability.fieldName()), | ||
updateColumnNullability.nullable(), | ||
capabilities); | ||
|
||
return TableChange.updateColumnNullability( | ||
applyCaseSensitiveOnColumnName(updateColumnNullability.fieldName(), capabilities), | ||
updateColumnNullability.nullable()); | ||
} | ||
|
||
private static Column applyCapabilities(Column column, Capability capabilities) { | ||
applyColumnNotNull(column, capabilities); | ||
applyColumnDefaultValue(column, capabilities); | ||
applyNameSpecification(Capability.Scope.COLUMN, column.name(), capabilities); | ||
|
||
return Column.of( | ||
applyCaseSensitiveOnName(Capability.Scope.COLUMN, column.name(), capabilities), | ||
column.dataType(), | ||
column.comment(), | ||
column.nullable(), | ||
column.autoIncrement(), | ||
column.defaultValue()); | ||
} | ||
|
||
private static String applyCaseSensitiveOnName( | ||
Capability.Scope scope, String name, Capability capabilities) { | ||
return capabilities.caseSensitiveOnName(scope).supported() ? name : name.toLowerCase(); | ||
} | ||
|
||
private static String[] applyCaseSensitiveOnColumnName(String[] name, Capability capabilities) { | ||
if (!capabilities.caseSensitiveOnName(Capability.Scope.COLUMN).supported()) { | ||
String[] standardizeColumnName = Arrays.copyOf(name, name.length); | ||
standardizeColumnName[0] = name[0].toLowerCase(); | ||
return standardizeColumnName; | ||
} | ||
return name; | ||
} | ||
|
||
private static void applyColumnNotNull(Column column, Capability capabilities) { | ||
applyColumnNotNull(column.name(), column.nullable(), capabilities); | ||
} | ||
|
||
private static void applyColumnNotNull( | ||
String columnName, boolean nullable, Capability capabilities) { | ||
Preconditions.checkArgument( | ||
capabilities.columnNotNull().supported() || nullable, | ||
capabilities.columnNotNull().unsupportedMessage() + " Illegal column: " + columnName); | ||
} | ||
|
||
private static void applyColumnDefaultValue(Column column, Capability capabilities) { | ||
Preconditions.checkArgument( | ||
capabilities.columnDefaultValue().supported() | ||
|| DEFAULT_VALUE_NOT_SET.equals(column.defaultValue()), | ||
capabilities.columnDefaultValue().unsupportedMessage() | ||
+ " Illegal column: " | ||
+ column.name()); | ||
} | ||
|
||
private static void applyNameSpecification( | ||
Capability.Scope scope, String name, Capability capabilities) { | ||
Preconditions.checkArgument( | ||
capabilities.specificationOnName(scope, name).supported(), | ||
capabilities.specificationOnName(scope, name).unsupportedMessage() | ||
+ " Illegal name: " | ||
+ name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is just one capability, why do you need to use plural?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method will apply multiple capabilities to the column, such as default value, not null, case sensitivity, and so on. Therefore I use plural