jiangxt2 commented on code in PR #11806:
URL: https://github.com/apache/gravitino/pull/11806#discussion_r3510798106
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseTableOperations.java:
##########
@@ -502,6 +519,42 @@ 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
+ */
+ private static String resolveGranularity(Index index) {
+ String granularity =
+ index.properties().getOrDefault(INDEX_GRANULARITY_KEY,
DEFAULT_INDEX_GRANULARITY);
+ Preconditions.checkArgument(
+ StringUtils.isNumeric(granularity) && Long.parseLong(granularity) >= 1,
+ "Index %s granularity must be a positive integer (>= 1), but got %s",
+ index.name(),
+ granularity);
+ return granularity;
Review Comment:
The `NumberFormatException` is already caught at line 542 and re-thrown as
`IllegalArgumentException` with a clear message including the index name and
invalid value. The catch block handles all `NumberFormatException` cases,
including overflow.
##########
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:
Good catch. I've added a `Preconditions.checkArgument` guard for null/blank
values before parsing, which throws `IllegalArgumentException` with a clear
message 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]