It actually works exactly as you describe. We generate SQL query to return aggregates based on SQL supplied in Cube.js schema. We never fetch raw data from SQL backend. Architecture overview can probably help to understand: https://github.com/statsbotco/cubejs-client#architecture