@Test public void testInsertOverwriteConf() throws Exception { createTestTable("test_insert_overwrite"); queryConf.setBoolean(LensConfConstants.QUERY_ADD_INSERT_OVEWRITE, false); String query = "SELECT ID FROM test_insert_overwrite"; QueryContext context = createContext(query, queryConf); driver.addPersistentPath(context); assertEquals(context.getUserQuery(), query); assertNotNull(context.getDriverContext().getDriverQuery(driver)); assertEquals(context.getDriverContext().getDriverQuery(driver), context.getUserQuery()); }
void addPersistentPath(QueryContext context) throws IOException { String hiveQuery; Configuration qdconf = context.getDriverConf(this); boolean addInsertOverwrite = qdconf.getBoolean( LensConfConstants.QUERY_ADD_INSERT_OVEWRITE, LensConfConstants.DEFAULT_ADD_INSERT_OVEWRITE); if (context.isDriverPersistent() && addInsertOverwrite && (context.getSelectedDriverQuery().startsWith("SELECT") || context.getSelectedDriverQuery().startsWith("select"))) { Path resultSetPath = context.getHDFSResultDir(); StringBuilder builder = new StringBuilder("INSERT OVERWRITE DIRECTORY "); context.setDriverResultPath( resultSetPath.makeQualified(resultSetPath.getFileSystem(context.getConf())).toString()); builder.append('"').append(resultSetPath).append("\" "); String outputDirFormat = qdconf.get(LensConfConstants.QUERY_OUTPUT_DIRECTORY_FORMAT); if (outputDirFormat != null) { builder.append(outputDirFormat); } builder.append(' ').append(context.getSelectedDriverQuery()).append(' '); hiveQuery = builder.toString(); } else { context.unSetDriverPersistent(); hiveQuery = context.getSelectedDriverQuery(); } log.info("Hive driver {} query:{}", getFullyQualifiedName(), hiveQuery); context.setSelectedDriverQuery(hiveQuery); }
HiveDriver extends AbstractLensDriver { void addPersistentPath(QueryContext context) throws IOException { String hiveQuery; Configuration qdconf = context.getDriverConf(this); boolean addInsertOverwrite = qdconf.getBoolean( LensConfConstants.QUERY_ADD_INSERT_OVEWRITE, LensConfConstants.DEFAULT_ADD_INSERT_OVEWRITE); if (context.isDriverPersistent() && addInsertOverwrite && (context.getSelectedDriverQuery().startsWith("SELECT") || context.getSelectedDriverQuery().startsWith("select"))) { Path resultSetPath = context.getHDFSResultDir(); StringBuilder builder = new StringBuilder("INSERT OVERWRITE DIRECTORY "); context.setDriverResultPath( resultSetPath.makeQualified(resultSetPath.getFileSystem(context.getConf())).toString()); builder.append('"').append(resultSetPath).append("\" "); String outputDirFormat = qdconf.get(LensConfConstants.QUERY_OUTPUT_DIRECTORY_FORMAT); if (outputDirFormat != null) { builder.append(outputDirFormat); } builder.append(' ').append(context.getSelectedDriverQuery()).append(' '); hiveQuery = builder.toString(); } else { context.unSetDriverPersistent(); hiveQuery = context.getSelectedDriverQuery(); } log.info("Hive driver {} query:{}", getFullyQualifiedName(), hiveQuery); context.setSelectedDriverQuery(hiveQuery); } }
HiveDriver extends AbstractLensDriver { void addPersistentPath(QueryContext context) throws IOException { String hiveQuery; Configuration qdconf = context.getDriverConf(this); boolean addInsertOverwrite = qdconf.getBoolean( LensConfConstants.QUERY_ADD_INSERT_OVEWRITE, LensConfConstants.DEFAULT_ADD_INSERT_OVEWRITE); if (context.isDriverPersistent() && addInsertOverwrite && (context.getSelectedDriverQuery().startsWith("SELECT") || context.getSelectedDriverQuery().startsWith("select"))) { Path resultSetPath = context.getHDFSResultDir(); StringBuilder builder = new StringBuilder("INSERT OVERWRITE DIRECTORY "); context.setDriverResultPath( resultSetPath.makeQualified(resultSetPath.getFileSystem(context.getConf())).toString()); builder.append('"').append(resultSetPath).append("\" "); String outputDirFormat = qdconf.get(LensConfConstants.QUERY_OUTPUT_DIRECTORY_FORMAT); if (outputDirFormat != null) { builder.append(outputDirFormat); } builder.append(' ').append(context.getSelectedDriverQuery()).append(' '); hiveQuery = builder.toString(); } else { context.unSetDriverPersistent(); hiveQuery = context.getSelectedDriverQuery(); } log.info("Hive driver {} query:{}", getFullyQualifiedName(), hiveQuery); context.setSelectedDriverQuery(hiveQuery); } HiveDriver(); }
HiveDriver extends AbstractLensDriver { void addPersistentPath(QueryContext context) throws IOException { String hiveQuery; Configuration qdconf = context.getDriverConf(this); boolean addInsertOverwrite = qdconf.getBoolean( LensConfConstants.QUERY_ADD_INSERT_OVEWRITE, LensConfConstants.DEFAULT_ADD_INSERT_OVEWRITE); if (context.isDriverPersistent() && addInsertOverwrite && (context.getSelectedDriverQuery().startsWith("SELECT") || context.getSelectedDriverQuery().startsWith("select"))) { Path resultSetPath = context.getHDFSResultDir(); StringBuilder builder = new StringBuilder("INSERT OVERWRITE DIRECTORY "); context.setDriverResultPath( resultSetPath.makeQualified(resultSetPath.getFileSystem(context.getConf())).toString()); builder.append('"').append(resultSetPath).append("\" "); String outputDirFormat = qdconf.get(LensConfConstants.QUERY_OUTPUT_DIRECTORY_FORMAT); if (outputDirFormat != null) { builder.append(outputDirFormat); } builder.append(' ').append(context.getSelectedDriverQuery()).append(' '); hiveQuery = builder.toString(); } else { context.unSetDriverPersistent(); hiveQuery = context.getSelectedDriverQuery(); } log.info("Hive driver {} query:{}", getFullyQualifiedName(), hiveQuery); context.setSelectedDriverQuery(hiveQuery); } HiveDriver(); boolean areDBResourcesAddedForSession(String sessionHandle, String database); void setResourcesAddedForSession(String sessionHandle, String database); @Override void configure(Configuration conf, String driverType, String driverName); @Override QueryCost estimate(AbstractQueryContext qctx); @Override HiveQueryPlan explain(AbstractQueryContext explainCtx); @Override DriverQueryPlan explainAndPrepare(PreparedQueryContext pContext); @Override void prepare(PreparedQueryContext pContext); @Override void closePreparedQuery(QueryPrepareHandle handle); LensResultSet execute(QueryContext ctx); @Override void executeAsync(QueryContext ctx); @Override void updateStatus(QueryContext context); @Override void closeResultSet(QueryHandle handle); @Override void closeQuery(QueryHandle handle); @Override boolean cancelQuery(QueryHandle handle); @Override void close(); @Override void registerDriverEventListener(LensEventListener<DriverEvent> driverEventListener); @Override Priority decidePriority(AbstractQueryContext ctx); @Override void registerForCompletionNotification(
    QueryContext context, long timeoutMillis, QueryCompletionListener listener); @Override void readExternal(ObjectInput in); @Override void writeExternal(ObjectOutput out); void closeSession(LensSessionHandle sessionHandle); boolean hasLensSession(LensSessionHandle session); }
