@Test public void testAliasWithSpaces() throws Exception { String query = "select id as `an id` from sample_dim"; try { ASTNode tree = HQLParser.parseHQL(query, conf); Assert.assertNotNull(tree); } catch (NullPointerException exc) { log.error("should not have thrown npe", exc); Assert.fail("should not have thrown npe"); } }
public static ASTNode parseHQL(String query, HiveConf conf) throws LensException { ParseDriver driver = new ParseDriver(); ASTNode tree = null; Context ctx = null; try { ctx = new Context(conf); tree = driver.parse(query, ctx); tree = ParseUtils.findRootNonNullToken(tree); } catch (ParseException e) { throw new LensException(SYNTAX_ERROR.getLensErrorInfo(), e, e.getMessage()); } catch (IOException e) { throw new RuntimeException(e); } finally { if (ctx != null) { try { ctx.clear(); } catch (IOException e) { } } } return tree; }
HQLParser { public static ASTNode parseHQL(String query, HiveConf conf) throws LensException { ParseDriver driver = new ParseDriver(); ASTNode tree = null; Context ctx = null; try { ctx = new Context(conf); tree = driver.parse(query, ctx); tree = ParseUtils.findRootNonNullToken(tree); } catch (ParseException e) { throw new LensException(SYNTAX_ERROR.getLensErrorInfo(), e, e.getMessage()); } catch (IOException e) { throw new RuntimeException(e); } finally { if (ctx != null) { try { ctx.clear(); } catch (IOException e) { } } } return tree; } }
HQLParser { public static ASTNode parseHQL(String query, HiveConf conf) throws LensException { ParseDriver driver = new ParseDriver(); ASTNode tree = null; Context ctx = null; try { ctx = new Context(conf); tree = driver.parse(query, ctx); tree = ParseUtils.findRootNonNullToken(tree); } catch (ParseException e) { throw new LensException(SYNTAX_ERROR.getLensErrorInfo(), e, e.getMessage()); } catch (IOException e) { throw new RuntimeException(e); } finally { if (ctx != null) { try { ctx.clear(); } catch (IOException e) { } } } return tree; } private  HQLParser(); }
HQLParser { public static ASTNode parseHQL(String query, HiveConf conf) throws LensException { ParseDriver driver = new ParseDriver(); ASTNode tree = null; Context ctx = null; try { ctx = new Context(conf); tree = driver.parse(query, ctx); tree = ParseUtils.findRootNonNullToken(tree); } catch (ParseException e) { throw new LensException(SYNTAX_ERROR.getLensErrorInfo(), e, e.getMessage()); } catch (IOException e) { throw new RuntimeException(e); } finally { if (ctx != null) { try { ctx.clear(); } catch (IOException e) { } } } return tree; } private  HQLParser(); static boolean isTableColumnAST(ASTNode astNode); static boolean isPrimitiveBooleanExpression(ASTNode ast); static boolean isPrimitiveBooleanFunction(ASTNode ast); static ASTNode getDotAST(String tableAlias, String fieldAlias); static ASTNode parseHQL(String query, HiveConf conf); static ASTNode parseExpr(String expr); static ASTNode parseExpr(String expr, Configuration conf); static ASTNode parseExpression(String command, Configuration conf); static void printAST(ASTNode node); static void printAST(Map<Integer, String> tokenMapping, ASTNode node, int level, int child); static Map<Integer, String> getHiveTokenMapping(); static ASTNode findNodeByPath(ASTNode root, int... path); static void bft(ASTNode root, ASTNodeVisitor visitor); static void toInfixString(ASTNode root, StringBuilder buf); static void toInfixString(ASTNode root, StringBuilder buf, AppendMode appendMode); static String getString(ASTNode tree, AppendMode appendMode); static String getString(ASTNode tree); static String getColName(ASTNode node); static Set<String> getColsInExpr(final String tableAlias, ASTNode expr); static boolean isAggregateAST(ASTNode node); static boolean isNonAggregateFunctionAST(ASTNode node); static boolean isSelectASTNode(final ASTNode node); static boolean hasAggregate(ASTNode node); static boolean equalsAST(ASTNode n1, ASTNode n2); static ASTNode leftMostChild(ASTNode node); }
HQLParser { public static ASTNode parseHQL(String query, HiveConf conf) throws LensException { ParseDriver driver = new ParseDriver(); ASTNode tree = null; Context ctx = null; try { ctx = new Context(conf); tree = driver.parse(query, ctx); tree = ParseUtils.findRootNonNullToken(tree); } catch (ParseException e) { throw new LensException(SYNTAX_ERROR.getLensErrorInfo(), e, e.getMessage()); } catch (IOException e) { throw new RuntimeException(e); } finally { if (ctx != null) { try { ctx.clear(); } catch (IOException e) { } } } return tree; } private  HQLParser(); static boolean isTableColumnAST(ASTNode astNode); static boolean isPrimitiveBooleanExpression(ASTNode ast); static boolean isPrimitiveBooleanFunction(ASTNode ast); static ASTNode getDotAST(String tableAlias, String fieldAlias); static ASTNode parseHQL(String query, HiveConf conf); static ASTNode parseExpr(String expr); static ASTNode parseExpr(String expr, Configuration conf); static ASTNode parseExpression(String command, Configuration conf); static void printAST(ASTNode node); static void printAST(Map<Integer, String> tokenMapping, ASTNode node, int level, int child); static Map<Integer, String> getHiveTokenMapping(); static ASTNode findNodeByPath(ASTNode root, int... path); static void bft(ASTNode root, ASTNodeVisitor visitor); static void toInfixString(ASTNode root, StringBuilder buf); static void toInfixString(ASTNode root, StringBuilder buf, AppendMode appendMode); static String getString(ASTNode tree, AppendMode appendMode); static String getString(ASTNode tree); static String getColName(ASTNode node); static Set<String> getColsInExpr(final String tableAlias, ASTNode expr); static boolean isAggregateAST(ASTNode node); static boolean isNonAggregateFunctionAST(ASTNode node); static boolean isSelectASTNode(final ASTNode node); static boolean hasAggregate(ASTNode node); static boolean equalsAST(ASTNode n1, ASTNode n2); static ASTNode leftMostChild(ASTNode node); static final Pattern P_WSPACE; static final Set<Integer> BINARY_OPERATORS; static final Set<Integer> N_ARY_OPERATORS; static final Set<Integer> FILTER_OPERATORS; static final Set<Integer> ARITHMETIC_OPERATORS; static final Set<Integer> UNARY_OPERATORS; static final Set<Integer> PRIMITIVE_TYPES; }