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

get subgraph 的 xml获取不到$p0 #132

Closed yiyi3681 closed 1 year ago

yiyi3681 commented 1 year ago

想查询指定vid的subgraph,xml如下:

    <select id="selectSubgraph" resultType="com.example.defaultcorpanalysis.pojo.Subgraph">
        get subgraph 1 steps from $p0
        yield vertices as nodes, edges as relationships
    </select>

pojo层的Subgraph类跟demo一摸一样;

dao如下:

public interface SubgraphDao {
    List<Subgraph> selectSubgraph(String vid);
}

测试模块:

    @Test
    public void getSubgraph(){
        List<Subgraph> subgraphs = subgraphDao.selectSubgraph("00041732");
        for(Subgraph subgraph : subgraphs){
            System.out.println(subgraph);
        }
    }

报错如下: org.nebula.contrib.ngbatis.exception.QueryException: 数据查询失败: 数据查询失败SyntaxError: Parameter is not supported in vid near ` $p'

将xml中的$p0替换成特定的vid可以正常查询,但是改为参数就不行了,麻烦帮忙看看谢谢啦

CorvusYe commented 1 year ago

那你可以试试使用:

CorvusYe commented 1 year ago

@wey-gu get subgraph 是不是也不支持参数化

image

yiyi3681 commented 1 year ago

那你可以试试使用:

  • 可以确定 p0 是 String
        get subgraph 1 steps from '${ p0 }'
        yield vertices as nodes, edges as relationships

或者:

  • p0 的类型不定
        get subgraph 1 steps from ${ ng.valueFmt( p0 ) }
        yield vertices as nodes, edges as relationships

这种也不行 org.nebula.contrib.ngbatis.exception.QueryException: 数据查询失败: 数据查询失败SyntaxError: syntax error near ` $'

CorvusYe commented 1 year ago
logging:
  level:
    org.nebula.contrib: DEBUG

可以在 yml 里追加上面这段配置,看看输出的的 nGQL 吗, 如果使用刚刚说的方式,$ 会在参数替换的过程被替换掉,传不到数据库里,也就不存在下面这个报错了

org.nebula.contrib.ngbatis.exception.QueryException: 数据查询失败: 数据查询失败SyntaxError: syntax error near ` $'

yiyi3681 commented 1 year ago

那你可以试试使用:

  • 可以确定 p0 是 String
        get subgraph 1 steps from '${ p0 }'
        yield vertices as nodes, edges as relationships

或者:

  • p0 的类型不定
        get subgraph 1 steps from ${ ng.valueFmt( p0 ) }
        yield vertices as nodes, edges as relationships

第一种可以了,单引号换成双引号也可以,感谢~