vizabi / core

Data fetching and transformation module with API based on Grammar of Graphics
1 stars 1 forks source link

Core sends an incorrect query when it knows there is no data to expect #45

Open angiehjort opened 1 month ago

angiehjort commented 1 month ago

The issue happens on vizabi mountain-chart + small-waffle, when the billy feature is disabled

mountain chart sends a query with empty "select.value" array to Billy dataset

LINK

To which ddfcsv reader in small waffle errors and pollutes the error log. Returns 500.

2024-07-11T14:54:52: Too many query structure errors:
2024-07-11T14:54:52: * 'select.value' clause for 'datapoints' queries must have at least 1 item undefined
2024-07-11T14:54:52:
2024-07-11T14:54:52:   InternalServerError: Internal Server Error

Big-waffle would gracefully return an empty array in this case (try)

Response:

{
"version":"bb66a61",
"header":["person","time"],
"rows": [

]}

billy mark has the config as provided before. notice how concept is null in many places, and the value for concept it is instead kept in "stash"

      billy: {
        data: {
          space: ["person", "time"],
          source: "billy"
        },
        requiredEncodings: ["x"],
        encoding: {
          x: {
            data: {
              space: ["person", "time"],
              concept: null,
              stash: "daily_income"
            }
          },

// BLABLABLA, full config in the comment
       }
      }

when needed, there is a UI logic that pulls the values out of stash, currently here

      if (showBilly)
        for (let enc of encs)
          marker.encoding[enc].data.config.concept = marker.encoding[enc].data.config.stash;
      else
        for (let enc of encs)
          marker.encoding[enc].data.config.concept = null;

this is a weird pattern but whatever. it would be nice to add a protection on vizabi core level, which would detect such situation and not send any query as it is known that there will be no data.

angiehjort commented 1 month ago

Full config

currently here https://github.com/Gapminder/tools-page/blob/develop/src/config/toolconfigs/MountainChart-v8.js#L354

      billy: {
        data: {
          space: ["person", "time"],
          source: "billy"
        },
        requiredEncodings: ["x"],
        encoding: {
          "order": {
            modelType: "order",
            direction: "desc",
            data: {
              ref: "markers.billy.config.encoding.x.data"
            }
          },
          x: {
            data: {
              space: ["person", "time"],
              concept: null,
              stash: "daily_income"
            }
          },
          name: {
            data: {
              space: ["person"],
              concept: null,
              stash: "name"
            }
          },
          slices: {
            data: {
              space: ["person"],
              concept: null,
              stash: "countries"
            }
          },
          frame: {
            value: "2022",
            modelType: "frame",
            loop: false,
            data: {
              concept: "time"
            },
            scale: {
              clampDomainToData: true
            }
          },
          selected: {
            modelType: "selection"
          },
          highlighted: {
            modelType: "selection"
          }
        }
      }