apache / incubator-graphar

An open source, standard data file format for graph data storage and retrieval.
https://graphar.apache.org/
Apache License 2.0
225 stars 46 forks source link

feat(c++): API design for multi-label support #614

Open acezen opened 2 months ago

acezen commented 2 months ago

Describe the enhancement requested

TBF

Component(s)

C++

Elssky commented 2 months ago

Neo4j Cypher statements involving tags can be mainly divided into the following categories:

1. Creation

2. Deletion and Renaming

3. Querying and Filtering

acezen commented 2 months ago

LDBC SNB Cypher statements:

Querying and Filtering

acezen commented 2 months ago

LDBC SNB Gremlin statements:

Querying and Filtering

Elssky commented 2 months ago

class VerticesCollection {
public:
    /**
     * @brief Query vertices with a specific label
     *
     * @param filter_label The label to query vertices by
     * @param graph_info A smart pointer to GraphInfo that contains details about the graph
     * @param type The type of vertices to query 
     * @return A VerticesCollection containing all vertices that have the specified label
     */
    static Result<std::shared_ptr<VerticesCollection>> verticesWithLabel(
        const std::string& filter_label, 
        const std::shared_ptr<GraphInfo>& graph_info, 
        const std::string& type);

    /**
     * @brief Query vertices with a specific label within a given collection
     *
     * @param filter_label The label to query vertices by
     * @param vertices_collection The collection of vertices to search within
     * @return A VerticesCollection containing all vertices from the specified collection that have the specified label
     */
    static Result<std::shared_ptr<VerticesCollection>> verticesWithLabel(
        const std::string& filter_label, 
        const std::shared_ptr<VerticesCollection>& vertices_collection);

    /**
     * @brief Query vertices with multiple labels
     *
     * @param filter_labels A vector of labels to query vertices by
     * @param graph_info A smart pointer to GraphInfo that contains details about the graph
     * @param type The type of vertices to query 
     * @return A VerticesCollection containing all vertices that have all of the specified labels
     */
    static Result<std::shared_ptr<VerticesCollection>> verticesWithMultipleLabels(
        const std::vector<std::string>& filter_labels, 
        const std::shared_ptr<GraphInfo>& graph_info, 
        const std::string& type);

    /**
     * @brief Query vertices with multiple labels within a given collection
     *
     * @param filter_labels A vector of labels to query vertices by
     * @param vertices_collection The collection of vertices to search within
     * @return A VerticesCollection containing all vertices from the specified collection that have all of the specified labels
     */
    static Result<std::shared_ptr<VerticesCollection>> verticesWithMultipleLabels(
        const std::vector<std::string>& filter_labels, 
        const std::shared_ptr<VerticesCollection>& vertices_collection);

    /**
     * @brief Query vertices with a specific label and properties
     *
     * @param filter_label The label to query vertices by
     * @param propery_filter_expr A shared pointers to Property filter expression that the vertices should match
     * @param graph_info A smart pointer to GraphInfo that contains details about the graph
     * @param type The type of vertices to query 
     * @return A VerticesCollection containing all vertices that have the specified label and match the given properties
     */
    static Result<std::shared_ptr<VerticesCollection>> verticesWithLabelAndProperty(
        const std::string& filter_label, 
        const std::shared_ptr<Expression> propery_filter_expr, 
        const std::shared_ptr<GraphInfo>& graph_info, 
        const std::string& type);

    /**
     * @brief Query vertices with a specific label and properties within a given collection
     *
     * @param filter_label The label to query vertices by
     * @param propery_filter_expr A shared pointers to Property filter expression that the vertices should match
     * @param vertices_collection The collection of vertices to search within
     * @return A VerticesCollection containing all vertices from the specified collection that have the specified label and match the given properties
     */
    static Result<std::shared_ptr<VerticesCollection>> verticesWithLabelAndProperty(
        const std::string& filter_label, 
        const std::shared_ptr<Expression> propery_filter_expr, 
        const std::shared_ptr<VerticesCollection>& vertices_collection);

};

class VertexIter {
    /**
     * @brief Check if the vertex has a specific label
     *
     * @param label The label to check for on the specified vertex
     * @return True if the vertex has the specified label, false otherwise
     */
    bool HasLabel(const std::string& label);
}
yecol commented 2 months ago

Please refers to the existing VerticesCollection, holding iterators would be better.

yecol commented 2 months ago

They should be static functions like Make I guess, rather than member functions of VerticesCollection

ref: https://github.com/apache/incubator-graphar/blob/a5c94a483f0373a619dcec18df06cbd48c10c103/cpp/src/graphar/high-level/graph_reader.h#L305

Elssky commented 2 months ago
MATCH (n:Label {property: value}) RETURN n

1. Query nodes with a specific label

Cypher:

MATCH (n:Label) RETURN n

Gremlin:

g.V().hasLabel('Label')

2. Query nodes with multiple labels

Cypher:

MATCH (n:Label1:Label2) RETURN n

Gremlin:

g.V().hasLabel('Label1').hasLabel('Label2')

3. Query nodes with a specific label and property

Cypher:

MATCH (n:Label {property: value}) RETURN n

Gremlin:

g.V().hasLabel('Label').has('property', value)