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

[Question] How to use the gremlin statement to trigger oltp query #2544

Closed
1 task done
dongma opened this issue May 29, 2024 · 4 comments
Closed
1 task done

[Question] How to use the gremlin statement to trigger oltp query #2544

dongma opened this issue May 29, 2024 · 4 comments
Labels
gremlin TinkerPop gremlin inactive question Further information is requested

Comments

@dongma
Copy link

dongma commented May 29, 2024

Problem Type (问题类型)

gremlin (结果不合预期)

Before submit

  • 我已经确认现有的 IssuesFAQ 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)

Environment (环境信息)

  • OS: xx CPUs, xx G RAM, Ubuntu 2x.x / CentOS 7.x
  • Data Size: xx vertices, xx edges

Server Version: 1.0.0 (Apache Release Version)
Backend: Hbase

Your Question (问题描述)

如下是从官方文档找到功能对应的PR,能提供一个gremlin触发的示例?
#1289

Vertex/Edge example (问题点 / 边数据举例)

No response

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

No response

@dosubot dosubot bot added gremlin TinkerPop gremlin question Further information is requested labels May 29, 2024
Copy link

dosubot bot commented May 29, 2024

To trigger an OLTP query in HugeGraph using a Gremlin statement, you can use the executeQuery method from the GremlinQueryService class. Here is an example of how you can use this method:

public GremlinResult executeQuery(int connId, GremlinQuery query) {
    HugeClient client = this.getClient(connId);
    log.debug("The original gremlin ==> {}", query.getContent());
    String gremlin = this.optimize(query.getContent());
    log.debug("The optimized gremlin ==> {}", gremlin);
    // Execute gremlin query
    ResultSet resultSet = this.executeGremlin(gremlin, client);
    // Scan data, vote the result type
    TypedResult typedResult = this.parseResults(resultSet);
    // Build json view
    JsonView jsonView = new JsonView(typedResult.getData());
    // Build table view
    TableView tableView = this.buildTableView(typedResult);
    // Build graph view
    GraphView graphView = this.buildGraphView(typedResult, client);
    return GremlinResult.builder()
                        .type(typedResult.getType())
                        .jsonView(jsonView)
                        .tableView(tableView)
                        .graphView(graphView)
                        .build();
}

To use this method, create an instance of GremlinQuery with your Gremlin statement and pass it along with the connection ID to the executeQuery method. The method will execute the query and return the results in a GremlinResult object.

Additionally, you can use the REST API to execute Gremlin queries in HugeGraph. Here is an example of how to post a Gremlin query using the REST API:

@Test
public void testPost() {
    String body = "{" +
                  "\"gremlin\":\"g.V()\"," +
                  "\"bindings\":{}," +
                  "\"language\":\"gremlin-groovy\"," +
                  "\"aliases\":{\"g\":\"__g_hugegraph\"}}";
    assertResponseStatus(200, client().post(path, body));
}

In this example, the testPost method sends a POST request to the /gremlin endpoint with a Gremlin query to retrieve all vertices (g.V()). The response status is then checked to ensure it is 200 (OK) [1][2][3].

Details

About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@dongma
Copy link
Author

dongma commented May 29, 2024

@dosu 在源代码中没有找到 GremlinQueryService这个类

Copy link

dosubot bot commented May 29, 2024

The GremlinQueryService class is used in the GremlinQueryController class, which is located in the hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/controller/query/GremlinQueryController.java file. You can find the GremlinQueryService class in the hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/service/query/GremlinQueryService.java file [1].

Here is an example of how you can use the executeQuery method from the GremlinQueryService class:

import org.apache.hugegraph.controller.query.GremlinQueryController;
import org.apache.hugegraph.entity.query.GremlinQuery;
import org.apache.hugegraph.entity.query.GremlinResult;
import org.apache.hugegraph.service.query.GremlinQueryService;
import org.springframework.beans.factory.annotation.Autowired;

public class GremlinQueryExecutor {

    @Autowired
    private GremlinQueryService queryService;

    public GremlinResult executeGremlinQuery(int connId, String gremlinQueryContent) {
        GremlinQuery query = new GremlinQuery();
        query.setContent(gremlinQueryContent);

        GremlinResult result = queryService.executeQuery(connId, query);
        // Process the result as needed
        return result;
    }
}

In this example, you need to create a GremlinQuery object, set the Gremlin query content, and then call the executeQuery method with the connection ID and the query. The result will be a GremlinResult object that you can process as needed [1].

Details

About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

Copy link

Due to the lack of activity, the current issue is marked as stale and will be closed after 20 days, any update will remove the stale label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gremlin TinkerPop gremlin inactive question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant