org.apache.hadoop.hive.ql.parse.ParseDriver Java Examples

The following examples show how to use org.apache.hadoop.hive.ql.parse.ParseDriver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HiveASTRewriter.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public String rewrite(String sourceQry) throws RewriteException {
    String result = sourceQry;
    ASTNode tree = null;
    try {
        ParseDriver pd = new ParseDriver();
        tree = pd.parse(sourceQry, queryContext, true);
        tree = ParseUtils.findRootNonNullToken(tree);
        this.rwCtx = new RewriteContext(sourceQry, tree, queryContext.getTokenRewriteStream());
        rewrite(tree);
        result = toSQL();
    } catch (ParseException e) {
       LOG.error("Could not parse the query {} ", sourceQry, e);
        throw new RewriteException("Could not parse query : " , e);
    }
    return result;
}
 
Example #2
Source File: TestSentryHiveAuthorizationTaskFactory.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
  conf = new HiveConf();
  baseDir = Files.createTempDir();
  baseDir.setWritable(true, false);
  conf.setVar(HiveConf.ConfVars.SCRATCHDIR, baseDir.getAbsolutePath());
  SessionState.start(conf);
  conf.setVar(ConfVars.HIVE_AUTHORIZATION_TASK_FACTORY,
      SentryHiveAuthorizationTaskFactoryImpl.class.getName());

  db = Mockito.mock(Hive.class);
  table = new Table(DB, TABLE);
  partition = new Partition(table);
  context = new Context(conf);
  parseDriver = new ParseDriver();
  analyzer = new DDLSemanticAnalyzer(conf, db);
  SessionState.start(conf);
  Mockito.when(db.getTable(TABLE, false)).thenReturn(table);
  Mockito.when(db.getPartition(table, new HashMap<String, String>(), false))
  .thenReturn(partition);

  HadoopDefaultAuthenticator auth = new HadoopDefaultAuthenticator();
  auth.setConf(conf);
  currentUser = auth.getUserName();

}
 
Example #3
Source File: AbstractHive3QLProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected Set<TableName> findTableNames(final String query) {
    final ASTNode node;
    try {
        node = new ParseDriver().parse(normalize(query));
    } catch (ParseException e) {
        // If failed to parse the query, just log a message, but continue.
        getLogger().debug("Failed to parse query: {} due to {}", new Object[]{query, e}, e);
        return Collections.emptySet();
    }
    final HashSet<TableName> tableNames = new HashSet<>();
    findTableNames(node, tableNames);
    return tableNames;
}
 
Example #4
Source File: AbstractHiveQLProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected Set<TableName> findTableNames(final String query) {
    final ASTNode node;
    try {
        node = new ParseDriver().parse(normalize(query));
    } catch (ParseException e) {
        // If failed to parse the query, just log a message, but continue.
        getLogger().debug("Failed to parse query: {} due to {}", new Object[]{query, e}, e);
        return Collections.emptySet();
    }

    final HashSet<TableName> tableNames = new HashSet<>();
    findTableNames(node, tableNames);
    return tableNames;
}
 
Example #5
Source File: AbstractHive_1_1QLProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected Set<TableName> findTableNames(final String query) {
    final ASTNode node;
    try {
        node = new ParseDriver().parse(normalize(query));
    } catch (ParseException e) {
        // If failed to parse the query, just log a message, but continue.
        getLogger().debug("Failed to parse query: {} due to {}", new Object[]{query, e}, e);
        return Collections.emptySet();
    }

    final HashSet<TableName> tableNames = new HashSet<>();
    findTableNames(node, tableNames);
    return tableNames;
}
 
Example #6
Source File: Parser.java    From Eagle with Apache License 2.0 2 votes vote down vote up
/** 
 * Parse an Hive QL into an Abstract Syntax Tree(AST).
 * @param query
 * @return
 * @throws ParseException
 */
public ASTNode generateAST(String query) throws ParseException {
  ParseDriver pd = new ParseDriver();
  return pd.parse(query);
}
 
Example #7
Source File: Parser.java    From eagle with Apache License 2.0 2 votes vote down vote up
/** 
 * Parse an Hive QL into an Abstract Syntax Tree(AST).
 * @param query
 * @return
 * @throws ParseException
 */
public ASTNode generateAST(String query) throws ParseException {
  ParseDriver pd = new ParseDriver();
  return pd.parse(query);
}