HiveDriver extends AbstractLensDriver { void addPersistentPath(QueryContext context) throws IOException { String hiveQuery; Configuration qdconf = context.getDriverConf(this); boolean addInsertOverwrite = qdconf.getBoolean( LensConfConstants.QUERY_ADD_INSERT_OVEWRITE, LensConfConstants.DEFAULT_ADD_INSERT_OVEWRITE); if (context.isDriverPersistent() && addInsertOverwrite && (context.getSelectedDriverQuery().startsWith("SELECT") || context.getSelectedDriverQuery().startsWith("select"))) { Path resultSetPath = context.getHDFSResultDir(); StringBuilder builder = new StringBuilder("INSERT OVERWRITE DIRECTORY "); context.setDriverResultPath( resultSetPath.makeQualified(resultSetPath.getFileSystem(context.getConf())).toString()); builder.append('"').append(resultSetPath).append("\" "); String outputDirFormat = qdconf.get(LensConfConstants.QUERY_OUTPUT_DIRECTORY_FORMAT); if (outputDirFormat != null) { builder.append(outputDirFormat); } builder.append(' ').append(context.getSelectedDriverQuery()).append(' '); hiveQuery = builder.toString(); } else { context.unSetDriverPersistent(); hiveQuery = context.getSelectedDriverQuery(); } log.info("Hive driver {} query:{}", getFullyQualifiedName(), hiveQuery); context.setSelectedDriverQuery(hiveQuery); } HiveDriver(); boolean areDBResourcesAddedForSession(String sessionHandle, String database); void setResourcesAddedForSession(String sessionHandle, String database); @Override void configure(Configuration conf, String driverType, String driverName); @Override QueryCost estimate(AbstractQueryContext qctx); @Override HiveQueryPlan explain(AbstractQueryContext explainCtx); @Override DriverQueryPlan explainAndPrepare(PreparedQueryContext pContext); @Override void prepare(PreparedQueryContext pContext); @Override void closePreparedQuery(QueryPrepareHandle handle); LensResultSet execute(QueryContext ctx); @Override void executeAsync(QueryContext ctx); @Override void updateStatus(QueryContext context); @Override void closeResultSet(QueryHandle handle); @Override void closeQuery(QueryHandle handle); @Override boolean cancelQuery(QueryHandle handle); @Override void close(); @Override void registerDriverEventListener(LensEventListener<DriverEvent> driverEventListener); @Override Priority decidePriority(AbstractQueryContext ctx); @Override void registerForCompletionNotification(
    QueryContext context, long timeoutMillis, QueryCompletionListener listener); @Override void readExternal(ObjectInput in); @Override void writeExternal(ObjectOutput out); void closeSession(LensSessionHandle sessionHandle); boolean hasLensSession(LensSessionHandle session); static final String HIVE_CONNECTION_CLASS; static final String HS2_CONNECTION_EXPIRY_DELAY; static final String HS2_CALCULATE_PRIORITY; static final String HS2_COST_CALCULATOR; static final String HS2_PRIORITY_RANGES; static final long DEFAULT_EXPIRY_DELAY; static final String HS2_PRIORITY_DEFAULT_RANGES; static final String SESSION_KEY_DELIMITER; }