Mapreduce 查询Hazelcast层次树结构

Mapreduce 查询Hazelcast层次树结构,mapreduce,hazelcast,Mapreduce,Hazelcast,我试图弄清楚如何在Hazelcast中查询层次树结构。假设我有一个组织类: public class Organization { private long id; private long parentId; } 我有一个用户类: public class NestupUser extends BaseEntity { private long id; private String firstName; private String lastName; private

我试图弄清楚如何在Hazelcast中查询层次树结构。假设我有一个组织类:

public class Organization {
  private long id;
  private long parentId;
}
我有一个用户类:

public class NestupUser extends BaseEntity {
  private long id;
  private String firstName;
  private String lastName;
  private String email;
  private String password;
  private long organizationId;
}
现在,给定一个organizationId,我想查找该组织的所有用户,以及将该组织作为父组织的所有组织,以及将这些组织作为父组织的所有组织,等等

我假设这将作为某种MapReduce工作,但是否可以在一个MapReduce中启动更多的MapReduce任务


谢谢你的帮助

我最终构建了一个非规范化的多重映射,这样我就可以找到给定组织id的所有可访问组织。这是在启动时设置结构的代码,如果其他节点尚未设置该结构。此类还实现了entry listener接口,以便在情况发生变化时获取回调,以保持结构同步(未显示,但不难做到):

@PostConstruct
公共void init(){
IMap organizationMap=organizationService.getMap();
listenerRegistration=organizationMap.addLocalEntryListener(此);
MultiMap orgStructureMap=getOrgStructureMap();
如果(orgStructureMap.keySet().size()==0){
Collection all=organizationService.getAll(null);
Set visted=新HashSet();
对于(下一个组织:全部){
如果(!visted.contains(next.getId())){
while(next!=null&&next.getParentId()!=null&&visited.contains(next.getParentId()){
next=next.getParentOrganization();
}
递归引用(已访问,下一步);
}
}
}
}
私有无效递归引用(已访问集合、组织组织){
addAllReferences(org);
visitored.add(org.getId());
设置childOrganizations=org.getChildOrganizations();
对于(子组织:子组织){
递归引用(已访问、子级);
}
}
私有void addAllReferences(组织){
MultiMap orgStructureMap=getOrgStructureMap();
字符串parentId=organization.getParentId();
if(parentId!=null){
Set entries=orgStructureMap.entrySet();
for(Map.Entry下一步:条目){
if(next.getValue().equals(parentId)){
orgStructureMap.put(next.getKey(),organization.getId());
}
}
}
orgStructureMap.put(organization.getId(),organization.getId());
}
私有void removeAllReferences(组织){
MultiMap orgStructureMap=getOrgStructureMap();
Set keys=orgStructureMap.keySet();
用于(字符串键:键){
remove(key,organization.getId());
}
}

我无法准确地可视化数据结构。你能发布一些样本数据吗?此外,预期的组织和用户数量?无法真正将其格式化。。。假设您有一个包含两个子组织child1和child2的父组织。Child1还有一个子组织Child1\u 1。考虑到父组织,我想在parent、child1、child2和child1_1中查找所有用户。谢谢。还有,有多少这样的上级组织以及层级的数量是多少?前面不知道。我正试图找出这个问题的一般解决办法。我正在考虑通过父组织键维护一个非规范化的子组织列表,这样我就可以用一个Map.get()找到它们
@PostConstruct
public void init() {
    IMap<String, Organization> organizationMap = organizationService.getMap();
    listenerRegistration = organizationMap.addLocalEntryListener(this);
    MultiMap<String, String> orgStructureMap = getOrgStructureMap();
    if (orgStructureMap.keySet().size() == 0) {
        Collection<Organization> all = organizationService.getAll(null);
        Set<String> visited = new HashSet<>();
        for (Organization next : all) {
            if (!visited.contains(next.getId())) {
                while (next != null && next.getParentId() != null && !visited.contains(next.getParentId())) {
                    next = next.getParentOrganization();
                }
                recurseReferences(visited, next);
            }
        }
    }
}

private void recurseReferences(Set<String> visited, Organization org) {
    addAllReferences(org);
    visited.add(org.getId());
    Set<Organization> childOrganizations = org.getChildOrganizations();
    for (Organization child : childOrganizations) {
        recurseReferences(visited, child);
    }
}

private void addAllReferences(Organization organization) {
    MultiMap<String, String> orgStructureMap = getOrgStructureMap();
    String parentId = organization.getParentId();
    if (parentId != null) {
        Set<Map.Entry<String, String>> entries = orgStructureMap.entrySet();
        for (Map.Entry<String, String> next : entries) {
            if (next.getValue().equals(parentId)) {
                orgStructureMap.put(next.getKey(),organization.getId());
            }
        }
    }
    orgStructureMap.put(organization.getId(), organization.getId());
}



private void removeAllReferences(Organization organization) {
    MultiMap<String, String> orgStructureMap = getOrgStructureMap();
    Set<String> keys = orgStructureMap.keySet();
    for (String key : keys) {
        orgStructureMap.remove(key, organization.getId());
    }
}