Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cdap-metadata-ext-spanner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cdap.cdap</groupId>
<artifactId>cdap-metadata-spi</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cdap.cdap</groupId>
<artifactId>cdap-common-unit-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public static FormattedMetadata from(MetadataEntity entity, Metadata metadata) t
}

private FormattedMetadata(MetadataEntity entity, Metadata metadata) throws IOException {
this.namespace = entity.getValue("namespace");
this.namespace = Optional.ofNullable(entity.getValue("namespace"))
.orElse("default");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is namespace is null, is it ok to use default value default or could it be system as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

namespace default value is default.

this.type = entity.getType().toLowerCase();
this.name = Objects.requireNonNull(entity.getValue(entity.getType())).toLowerCase();

Expand Down Expand Up @@ -142,12 +143,6 @@ private Map<String, Set<Property>> reformatProperties(Map<ScopedName, String> pr
String name = key.getName().toLowerCase();
String scope = key.getScope().name();
String value = entry.getValue().toLowerCase();

// If it's a schema key, reformat it.
if (MetadataConstants.SCHEMA_KEY.equals(name)) {
continue;
}

extracted.add(new Property(scope, name, value));
propertyNames.add(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.cdap.cdap.metadata.spanner;

import static io.cdap.cdap.metadata.spanner.SpannerMetadataStorage.DISCARD;
import static io.cdap.cdap.metadata.spanner.SpannerMetadataStorage.GSON;
import static io.cdap.cdap.metadata.spanner.SpannerMetadataStorage.METADATA_PROPS_TABLE;
import static io.cdap.cdap.metadata.spanner.SpannerMetadataStorage.METADATA_TABLE;
Expand Down Expand Up @@ -189,10 +190,6 @@ private static Set<MetadataScope> determineAffectedScopes(Metadata metadata) {
private static ChangeRequest drop(MetadataEntity entity, VersionedMetadata before) {
List<Mutation> mutations = new ArrayList<>();
String metadataId = toMetadataId(entity);
if (before.getVersion() == null) {
throw new IllegalArgumentException("existingVersion cannot be null when deleting a "
+ "specific version of a metadata entity.");
}
mutations.add(Mutation.delete(METADATA_TABLE, Key.of(metadataId)));
return new ChangeRequest(mutations, new MetadataChange(entity, before.getMetadata(), Metadata.EMPTY));
}
Expand Down Expand Up @@ -225,7 +222,7 @@ private static ChangeRequest update(MetadataEntity entity, VersionedMetadata bef
* @return the list of mutations to execute and the change caused by the mutation
*/
private static ChangeRequest remove(VersionedMetadata before, MetadataMutation.Remove remove) throws IOException {
Metadata after = filterMetadata(before.getMetadata(), false,
Metadata after = filterMetadata(before.getMetadata(), DISCARD,
remove.getKinds(), remove.getScopes(), remove.getRemovals());
return new ChangeRequest(bufferWrites(remove.getEntity(), before.getVersion(), after),
new MetadataChange(remove.getEntity(), before.getMetadata(), after));
Expand Down Expand Up @@ -288,8 +285,6 @@ private static List<Mutation> createMetadataPropsTableMutations(MetadataEntity e
for (FormattedMetadata.Property prop : formattedMetadata.getMetadataProps()) {
propMutations.add(Mutation.newInsertOrUpdateBuilder(METADATA_PROPS_TABLE)
.set(Tables.MetadataProps.METADATA_ID_FIELD).to(entityId)
.set(Tables.MetadataProps.NAMESPACE_FIELD).to(formattedMetadata.getNamespace())
.set(Tables.MetadataProps.TYPE_FIELD).to(formattedMetadata.getType())
.set(Tables.MetadataProps.NESTED_SCOPE_FIELD).to(prop.getScope())
.set(Tables.MetadataProps.NESTED_NAME_FIELD).to(prop.getName())
.set(Tables.MetadataProps.NESTED_VALUE_FIELD).to(prop.getValue())
Expand Down
Loading
Loading