nebula-contrib / ngbatis

NGBATIS is a database ORM framework base NebulaGraph + spring-boot, which takes advantage of the mybatis’ fashion development, including some de-factor operations in single table and vertex-edge, like mybatis-plus. NGBATIS 是一款针对 NebulaGraph + Springboot 的数据库 ORM 框架。借鉴于 MyBatis 的使用习惯进行开发。https://graph-cn.github.io/ngbatis-docs/
https://nebula-contrib.github.io/ngbatis/
Apache License 2.0
132 stars 42 forks source link

hacktober tasks #234

Open wey-gu opened 1 year ago

wey-gu commented 1 year ago
wey-gu commented 1 year ago

For anyone would like to take, I'll create corresponding tasks in separate issue.

cc @CorvusYe

amritagg commented 1 year ago

Hi @wey-gu, I would like to contribute for the above task, if you could just explain in a little detail what needs to be done exactly.

wey-gu commented 1 year ago

Hi @wey-gu, I would like to contribute for the above task, if you could just explain in a little detail what needs to be done exactly.

Wow, welcome to the NebulaGraph community!

@CorvusYe could you plz help explain some of the tasks that @amritagg could start from?

CorvusYe commented 1 year ago

Hi @amritagg I'm glad you're interested in these features.

We need to add methods to NebulaDaoBasic that allow developers to quickly access data without having to write ngql Just like its other interfaces.https://github.com/nebula-contrib/ngbatis/blob/master/src/main/java/org/nebula/contrib/ngbatis/proxy/NebulaDaoBasic.java

The idea is to extract the more commonly used scripts, as the name of the task item means.

For example, show metas, developers can quickly get schema information by calling the interface, tag, edgeType, etc.

cc: @wey-gu

wey-gu commented 1 year ago

@CorvusYe @amritagg

Created subtask for this in https://github.com/nebula-contrib/ngbatis/issues/237

amritagg commented 1 year ago

@wey-gu @CorvusYe thanks for explaining the task to be me but I won't be able to complete this task as this is quite complicated for me.

CorvusYe commented 1 year ago

The API is similar to this section, but without the process of parsing the results.

shbone commented 1 year ago

I want to have a try to achieve insertEdgeBatch or insertTripletBatch .

And I want to imitate this interface insertEdge https://github.com/nebula-contrib/ngbatis/blob/d6b73ea97c55bb233fabc7ccf20bc972516b22d5/src/main/java/org/nebula/contrib/ngbatis/proxy/NebulaDaoBasic.java#L319-L334

@CorvusYe If I need to add this to the demo first and test it ,then add it to the src directory? Thank you

CorvusYe commented 1 year ago

@shbone Yes, you are right about that.

And one more thing is that these interfaces should preferably have a batched parameter. Because there is a limit to the length of a script that can be executed once.

shbone commented 1 year ago

How to debug and print the nGQL script with Beetl Template? Thank you! @CorvusYe print or other method ? I have some problme with the use of nGQL.

CorvusYe commented 1 year ago

@shbone Do you mean to print nGQL on the console?

Add the following configuration to yml

logging:
  level:
    org.nebula.contrib: DEBUG

https://graph-cn.github.io/ngbatis-docs/step-forward-docs/advanced-configuration.html

CorvusYe commented 1 year ago

And the only entry and exit for the generated nGQL is here

shbone commented 1 year ago

@shbone Do you mean to print nGQL on the console?

Add the following configuration to yml

logging:
  level:
    org.nebula.contrib: DEBUG

https://graph-cn.github.io/ngbatis-docs/step-forward-docs/advanced-configuration.html

I have add the configuration and output is here. But I don't know how to fix the nGQL error, and I want to debug the script with the use of print

