yifan-c commented on code in PR #4458:
URL: https://github.com/apache/cassandra/pull/4458#discussion_r2495999305
##########
src/java/org/apache/cassandra/schema/SystemDistributedKeyspace.java:
##########
@@ -458,22 +458,78 @@ public static CompressionDictionary
retrieveLatestCompressionDictionary(String k
}
/**
- * Retrieves a specific compression dictionary for a given keyspace and
table.
+ * Retrieves the latest compression dictionary for a given keyspace and
table
+ * backed by {@link LightweightCompressionDictionary} object.
+ *
+ * @param keyspaceName the keyspace name to retrieve the dictionary for
+ * @param tableName the table name to retrieve the dictionary for
+ * @return the latest compression dictionary for the specified keyspace
and table,
+ * or null if no dictionary exists or if an error occurs during
retrieval
+ */
+ @Nullable
+ public static LightweightCompressionDictionary
retrieveLightweightLatestCompressionDictionary(String keyspaceName, String
tableName)
+ {
+ String query = "SELECT keyspace_name, table_name, kind, dict_id,
dict_checksum, dict_length FROM %s.%s WHERE keyspace_name='%s' AND
table_name='%s' LIMIT 1";
+ String fmtQuery = format(query,
SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, COMPRESSION_DICTIONARIES,
keyspaceName, tableName);
+ try
+ {
+ return
CompressionDictionary.createFromRowLightweight(QueryProcessor.execute(fmtQuery,
ConsistencyLevel.ONE).one());
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Retrieves a specific compression dictionary for a given keyspace and
table
+ * backed by {@link LightweightCompressionDictionary} object.
*
* @param keyspaceName the keyspace name to retrieve the dictionary for
* @param tableName the table name to retrieve the dictionary for
* @param dictionaryId the dictionary id to retrieve the dictionary for
* @return the compression dictionary identified by the specified
keyspace, table and dictionaryId,
* or null if no dictionary exists or if an error occurs during
retrieval
*/
- public static CompressionDictionary retrieveCompressionDictionary(String
keyspaceName, String tableName, CompressionDictionary.DictId dictionaryId)
+ @Nullable
+ public static CompressionDictionary retrieveCompressionDictionary(String
keyspaceName, String tableName, long dictionaryId)
{
String query = "SELECT kind, dict_id, dict, dict_length, dict_checksum
FROM %s.%s WHERE keyspace_name='%s' AND table_name='%s' AND dict_id=%s";
- String fmtQuery = format(query,
SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, COMPRESSION_DICTIONARIES,
keyspaceName, tableName, dictionaryId.id);
+ String fmtQuery = format(query,
SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, COMPRESSION_DICTIONARIES,
keyspaceName, tableName, dictionaryId);
try
{
- UntypedResultSet.Row row = QueryProcessor.execute(fmtQuery,
ConsistencyLevel.ONE).one();
- return CompressionDictionary.createFromRow(row);
+ return
CompressionDictionary.createFromRow(QueryProcessor.execute(fmtQuery,
ConsistencyLevel.ONE).one());
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Retrieves all dictionaries for a given keyspace and table.
+ *
+ * @param keyspaceName the keyspace name to retrieve the dictionary for
+ * @param tableName the table name to retrieve the dictionary for
+ * @return the compression dictionaries identified by the specified
keyspace and table,
+ * or null if no dictionary exists or if an error occurs during
retrieval
+ */
+ @Nullable
+ public static List<LightweightCompressionDictionary>
retrieveLightweightCompressionDictionaries(String keyspaceName, String
tableName)
+ {
+ String query = "SELECT keyspace_name, table_name, kind, dict_id,
dict_length, dict_checksum, size FROM %s.%s WHERE keyspace_name='%s' AND
table_name='%s'";
+ String fmtQuery = format(query,
SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, COMPRESSION_DICTIONARIES,
keyspaceName, tableName);
+ try
+ {
+ List<LightweightCompressionDictionary> dictionaries = new
ArrayList<>();
+ UntypedResultSet result = QueryProcessor.execute(fmtQuery,
ConsistencyLevel.ONE);
Review Comment:
nit: could delay the creation of array list.
```suggestion
UntypedResultSet result = QueryProcessor.execute(fmtQuery,
ConsistencyLevel.ONE);
if (result.isEmpty())
return Collections.emptyList();
List<LightweightCompressionDictionary> dictionaries = new
ArrayList<>();
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]