Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add a string of OLAP algorithms #1984

Merged
merged 34 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6ff96f9
implement 8 olap algorithms (#4)
javeme Apr 9, 2020
aae07a7
add fusiform_similarity,rings_detect and kcore ap algorithm (#5)
zhoney Apr 9, 2020
ae7a9de
set louvain max community members limit 10w (#9)
javeme Apr 10, 2020
529e4b2
fix inconsistent error messages with clabel (#10)
javeme Apr 11, 2020
18f1de4
optimize filterNonShortestPath() for betweeness_centrality (#12)
javeme Apr 15, 2020
263b14e
add direction and label parameter for centrality algorithms (#13)
javeme Apr 15, 2020
7151c80
louvain: add modularity parameter and fix isolated community lost (#14)
javeme May 6, 2020
366fe37
support parallel: Louvain,LPA,Rings,K-Core,Fusiform (#15)
javeme May 12, 2020
5974fd1
fix parallel LPA not commit by threads (#16)
javeme May 20, 2020
2ee51c4
Support ring detect count (#17)
zhoney May 26, 2020
ff88f11
fix algorithm can't stop caused by threads exception (#18)
javeme Jun 3, 2020
d4be504
add page rank algorithm (#19)
houzhizhen Jun 4, 2020
1449cac
add weak connected component analysis (#21)
houzhizhen Jun 5, 2020
12b6bdf
add subgraph_stat algorithm (#23)
javeme Jun 9, 2020
abb5ddd
add BOTH direction support for triangle_count/cluster_coeffcient (#24)
javeme Jun 24, 2020
69ebdfd
rebase master(0.11.1)
javeme Jun 5, 2020
909a110
fix no auth with worker thread of olap algo (#27)
javeme Jul 28, 2020
b0f7981
fix server id/role NPE in initServerInfo when truncate temp graph (#28)
javeme Aug 3, 2020
320402a
add parameter top to print the top result in job result (#32)
houzhizhen Aug 11, 2020
5def931
add skipi_isolated param for louvain (#37)
javeme Aug 14, 2020
4cd6eb3
fix DegreeCentrality degree count limit OOL (#39)
javeme Aug 16, 2020
52fa08b
add with_boundary parameter for betweeness (#42)
javeme Aug 19, 2020
029f66c
add export_community for lounvain (#43)
javeme Aug 20, 2020
65c3798
update Betweenness with Stressness (#60)
houzhizhen Sep 21, 2020
a6fbb7c
add betweenness algorithm (#63)
houzhizhen Sep 27, 2020
6d19a9e
fix closeness distance: 1 extra length is calculated (#67)
javeme Oct 13, 2020
9158f61
add depth-first version betweennes centrality (#68)
javeme Oct 13, 2020
3519c27
add StressCentrality v2 (#65)
houzhizhen Oct 14, 2020
2729971
performance improvement: the meetNode is invoked only when node.dist…
houzhizhen Oct 15, 2020
5ba5b94
fix ap compile error for edition 0.11 (#72)
zhoney Dec 16, 2020
c2e3082
fix fusiform and kcore min_groups args default value (#79)
zhoney Feb 2, 2021
36f7cd0
fix lpa not exist c_label property when a request pass source_label (…
javeme Feb 2, 2021
97748a4
adapt the latest version & clean code
imbajin Nov 1, 2022
288a1a4
Merge branch 'master' into olap-algo
imbajin Nov 9, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2017 HugeGraph Authors
*
* 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 com.baidu.hugegraph.api.job;

import java.util.Map;

import org.slf4j.Logger;

import com.baidu.hugegraph.HugeGraph;
import com.baidu.hugegraph.api.API;
import com.baidu.hugegraph.api.filter.StatusFilter.Status;
import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.core.GraphManager;
import com.baidu.hugegraph.job.AlgorithmJob;
import com.baidu.hugegraph.job.JobBuilder;
import com.baidu.hugegraph.server.RestServer;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.JsonUtil;
import com.baidu.hugegraph.util.Log;
import com.codahale.metrics.annotation.Timed;
import com.google.common.collect.ImmutableMap;

import jakarta.inject.Singleton;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;

@Path("graphs/{graph}/jobs/algorithm")
@Singleton
public class AlgorithmAPI extends API {

private static final Logger LOG = Log.logger(RestServer.class);

@POST
@Timed
@Path("/{name}")
@Status(Status.CREATED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
public Map<String, Id> post(@Context GraphManager manager,
@PathParam("graph") String graph,
@PathParam("name") String algorithm,
Map<String, Object> parameters) {
LOG.debug("Graph [{}] schedule algorithm job: {}", graph, parameters);
E.checkArgument(algorithm != null && !algorithm.isEmpty(),
"The algorithm name can't be empty");
if (parameters == null) {
parameters = ImmutableMap.of();
}
if (!AlgorithmJob.check(algorithm, parameters)) {
throw new NotFoundException("Not found algorithm: " + algorithm);
}

HugeGraph g = graph(manager, graph);
Map<String, Object> input = ImmutableMap.of("algorithm", algorithm,
"parameters", parameters);
JobBuilder<Object> builder = JobBuilder.of(g);
builder.name("algorithm:" + algorithm)
.input(JsonUtil.toJson(input))
.job(new AlgorithmJob());
return ImmutableMap.of("task_id", builder.schedule().id());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2017 HugeGraph Authors
*
* 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 com.baidu.hugegraph.job;

import java.util.Map;

import com.baidu.hugegraph.job.algorithm.Algorithm;
import com.baidu.hugegraph.job.algorithm.AlgorithmPool;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.JsonUtil;

public class AlgorithmJob extends UserJob<Object> {

public static final String TASK_TYPE = "algorithm";

public static boolean check(String name, Map<String, Object> parameters) {
Algorithm algorithm = AlgorithmPool.instance().find(name);
if (algorithm == null) {
return false;
}
algorithm.checkParameters(parameters);
return true;
}

@Override
public String type() {
return TASK_TYPE;
}

@Override
public Object execute() throws Exception {
String input = this.task().input();
E.checkArgumentNotNull(input, "The input can't be null");
@SuppressWarnings("unchecked")
Map<String, Object> map = JsonUtil.fromJson(input, Map.class);

Object value = map.get("algorithm");
E.checkArgument(value instanceof String,
"Invalid algorithm name '%s'", value);
String name = (String) value;

value = map.get("parameters");
E.checkArgument(value instanceof Map,
"Invalid algorithm parameters '%s'", value);
@SuppressWarnings("unchecked")
Map<String, Object> parameters = (Map<String, Object>) value;

AlgorithmPool pool = AlgorithmPool.instance();
Algorithm algorithm = pool.find(name);
E.checkArgument(algorithm != null,
"There is no algorithm named '%s'", name);
return algorithm.call(this, parameters);
}
}
Loading