hqbhoho commented on code in PR #7733:
URL: https://github.com/apache/gravitino/pull/7733#discussion_r2210140659
##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/jdbc/mysql/MySQLMetadataAdapter.java:
##########
@@ -92,6 +101,53 @@ public GravitinoTable createTable(ConnectorTableMetadata
tableMetadata) {
return new GravitinoTable(schemaName, tableName, columns, comment,
properties);
}
+ @Override
+ public ConnectorTableMetadata getTableMetadata(GravitinoTable
gravitinoTable) {
+ SchemaTableName schemaTableName =
+ new SchemaTableName(gravitinoTable.getSchemaName(),
gravitinoTable.getName());
+ ArrayList<ColumnMetadata> columnMetadataList = new ArrayList<>();
+ for (GravitinoColumn column : gravitinoTable.getColumns()) {
+ columnMetadataList.add(getColumnMetadata(column));
+ }
+
+ Map<String, Object> properties =
toTrinoTableProperties(gravitinoTable.getProperties());
+ Index[] indexes = gravitinoTable.getIndexes();
+
+ if (ArrayUtils.isNotEmpty(indexes)) {
+ List<String> primaryKeys = new ArrayList<>();
+ List<String> uniqueKeys = new ArrayList<>();
+ for (int i = 0; i < indexes.length; i++) {
+ Index index = indexes[i];
+ switch (index.type()) {
+ case PRIMARY_KEY:
+ Arrays.stream(index.fieldNames())
+ .flatMap(Arrays::stream)
+ .forEach(col -> primaryKeys.add(col));
+ break;
+
+ case UNIQUE_KEY:
+ List<String> columns =
+ Arrays.stream(index.fieldNames())
+ .flatMap(Arrays::stream)
+ .collect(Collectors.toUnmodifiableList());
+ uniqueKeys.add(String.format("%s:%s", index.name(),
Strings.join(columns, ',')));
+ break;
+ }
+ }
+ if (!primaryKeys.isEmpty()) {
+ properties.put(TABLE_PRIMARY_KEY, primaryKeys);
Review Comment:
> You'd better make a copy of `properties` as we do not know whether it is
an immutable map or not.
the `porperties` come from `PropertyConverter#gravitinoToEngineProperties`
will be a HashMap.
```
public Map<String, String> gravitinoToEngineProperties(Map<String, String>
gravitinoProperties) {
Map<String, String> engineProperties = new HashMap<>();
Map<String, String> gravitinoToEngineMapping =
reverseMap(engineToGravitinoMapping());
for (Map.Entry<String, String> entry : gravitinoProperties.entrySet()) {
String engineKey = gravitinoToEngineMapping.get(entry.getKey());
if (engineKey != null) {
engineProperties.put(engineKey, entry.getValue());
} else {
LOG.info("Property {} is not supported by engine", entry.getKey());
}
}
return engineProperties;
}
```
--
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]