Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ public Fileset createMultipleLocationFileset(

// Either catalog property "location", or schema property "location", or storageLocation must be
// set for managed fileset.
for (Map.Entry<String, String> e : storageLocations.entrySet()) {
if (StringUtils.isBlank(e.getValue())) {
throw new IllegalArgumentException(
"Storage location for name '" + e.getKey() + "' must not be null or blank");
}
}
Map<String, Path> schemaPaths =
getAndCheckSchemaPaths(schemaIdent.name(), schemaEntity.properties());
if (schemaPaths.isEmpty() && storageLocations.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

only need to change this line to:
if (schemaPaths.isEmpty() && (storageLocations.isEmpty() || storageLocations.values().stream().allMatch(StringUtils::isBlank)))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for suggestion. I applied this change, but during testing, I encountered a NullPointerException when the input storageLocations map contained a mix of valid values and blank/null values.

Copy link
Contributor

Choose a reason for hiding this comment

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

NPE from where?

Copy link
Contributor Author

@KyleLin0927 KyleLin0927 May 26, 2025

Choose a reason for hiding this comment

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

You may refer to the unit test I added in this PR (TestHadoopCatalogOperations.java line 1559) If I only use

if (schemaPaths.isEmpty() && (storageLocations.isEmpty() || storageLocations.values().stream().allMatch(StringUtils::isBlank)))

and the storageLocations input contains both a valid entry and a blank value, it will still trigger an NPE in calculateFilesetPaths. If you think this test is not appropriate, I will remove it.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

let me think it over.

Copy link
Contributor

Choose a reason for hiding this comment

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

@KyleLin0927 You can use the code from this commit and complete the tests.

mchades@926f49e

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,58 @@ public void testCreateMultipleLocationsWithExceptions() throws IOException {
.contains(
"Default location name must be set and must be one of the fileset locations"),
"Exception message: " + exception.getMessage());

Schema emptySchema =
createMultiLocationSchema(
"emptySchema", "no-location", ImmutableMap.of(), ImmutableMap.of());

// storage location value is blank
exception =
Assertions.assertThrows(
IllegalArgumentException.class,
() ->
createMultiLocationFileset(
"fs2",
emptySchema.name(),
null,
Fileset.Type.MANAGED,
ImmutableMap.of(),
ImmutableMap.of("v1", ""),
ImmutableMap.of()));
Assertions.assertEquals(
"Storage location for name 'v1' must not be null or blank", exception.getMessage());

// storage location value is blank
exception =
Assertions.assertThrows(
IllegalArgumentException.class,
() ->
createMultiLocationFileset(
"fs3",
emptySchema.name(),
null,
Fileset.Type.MANAGED,
ImmutableMap.of(),
ImmutableMap.of("v1", " "),
ImmutableMap.of()));
Assertions.assertEquals(
"Storage location for name 'v1' must not be null or blank", exception.getMessage());

// two storage locations, one valid and one is blank
exception =
Assertions.assertThrows(
IllegalArgumentException.class,
() ->
createMultiLocationFileset(
"fs5",
emptySchema.name(),
null,
Fileset.Type.MANAGED,
ImmutableMap.of(),
ImmutableMap.of("v1", TEST_ROOT_PATH + "/valid", "v2", ""),
ImmutableMap.of()));
Assertions.assertEquals(
"Storage location for name 'v2' must not be null or blank", exception.getMessage());
}
}

Expand Down