2023-10-09 12:41:40.311 DEBUG 91379 --- [           main] o.n.contrib.ngbatis.proxy.MapperProxy    : 
    - proxyMethod: sun.reflect.NativeMethodAccessorImpl#invoke
    - session space: null
    - auto switch to: test
    - nGql:

    - params: {p0=[{"person2":{"name":"P2_0"},"person1":{"name":"P1_0"},"like":{"likeness":0.202210171102}},{"person2":{"name":"P2_1"},"person1":{"name":"P1_1"},"like":{"likeness":0.202210171102}},{"person2":{"name":"P2_2"},"person1":{"name":"P1_2"},"like":{"likeness":0.202210171102}}]}
    - result:ExecutionResponse (
  error_code : E_STATEMENT_EMPTY (E_STATEMENT_EMPTY),
  latency_in_us : 90,
  space_name : 74 65 73 74,
  error_msg : 53 74 61 74 65 6D 65 6E 74 45 6D 70 74 79 3A 20
)

org.nebula.contrib.ngbatis.exception.QueryException: 数据查询失败: 数据查询失败StatementEmpty: 

    at org.nebula.contrib.ngbatis.proxy.MapperProxy.executeWithParameter(MapperProxy.java:241)
    at org.nebula.contrib.ngbatis.proxy.MapperProxy.invoke(MapperProxy.java:131)
    at org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic.insertEdgeBatch(NebulaDaoBasic.java:338)
    at ye.weicheng.ngbatis.demo.NebulaBasicDaoTests.insertEdgeBatchWithProps(NebulaBasicDaoTests.java:419)

The nGQL script is to insert the batch of edges , and I use the personLikePerson class, But it have this error. I want to know how to fix it.Thank you!

    <insert id="insertEdgeBatch">
        @for ( row in ng_args[0] ) {
        @var kv = ng.kv( row,  '', true, true );
        print(kv)
        @}
    </insert>
CorvusYe commented 1 year ago

You can refer to this http://bbs.ibeetl.com/beetlonline/ image

But you need to change @for to <% for

CorvusYe commented 1 year ago

What do you think ablout declaring a model, such as:

public class NgTriplet<I> {
  private I srcId;
  private I dstId;
  private Object start;
  private Object edge;
  private Object end;

  NgTriplet( Object start, Object edge, Object end ) {
     // ...
  }
}    
triplets = new ArrayList() {{
    add( new NgTriplet( person1, like, person2) );
}};

So that, we can use dao.insertEdgeBatch( triplets )

XML is roughly like this. But there may be some errors, you can debug it again

    <insert id="insertEdgeBatch">
        @for ( row in ng_args[0] ) {
          @var kv = ng.kv( row.edge, '', null, null, false );
          @var vId1 = ng.id( row.start );
          @var rank = ng.id( row.edge, false );
          @var vId2 = ng.id( row.end );
          @var e = ng.tagName( row.edge );
          INSERT EDGE `${ e }` (
              ${ ng.join( @kv.columns, ", ", "ng.schemaFmt" ) }
          )
          VALUES ${ vId1 }-> ${ vId2 } ${ isNotEmpty( rank ) ? ('@' + rank) : ''  } :(
              ${ ng.join( @kv.values ) }
          );
        @}
    </insert>
shbone commented 1 year ago

Thank you your template! I will have a try

What do you think ablout declaring a model, such as:

public class NgTriplet<I> {
  private I srcId;
  private I dstId;
  private Object start;
  private Object edge;
  private Object end;

  NgTriplet( Object start, Object edge, Object end ) {
     // ...
  }
}    
triplets = new ArrayList() {{
    add( new NgTriplet( person1, like, person2) );
}};

So that, we can use dao.insertEdgeBatch( triplets )

XML is roughly like this. But there may be some errors, you can debug it again

    <insert id="insertEdgeBatch">
        @for ( row in ng_args[0] ) {
          @var kv = ng.kv( row.edge, '', null, null, false );
          @var vId1 = ng.id( row.start );
          @var rank = ng.id( row.edge, false );
          @var vId2 = ng.id( row.end );
          @var e = ng.tagName( row.edge );
          INSERT EDGE `${ e }` (
              ${ ng.join( @kv.columns, ", ", "ng.schemaFmt" ) }
          )
          VALUES ${ vId1 }-> ${ vId2 } ${ isNotEmpty( rank ) ? ('@' + rank) : ''  } :(
              ${ ng.join( @kv.values ) }
          );
        @}
    </insert>