[#7] Wrong column reference generated when column is not fully qualified

- Added failing test case
- Improved code generation