本文整理汇总了Java中org.apache.hadoop.hive.ql.parse.HiveParser.TOK_QUERY属性的典型用法代码示例。如果您正苦于以下问题:Java HiveParser.TOK_QUERY属性的具体用法?Java HiveParser.TOK_QUERY怎么用?Java HiveParser.TOK_QUERY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.hadoop.hive.ql.parse.HiveParser
的用法示例。
在下文中一共展示了HiveParser.TOK_QUERY属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMockedCubeContext
/**
* Gets the mocked cube context.
*
* @param ast the ast
* @return the mocked cube context
* @throws ParseException the parse exception
* @throws LensException the lens exception
*/
private CubeQueryContext getMockedCubeContext(ASTNode ast) throws ParseException, LensException {
CubeQueryContext context = Mockito.mock(CubeQueryContext.class);
if (ast.getToken().getType() == HiveParser.TOK_QUERY) {
if (((ASTNode) ast.getChild(0)).getToken().getType() == HiveParser.KW_CUBE) {
// remove cube child from AST
for (int i = 0; i < ast.getChildCount() - 1; i++) {
ast.setChild(i, ast.getChild(i + 1));
}
ast.deleteChild(ast.getChildCount() - 1);
}
}
StringBuilder builder = new StringBuilder();
HQLParser.toInfixString(ast, builder);
Mockito.when(context.toHQL()).thenReturn(builder.toString());
Mockito.when(context.toAST(Matchers.any(Context.class))).thenReturn(ast);
return context;
}
示例2: rewriteQuery
/**
* Rewrite query.
*
* @return the string
* @throws LensException the lens exception
*/
protected String rewriteQuery(AbstractQueryContext ctx) throws LensException {
if (ctx.getFinalDriverQuery(this) != null) {
return ctx.getFinalDriverQuery(this);
}
String query = ctx.getDriverQuery(this);
Configuration driverQueryConf = ctx.getDriverConf(this);
MethodMetricsContext checkForAllowedQuery = MethodMetricsFactory.createMethodGauge(driverQueryConf, true,
CHECK_ALLOWED_QUERY);
// check if it is select query
ASTNode ast = HQLParser.parseHQL(query, ctx.getHiveConf());
if (ast.getToken().getType() != HiveParser.TOK_QUERY) {
throw new LensException("Not allowed statement:" + query);
} else {
// check for insert clause
ASTNode dest = HQLParser.findNodeByPath(ast, HiveParser.TOK_INSERT);
if (dest != null
&& ((ASTNode) (dest.getChild(0).getChild(0).getChild(0))).getToken().getType() != HiveParser.TOK_TMP_FILE) {
throw new LensException("Not allowed statement:" + query);
}
}
checkForAllowedQuery.markSuccess();
QueryRewriter rewriter = getQueryRewriter();
String rewrittenQuery = rewriter.rewrite(query, driverQueryConf, ctx.getHiveConf());
ctx.setFinalDriverQuery(this, rewrittenQuery);
return rewrittenQuery;
}