-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### What changes were proposed in this pull request? This PR adds the ModelOperationDispatcher logic in core. ### Why are the changes needed? This is a part of work to support model management. Fix: #5794 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Added UTs to test.
- Loading branch information
Showing
17 changed files
with
1,000 additions
and
40 deletions.
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
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
94 changes: 94 additions & 0 deletions
94
core/src/main/java/org/apache/gravitino/catalog/EntityCombinedModel.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,94 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.gravitino.catalog; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import org.apache.gravitino.Audit; | ||
import org.apache.gravitino.meta.AuditInfo; | ||
import org.apache.gravitino.meta.ModelEntity; | ||
import org.apache.gravitino.model.Model; | ||
|
||
public final class EntityCombinedModel implements Model { | ||
|
||
private final Model model; | ||
|
||
private final ModelEntity modelEntity; | ||
|
||
private Set<String> hiddenProperties = Collections.emptySet(); | ||
|
||
private EntityCombinedModel(Model model, ModelEntity modelEntity) { | ||
this.model = model; | ||
this.modelEntity = modelEntity; | ||
} | ||
|
||
public static EntityCombinedModel of(Model model, ModelEntity modelEntity) { | ||
return new EntityCombinedModel(model, modelEntity); | ||
} | ||
|
||
public static EntityCombinedModel of(Model model) { | ||
return new EntityCombinedModel(model, null); | ||
} | ||
|
||
public EntityCombinedModel withHiddenProperties(Set<String> hiddenProperties) { | ||
this.hiddenProperties = hiddenProperties; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return model.name(); | ||
} | ||
|
||
@Override | ||
public String comment() { | ||
return model.comment(); | ||
} | ||
|
||
@Override | ||
public Map<String, String> properties() { | ||
return model.properties() == null | ||
? null | ||
: model.properties().entrySet().stream() | ||
.filter(e -> !hiddenProperties.contains(e.getKey())) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
@Override | ||
public int latestVersion() { | ||
return model.latestVersion(); | ||
} | ||
|
||
@Override | ||
public Audit auditInfo() { | ||
AuditInfo mergedAudit = | ||
AuditInfo.builder() | ||
.withCreator(model.auditInfo().creator()) | ||
.withCreateTime(model.auditInfo().createTime()) | ||
.withLastModifier(model.auditInfo().lastModifier()) | ||
.withLastModifiedTime(model.auditInfo().lastModifiedTime()) | ||
.build(); | ||
|
||
return modelEntity == null | ||
? mergedAudit | ||
: mergedAudit.merge(modelEntity.auditInfo(), true /* overwrite */); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
core/src/main/java/org/apache/gravitino/catalog/EntityCombinedModelVersion.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,101 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.gravitino.catalog; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import org.apache.gravitino.Audit; | ||
import org.apache.gravitino.meta.AuditInfo; | ||
import org.apache.gravitino.meta.ModelVersionEntity; | ||
import org.apache.gravitino.model.ModelVersion; | ||
|
||
public final class EntityCombinedModelVersion implements ModelVersion { | ||
|
||
private final ModelVersion modelVersion; | ||
|
||
private final ModelVersionEntity modelVersionEntity; | ||
|
||
private Set<String> hiddenProperties = Collections.emptySet(); | ||
|
||
private EntityCombinedModelVersion( | ||
ModelVersion modelVersion, ModelVersionEntity modelVersionEntity) { | ||
this.modelVersion = modelVersion; | ||
this.modelVersionEntity = modelVersionEntity; | ||
} | ||
|
||
public static EntityCombinedModelVersion of( | ||
ModelVersion modelVersion, ModelVersionEntity modelVersionEntity) { | ||
return new EntityCombinedModelVersion(modelVersion, modelVersionEntity); | ||
} | ||
|
||
public static EntityCombinedModelVersion of(ModelVersion modelVersion) { | ||
return new EntityCombinedModelVersion(modelVersion, null); | ||
} | ||
|
||
public EntityCombinedModelVersion withHiddenProperties(Set<String> hiddenProperties) { | ||
this.hiddenProperties = hiddenProperties; | ||
return this; | ||
} | ||
|
||
@Override | ||
public int version() { | ||
return modelVersion.version(); | ||
} | ||
|
||
@Override | ||
public String comment() { | ||
return modelVersion.comment(); | ||
} | ||
|
||
@Override | ||
public Map<String, String> properties() { | ||
return modelVersion.properties() == null | ||
? null | ||
: modelVersion.properties().entrySet().stream() | ||
.filter(e -> !hiddenProperties.contains(e.getKey())) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
@Override | ||
public String uri() { | ||
return modelVersion.uri(); | ||
} | ||
|
||
@Override | ||
public String[] aliases() { | ||
return modelVersion.aliases(); | ||
} | ||
|
||
@Override | ||
public Audit auditInfo() { | ||
AuditInfo mergedAudit = | ||
AuditInfo.builder() | ||
.withCreator(modelVersion.auditInfo().creator()) | ||
.withCreateTime(modelVersion.auditInfo().createTime()) | ||
.withLastModifier(modelVersion.auditInfo().lastModifier()) | ||
.withLastModifiedTime(modelVersion.auditInfo().lastModifiedTime()) | ||
.build(); | ||
|
||
return modelVersionEntity == null | ||
? mergedAudit | ||
: mergedAudit.merge(modelVersionEntity.auditInfo(), true /* overwrite */); | ||
} | ||
} |
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
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.