public static void main(String[] args) {
SessionState.initHiveLog4j();
CliSessionState ss = new CliSessionState(new HiveConf(SessionState.class));
ss.in = System.in;
try {
ss.out = new PrintStream(System.out, true, "UTF-8");
ss.err = new PrintStream(System.err, true, "UTF-8");
} catch (UnsupportedEncodingException e) {
System.exit(1);
}
HiveConf conf = ss.getConf();
HiveConf.setVar(conf, ConfVars.SEMANTIC_ANALYZER_HOOK, HowlSemanticAnalyzer.class.getName());
SessionState.start(ss);
DefaultOptionBuilder builder = new DefaultOptionBuilder("-", "--", false);
ArgumentBuilder argBuilder = new ArgumentBuilder();
// -e
Option execOption = createOptionWithArg(builder, "exec", "e", "execute the following command",argBuilder.withMinimum(1).withMaximum(1).create());
// -f
Option fileOption = createOptionWithArg(builder, "file", "f","execute commands from the following file", argBuilder.withMinimum(1).withMaximum(1).create());
// -g
Option grpOption = createOptionWithArg(builder, "group", "g","group for the db/table specified in CREATE statement", argBuilder.withMinimum(1).withMaximum(1).create());
// -p
Option permOption = createOptionWithArg(builder, "perms", "p","permissions for the db/table specified in CREATE statement",
argBuilder.withMinimum(1).withMaximum(1).create());
builder.reset();
Option isHelpOption = builder.withShortName("h").withLongName("help").withDescription("help").create();
new PropertyOption();
Group allOptions = new GroupBuilder().withOption(isHelpOption).withOption(execOption).withOption(fileOption).withOption(grpOption).withOption(permOption).create();
Parser parser = new Parser();
parser.setGroup(allOptions);
CommandLine cmdLine = null;
try {
cmdLine = parser.parse(args);
} catch (OptionException e1) {
printErrString(null, System.err);
System.exit(1);
}
// -e
String execString = (String) cmdLine.getValue(execOption);
// -f
String fileName = (String) cmdLine.getValue(fileOption);
// -h
if (cmdLine.hasOption(isHelpOption)) {
printErrString(null, System.out);
System.exit(1);
}
if (execString != null && fileName != null) {
printErrString("Please specify either -e or -f option.", System.err);
System.exit(1);
}
// -p
String perms = (String) cmdLine.getValue(permOption);
if(perms != null){
validatePermissions(ss, conf, perms);
}
// -g
String grp = (String) cmdLine.getValue(grpOption);
if(grp != null){
conf.set(HowlConstants.HOWL_GROUP, grp);
}
if (execString != null) {
System.exit(processLine(execString));
}