alibaba / alibaba/fastjson2

[BUG]复杂筛选升级后的查询结果重复

Open
#1,700 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述
首先非常感谢温少增加了复杂的筛选规则。详见:https://github.com/alibaba/fastjson2/issues/1410
我升级到2.0.35后,又发现了个问题,仅有唯一查询条件的情况下,查询的结果重复,烦请温少帮忙看一下原因。

### 环境信息
- OS信息: [e.g.:Window11 4Core 3.10GHz 16 GB]
- JDK信息: [e.g.:Openjdk 1.8.0_312]
- 版本信息:[e.g.:Fastjson2 2.0.35]

### 重现步骤
String path="$..[?( @.dictId =='101' )]"; //开头的$后面两个点,即:“$..”,相当于递归查询所有子节点
Object childArr=JSONPath.eval(jsonArr, path); //此时返回的childArr的值为两个取值相同的JSONObject对象,而在jsonArr只有一个dictId =='101'的JSONObject节点
结果详见“附录:childArr结果2”

### 期待的正确结果
childArr的期待结果详见“附录1:childArr结果1”,应该返回仅有一个dictId =='101'的JSONObject节点

### 相关日志输出
*请复制并粘贴任何相关的日志输出。*

#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*

{
"dictId": "CN",
"dictName": "China",
"dictTypeId": "country",
"level": 1,
"rank": 1,
"seqno": ".CN.",
"sortno": 1,
"status": 1,
"children": [
{
"dictId": "1",
"dictName": "Jiangsu",
"dictTypeId": "province",
"level": 1,
"parentId": "CN",
"rank": 2,
"seqno": ".CN.1.",
"sortno": 1,
"status": 1,
"children": [
{
"dictId": "101",
"dictName": "Nanjing",
"dictTypeId": "city",
"level": 1,
"parentId": "1",
"rank": 3,
"seqno": ".CN.1.101.",
"sortno": 1,
"status": 1
},
{
"dictId": "102",
"dictName": "Changzhou",
"dictTypeId": "city",
"level": 1,
"parentId": "1",
"rank": 3,
"seqno": ".CN.1.102.",
"sortno": 2,
"status": 1
},
{
"dictId": "103",
"dictName": "Wuxi",
"dictTypeId": "city",
"level": 1,
"parentId": "1",
"rank": 3,
"seqno": ".CN.1.103.",
"sortno": 3,
"status": 1
}
]
},
{
"dictId": "2",
"dictName": "Guangdong",
"dictTypeId": "province",
"level": 1,
"parentId": "CN",
"rank": 2,
"seqno": ".CN.2.",
"sortno": 2,
"status": 1,
"children": [
{
"dictId": "201",
"dictName": "Guangzhou",
"dictTypeId": "city",
"level": 1,
"parentId": "2",
"rank": 3,
"seqno": ".CN.2.201.",
"sortno": 1,
"status": 1
},
{
"dictId": "202",
"dictName": "Shantou",
"dictTypeId": "city",
"level": 1,
"parentId": "2",
"rank": 3,
"seqno": ".CN.2.202.",
"sortno": 2,
"status": 1
},
{
"dictId": "203",
"dictName": "Shenzhen",
"dictTypeId": "city",
"level": 1,
"parentId": "2",
"rank": 3,
"seqno": ".CN.2.203.",
"sortno": 3,
"status": 1
}
]
},
{
"dictId": "3",
"dictName": "Fujian",
"dictTypeId": "province",
"level": 1,
"parentId": "CN",
"rank": 2,
"seqno": ".CN.3.",
"sortno": 3,
"status": 1,
"children": [
{
"dictId": "301",
"dictName": "Xiamen",
"dictTypeId": "city",
"level": 1,
"parentId": "3",
"rank": 3,
"seqno": ".CN.3.301.",
"sortno": 1,
"status": 1
},
{
"dictId": "302",
"dictName": "Fuzhou",
"dictTypeId": "city",
"level": 1,
"parentId": "3",
"rank": 3,
"seqno": ".CN.3.302.",
"sortno": 2,
"status": 1
}
]
}
]
}

附录:childArr结果1 -- 期待结果

[
{
"dictId": "101",
"dictName": "Nanjing",
"dictTypeId": "city",
"level": 1,
"parentId": "1",
"rank": 3,
"seqno": ".CN.1.101.",
"sortno": 1,
"status": 1
}
]

Contributor guide

Open the contributing guide

Research direction

Start at the JSONPath.eval entry point and reproduce the supplied recursive path, filter expression, and JSON tree. Compare the returned objects with the expected single-item result; done means the unique dictId 101 node is returned only once.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.