Summary
The channel dimension query used by analyticsDimensionStats generates CAST(... AS TEXT). MySQL does not support TEXT as a CAST target type, so the Analytics query fails with error 1064.
The same code is currently present on the unstable branch.
Environment
- AxonHub:
v1.0.0-beta6
- Package:
windows_amd64
- Database: MySQL
- Deployment: standalone binary with automatic migrations enabled
Steps to reproduce
- Run AxonHub
v1.0.0-beta6 with a MySQL database.
- Open the Analytics page or execute the
analyticsDimensionStats GraphQL query.
- Request dimension statistics that include channels.
Actual result
{
"errors": [
{
"message": "failed to get analytics stats by channel: Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TEXT) AS \`id\`, \`t1\`.\`name\` AS \`name\`, COUNT(\`usage_logs\`.\`id\`) AS \`request_count\`' at line 1",
"path": ["analyticsDimensionStats"]
}
],
"data": null
}
Root cause
internal/server/gql/analytics_helpers.go builds the channel ID projection with:
sql.As(fmt.Sprintf("CAST(%s AS TEXT)", s.C(usagelog.FieldChannelID)), "id")
MySQL accepts targets such as CHAR, but not TEXT, in this form. The SQL fails during parsing before table data or schema can be evaluated.
Source:
https://github.com/looplj/axonhub/blob/v1.0.0-beta6/internal/server/gql/analytics_helpers.go#L180
Expected result
analyticsDimensionStats should return channel statistics successfully on every supported database dialect.
Suggested fix
For a cross-dialect fix, avoid the SQL cast: scan channel_id into an integer field and convert it to the GraphQL string ID in Go. A MySQL-only change to CAST(... AS CHAR) would fix MySQL but would retain dialect-specific behavior.
A regression test should cover the generated/executed channel dimension query for MySQL.
Summary
The channel dimension query used by
analyticsDimensionStatsgeneratesCAST(... AS TEXT). MySQL does not supportTEXTas aCASTtarget type, so the Analytics query fails with error 1064.The same code is currently present on the
unstablebranch.Environment
v1.0.0-beta6windows_amd64Steps to reproduce
v1.0.0-beta6with a MySQL database.analyticsDimensionStatsGraphQL query.Actual result
{ "errors": [ { "message": "failed to get analytics stats by channel: Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TEXT) AS \`id\`, \`t1\`.\`name\` AS \`name\`, COUNT(\`usage_logs\`.\`id\`) AS \`request_count\`' at line 1", "path": ["analyticsDimensionStats"] } ], "data": null }Root cause
internal/server/gql/analytics_helpers.gobuilds the channel ID projection with:MySQL accepts targets such as
CHAR, but notTEXT, in this form. The SQL fails during parsing before table data or schema can be evaluated.Source:
https://github.com/looplj/axonhub/blob/v1.0.0-beta6/internal/server/gql/analytics_helpers.go#L180
Expected result
analyticsDimensionStatsshould return channel statistics successfully on every supported database dialect.Suggested fix
For a cross-dialect fix, avoid the SQL cast: scan
channel_idinto an integer field and convert it to the GraphQL string ID in Go. A MySQL-only change toCAST(... AS CHAR)would fix MySQL but would retain dialect-specific behavior.A regression test should cover the generated/executed channel dimension query for MySQL.