Copilot commented on code in PR #11806:
URL: https://github.com/apache/gravitino/pull/11806#discussion_r3510268285
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseTableOperations.java:
##########
@@ -502,6 +519,52 @@ private void appendIndexesSql(Index[] indexes,
StringBuilder sqlBuilder) {
}
}
+ /**
+ * Resolves the GRANULARITY value for a data skipping index from its
properties, falling back to
+ * the ClickHouse default. The value is interpolated directly into DDL, so
it must be a positive
+ * integer (≥ 1) to avoid generating malformed SQL.
+ *
+ * @param index the index whose {@code granularity} property is read
+ * @return the validated GRANULARITY value as a string
+ * @throws IllegalArgumentException if the value is not a positive integer
+ */
+ private static String resolveGranularity(Index index) {
+ String granularity =
+ index.properties().getOrDefault(INDEX_GRANULARITY_KEY,
DEFAULT_INDEX_GRANULARITY);
+ try {
+ long value = Long.parseLong(granularity);
+ Preconditions.checkArgument(
+ value >= 1,
+ "Index %s granularity must be a positive integer (>= 1), but got %s",
+ index.name(),
+ granularity);
+ return String.valueOf(value);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(
+ String.format(
+ "Index %s granularity must be a positive integer (>= 1), but got
'%s'",
+ index.name(), granularity),
+ e);
+ }
+ }
Review Comment:
`resolveGranularity()` can throw a NullPointerException if the index
properties map contains the `granularity` key with a null/blank value (e.g.
`Map.of()` disallows nulls, but a user-supplied `HashMap` can contain
`granularity -> null`). Since this value is interpolated into DDL, it should
fail with a clear `IllegalArgumentException` instead of an NPE.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]