当前位置: 首页 > news >正文

Doris json_contains 查询报错

### SQL: SELECT count(0) FROM or_sales_info WHERE deleted = 0 AND (order_code IN (?, ?) AND shop_company_name = ? AND business_type IN (?) AND status = ? AND create_time >= ? AND create_time < ? AND is_confirm_after_sales = ? AND (JSON_CONTAINS(order_labels, '1') AND JSON_CONTAINS(order_labels, '4')))
### Cause: java.sql.SQLException: errCode = 2, detailMessage = No matching function with signature: json_contains(JSON, VARCHAR(65533)).
; uncategorized SQLException; SQL state [HY000]; error code [1105]; errCode = 2, detailMessage = No matching function with signature: json_contains(JSON, VARCHAR(65533)).; nested exception is java.sql.SQLException: errCode = 2, detailMessage = No matching function with signature: json_contains(JSON, VARCHAR(65533)).]
org.springframework.jdbc.UncategorizedSQLException: 
### Error querying database.  Cause: java.sql.SQLException: errCode = 2, detailMessage = No matching function with signature: json_contains(JSON, VARCHAR(65533)).
### The error may exist in com/cloud/dw/mapper/oms/SalesInfoMapper.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT count(0) FROM or_sales_info WHERE deleted = 0 AND (order_code IN (?, ?) AND shop_company_name = ? AND business_type IN (?) AND status = ? AND create_time >= ? AND create_time < ? AND is_confirm_after_sales = ? AND (JSON_CONTAINS(order_labels, '1') AND JSON_CONTAINS(order_labels, '4')))
### Cause: java.sql.SQLException: errCode = 2, detailMessage = No matching function with signature: json_contains(JSON, VARCHAR(65533)).
; uncategorized SQLException; SQL state [HY000]; error code [1105]; errCode = 2, detailMessage = No matching function with signature: json_contains(JSON, VARCHAR(65533)).; nested exception is java.sql.SQLException: errCode = 2, detailMessage = No matching function with signature: json_contains(JSON, VARCHAR(65533)).at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)at com.sun.proxy.$Proxy155.selectList(Unknown Source)

根据错误信息,Doris数据库的JSON_CONTAINS函数签名不匹配。Doris要求第二个参数也是JSON格式,而不是字符串。需要对代码进行改造以兼容Doris的JSON函数语法。

查询sql

select * from or_sales_info where 1=1

and JSON_CONTAINS(order_labels, CAST('4' AS JSON))

and JSON_CONTAINS(order_labels, CAST('1' AS JSON))

and create_time between '2025-05-01 00:00:00' and '2025-05-30 23:59:59';

代码

    private static <T> Wrapper<T> generateJsonArrayFieldToWrapper(final Field field, final QueryCondition cond, final Object value, final Boolean isOr, final Boolean isDoris) {QueryWrapper<T> wrapper = Wrappers.query();String customSubSql = "JSON_CONTAINS({}, '{}')";if (Boolean.TRUE.equals(isDoris)) {customSubSql = "JSON_CONTAINS({}, CAST('{}' AS JSON))";}// 判断是否为数组if (value.getClass().isArray()) {Class<?> componentType = value.getClass().getComponentType();if (componentType.equals(String.class)) {customSubSql = "JSON_CONTAINS({}, '\"{}\"')";if (Boolean.TRUE.equals(isDoris)) {customSubSql = "JSON_CONTAINS({}, CAST('\"{}\"' AS JSON))";}}// 获取数组的值for (int i = 0; i < Array.getLength(value); i++) {applyJsonArrayCondition(wrapper, cond, Array.get(value, i), customSubSql, isOr);}} else if (value instanceof Collection) {Type genricType = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];if (genricType.equals(String.class)) {customSubSql = "JSON_CONTAINS({}, '\"{}\"')";if (Boolean.TRUE.equals(isDoris)) {customSubSql = "JSON_CONTAINS({}, CAST('\"{}\"' AS JSON))";}}for (Object element : (Collection<?>) value) {applyJsonArrayCondition(wrapper, cond, element, customSubSql, isOr);}}return wrapper;}
    private static <T> void applyJsonArrayCondition(QueryWrapper<T> wrapper, QueryCondition cond, Object element, String customSubSql, Boolean isOr) {if (isOr) {wrapper.or();}wrapper.apply(StrUtil.format(customSubSql, cond.getFiledName(), element));}

http://www.dtcms.com/a/313361.html

相关文章:

  • 数据结构总纲以及单向链表详解:
  • 【LeetCode刷题指南】--对称二叉树,另一颗树的子树
  • [创业之路-531]:知识、技能、技术、科学之间的区别以及它们对于职业的选择的指导作用?
  • 【OpenGL】LearnOpenGL学习笔记02 - 绘制三角形、矩形
  • 13-day10生成式任务
  • 基于MBA与BP神经网络分类模型的特征选择方法研究(Python实现)
  • 在ANSYS Maxwell中对永磁体无线充电进行建模
  • 【大模型核心技术】Agent 理论与实战
  • 【设计模式】5.代理模式
  • Manus AI与多语言手写识别
  • 什么是“痛苦指数”(Misery Index)?
  • 如何获取网页中点击按钮跳转后的链接呢
  • 在 Cursor 中设置浅色背景和中文界面
  • 抽奖系统中 Logback 的日志配置文件说明
  • 03.一键编译安装Redis脚本
  • 【MySQL】MySQL 中的数据排序是怎么实现的?
  • 深入理解流式输出:原理、应用与大模型聊天软件中的实现
  • 跨语言模型中的翻译任务:XLM-RoBERTa在翻译任务中的应用
  • python---python中的内存分配
  • AI Agent 重塑产业发展新格局
  • 联想笔记本安装系统之后一直转圈圈的问题了?无法正常进入到系统配置界面,原来是BIOS中的VMD问题
  • Autoswagger:揭露隐藏 API 授权缺陷的开源工具
  • 使用CMake构建项目的完整指南
  • [LINUX操作系统]shell脚本之循环
  • 【Qt】QObject::startTimer: Timers cannot be started from another thread
  • 如何玩转 Kubernetes K8S
  • 【QT】概述
  • 快速搭建一个非生产k8s环境
  • Android 之 网络通信(HTTP/TCP/UDP/JSON)
  • 量子物理学的前沿意义虚无、形式混乱