jiangxt2 commented on code in PR #13498:
URL: https://github.com/apache/gravitino/pull/13498#discussion_r4124051600
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseTableOperations.java:
##########
@@ -953,6 +983,80 @@ SystemTableMetadata getSystemTableMetadata(
throw new NoSuchTableException("Table %s does not exist in %s.",
tableName, databaseName);
}
+ @VisibleForTesting
+ @Nullable
+ String getProjectionProperty(Connection connection, String databaseName,
String tableName)
+ throws SQLException {
+ // Probe the stable columns directly so ClickHouse 24.8, which has no
system.projections table,
+ // can continue serving ordinary catalog metadata. Only UNKNOWN_TABLE
means the capability is
+ // unavailable; access and other query errors must remain visible to the
caller.
+ try (PreparedStatement probe =
+ connection.prepareStatement("SELECT database FROM
system.projections LIMIT 0");
+ ResultSet probeResult = probe.executeQuery()) {
+ if (probeResult.next()) {
+ throw new SQLException(
+ "Unexpected row returned by the system.projections capability
probe");
+ }
+ } catch (SQLException e) {
+ if (e.getErrorCode() == ERROR_CODE_UNKNOWN_TABLE) {
+ if (projectionSourceUnavailableWarningLogged.compareAndSet(false,
true)) {
+ LOG.warn(
+ "ClickHouse does not provide system.projections; projection
metadata round-trip "
+ + "requires ClickHouse 24.9 or later");
+ }
+ return null;
+ }
+ throw e;
+ }
+
+ Set<String> projectionColumns = new HashSet<>();
+ try (PreparedStatement statement =
+ connection.prepareStatement(
+ "SELECT name FROM system.columns "
+ + "WHERE database = 'system' AND table = 'projections'");
+ ResultSet resultSet = statement.executeQuery()) {
+ while (resultSet.next()) {
+ projectionColumns.add(resultSet.getString("name"));
+ }
+ }
+ if (!projectionColumns.containsAll(REQUIRED_PROJECTION_COLUMNS)) {
+ Set<String> missingColumns = new HashSet<>(REQUIRED_PROJECTION_COLUMNS);
+ missingColumns.removeAll(projectionColumns);
+ throw new SQLException(
+ "system.projections is missing required columns: "
+ + missingColumns.stream().sorted().collect(Collectors.joining(",
")));
+ }
+
+ boolean hasSettingsColumn = projectionColumns.contains("settings");
+ String query =
+ "SELECT name, type, query"
+ + (hasSettingsColumn ? ", toJSONString(settings) AS settings_json"
: "")
+ + " FROM system.projections WHERE database = ? AND table = ? ORDER
BY name";
+ List<ClickHouseTableSqlUtils.ProjectionDefinition> definitions = new
ArrayList<>();
+ try (PreparedStatement statement = connection.prepareStatement(query)) {
+ statement.setString(1, databaseName);
+ statement.setString(2, tableName);
+ try (ResultSet resultSet = statement.executeQuery()) {
+ while (resultSet.next()) {
+ Map<String, String> settings =
+ hasSettingsColumn
+ ? ClickHouseTableSqlUtils.parseProjectionSettings(
+ resultSet.getString("settings_json"))
+ : Collections.emptyMap();
+ definitions.add(
+ new ClickHouseTableSqlUtils.ProjectionDefinition(
+ resultSet.getString("name"),
+ resultSet.getString("type"),
+ resultSet.getString("query"),
+ settings));
+ }
+ }
+ }
+ return definitions.isEmpty()
+ ? null
+ : ClickHouseTableSqlUtils.serializeProjectionDefinitions(definitions);
Review Comment:
Fixed in 2f012c4.
- On load, an unsupported projection definition or setting now causes the
entire clickhouse.projections property to be omitted with a warning; other
table metadata still loads. createTable validation and SQL error handling are
unchanged.
- Added unit coverage for this fallback and a ClickHouse 25.12 IT with
_part_offset.
- Final-head local checks passed: 144 unit tests, ProjectionIT 2/2
(24.9/25.12), targeted 24.8 IT 1/1, and ClusterIT 20/20; no failures or skips.
--
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]