apache / apache/iotdb

[Bug] There is a logical error in the precedence of arithmetic operators.

Open
#14,290 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
6.4k
Forks
1.2k
Avg merge
1d 23h
Merged PRs (30d)
115

Description

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/iotdb/issues) and found nothing similar.

### Version

version 1.3.3 (Build: ad95a7e)

### Describe the bug and provide the minimal reproduce step

```
DROP DATABASE root.db0
CREATE DATABASE root.db0

CREATE TIMESERIES root.db0.t1 WITH datatype=INT32;
INSERT INTO root.db0(timestamp, t1) VALUES (1641024000000, 0);

# query 1
SELECT (t1 * -1000) FROM root.db0

# query 2
SELECT (t1 * (-1000)) FROM root.db0
```

### What did you expect to see?

Query 1 returned result set: **-0**

Query 2 returned result set: **-0**

### What did you see instead?

Query 1 returned result set: **-1000**

Query 2 returned result set: **-0**

### Anything else?

Dear IoTDB team, In the above scenario, we combine the `unary negation operator` with column t1 and perform a multiplication operation to examine the result returned by IotDB. In Query 1, we did not enclose `-t1` in parentheses to treat it as a whole, and the returned result was **-1000**, which does not match our expectations. In principle, the unary negation operator should have a higher precedence than the multiplication operator, and the presence or absence of parentheses should not affect the final result.

### Are you willing to submit a PR?

- [x] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Research direction

The payload names no implementation files or tests. Start by running the minimal reproduction in the issue against IoTDB and comparing query 1 with query 2; done means both expressions produce the expected equivalent result, with unary negation taking precedence over multiplication.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.