Skip to content
Merged
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
Prev Previous commit
Next Next commit
Done
  • Loading branch information
Dexter Lee committed Jun 15, 2021
commit 7f8745d032f891b2b52fbc76e2c8c6d695d43a90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.linkedin.data.DataMap;
import com.linkedin.data.schema.RecordDataSchema;
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.metadata.models.registry.EntityRegistry;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import javax.annotation.Nonnull;
Expand All @@ -29,8 +28,7 @@ private EntityKeyUtils() {
* @throws {@link IllegalArgumentException} if the urn cannot be converted into the key schema (field number or type mismatch)
*/
@Nonnull
public static RecordTemplate convertUrnToEntityKey(@Nonnull final Urn urn,
@Nonnull final RecordDataSchema keySchema) {
public static RecordTemplate convertUrnToEntityKey(@Nonnull final Urn urn, @Nonnull final RecordDataSchema keySchema) {

// #1. Ensure we have a class to bind into.
Class<? extends RecordTemplate> clazz;
Expand Down Expand Up @@ -65,24 +63,4 @@ public static RecordTemplate convertUrnToEntityKey(@Nonnull final Urn urn,
clazz.getName()));
}
}

/**
* Implicitly converts a normal {@link Urn} into a {@link RecordTemplate} Entity Key fetched from {@link EntityRegistry}
*
* Parts of the urn are bound into fields in the keySchema based on field <b>index</b>. If the
* number of urn key parts does not match the number of fields in the key schema, an {@link IllegalArgumentException} will be thrown.
*
* @param urn raw entity urn
* @param entityRegistry entity registry used to fetch the key aspect spec
* @return a {@link RecordTemplate} created by mapping the fields of the urn to fields of
* the provided key schema in order.
* @throws {@link IllegalArgumentException} if the urn cannot be converted into the key schema (field number or type mismatch)
*/
public static RecordTemplate convertUrnToEntityKey(@Nonnull final Urn urn,
@Nonnull final EntityRegistry entityRegistry) {
final EntitySpec spec = entityRegistry.getEntitySpec(urn.getEntityType());
final AspectSpec keySpec = spec.getKeyAspectSpec();
final RecordDataSchema keySchema = keySpec.getPegasusSchema();
return EntityKeyUtils.convertUrnToEntityKey(urn, keySchema);
}
}
Loading