Repository navigation
Description
Is your feature request related to a problem? Please describe.
Currently, the JSON responses of successful queries are very verbose, and contain a lot of duplicate information, which yields the following
- Increased network traffic (which will imply costs with cloud providers)
- Increased response times until the data is received
- Increased time consumed on the client side to parse the data
- Eventually, it's possible to hit hard limits like the API Gateway 6mb response limit, leading to obscure errors
- "Consistency" problems, as it's not possible for us to anticipate what kind of on-demand queries our users produce
Describe the solution you'd like
Ideally, there would be the possibility to use a "compact mode" for the query responses when the production mode is used (via configuration flag or something similar)
This would then change the response data format from something like
{
"query": {
"dimensions": [
"PV.path",
"PV.edgeCity",
"PV.edgeCountry",
"PV.referrerDomainName"
],
"timeDimensions": [
{
"dimension": "PV.eventDate",
"dateRange": [
"2020-07-20T00:00:00.000",
"2020-07-20T23:59:59.999"
],
"granularity": "day"
}
],
"measures": [
"PV.pageViews"
],
"filters": [
{
"dimension": "PV.domainName",
"operator": "equals",
"values": [
"mydomain.io"
]
},
{
"dimension": "PV.customerId",
"operator": "equals",
"values": [
"ac2011e1-a2f3-4002-9999-66c0fb8d839f"
]
}
],
"timezone": "UTC",
"order": []
},
"data": [
{
"PV.path": "/tutorials/test",
"PV.edgeCity": "Sao Paulo",
"PV.edgeCountry": "Brazil",
"PV.referrerDomainName": null,
"PV.eventDate.day": "2020-07-20T00:00:00.000",
"PV.eventDate": "2020-07-20T00:00:00.000",
"PV.pageViews": 2
},
{
"PV.path": "/plugins/test",
"PV.edgeCity": "Boston",
"PV.edgeCountry": "United States",
"PV.referrerDomainName": "www.npmjs.com",
"PV.eventDate.day": "2020-07-20T00:00:00.000",
"PV.eventDate": "2020-07-20T00:00:00.000",
"PV.pageViews": 1
}
],
"lastRefreshTime": "2020-08-27T07:22:44.424Z",
"annotation": {
"measures": {
"PV.pageViews": {
"title": "P V Number of Page Views",
"shortTitle": "Number of Page Views",
"type": "number",
"drillMembers": [],
"drillMembersGrouped": {
"measures": [],
"dimensions": []
}
}
},
"dimensions": {
"PV.path": {
"title": "P V Path",
"shortTitle": "Path",
"type": "string"
},
"PV.edgeCity": {
"title": "P V City",
"shortTitle": "City",
"type": "string"
},
"PV.edgeCountry": {
"title": "P V Country",
"shortTitle": "Country",
"type": "string"
},
"PV.referrerDomainName": {
"title": "P V Referrer Domain Name",
"shortTitle": "Referrer Domain Name",
"type": "string"
}
},
"segments": {},
"timeDimensions": {
"PV.eventDate.day": {
"title": "P V Date",
"shortTitle": "Date",
"type": "time"
},
"PV.eventDate": {
"title": "P V Date",
"shortTitle": "Date",
"type": "time"
}
}
}
}
to
{
"query": {
"dimensions": [
"PV.path",
"PV.edgeCity",
"PV.edgeCountry",
"PV.referrerDomainName"
],
"timeDimensions": [
{
"dimension": "PV.eventDate",
"dateRange": [
"2020-07-20T00:00:00.000",
"2020-07-20T23:59:59.999"
],
"granularity": "day"
}
],
"measures": [
"PV.pageViews"
],
"filters": [
{
"dimension": "PV.domainName",
"operator": "equals",
"values": [
"mydomain.io"
]
},
{
"dimension": "PV.customerId",
"operator": "equals",
"values": [
"ac2011e1-a2f3-4002-9999-66c0fb8d839f"
]
}
],
"timezone": "UTC",
"order": []
},
"data": [
[ "/tutorials/test",
"Sao Paulo",
"Brazil",
null,
"2020-07-20T00:00:00.000",
"2020-07-20T00:00:00.000",
2
],
[
"/plugins/test",
"Boston",
"United States",
"www.npmjs.com",
"2020-07-20T00:00:00.000",
"2020-07-20T00:00:00.000",
1
]
],
"lastRefreshTime": "2020-08-27T07:22:44.424Z",
"annotation": {
"mapping": {
"columns": [
"PV.path",
"PV.edgeCity",
"PV.edgeCountry",
"PV.referrerDomainName",
"PV.eventDate.day",
"PV.eventDate",
"PV.pageViews"
]
},
"measures": {
"PV.pageViews": {
"title": "P V Number of Page Views",
"shortTitle": "Number of Page Views",
"type": "number",
"drillMembers": [],
"drillMembersGrouped": {
"measures": [],
"dimensions": []
}
}
},
"dimensions": {
"PV.path": {
"title": "P V Path",
"shortTitle": "Path",
"type": "string"
},
"PV.edgeCity": {
"title": "P V City",
"shortTitle": "City",
"type": "string"
},
"PV.edgeCountry": {
"title": "P V Country",
"shortTitle": "Country",
"type": "string"
},
"PV.referrerDomainName": {
"title": "P V Referrer Domain Name",
"shortTitle": "Referrer Domain Name",
"type": "string"
}
},
"segments": {},
"timeDimensions": {
"PV.eventDate.day": {
"title": "P V Date",
"shortTitle": "Date",
"type": "time"
},
"PV.eventDate": {
"title": "P V Date",
"shortTitle": "Date",
"type": "time"
}
}
}
}So, basically, send the data as an array of records, where a record is an array of ray values in the original data type, and additionally an annotation.mapping object containing a colums property which defined the sequence of "columns" in the record.
In the example above, this would shrink the data payload from 577 chars to 329 chars, which is a reduction of around 43%. I assume this will be proportional to more "columns" and more records.
This change would also need to be included in the cube.js frontend libraries.
Activity
tobilg commentedon Aug 27, 2020
Relevant discussion in Slack was https://cube-js.slack.com/archives/CC0403RRR/p1598379807118300 cc @paveltiunov
ifokeev commentedon Aug 27, 2020
Yeah, have the same problem. That's better to have
pandasdataframesplitformat:https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_json.html
That's the best format for
rowsdata indeed. Also we will gain nativepandas.read_jsonparsingamitripshtos commentedon Aug 27, 2020
I totally agree also that it is crucial to run cubejs faster, with less memory and less network bandwidth.
I think the main discussion here should be:
I also up to the task to help with this one!
paveltiunov commentedon Sep 2, 2020
Let's introduce
compactflag for load method passed by client and stick with format proposed by @tobilg. We can check something likeNODE_ENVon the client side to pass this flag by default so production builds always use compact format.@amitripshtos Contributions are very welcomed here!
tobilg commentedon Sep 4, 2020
Hi @paveltiunov, could you eventually point us to the relevant code portions which are used for generating the output? Thanks!
vasilev-alex commentedon Sep 9, 2020
Hey @tobilg! Please see https://github.com/cube-js/cube.js/blob/18e48e1b9c6bbec86d469025779f93d91883d42b/packages/cubejs-api-gateway/index.js#L610