Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect SQL Query Generation for Nested JSON Fields #1101

Open
qazi9amaan opened this issue Jul 28, 2024 · 0 comments
Open

Incorrect SQL Query Generation for Nested JSON Fields #1101

qazi9amaan opened this issue Jul 28, 2024 · 0 comments
Labels

Comments

@qazi9amaan
Copy link

qazi9amaan commented Jul 28, 2024

Description
I am using react-awesome-query-builder to create a query to fetch users with paymentStatus = 'Refunded' stored in a nested JSON column lastOrder. The configuration uses !struct for nested objects.
However, the generated SQL query is incorrect:.

lastOrder.paymentStatus = 'Refunded';

Edit react-awesome-query-builder-sql-json

This SQL query does not work as expected with JSON columns.
image

Steps to reproduce

  • Use the following query configuration:
{
  "label": "Last Order",
  "subfields": {
    "paymentStatus": {
      "label": "Payment Status",
      "listValues": {
        "Pending": "Pending",
        "Paid": "Paid",
        "Refunded": "Refunded"
      },
      "type": "select",
      "valueSources": [
        "value"
      ]
    },
    "orderStatus": {
      "label": "Order Status",
      "listValues": {
        "Pending": "Pending",
        "Delivered": "Delivered",
        "Cancelled": "Cancelled",
        "Returned": "Returned"
      },
      "type": "select",
      "valueSources": [
        "value"
      ]
    }
  },
  "type": "!struct"
}
  • Create a query to filter lastOrder.paymentStatus = 'Refunded'.
  • Observe the generated SQL query.

Example JSON Tree:
This is how the JSON tree looks

{
  "id": "a8999ba8-0123-4456-b89a-b190fa823c98",
  "type": "group",
  "path": [
    "a8999ba8-0123-4456-b89a-b190fa823c98"
  ],
  "children1": {
    "a89bbb88-4567-489a-bcde-f190fa84d826": {
      "type": "rule",
      "id": "a89bbb88-4567-489a-bcde-f190fa84d826",
      "properties": {
        "fieldSrc": "field",
        "field": "lastOrder.paymentStatus",
        "operator": "select_equals",
        "value": [
          "Refunded"
        ],
        "valueSrc": [
          "value"
        ],
        "operatorOptions": null,
        "valueType": [
          "select"
        ],
        "valueError": [
          null
        ]
      },
      "path": [
        "a8999ba8-0123-4456-b89a-b190fa823c98",
        "a89bbb88-4567-489a-bcde-f190fa84d826"
      ]
    }
  }
}

Expected Behavior:
The generated SQL query should correctly handle the nested JSON field:

json_extract(lastOrder, '$.paymentStatus') = 'Refunded';

Current Behavior:
The generated SQL query is:

lastOrder.paymentStatus = 'Refunded';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants