Source:
<code>public List<List<Object>> execute() { List<Tuple2<Integer, PrestoSparkRow>> rddResults; try { rddResults = doExecute(plan); commit(session, transactionManager); } catch (Exception executionFailure) { try { rollback(session, transactionManager); } catch (RuntimeException rollbackFailure) { log.error(rollbackFailure, "Encountered error when performing rollback"); } try { queryCompletedEvent(Optional.of(executionFailure)); } catch (RuntimeException eventFailure) { log.error(eventFailure, "Error publishing query completed event"); } if (executionFailure instanceof SparkException) { Optional<ExecutionFailureInfo> executionFailureInfo = executionExceptionFactory.tryDecode((SparkException) executionFailure); if (executionFailureInfo.isPresent()) { throw executionFailureInfo.get().toFailure(); } throw toFailure(executionFailure).toFailure(); <START> } <END> if (executionFailure instanceof PrestoSparkExecutionException) { Optional<ExecutionFailureInfo> executionFailureInfo = executionExceptionFactory.tryDecode((PrestoSparkExecutionException) executionFailure); verify(executionFailureInfo.isPresent()); throw executionFailureInfo.get().toFailure(); } throw toFailure(executionFailure).toFailure(); } queryCompletedEvent(Optional.empty()); ConnectorSession connectorSession = session.toConnectorSession(); List<Type> types = plan.getFragment().getTypes(); ImmutableList.Builder<List<Object>> result = ImmutableList.builder(); for (Tuple2<Integer, PrestoSparkRow> tuple : rddResults) { PrestoSparkRow row = tuple._2; SliceInput sliceInput = new BasicSliceInput(Slices.wrappedBuffer(row.getBytes(), 0, row.getLength())); List<Object> columns = new ArrayList<>(); for (Type type : types) { BlockBuilder blockBuilder = type.createBlockBuilder(null, 1); blockBuilder.readPositionFrom(sliceInput); columns.add(type.getObjectValue(connectorSession.getSqlFunctionProperties(), blockBuilder, 0)); } result.add(unmodifiableList(columns)); } return result.build(); }</code><technical_language>Instead of instanceof here, try catch SparkException PrestoSparkExecutionException in line 357? -- is more "Java" handle exceptions? In order do that, need refactor line 358 370 tryRollbackAndLog</technical_language>

Target:
public List<List<Object>> execute() { List<Tuple2<Integer, PrestoSparkRow>> rddResults; try { rddResults = doExecute(plan); commit(session, transactionManager); } catch (Exception executionFailure) { try { rollback(session, transactionManager); } catch (RuntimeException rollbackFailure) { log.error(rollbackFailure, "Encountered error when performing rollback"); } try { queryCompletedEvent(Optional.of(executionFailure)); } catch (RuntimeException eventFailure) { log.error(eventFailure, "Error publishing query completed event"); } if (executionFailure instanceof SparkException) { Optional<ExecutionFailureInfo> executionFailureInfo = executionExceptionFactory.extractExecutionFailureInfo((SparkException) executionFailure); if (executionFailureInfo.isPresent()) { throw executionFailureInfo.get().toFailure(); } throw toFailure(executionFailure).toFailure(); } if (executionFailure instanceof PrestoSparkExecutionException) { Optional<ExecutionFailureInfo> executionFailureInfo = executionExceptionFactory.extractExecutionFailureInfo((PrestoSparkExecutionException) executionFailure); verify(executionFailureInfo.isPresent()); throw executionFailureInfo.get().toFailure(); } throw toFailure(executionFailure).toFailure(); } queryCompletedEvent(Optional.empty()); ConnectorSession connectorSession = session.toConnectorSession(); List<Type> types = plan.getFragment().getTypes(); ImmutableList.Builder<List<Object>> result = ImmutableList.builder(); for (Tuple2<Integer, PrestoSparkRow> tuple : rddResults) { PrestoSparkRow row = tuple._2; SliceInput sliceInput = new BasicSliceInput(Slices.wrappedBuffer(row.getBytes(), 0, row.getLength())); List<Object> columns = new ArrayList<>(); for (Type type : types) { BlockBuilder blockBuilder = type.createBlockBuilder(null, 1); blockBuilder.readPositionFrom(sliceInput); columns.add(type.getObjectValue(connectorSession.getSqlFunctionProperties(), blockBuilder, 0)); } result.add(unmodifiableList(columns)); } return result.build(); }