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

Alias too long when querying views against Postgres #9272

Open
hvavhp opened this issue Feb 26, 2025 · 0 comments
Open

Alias too long when querying views against Postgres #9272

hvavhp opened this issue Feb 26, 2025 · 0 comments

Comments

@hvavhp
Copy link

hvavhp commented Feb 26, 2025

Describe the bug
Hi. This issue is fairly easy to explain. Suppose my underlying database is Postgres. I create a view with name analytics_view_for_performance_marketing, which consists of a field name total_marketing_expense in a cube called marketing_transactions. Then when I query this field, either using REST API or SQL API, cubejs will translate it to a SQL query to be executed against my database as follow:

SELECT ... AS analytics_view_for_performance_marketing__marketing_transactions_total_marketing_expense
FROM ...

Postgres has a limit of 63 characters for alias, which means the above query will return a column with the following column name: analytics_view_for_performance_marketing__marketing_transaction.

I believe that cubejs will not be able to handle this well, and produces an error.

To Reproduce
When using cubejs in production mode, with TRACE logging turned on. This is the error log we get:

{"message":"Query completed","duration":344,"query":"SELECT \"model_01_2102_nhanvien\".tennhanvien \"view_02_nhanvien_sanpham__model_01_2102_nhanvien_tennhanvien\", \"model_01_2102_nhanviensanpham\".tennhanvien \"view_02_nhanvien_sanpham__model_01_2102_nhanviensanpham_tennhanvien\", \"model_01_2102_nhanviensanpham\".tensanpham \"view_02_nhanvien_sanpham__model_01_2102_nhanviensanpham_tensanpham\" FROM test.model_01_2102_nhanvien AS \"model_01_2102_nhanvien\" LEFT JOIN test.model_01_2102_nhanviensanpham AS \"model_01_2102_nhanviensanpham\" ON \"model_01_2102_nhanvien\".nhanvienid = \"model_01_2102_nhanviensanpham\".nhanvienid GROUP BY 1, 2, 3 LIMIT 100","params":[],"requestId":"c607e880-fd3b-4fa8-bf19-0bd1db8475bf-span-1"}
2025-02-26 03:20:09,188 TRACE [cubejs_native::python::runtime] New task
{"message":"Load Request Success","query":{"dimensions":["view_02_nhanvien_sanpham.model_01_2102_nhanvien_tennhanvien","view_02_nhanvien_sanpham.model_01_2102_nhanviensanpham_tennhanvien","view_02_nhanvien_sanpham.model_01_2102_nhanviensanpham_tensanpham"],"measures":[],"filters":[],"order":{},"limit":100},"duration":4891,"apiType":"rest","isPlayground":false,"queries":1,"queriesWithPreAggregations":0,"dbType":["postgres"],"securityContext":{"project_code":"Prj_test_cube_1","iat":1740540004,"iss":"test.recurve.cloud","exp":1740626404,"aud":"cubejs-recurve"},"requestId":"c607e880-fd3b-4fa8-bf19-0bd1db8475bf-span-1"}
{"message":"Internal Server Error","query":{"dimensions":["view_02_nhanvien_sanpham.model_01_2102_nhanvien_tennhanvien","view_02_nhanvien_sanpham.model_01_2102_nhanviensanpham_tennhanvien","view_02_nhanvien_sanpham.model_01_2102_nhanviensanpham_tensanpham"],"measures":[],"filters":[],"order":{},"limit":100},"error":"Error: Member name not found for alias: 'view_02_nhanvien_sanpham__model_01_2102_nhanviensanpham_tensanp'","duration":4894,"securityContext":{"project_code":"Prj_test_cube_1","iat":1740540004,"iss":"test.recurve.cloud","exp":1740626404,"aud":"cubejs-recurve"},"requestId":"c607e880-fd3b-4fa8-bf19-0bd1db8475bf-span-1"}

Expected behavior
This should not have happened, whether for Postgres or other databases. Perhaps there should be a different way to write an alias for a query being sent to the underlying database to make sure that its length is within limit.

Screenshots
NA

Minimally reproducible Cube Schema
I think the problem is quite clear

Version:
1.2.11

Additional context
Nothing more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant