@Override
    public Optional<Page> commit()
    {
        try {
            orcWriter.close();
        }
        catch (IOException | UncheckedIOException | PrestoException e) {
            try {
                rollbackAction.call();
            }
            catch (Exception ignored) {
                // ignore
            }
            throwIfInstanceOf(e, PrestoException.class);
            throw new PrestoException(HIVE_WRITER_CLOSE_ERROR, "Error committing write to Hive. " + e.getMessage(), e);
        }

        if (validationInputFactory.isPresent()) {
            try {
                try (OrcDataSource input = validationInputFactory.get().get()) {
                    long startThreadCpuTime = THREAD_MX_BEAN.getCurrentThreadCpuTime();
                    orcWriter.validate(input);
                    validationCpuNanos += THREAD_MX_BEAN.getCurrentThreadCpuTime() - startThreadCpuTime;
                }
            }
            catch (IOException | UncheckedIOException e) {
                throw new PrestoException(HIVE_WRITE_VALIDATION_FAILED, e);
            }
        }

        return Optional.of(createFileStatisticsPage(getFileSizeInBytes(), rowCount));
    }
@Test
    public void testPrestoExceptionPropagation()
    {
        // This test is to verify that a PrestoException thrown by the underlying data sink implementation is propagated as is
        OrcFileWriter orcFileWriter = createOrcFileWriter(true);

        try {
            // Throws PrestoException with STORAGE_ERROR error code
            orcFileWriter.commit();
        }
        catch (Exception e) {
            assertEquals(e.getClass(), PrestoException.class);
            assertEquals(e.getMessage(), "Dummy PrestoException from mocked data sink instance");
            assertEquals(((PrestoException) e).getErrorCode(), STORAGE_ERROR_CODE);
        }
    }