Replaces the $ with their actual values @param qstr the pig script to rewrite @param vars parameters and their values @return the modified version
(String qstr, Map<String, Object> vars)
| 297 | * @return the modified version |
| 298 | */ |
| 299 | private String replaceParameters(String qstr, Map<String, Object> vars) |
| 300 | throws IOException { |
| 301 | |
| 302 | List<String> params = new ArrayList<String>(); |
| 303 | for (Entry<String, Object> entry : vars.entrySet()) { |
| 304 | params.add(entry.getKey() + "=" |
| 305 | + fixNonEscapedDollarSign(entry.getValue().toString())); |
| 306 | } |
| 307 | |
| 308 | PigContext context = getScriptContext().getPigContext(); |
| 309 | List<String> contextParams = context.getParams(); |
| 310 | if (contextParams != null) { |
| 311 | for (String param : contextParams) { |
| 312 | params.add(param); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | BufferedReader reader = new BufferedReader(new StringReader(qstr)); |
| 317 | String substituted = context.doParamSubstitution(reader, params, context.getParamFiles()); |
| 318 | context.setParams(contextParams); // reset params that were originally in PigContext |
| 319 | return substituted; |
| 320 | } |
| 321 | |
| 322 | // Escape the $ so that we can use the parameter substitution |
| 323 | // to perform bind operation. Parameter substitution will un-escape $ |
no test coverage detected