codeant-ai-for-open-source[bot] commented on code in PR #44739:
URL: https://github.com/apache/superset/pull/44739#discussion_r4119158612


##########
superset-frontend/src/components/FilterableTable/sortResults.ts:
##########
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+type CellValue = string | number | null;
+
+// Compare significands and decimal orders, never coerce exact strings to 
Number.
+// Keeping the exponent separate also avoids allocating 10**exponent zeroes.
+const DECIMAL = /^([+-]?)(?:(\d+)(?:\.(\d*))?|\.(\d+))(?:[eE]([+-]?\d+))?$/;
+
+function decimalParts(value: Exclude<CellValue, null>) {
+  const match = DECIMAL.exec(String(value));
+  if (!match) return null;
+  const fraction = match[3] ?? match[4] ?? '';
+  const digits = `${match[2] ?? ''}${fraction}`.replace(/^0+/, '');
+  return {
+    sign: digits ? (match[1] === '-' ? -1 : 1) : 0,
+    digits,
+    order:
+      BigInt(digits.length) + BigInt(match[5] ?? '0') - 
BigInt(fraction.length),
+  };
+}
+
+export function sortResults(valueA: CellValue, valueB: CellValue): number {
+  if (valueA === valueB) return 0;
+  if (valueA === null) return 1;
+  if (valueB === null) return -1;
+
+  const a = decimalParts(valueA);
+  const b = decimalParts(valueB);
+  if (a && b) {
+    if (a.sign !== b.sign) return a.sign < b.sign ? -1 : 1;
+    if (a.sign === 0) return 0;
+    if (a.order !== b.order) return (a.order < b.order ? -1 : 1) * a.sign;
+    const width = Math.max(a.digits.length, b.digits.length);
+    const left = a.digits.padEnd(width, '0');
+    const right = b.digits.padEnd(width, '0');
+    return left === right ? 0 : (left < right ? -1 : 1) * a.sign;
+  }
+
+  // Retain the table's existing numeric-string, text and infinity behavior.
+  const numberOrText = (value: Exclude<CellValue, null>) =>
+    typeof value === 'string' &&
+    /^(NaN|-?((\d*\.\d+|\d+)([Ee][+-]?\d+)?|Infinity))$/.test(value)
+      ? Number(value)
+      : value;
+  const left = numberOrText(valueA);
+  const right = numberOrText(valueB);
+  return left === right ? 0 : left < right ? -1 : 1;

Review Comment:
   **Suggestion:** When one value is numeric and the other is text or NaN, both 
comparison directions return 1, so mixed-type columns do not have a consistent 
sort order.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Incorrect condition 
logic`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=329260ceabd94600b08d72c69536b2e6&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=329260ceabd94600b08d72c69536b2e6&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/components/FilterableTable/sortResults.ts
   **Line:** 61:63
   **Comment:**
        *Incorrect Condition Logic: When one value is numeric and the other is 
text or NaN, both comparison directions return 1, so mixed-type columns do not 
have a consistent sort order.
   
   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%2F44739&comment_hash=ab878dfbae88cf19a8fc33696ab57d9f3429a103795e4f137833793d3b6f7ba9&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44739&comment_hash=ab878dfbae88cf19a8fc33696ab57d9f3429a103795e4f137833793d3b6f7ba9&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset/dataframe.py:
##########
@@ -72,7 +86,9 @@ def df_to_records(dframe: pd.DataFrame) -> list[dict[str, 
Any]]:
     for record in records:
         for key in record:
             record[key] = (
-                None if _is_na(record[key]) else 
_convert_big_integers(record[key])
+                None
+                if _is_na(record[key])
+                else _convert_decimals(_convert_big_integers(record[key]))
             )

Review Comment:
   **Suggestion:** The decimal conversion only runs through `df_to_records`, 
but the executor's JSON cache writer still calls `to_dict` directly, so cached 
decimals can lose precision.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Sometimes` ยท ๐Ÿท๏ธ `Incomplete 
implementation`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=f328b39aed28418aacca6636555a1760&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=f328b39aed28418aacca6636555a1760&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/dataframe.py
   **Line:** 88:92
   **Comment:**
        *Incomplete Implementation: The decimal conversion only runs through 
`df_to_records`, but the executor's JSON cache writer still calls `to_dict` 
directly, so cached decimals can lose precision.
   
   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%2F44739&comment_hash=155b11dc331b593e8a0e8c10f91edc84c31bb3375f8e88de0c1c2bde5b6d3e5c&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44739&comment_hash=155b11dc331b593e8a0e8c10f91edc84c31bb3375f8e88de0c1c2bde5b6d3e5c&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]

Reply via email to