use of io.trino.plugin.clickhouse.ClickHouseTableProperties.SAMPLE_BY_PROPERTY in project trino by trinodb.
the class ClickHouseClient method setTableProperties.
@Override
public void setTableProperties(ConnectorSession session, JdbcTableHandle handle, Map<String, Optional<Object>> nullableProperties) {
// TODO: Support other table properties
checkArgument(nullableProperties.size() == 1 && nullableProperties.containsKey(SAMPLE_BY_PROPERTY), "Only support setting 'sample_by' property");
// TODO: Support sampling key removal when we support a newer version of ClickHouse. See https://github.com/ClickHouse/ClickHouse/pull/30180.
checkArgument(nullableProperties.values().stream().noneMatch(Optional::isEmpty), "Setting a property to null is not supported");
Map<String, Object> properties = nullableProperties.entrySet().stream().filter(entry -> entry.getValue().isPresent()).collect(toImmutableMap(Entry::getKey, entry -> entry.getValue().orElseThrow()));
ImmutableList.Builder<String> tableOptions = ImmutableList.builder();
ClickHouseTableProperties.getSampleBy(properties).ifPresent(value -> tableOptions.add("SAMPLE BY " + value));
try (Connection connection = connectionFactory.openConnection(session)) {
String sql = format("ALTER TABLE %s MODIFY %s", quoted(handle.asPlainTable().getRemoteTableName()), join(" ", tableOptions.build()));
execute(connection, sql);
} catch (SQLException e) {
throw new TrinoException(JDBC_ERROR, e);
}
}
Aggregations