MCPcopy Create free account
hub / github.com/apache/pig / sql

Method sql

src/org/apache/pig/scripting/Pig.java:81–95  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

getScriptContextMethod · 0.95
getPigContextMethod · 0.95
runSQLCommandMethod · 0.95
getMethod · 0.65
existsMethod · 0.65
equalsMethod · 0.45
getPropertiesMethod · 0.45

Tested by

no test coverage detected