Run a sql command. Any output from this command is written to stdout or stderr as appropriate. @param cmd sql command to run along with its arguments as one string. Currently only hcat is supported as a sql backend @throws IOException
(String cmd)
| 79 | * @throws IOException |
| 80 | */ |
| 81 | public static int sql(String cmd) throws IOException { |
| 82 | ScriptPigContext ctx = getScriptContext(); |
| 83 | if (!ctx.getPigContext().getProperties().get("pig.sql.type").equals("hcat")) { |
| 84 | throw new IOException("sql command only support hcat currently"); |
| 85 | } |
| 86 | if (ctx.getPigContext().getProperties().get("hcat.bin")==null) { |
| 87 | throw new IOException("hcat.bin is not defined. Define it to be your hcat script (Usually $HCAT_HOME/bin/hcat"); |
| 88 | } |
| 89 | String hcatBin = (String)ctx.getPigContext().getProperties().get("hcat.bin"); |
| 90 | if (new File("hcat.bin").exists()) { |
| 91 | throw new IOException(hcatBin + " does not exist. Please check your 'hcat.bin' setting in pig.properties."); |
| 92 | } |
| 93 | int ret = GruntParser.runSQLCommand(hcatBin, cmd, false); |
| 94 | return ret; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Register a jar for use in Pig. Once this is done this jar will be |
nothing calls this directly
no test coverage detected