Skip to content

Add a simple graph algorithm: Degree #795

@Leomrlin

Description

@Leomrlin

What & why

The most basic graph metric is a vertex's degree — in-degree, out-degree,
total. It's a building block for many heavier algorithms, but there's no built-in
one-shot version yet. This is the best possible first taste of the
vertex-centric / message-passing model: simpler than PageRank, but you still walk
the full algorithm interface end to end.

图分析最基础的指标就是顶点的(入度/出度/总度),它是很多复杂算法的前置特征,
但目前没有内置算法。这是入门"顶点中心 / 消息传递"模型的最佳第一题——比 PageRank 简单,
却完整走一遍算法接口。

The task

Implement Degree: for each vertex, output (id, in_degree, out_degree).
No message passing needed — you can count directly with loadEdges(IN/OUT),
which makes it a clean way to learn the API.

实现 Degree:每个顶点输出 (id, in_degree, out_degree)。不用消息传递,直接用
loadEdges(IN/OUT) 统计即可,特别适合熟悉 API。

Where to look

  1. The simplest reference is udf/graph/KCore.java. Implement the
    AlgorithmUserFunction<Object, ?> interface — init / process / finish / getOutputType — and in process count edges with
    context.loadEdges(EdgeDirection.IN/OUT).
  2. Register in BuildInSqlFunctionTable.java (the UDGA section).
  3. Test with modern_graph.sql under query/ + expect/, verifying each
    vertex's in/out degree by hand.

Done when

  • Implemented and registered; output schema has id / in_degree / out_degree
  • Isolated vertices (degree 0) are output correctly too
  • .sql + .txt tests pass, expectations checked by hand
  • The PR explains why no iteration / message passing is needed

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions