From 7931a17d150e8a3a6245eae42a59ff5795ab99e0 Mon Sep 17 00:00:00 2001 From: Nisarg Thakkar Date: Thu, 21 Sep 2023 13:41:29 -0700 Subject: [PATCH] [producer] Allow deleting records via the shell producer (#646) The shell producer can allow deleting records by accepting the value null regardless of the fact that it is compatible with the store schema or not. Note that other forms of null like "null", 'null', etc are not allowed. --- .../venice/producer/online/ProducerTool.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/clients/venice-producer/src/main/java/com/linkedin/venice/producer/online/ProducerTool.java b/clients/venice-producer/src/main/java/com/linkedin/venice/producer/online/ProducerTool.java index 24c6e724c3..f5e39ca6df 100644 --- a/clients/venice-producer/src/main/java/com/linkedin/venice/producer/online/ProducerTool.java +++ b/clients/venice-producer/src/main/java/com/linkedin/venice/producer/online/ProducerTool.java @@ -184,10 +184,14 @@ private static void writeToStore(ProducerContext producerContext) throws Excepti RouterBasedStoreSchemaFetcher schemaFetcher = new RouterBasedStoreSchemaFetcher(castClient); Schema keySchema = schemaFetcher.getKeySchema(); Object key = adaptDataToSchema(producerContext.key, keySchema); - Object value = getValueObject(producerContext.value, schemaFetcher); - - producer.asyncPut(key, value).get(); - System.out.println("Data written to Venice!"); + if (producerContext.value.equals("null")) { // Only allow `null`. Not "null", or 'null', or whatever. + producer.asyncDelete(key).get(); + System.out.println("Record deleted from Venice!"); + } else { + Object value = getValueObject(producerContext.value, schemaFetcher); + producer.asyncPut(key, value).get(); + System.out.println("Data written to Venice!"); + } } catch (Exception e) { System.err.println(ExceptionUtils.stackTraceToString(e)); System.exit(1);