codeant-ai-for-open-source[bot] commented on code in PR #39452:
URL: https://github.com/apache/superset/pull/39452#discussion_r3531044326
##########
superset-frontend/plugins/legacy-plugin-chart-paired-t-test/src/TTestTable.tsx:
##########
@@ -32,279 +32,325 @@ export interface DataEntry {
}
interface TTestTableProps {
- alpha: number;
+ alpha?: number;
data: DataEntry[];
groups: string[];
- liftValPrec: number;
+ liftValPrec?: number;
metric: string;
- pValPrec: number;
+ pValPrec?: number;
}
-interface TTestTableState {
- control: number;
- liftValues: (string | number)[];
- pValues: (string | number)[];
-}
-
-const defaultProps = {
- alpha: 0.05,
- liftValPrec: 4,
- pValPrec: 6,
-};
+function TTestTable({
+ alpha = 0.05,
+ data,
+ groups,
+ liftValPrec = 4,
+ metric,
+ pValPrec = 6,
+}: TTestTableProps) {
+ const [control, setControl] = useState(0);
+ // Mirrors `control` so the data-change effect can read the latest value
+ // without re-running (and recomputing) after every row click
+ const controlRef = useRef(0);
+ const [liftValues, setLiftValues] = useState<(string | number)[]>([]);
+ const [pValues, setPValues] = useState<(string | number)[]>([]);
-class TTestTable extends Component<TTestTableProps, TTestTableState> {
- static defaultProps = defaultProps;
-
- constructor(props: TTestTableProps) {
- super(props);
- this.state = {
- control: 0,
- liftValues: [],
- pValues: [],
- };
- }
+ const computeLift = useCallback(
+ (values: DataPointValue[], controlValues: DataPointValue[]): string => {
+ // Compute the lift value between two time series
+ let sumValues = 0;
+ let sumControl = 0;
+ values.forEach((value, i) => {
+ sumValues += value.y;
+ sumControl += controlValues[i].y;
+ });
Review Comment:
**Suggestion:** This loop assumes both series have identical length and
dereferences `controlValues[i]` unconditionally; if the incoming rows are
uneven (common with sparse/missing points), it will throw at runtime. Guard
index access (or iterate only over the shared length) before reading `.y`.
[null pointer]
<details>
<summary><b>Severity Level:</b> Critical 🚨</summary>
```mdx
- ❌ Paired t-test chart crashes on uneven series lengths.
- ⚠️ Users lose lift metrics for affected comparisons.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. The Paired T-Test chart plugin registers `PairedTTest` and loads it via
`loadChart: ()
=> import('./PairedTTest')` in
`superset-frontend/plugins/legacy-plugin-chart-paired-t-test/src/index.ts:41-48`,
with
props produced by `transformProps.ts:21-41`.
2. `transformProps` at
`superset-frontend/plugins/legacy-plugin-chart-paired-t-test/src/transformProps.ts:21-41`
forwards `queriesData[0].data` as `data`, which in `PairedTTest.tsx:24-32`
is typed as
`Record<string, DataEntry[]>` and passed to `TTestTable` as
`data={data[metric]}` at
`PairedTTest.tsx:124-133`.
3. Inside `TTestTable`, the `computeTTest` function at
`TTestTable.tsx:113-140` iterates
each row and, for non-control rows, calls `computeLift(data[i].values,
data[controlIndex].values)` at lines 127-132, passing two `values` arrays
that may differ
in length if the backend returns uneven time series (for example missing
timestamps in one
group).
4. `computeLift` at `TTestTable.tsx:58-75` loops with
`values.forEach((value, i) => {
sumValues += value.y; sumControl += controlValues[i].y; })` (lines 63-66);
when `i`
exceeds `controlValues.length - 1`, `controlValues[i]` is `undefined`, so
accessing `.y`
throws a runtime TypeError, crashing the Paired T-Test chart render when
such uneven
series are supplied.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=d7e5aba58c8640b09891f28b1694936b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=d7e5aba58c8640b09891f28b1694936b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/plugins/legacy-plugin-chart-paired-t-test/src/TTestTable.tsx
**Line:** 63:66
**Comment:**
*Null Pointer: This loop assumes both series have identical length and
dereferences `controlValues[i]` unconditionally; if the incoming rows are
uneven (common with sparse/missing points), it will throw at runtime. Guard
index access (or iterate only over the shared length) before reading `.y`.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39452&comment_hash=2e38a245bc3c0e7b8b91b93b0d21b226727f5913a5a08390c173bc82b6aabc0e&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39452&comment_hash=2e38a245bc3c0e7b8b91b93b0d21b226727f5913a5a08390c173bc82b6aabc0e&reaction=dislike'>👎</a>
##########
superset-frontend/plugins/legacy-plugin-chart-paired-t-test/src/TTestTable.tsx:
##########
@@ -32,279 +32,325 @@ export interface DataEntry {
}
interface TTestTableProps {
- alpha: number;
+ alpha?: number;
data: DataEntry[];
groups: string[];
- liftValPrec: number;
+ liftValPrec?: number;
metric: string;
- pValPrec: number;
+ pValPrec?: number;
}
-interface TTestTableState {
- control: number;
- liftValues: (string | number)[];
- pValues: (string | number)[];
-}
-
-const defaultProps = {
- alpha: 0.05,
- liftValPrec: 4,
- pValPrec: 6,
-};
+function TTestTable({
+ alpha = 0.05,
+ data,
+ groups,
+ liftValPrec = 4,
+ metric,
+ pValPrec = 6,
+}: TTestTableProps) {
+ const [control, setControl] = useState(0);
+ // Mirrors `control` so the data-change effect can read the latest value
+ // without re-running (and recomputing) after every row click
+ const controlRef = useRef(0);
+ const [liftValues, setLiftValues] = useState<(string | number)[]>([]);
+ const [pValues, setPValues] = useState<(string | number)[]>([]);
-class TTestTable extends Component<TTestTableProps, TTestTableState> {
- static defaultProps = defaultProps;
-
- constructor(props: TTestTableProps) {
- super(props);
- this.state = {
- control: 0,
- liftValues: [],
- pValues: [],
- };
- }
+ const computeLift = useCallback(
+ (values: DataPointValue[], controlValues: DataPointValue[]): string => {
+ // Compute the lift value between two time series
+ let sumValues = 0;
+ let sumControl = 0;
+ values.forEach((value, i) => {
+ sumValues += value.y;
+ sumControl += controlValues[i].y;
+ });
- componentDidMount() {
- const { control } = this.state;
- this.computeTTest(control); // initially populate table
- }
-
- getLiftStatus(row: number): string {
- const { control, liftValues } = this.state;
- // Get a css class name for coloring
- if (row === control) {
- return 'control';
- }
- const liftVal = liftValues[row];
- if (Number.isNaN(liftVal) || !Number.isFinite(liftVal)) {
- return 'invalid'; // infinite or NaN values
- }
-
- return Number(liftVal) >= 0 ? 'true' : 'false'; // green on true, red on
false
- }
+ // A zero control sum yields "Infinity" (or "NaN" for 0/0) via toFixed,
+ // matching the original class component's output
+ return (((sumValues - sumControl) / sumControl) * 100).toFixed(
+ liftValPrec,
+ );
+ },
+ [liftValPrec],
+ );
- getPValueStatus(row: number): string {
- const { control, pValues } = this.state;
- if (row === control) {
- return 'control';
- }
- const pVal = pValues[row];
- if (Number.isNaN(pVal) || !Number.isFinite(pVal)) {
- return 'invalid';
- }
+ const computePValue = useCallback(
+ (
+ values: DataPointValue[],
+ controlValues: DataPointValue[],
+ ): string | number => {
+ // Compute the p-value from Student's t-test
+ // between two time series
+ let diffSum = 0;
+ let diffSqSum = 0;
+ let finiteCount = 0;
+ values.forEach((value, i) => {
+ const diff = controlValues[i].y - value.y;
+ /* eslint-disable-next-line */
+ if (isFinite(diff)) {
+ finiteCount += 1;
+ diffSum += diff;
+ diffSqSum += diff * diff;
+ }
+ });
Review Comment:
**Suggestion:** This p-value computation also dereferences
`controlValues[i]` without validating that the control row has a value at that
index, which can throw when data contains missing timestamps. Use a bounded
iteration or skip indices where either side is missing. [null pointer]
<details>
<summary><b>Severity Level:</b> Critical 🚨</summary>
```mdx
- ❌ Paired t-test p-value computation crashes on uneven data.
- ⚠️ Statistical significance column unavailable for impacted charts.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. As in the previous suggestion, the Paired T-Test plugin uses
`transformProps` at
`superset-frontend/plugins/legacy-plugin-chart-paired-t-test/src/transformProps.ts:21-41`
to pass `queriesData[0].data` to `PairedTTest`, which then passes
`data[metric]` into
`TTestTable` at `PairedTTest.tsx:124-133` without enforcing equal
`values.length` across
groups.
2. `TTestTable`'s `computeTTest` at
`superset-frontend/plugins/legacy-plugin-chart-paired-t-test/src/TTestTable.tsx:113-140`
invokes `computePValue(data[i].values, data[controlIndex].values)` for each
non-control
row (line 128), again assuming both `values` arrays are the same length.
3. In `computePValue` at `TTestTable.tsx:77-111`, the loop
`values.forEach((value, i) => {
const diff = controlValues[i].y - value.y; ... })` (lines 87-95) dereferences
`controlValues[i].y` for every index present in the non-control series,
without checking
whether `controlValues[i]` exists.
4. When the control series has fewer points than the comparison series (for
example, due
to missing timestamps or truncated history for the control group), the loop
reaches an
index where `controlValues[i]` is `undefined`, and `controlValues[i].y` at
`TTestTable.tsx:88` crashes with a TypeError, breaking the p-value
computation and the
entire Paired T-Test table rendering.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=aca7833ad20b477eb87d7c1dee0c4003&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=aca7833ad20b477eb87d7c1dee0c4003&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/plugins/legacy-plugin-chart-paired-t-test/src/TTestTable.tsx
**Line:** 87:95
**Comment:**
*Null Pointer: This p-value computation also dereferences
`controlValues[i]` without validating that the control row has a value at that
index, which can throw when data contains missing timestamps. Use a bounded
iteration or skip indices where either side is missing.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39452&comment_hash=c2e967325f02666b1f8944064e9d7ebae14f073fb26caddef7cd9a57924550ce&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39452&comment_hash=c2e967325f02666b1f8944064e9d7ebae14f073fb26caddef7cd9a57924550ce&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]