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

插入数据后,返回的result是null,报错Only support convert boolean/float/int/string/map/list to nebula.Value but wasjava.sql.Timestamp #89

Closed
btbox opened this issue Nov 19, 2022 · 13 comments
Labels
bug Something isn't working

Comments

@btbox
Copy link

btbox commented Nov 19, 2022

image

@btbox
Copy link
Author

btbox commented Nov 19, 2022

我将valueFmt 的函数转换成自己自定义的,date是转换成string而不用datetime()

public class MyValueFmtFn extends AbstractFunction<Object, Boolean, Void, Void, Void, Void> {

  @Override
  public Object call(Object value, Boolean ifStringLike) {
    ifStringLike = ifStringLike != null && ifStringLike;
    if (value == null) {
      return null;
    }
    if (value instanceof String) {
      return ifStringLike ? "'.*" + value + ".*'" : "'" + value + "'";
    }

    if (value instanceof Date) {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss");
//      String fn = "datetime";
//      Class<?> objClass = value.getClass();
//      fn = objClass == java.util.Date.class ? "datetime"
//        : objClass == java.sql.Date.class ? "date"
//          : objClass == java.sql.Time.class ? "time"
//            : fn;
      return String.format("'%s'", sdf.format(value));
    }
    return value;
  }
}

@btbox
Copy link
Author

btbox commented Nov 19, 2022

我的数据是 pgsql的,字段是 timestamp 我看见他转换成参数变为时间戳了
image

@CorvusYe
Copy link
Collaborator

使用ng_args可以拿到最原始的数据类型

@CorvusYe
Copy link
Collaborator

image

还有一种方式,可以在DefaultArgsResolver追加Timestamp类型的value setter

@btbox btbox closed this as completed Nov 24, 2022
@CorvusYe
Copy link
Collaborator

我将valueFmt 的函数转换成自己自定义的,date是转换成string而不用datetime()

public class MyValueFmtFn extends AbstractFunction<Object, Boolean, Void, Void, Void, Void> {

  @Override
  public Object call(Object value, Boolean ifStringLike) {
    ifStringLike = ifStringLike != null && ifStringLike;
    if (value == null) {
      return null;
    }
    if (value instanceof String) {
      return ifStringLike ? "'.*" + value + ".*'" : "'" + value + "'";
    }

    if (value instanceof Date) {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss");
//      String fn = "datetime";
//      Class<?> objClass = value.getClass();
//      fn = objClass == java.util.Date.class ? "datetime"
//        : objClass == java.sql.Date.class ? "date"
//          : objClass == java.sql.Time.class ? "time"
//            : fn;
      return String.format("'%s'", sdf.format(value));
    }
    return value;
  }
}

这个是你的解决方案吗

刚刚跟了一下代码,感觉自己的回复理解错了。
是调用的 基类的 insert 接口插入的还是自己写的 xml

@btbox
Copy link
Author

btbox commented Nov 29, 2022

并不是的,我又发现 数据查询失败:Only support convert boolean/float/int/string/map/list to nebula.Value but wasjava.math.BigDecimal
应该是参数转换问题?

我是直接写的xml,项目都是动态的不允许我使用基类

@CorvusYe
Copy link
Collaborator

有个新版本正在发布中,这个类型的问题一会儿一并修复哈~

@btbox
Copy link
Author

btbox commented Nov 29, 2022

好的谢谢,

@btbox
Copy link
Author

btbox commented Nov 30, 2022

我在更新1.1.0后,发生报错:数据查询失败:Only support convert boolean/float/int/string/map/list to nebula.Value but wasjava.util.HashSet,但是我用的是自己拼接的字符串,插入的字段和value都是我字符串拼接的
插入日志如下

INSERT VERTEX tag_milk
        (
        `price`,
        `brand`,
        `key`
        )
        VALUES
        "milk_yili_2":(49.9,"\u4F0A\u5229","yili_2");
	- params: {spaceName=subgraph_1669728312405, tagName=tag_milk, params=["price","brand","key"], dataStr="milk_yili_2":(49.9,"\u4F0A\u5229","yili_2")}
	- result:null

@CorvusYe
Copy link
Collaborator

1.1.0 没发布成功呀,可以在配置 ngbatis 的地方写把这段加进去,替换掉原有的 value setter

COMPLEX_TYPE_AND_SETTER.put(
    Set.class, 
    (Setter<Set<?>>) (set) -> {
      List<Object> values = new ArrayList<>();
      set.forEach(el -> values.add(toNebulaValueType(el)));
      return values;
    });

CorvusYe added a commit to CorvusYe/ngbatis that referenced this issue Nov 30, 2022
CorvusYe added a commit to CorvusYe/ngbatis that referenced this issue Nov 30, 2022
CorvusYe added a commit that referenced this issue Nov 30, 2022
fix #89 BigDecimal / Set / Collection serialization to NebulaValue
@CorvusYe
Copy link
Collaborator

我在更新1.1.0后,发生报错:数据查询失败:Only support convert boolean/float/int/string/map/list to nebula.Value but wasjava.util.HashSet,但是我用的是自己拼接的字符串,插入的字段和value都是我字符串拼接的 插入日志如下

INSERT VERTEX tag_milk
        (
        `price`,
        `brand`,
        `key`
        )
        VALUES
        "milk_yili_2":(49.9,"\u4F0A\u5229","yili_2");
	- params: {spaceName=subgraph_1669728312405, tagName=tag_milk, params=["price","brand","key"], dataStr="milk_yili_2":(49.9,"\u4F0A\u5229","yili_2")}
	- result:null

因为ngbatis并没有对xml内的内容进行解析,不能确定哪些区分哪些参数是自己拼接哪些参数是给nebula占位符的
所以目前传给 dao 的参数都会再传给 nebula。
原来的序列化有一些问题。

@CorvusYe CorvusYe reopened this Nov 30, 2022
@CorvusYe CorvusYe added the bug Something isn't working label Nov 30, 2022
@CorvusYe
Copy link
Collaborator

CorvusYe commented Nov 30, 2022

@hejiahuichengxuyuan

  • 关于BigDecimal的问题
    因为不能确定BigDecimal的属性在项目数据库中所对应的具体类型,项目中需要根据自身需要进行配置:

    1. 参考 ValueType 创建能为实体属性做类型区分的注解(或使用自身项目中已有注解)
    2. 参考 BigDecimalSetter 对不同的字段类型配置。
    3. 将注解放置到java实体类的BigDecimal属性上,如 Person 中的 height 属性。
  • 关于 Set 问题
    最新的1.1.1版本已经发布,COMPLEX_TYPE_AND_SETTER.put 的部分可以不需要了。

@btbox
Copy link
Author

btbox commented Nov 30, 2022

明白,谢谢大佬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants