Building query definition