Add `TYPE_NAME` to the complex serde classes and replace the hardcoded names. (#14317)

* Add TYPE_NAME to the serde classes and reuse them instead of hardcoded strings.

* Static check fixes.
This commit is contained in:
Abhishek Radhakrishnan 2023-05-22 22:54:47 -07:00 committed by GitHub
parent 6b3a6113c4
commit a5e04d95a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 46 additions and 38 deletions

View File

@ -152,7 +152,7 @@ public class FilterPartitionBenchmark
{
log.info("SETUP CALLED AT " + System.currentTimeMillis());
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
schemaInfo = GeneratorBasicSchemas.SCHEMA_MAP.get(schema);

View File

@ -158,7 +158,7 @@ public class FilteredAggregatorBenchmark
{
log.info("SETUP CALLED AT " + System.currentTimeMillis());
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
schemaInfo = GeneratorBasicSchemas.SCHEMA_MAP.get(schema);

View File

@ -273,7 +273,7 @@ public class GroupByTypeInterfaceBenchmark
{
log.info("SETUP CALLED AT %d", System.currentTimeMillis());
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
setupQueries();

View File

@ -238,7 +238,7 @@ public class TopNTypeInterfaceBenchmark
{
log.info("SETUP CALLED AT " + System.currentTimeMillis());
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
setupQueries();

View File

@ -103,7 +103,7 @@ public class IncrementalIndexReadBenchmark
{
log.info("SETUP CALLED AT " + +System.currentTimeMillis());
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
schemaInfo = GeneratorBasicSchemas.SCHEMA_MAP.get(schema);

View File

@ -86,7 +86,7 @@ public class IndexIngestionBenchmark
@Setup
public void setup() throws JsonProcessingException
{
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
schemaInfo = GeneratorBasicSchemas.SCHEMA_MAP.get(schema);

View File

@ -117,7 +117,7 @@ public class IndexMergeBenchmark
log.info("SETUP CALLED AT " + System.currentTimeMillis());
indexMergerV9 = new IndexMergerV9(JSON_MAPPER, INDEX_IO, getSegmentWriteOutMediumFactory(factoryType));
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
indexesToMerge = new ArrayList<>();

View File

@ -107,7 +107,7 @@ public class IndexPersistBenchmark
{
log.info("SETUP CALLED AT " + System.currentTimeMillis());
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
schemaInfo = GeneratorBasicSchemas.SCHEMA_MAP.get(schema);

View File

@ -434,7 +434,7 @@ public class GroupByBenchmark
{
log.info("SETUP CALLED AT " + +System.currentTimeMillis());
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
setupQueries();

View File

@ -244,7 +244,7 @@ public class ScanBenchmark
{
log.info("SETUP CALLED AT " + +System.currentTimeMillis());
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
setupQueries();

View File

@ -317,7 +317,7 @@ public class SearchBenchmark
{
log.info("SETUP CALLED AT " + +System.currentTimeMillis());
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
setupQueries();

View File

@ -245,7 +245,7 @@ public class TimeseriesBenchmark
{
log.info("SETUP CALLED AT " + System.currentTimeMillis());
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
setupQueries();

View File

@ -216,7 +216,7 @@ public class TopNBenchmark
{
log.info("SETUP CALLED AT " + System.currentTimeMillis());
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
setupQueries();

View File

@ -285,7 +285,7 @@ public class TimeCompareBenchmark
{
log.info("SETUP CALLED AT " + System.currentTimeMillis());
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
executorService = Execs.multiThreaded(numSegments, "TopNThreadPool");

View File

@ -66,7 +66,7 @@ public class ApproximateHistogramDruidModule implements DruidModule
@VisibleForTesting
public static void registerSerde()
{
ComplexMetrics.registerSerde("approximateHistogram", new ApproximateHistogramFoldingSerde());
ComplexMetrics.registerSerde(ApproximateHistogramFoldingSerde.TYPE_NAME, new ApproximateHistogramFoldingSerde());
ComplexMetrics.registerSerde(FixedBucketsHistogramAggregator.TYPE_NAME, new FixedBucketsHistogramSerde());
}
}

View File

@ -38,10 +38,12 @@ import java.util.Collection;
public class ApproximateHistogramFoldingSerde extends ComplexMetricSerde
{
public static final String TYPE_NAME = "approximateHistogram";
@Override
public String getTypeName()
{
return "approximateHistogram";
return TYPE_NAME;
}
@Override

View File

@ -65,6 +65,6 @@ public class DruidStatsModule implements DruidModule
SqlBindings.addAggregator(binder, BaseVarianceSqlAggregator.StdDevSampSqlAggregator.class);
SqlBindings.addAggregator(binder, BaseVarianceSqlAggregator.StdDevSqlAggregator.class);
}
ComplexMetrics.registerSerde("variance", new VarianceSerde());
ComplexMetrics.registerSerde(VarianceSerde.TYPE_NAME, new VarianceSerde());
}
}

View File

@ -38,13 +38,15 @@ import java.util.List;
*/
public class VarianceSerde extends ComplexMetricSerde
{
public static final String TYPE_NAME = "variance";
private static final Ordering<VarianceAggregatorCollector> COMPARATOR =
Ordering.from(VarianceAggregatorCollector.COMPARATOR).nullsFirst();
@Override
public String getTypeName()
{
return "variance";
return TYPE_NAME;
}
@Override

View File

@ -79,9 +79,9 @@ public class AggregatorsModule extends SimpleModule
{
super("AggregatorFactories");
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde("preComputedHyperUnique", new PreComputedHyperUniquesSerde());
ComplexMetrics.registerSerde("serializablePairLongString", new SerializablePairLongStringComplexMetricSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
ComplexMetrics.registerSerde(PreComputedHyperUniquesSerde.TYPE_NAME, new PreComputedHyperUniquesSerde());
ComplexMetrics.registerSerde(SerializablePairLongStringComplexMetricSerde.TYPE_NAME, new SerializablePairLongStringComplexMetricSerde());
setMixInAnnotation(AggregatorFactory.class, AggregatorFactoryMixin.class);
setMixInAnnotation(PostAggregator.class, PostAggregatorMixin.class);

View File

@ -38,6 +38,8 @@ import java.util.List;
public class HyperUniquesSerde extends ComplexMetricSerde
{
public static final String TYPE_NAME = "hyperUnique";
private static Comparator<HyperLogLogCollector> comparator =
Comparator.nullsFirst(Comparator.comparing(HyperLogLogCollector::toByteBuffer));
@ -56,7 +58,7 @@ public class HyperUniquesSerde extends ComplexMetricSerde
@Override
public String getTypeName()
{
return "hyperUnique";
return TYPE_NAME;
}
@Override

View File

@ -29,6 +29,8 @@ import java.nio.ByteBuffer;
public class PreComputedHyperUniquesSerde extends HyperUniquesSerde
{
public static final String TYPE_NAME = "preComputedHyperUnique";
public PreComputedHyperUniquesSerde()
{
super();

View File

@ -126,7 +126,7 @@ public class FrameWriterTest extends InitializedNullHandlingTest
@BeforeClass
public static void setUpClass()
{
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
}
@Test

View File

@ -135,7 +135,7 @@ public class FrameWritersTest extends InitializedNullHandlingTest
{
// Register, but don't unregister at the end of this test, because many other tests out there expect this to exist
// even though they don't explicitly register it.
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
final IllegalArgumentException e = Assert.assertThrows(
IllegalArgumentException.class,

View File

@ -88,7 +88,7 @@ public class SchemalessIndexTest
private static QueryableIndex mergedIndex = null;
static {
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
}
private final IndexMerger indexMerger;

View File

@ -153,7 +153,7 @@ public class TestIndex
public static final IndexIO INDEX_IO = TestHelper.getTestIndexIO();
static {
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
}
private static Supplier<IncrementalIndex> realtimeIndex = Suppliers.memoize(

View File

@ -137,7 +137,7 @@ public class SegmentGenerator implements Closeable
)
{
// In case we need to generate hyperUniques or json
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
NestedDataModule.registerHandlersAndSerde();
final String dataHash = Hashing.sha256()
@ -260,7 +260,7 @@ public class SegmentGenerator implements Closeable
)
{
// In case we need to generate hyperUniques.
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
final String dataHash = Hashing.sha256()
.newHasher()

View File

@ -34,9 +34,9 @@ public class ComplexMetricsTest
@Test
public void testRegister()
{
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
ComplexMetricSerde serde = ComplexMetrics.getSerdeForType("hyperUnique");
ComplexMetricSerde serde = ComplexMetrics.getSerdeForType(HyperUniquesSerde.TYPE_NAME);
Assert.assertNotNull(serde);
Assert.assertTrue(serde instanceof HyperUniquesSerde);
}
@ -44,15 +44,15 @@ public class ComplexMetricsTest
@Test
public void testRegisterDuplicate()
{
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
ComplexMetricSerde serde = ComplexMetrics.getSerdeForType("hyperUnique");
ComplexMetricSerde serde = ComplexMetrics.getSerdeForType(HyperUniquesSerde.TYPE_NAME);
Assert.assertNotNull(serde);
Assert.assertTrue(serde instanceof HyperUniquesSerde);
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
serde = ComplexMetrics.getSerdeForType("hyperUnique");
serde = ComplexMetrics.getSerdeForType(HyperUniquesSerde.TYPE_NAME);
Assert.assertNotNull(serde);
Assert.assertTrue(serde instanceof HyperUniquesSerde);
}
@ -60,18 +60,18 @@ public class ComplexMetricsTest
@Test
public void testConflicting()
{
ComplexMetrics.registerSerde("hyperUnique", new HyperUniquesSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new HyperUniquesSerde());
ComplexMetricSerde serde = ComplexMetrics.getSerdeForType("hyperUnique");
ComplexMetricSerde serde = ComplexMetrics.getSerdeForType(HyperUniquesSerde.TYPE_NAME);
Assert.assertNotNull(serde);
Assert.assertTrue(serde instanceof HyperUniquesSerde);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Incompatible serializer for type[hyperUnique] already exists. Expected [org.apache.druid.query.aggregation.SerializablePairLongStringComplexMetricSerde], found [org.apache.druid.query.aggregation.hyperloglog.HyperUniquesSerde");
ComplexMetrics.registerSerde("hyperUnique", new SerializablePairLongStringComplexMetricSerde());
ComplexMetrics.registerSerde(HyperUniquesSerde.TYPE_NAME, new SerializablePairLongStringComplexMetricSerde());
serde = ComplexMetrics.getSerdeForType("hyperUnique");
serde = ComplexMetrics.getSerdeForType(HyperUniquesSerde.TYPE_NAME);
Assert.assertNotNull(serde);
Assert.assertTrue(serde instanceof HyperUniquesSerde);
}