Assets Use cases
Access Hagrid Internal Services
In each bean, a developer can access Hagrid's internal services via service SyncContainerService. Each step inherits a method called
getSyncContainerService() from parent class AbstractAsset.
Using method getSyncContainerService(), developer can access the sync container. Once developer has the syncContainerService, any internal service
can be accessed like this
SyncContainerService syncContainerService = getSyncContainerService();
SyncService syncService = syncContainerService.getBean(SyncService.class);
AnalyticsFactory analyticsFactory = syncContainerService.getBean(AnalyticsFactory.class);
Namespace namespace = syncServiceContainer.getBean(Namespace.class);
AnalyticsService analyticsService = analyticsFactory.getAnalyticsService(namespace.getNamespace());
Add, Update or Delete Attributes
Suppose, you want to add , update or delete attributes of the assets, then it can be done via transform method that is
inherited from parent class AbstractAsset
import java.util.Date;
// Add attributes
@Override
public void transform() {
this.created_at = new Date();
}
// Modify attributes
@Override
public void transform() {
this.name = this.name.toLower();
}
// Delete unwanted attributes
@Override
public void transform() {
this.unwantedAttribute = null;
}
Filter Assets
You can also filter assets which does not meet the business requirements. For this Hagrid provides a method filter which
is inherited from the class AbstactAsset
Creating Non Primitive Assets
@Freshjoins joins the two assets to create another asset. Like in the above case, we are creating the asset UserCommunities, which are the join of two beans Community and User.
@FreshJoin(rightClass = FbCommunityAsset.class, rightClassFieldName = "creator_id", leftClass = FbUser.class, leftClassFieldName = "userId", uniqueJoinName = "user_community_join", join_type = FreshJoin.JOIN_TYPE.INNER_JOIN)
class UserCommunities{
String communityOwner; // it would the userName from user bean
String communityName; // It would be the community name from community bean
void setCommunityOwner(User user){
this.communityOwner = user.getUserName();
}
void setCommunityName(Community community){
this.communityName = community.getName();
}
}
The assets are joined based on a common key, which are provided in @Freshjoin. Unlike Kafka, there is not a time window of the join. Like Kafka uses data store to look up the events (assets in our case), Hagrid also uses the data structure called key_value to store the stream of assets for lookup.
Inner Joins
If and only if both sides are available, a join is emitted. Thus, if the left class asset has already come but the right class has not, then nothing will be emitted.
Outer Joins [ Not yet implemented ]
With an outer join, both (left and right class ) assets always produce an output an asset. If both the left side and the right side are available, a join of the two is returned. If only the left side is available, the join will have the value of the left side and a null for the right side. The converse is true: If only the right side is available, the join will include the value of the right side and a null for the left side.
Left-Outer Joins
Left-outer joins also always create the assets. If both sides are available, the join consists of both sides. Otherwise, the left side will be returned with a null for the right side.