in catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonCatalogOperations.java [321:400]
public GravitinoPaimonTable createTable(
NameIdentifier identifier,
Column[] columns,
String comment,
Map<String, String> properties,
Transform[] partitioning,
Distribution distribution,
SortOrder[] sortOrders,
Index[] indexes)
throws NoSuchSchemaException, TableAlreadyExistsException {
NameIdentifier nameIdentifier = buildPaimonNameIdentifier(identifier);
NameIdentifier schemaIdentifier = NameIdentifier.of(nameIdentifier.namespace().levels());
if (!schemaExists(schemaIdentifier)) {
throw new NoSuchSchemaException(NO_SUCH_SCHEMA_EXCEPTION, schemaIdentifier);
}
if (partitioning == null) {
partitioning = EMPTY_TRANSFORM;
}
if (indexes == null) {
indexes = EMPTY_INDEXES;
}
Preconditions.checkArgument(
Arrays.stream(partitioning)
.allMatch(
partition -> {
NamedReference[] references = partition.references();
return references.length == 1
&& references[0] instanceof NamedReference.FieldReference;
}),
"Paimon partition columns should not be nested.");
Preconditions.checkArgument(
distribution == null || distribution.strategy() == Distributions.NONE.strategy(),
"Distribution is not supported for Paimon in Gravitino now.");
Preconditions.checkArgument(
sortOrders == null || sortOrders.length == 0,
"Sort orders are not supported for Paimon in Gravitino.");
checkPaimonIndexes(indexes);
String currentUser = currentUser();
GravitinoPaimonTable createdTable =
GravitinoPaimonTable.builder()
.withName(identifier.name())
.withColumns(
Arrays.stream(columns)
.map(
column -> {
TableOpsUtils.checkColumnCapability(
column.name(), column.defaultValue(), column.autoIncrement());
return GravitinoPaimonColumn.builder()
.withName(column.name())
.withType(column.dataType())
.withComment(column.comment())
.withNullable(column.nullable())
.withAutoIncrement(column.autoIncrement())
.withDefaultValue(column.defaultValue())
.build();
})
.toArray(GravitinoPaimonColumn[]::new))
.withPartitioning(partitioning)
.withComment(comment)
.withProperties(properties)
.withIndexes(indexes)
.withAuditInfo(
AuditInfo.builder().withCreator(currentUser).withCreateTime(Instant.now()).build())
.build();
try {
Schema paimonTableSchema = createdTable.toPaimonTableSchema();
paimonCatalogOps.createTable(nameIdentifier.toString(), paimonTableSchema);
} catch (Catalog.DatabaseNotExistException e) {
throw new NoSuchSchemaException(e, NO_SUCH_SCHEMA_EXCEPTION, identifier);
} catch (Catalog.TableAlreadyExistException e) {
throw new TableAlreadyExistsException(e, TABLE_ALREADY_EXISTS_EXCEPTION, identifier);
}
LOG.info(
"Created Paimon table: {}. Current user: {}. Comment: {}. Metadata: {}.",
identifier,
currentUser,
comment,
properties);
return createdTable;
}