Fix serialization bug in PassthroughAggregatorFactory (#15830)

PassthroughAggregatorFactory overrides a deprecated method in the AggregatorFactory, on which it relies on for serializing one of its fields complexTypeName. This was accidentally removed, leading to a bug in the factory, where the type name doesn't get serialized properly, and places null in the type name. This PR revives that method with a different name and adds tests for the same.
This commit is contained in:
Laksh Singla 2024-02-05 15:11:10 +05:30 committed by GitHub
parent de959e513d
commit ee78a0367d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 1 deletions

View File

@ -66,12 +66,23 @@ public class PassthroughAggregatorFactory extends AggregatorFactory
this.complexTypeName = complexTypeName;
}
@JsonProperty
@JsonProperty("columnName")
public String getColumnName()
{
return columnName;
}
/**
* The getter for this variable is named differently because the 'getComplexTypeName' is a deprecated method present
* in the super class {@link AggregatorFactory}, and can be removed discriminately here, leading to incorrect serde of
* the aggregator factory over the wire
*/
@JsonProperty("complexTypeName")
public String getComplexName()
{
return complexTypeName;
}
@Override
public byte[] getCacheKey()
{

View File

@ -19,8 +19,11 @@
package org.apache.druid.msq.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.apache.druid.jackson.DefaultObjectMapper;
import org.apache.druid.query.aggregation.AggregatorFactory;
import org.apache.druid.query.aggregation.AggregatorFactoryNotMergeableException;
import org.junit.Assert;
@ -28,6 +31,21 @@ import org.junit.Test;
public class PassthroughAggregatorFactoryTest
{
@Test
public void testSerde() throws JsonProcessingException
{
ObjectMapper objectMapper = new DefaultObjectMapper();
objectMapper.registerSubtypes(PassthroughAggregatorFactory.class);
AggregatorFactory aggregatorFactory = new PassthroughAggregatorFactory("x", "y");
String serializedvalue = objectMapper.writeValueAsString(aggregatorFactory);
Assert.assertEquals(
"{\"type\":\"passthrough\",\"columnName\":\"x\",\"complexTypeName\":\"y\"}",
serializedvalue
);
Assert.assertEquals(aggregatorFactory, objectMapper.readValue(serializedvalue, AggregatorFactory.class));
}
@Test
public void testRequiredFields()
{