@Test public void testDDLQueries() { String query = "DROP TABLE TEMP"; Throwable th = null; try { driver.rewriteQuery(createQueryContext(query)); } catch (LensException e) { log.error("Error running DDL query.", e); th = e; } Assert.assertNotNull(th); query = "create table temp(name string, msr int)"; th = null; try { driver.rewriteQuery(createQueryContext(query)); } catch (LensException e) { log.error("Error running DDL query", e); th = e; } Assert.assertNotNull(th); query = "insert overwrite table temp SELECT * FROM execute_test"; th = null; try { driver.rewriteQuery(createQueryContext(query)); } catch (LensException e) { log.error("Error running DDL query", e); th = e; } Assert.assertNotNull(th); query = "create table temp2 as SELECT * FROM execute_test"; th = null; try { driver.rewriteQuery(createQueryContext(query)); } catch (LensException e) { log.error("Error running DDL query", e); th = e; } Assert.assertNotNull(th); }
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); ASTNode ast = HQLParser.parseHQL(query, ctx.getHiveConf()); if (ast.getToken().getType() != HiveParser.TOK_QUERY) { throw new LensException("Not allowed statement:" + query); } else { 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; }
JDBCDriver extends AbstractLensDriver { 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); ASTNode ast = HQLParser.parseHQL(query, ctx.getHiveConf()); if (ast.getToken().getType() != HiveParser.TOK_QUERY) { throw new LensException("Not allowed statement:" + query); } else { 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; } }
JDBCDriver extends AbstractLensDriver { 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); ASTNode ast = HQLParser.parseHQL(query, ctx.getHiveConf()); if (ast.getToken().getType() != HiveParser.TOK_QUERY) { throw new LensException("Not allowed statement:" + query); } else { 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; }  }
JDBCDriver extends AbstractLensDriver { 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); ASTNode ast = HQLParser.parseHQL(query, ctx.getHiveConf()); if (ast.getToken().getType() != HiveParser.TOK_QUERY) { throw new LensException("Not allowed statement:" + query); } else { 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; }  @Override void configure(Configuration conf, String driverType, String driverName); void init(); QueryCost calculateQueryCost(AbstractQueryContext qctx); @Override QueryCost estimate(AbstractQueryContext qctx); @Override DriverQueryPlan explain(AbstractQueryContext explainCtx); void validate(AbstractQueryContext pContext); @Override void prepare(PreparedQueryContext pContext); @Override DriverQueryPlan explainAndPrepare(PreparedQueryContext pContext); @Override void closePreparedQuery(QueryPrepareHandle handle); @Override LensResultSet execute(QueryContext context); @Override void executeAsync(QueryContext context); @Override void updateStatus(QueryContext context); @Override void closeResultSet(QueryHandle handle); @Override boolean cancelQuery(QueryHandle handle); @Override void closeQuery(QueryHandle handle); @Override void close(); @Override void registerDriverEventListener(LensEventListener<DriverEvent> driverEventListener); @Override void readExternal(ObjectInput arg0); @Override void writeExternal(ObjectOutput arg0); @Override StatusUpdateMethod getStatusUpdateMethod(); }
JDBCDriver extends AbstractLensDriver { 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); ASTNode ast = HQLParser.parseHQL(query, ctx.getHiveConf()); if (ast.getToken().getType() != HiveParser.TOK_QUERY) { throw new LensException("Not allowed statement:" + query); } else { 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; }  @Override void configure(Configuration conf, String driverType, String driverName); void init(); QueryCost calculateQueryCost(AbstractQueryContext qctx); @Override QueryCost estimate(AbstractQueryContext qctx); @Override DriverQueryPlan explain(AbstractQueryContext explainCtx); void validate(AbstractQueryContext pContext); @Override void prepare(PreparedQueryContext pContext); @Override DriverQueryPlan explainAndPrepare(PreparedQueryContext pContext); @Override void closePreparedQuery(QueryPrepareHandle handle); @Override LensResultSet execute(QueryContext context); @Override void executeAsync(QueryContext context); @Override void updateStatus(QueryContext context); @Override void closeResultSet(QueryHandle handle); @Override boolean cancelQuery(QueryHandle handle); @Override void closeQuery(QueryHandle handle); @Override void close(); @Override void registerDriverEventListener(LensEventListener<DriverEvent> driverEventListener); @Override void readExternal(ObjectInput arg0); @Override void writeExternal(ObjectOutput arg0); @Override StatusUpdateMethod getStatusUpdateMethod(); static final AtomicInteger THID; }