Skip to content

[FOLLOW-UP] HIVE-28373: Iceberg: Refactor the code of HadoopTableOptions#6345

Draft
BsoBird wants to merge 2 commits intoapache:masterfrom
BsoBird:followup-HIVE-28373
Draft

[FOLLOW-UP] HIVE-28373: Iceberg: Refactor the code of HadoopTableOptions#6345
BsoBird wants to merge 2 commits intoapache:masterfrom
BsoBird:followup-HIVE-28373

Conversation

@BsoBird
Copy link
Contributor

@BsoBird BsoBird commented Mar 3, 2026

What changes were proposed in this pull request?

Modify the test case to ensure it can run on macOS environments.

Why are the changes needed?

Since a considerable number of developers use macOS as their local development environment, the test case code should avoid relying on Linux-specific commands.

Does this PR introduce any user-facing change?

No

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please drop the unnecessary casts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

String cmd = String.format("mv -n %s %s", srcPathStr, dstPathStr);
Process process = Runtime.getRuntime().exec(cmd);
assertThat(process.waitFor()).isZero();
Files.move(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why such a massive copy-paste?

try {
        HadoopTableOperations tableOperations = (HadoopTableOperations) baseTable.operations();
        HadoopTableOperations spyOps = spy(tableOperations);
        doNothing().when(spyOps).tryLock(any(), any());
        doAnswer(x -> {
          countDownLatch.countDown();
          countDownLatch.await();
          return x.callRealMethod();
        }).when(spyOps).renameMetaDataFileAndCheck(any(), any(), any(), anyBoolean());
        doAnswer(x -> {
          Path srcPath = x.getArgument(1);
          Path dstPath = x.getArgument(2);
          Files.move(
              Paths.get(srcPath.toUri()), Paths.get(dstPath.toUri()),
              StandardCopyOption.ATOMIC_MOVE
          );
          return true;
        }).when(spyOps).renameMetaDataFile(any(), any(), any());
        TableMetadata metadataV1 = spyOps.current();
        SortOrder dataSort = SortOrder.builderFor(baseTable.schema()).asc("data").build();
        TableMetadata metadataV2 = metadataV1.replaceSortOrder(dataSort);
        spyOps.commit(metadataV1, metadataV2);
      } catch (CommitFailedException e) {
        expectedException.set(e);
      } catch (Throwable e) {
        unexpectedException.set(e);
      }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 8 threads? Executors.newFixedThreadPool(8)
use virtual threads instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    Runnable commitTask = () -> {
      try {
        HadoopTableOperations tableOperations = (HadoopTableOperations) baseTable.operations();
        HadoopTableOperations spyOps = spy(tableOperations);
        doNothing().when(spyOps).tryLock(any(), any());
        doAnswer(x -> {
          countDownLatch.countDown();
          countDownLatch.await();
          return x.callRealMethod();
        }).when(spyOps).renameMetaDataFileAndCheck(any(), any(), any(), anyBoolean());
        doAnswer(x -> {
          Path srcPath = x.getArgument(1);
          Path dstPath = x.getArgument(2);

          var src = Paths.get(srcPath.toUri());
          var dst = Paths.get(dstPath.toUri());
          Files.move(src, dst, StandardCopyOption.ATOMIC_MOVE);

          return Files.exists(dst) && Files.notExists(src);
        }).when(spyOps).renameMetaDataFile(any(), any(), any());

        TableMetadata metadataV1 = spyOps.current();
        SortOrder dataSort = SortOrder.builderFor(baseTable.schema()).asc("data").build();
        TableMetadata metadataV2 = metadataV1.replaceSortOrder(dataSort);
        spyOps.commit(metadataV1, metadataV2);
      } catch (CommitFailedException e) {
        expectedException.set(e);
      } catch (Throwable e) {
        unexpectedException.set(e);
      }
    };

    Tasks.range(2)
        .executeWith(executorService)
        .run(i -> commitTask.run());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

@BsoBird BsoBird marked this pull request as draft March 3, 2026 17:39
2.remove unnecessary casts
3.remove massive copy-paste
@deniskuzZ
Copy link
Member

deniskuzZ commented Mar 3, 2026

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 3, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants