全部产品
云市场

CC算法执行

更新时间:2019-08-30 18:11:12

CC算法运行示例:

  1. /**
  2. * cname_to
  3. * domain-----------------> domain
  4. * sample data : domain_1 -> domain_2 -> domain_3 -> domain_4 -> domain_5 @see RealtimeWriterExample.writeCnameTo
  5. *
  6. * create table cc_output_tmp(domain_name string, cid bigint);
  7. * expect result: these domain have same cid
  8. * +-------------+------------+
  9. | domain_name | cid |
  10. +-------------+------------+
  11. | domain_2 | -4992513677848550377 |
  12. | domain_1 | -4992513677848550377 |
  13. | domain_4 | -4992513677848550377 |
  14. | domain_3 | -4992513677848550377 |
  15. | domain_5 | -4992513677848550377 |
  16. +-------------+------------+
  17. *
  18. */
  19. public class CCAlgorithmExample extends Example{
  20. public static void main(String[] args) {
  21. MaxGraph maxGraph = null;
  22. try {
  23. maxGraph = MaxGraph.newConnector(graphName, endpoint).setTimeout(30).setUserName(username)
  24. .setPassword(password).connect();
  25. //SchemaClient add cid property used for cc output
  26. SchemaClient schemaClient = maxGraph.schemaClient();
  27. if(!schemaClient.getSchema().getType("domain").get()
  28. .getPropertyDefList().stream()
  29. .filter(propertyDef -> propertyDef.name.equals("cid")).findFirst().isPresent()){
  30. PropertyDef _cid = new PropertyDef("cid", DataType.STRING, "cid");
  31. schemaClient.addTypeProperties("domain", _cid);
  32. }
  33. //run cc algorithm Program.graphCC()
  34. MaxGraphQueryClient maxGraphQueryClient = maxGraph.createQueryClient();
  35. String cc = "g.timeoutSec(600).E().hasLabel('cname_to').subgraph('s').cap('s')"
  36. + " .program(Program.graphCC().output('cid')"
  37. + " .iteration(30))"
  38. + " .map(Prop.fill('domain_name', 'cid'))"
  39. + " .map(Output.writeOdps()"
  40. + " .endpoint('http://service.odpsstg.aliyun-inc.com/stgnew')"
  41. + " .accessId(\"LTAIcR6VLDB646Ti\")"
  42. + " .accessKey(\"SOCc6eCYIvmEuULNiJsvNaW9caVzvb\")"
  43. + " .project(\"biggraph_dev\").table(\"cc_output_tmp\")"
  44. + " .write('domain_name', 'cid'))";
  45. Iterator<Result> resultList = maxGraphQueryClient.query(cc);
  46. while (resultList.hasNext()) {
  47. Result result = resultList.next();
  48. System.out.println(result.getObject());
  49. }
  50. maxGraphQueryClient.close();
  51. } catch (Exception e) {
  52. e.printStackTrace();
  53. } finally {
  54. if(maxGraph != null){
  55. maxGraph.close();
  56. }
  57. }
  58. }
  59. }