Hi I am wondering how people productionise their GSQL queries? Is there any unit testing? Are queries encouraged to be short? Long? Any rules for readability such as number of variables?
@emackie Productionizing GSQL queries involves making them ready for deployment in a production environment. While there might not be strict rules universally applicable, here are some common practices:
1. Unit Testing: unit testing is encouraged. Creating test cases that cover different scenarios helps ensure that your queries work as expected. Tools like “gsqltest” are often used for testing GSQL queries.
2. Query Length: There’s no hard rule, but generally, queries should be structured and organized. Breaking complex queries into smaller logical steps can improve readability and maintainability.
3. Readability: Clear and well-documented code is essential. Use meaningful variable and function names. Include comments to explain complex logic. Follow a consistent coding style.
4. Code Reusability: Encourage creating reusable queries. This reduces duplication and eases maintenance.
5. Complexity: Queries should strike a balance between complexity and performance. Highly complex queries might be harder to maintain. It’s often better to split complex logic into multiple simpler queries.
6. Version Control: Use version control systems (like Git) to manage queries. This helps track changes, collaborate effectively, and roll back if needed.
7. Error Handling: Design queries to handle potential errors gracefully. This ensures queries don’t fail catastrophically in a production setting
8. Documentation: Maintain documentation for your queries, explaining their purpose, input/output, and usage.
I hope the above points will help you
Would you be able to point me to any example of gsqltest and documentation? Is this integrated with python at all?
In addition, for “6. Version Control” would you have any thoughts on how to link the git version of a query to the “installed” version on the Tigergraph server in a production-best-practice?
@emackie If you’re looking to perform unit tests using GSQL and Python, you might find this community-published blog helpful. It provides insights on creating solution unit tests for PyTigerGraph projects using pytest. Here’s the link: Medium Blog. I hope this resource helps guide you in the right direction!
Nice thanks I have seen this before. I find it more helpful now I am more familiar with TG.
One thing though I think querying the db or running pytigergraph methods in unit tests should be considered bad practice. To unit test my python code I usually mock the pytigergraph connection.
I think what I really lack is the knowledge to turn my GSQL query strings into “more” than just large strings… but this could be said for any SQL I write also.