gianm commented on code in PR #17065:
URL: https://github.com/apache/druid/pull/17065#discussion_r1759975909
##########
server/src/main/java/org/apache/druid/segment/indexing/DataSchema.java:
##########
@@ -457,4 +413,108 @@ public String toString()
", inputRowParser=" + inputRowParser +
'}';
}
+
+ public static class Builder
+ {
+ private String dataSource;
+ private AggregatorFactory[] aggregators;
+ private GranularitySpec granularitySpec;
+ private TransformSpec transformSpec;
+ private Map<String, Object> parserMap;
+ private ObjectMapper objectMapper;
+
+ // The below fields can be initialized lazily from parser for backward
compatibility.
+ private TimestampSpec timestampSpec;
+ private DimensionsSpec dimensionsSpec;
+
+ public Builder()
+ {
+
+ }
+
+ public Builder(DataSchema schema)
+ {
+ this.dataSource = schema.dataSource;
+ this.aggregators = schema.aggregators;
+ this.granularitySpec = schema.granularitySpec;
+ this.transformSpec = schema.transformSpec;
+ this.parserMap = schema.parserMap;
+ this.objectMapper = schema.objectMapper;
+ this.timestampSpec = schema.timestampSpec;
+ this.dimensionsSpec = schema.dimensionsSpec;
+ }
+
+ public Builder withDataSource(String dataSource)
+ {
+ this.dataSource = dataSource;
+ return this;
+ }
+
+ public Builder withTimestamp(TimestampSpec timestampSpec)
+ {
+ this.timestampSpec = timestampSpec;
+ return this;
+ }
+
+ public Builder withDimensions(DimensionsSpec dimensionsSpec)
+ {
+ this.dimensionsSpec = dimensionsSpec;
+ return this;
+ }
+
+ public Builder withDimensions(List<DimensionSchema> dimensions)
+ {
+ this.dimensionsSpec =
DimensionsSpec.builder().setDimensions(dimensions).build();
+ return this;
+ }
+
+ public Builder withDimensions(DimensionSchema... dimensions)
+ {
+ return withDimensions(Arrays.asList(dimensions));
+ }
+
+ public Builder withAggregators(AggregatorFactory... aggregators)
+ {
+ this.aggregators = aggregators;
+ return this;
+ }
+
+ public Builder withGranularity(GranularitySpec granularitySpec)
+ {
+ this.granularitySpec = granularitySpec;
+ return this;
+ }
+
+ public Builder withTransform(TransformSpec transformSpec)
+ {
+ this.transformSpec = transformSpec;
+ return this;
+ }
+
+ public Builder withObjectMapper(ObjectMapper objectMapper)
+ {
+ this.objectMapper = objectMapper;
+ return this;
+ }
+
+ public Builder withParserMap(Map<String, Object> parserMap)
Review Comment:
Include `@Deprecated` to match the annotation in the constructor?
##########
server/src/main/java/org/apache/druid/segment/indexing/DataSchema.java:
##########
@@ -457,4 +413,108 @@ public String toString()
", inputRowParser=" + inputRowParser +
'}';
}
+
+ public static class Builder
+ {
+ private String dataSource;
+ private AggregatorFactory[] aggregators;
+ private GranularitySpec granularitySpec;
+ private TransformSpec transformSpec;
+ private Map<String, Object> parserMap;
+ private ObjectMapper objectMapper;
+
+ // The below fields can be initialized lazily from parser for backward
compatibility.
+ private TimestampSpec timestampSpec;
+ private DimensionsSpec dimensionsSpec;
+
+ public Builder()
+ {
+
+ }
+
+ public Builder(DataSchema schema)
+ {
+ this.dataSource = schema.dataSource;
+ this.aggregators = schema.aggregators;
+ this.granularitySpec = schema.granularitySpec;
+ this.transformSpec = schema.transformSpec;
+ this.parserMap = schema.parserMap;
+ this.objectMapper = schema.objectMapper;
+ this.timestampSpec = schema.timestampSpec;
+ this.dimensionsSpec = schema.dimensionsSpec;
+ }
+
+ public Builder withDataSource(String dataSource)
+ {
+ this.dataSource = dataSource;
+ return this;
+ }
+
+ public Builder withTimestamp(TimestampSpec timestampSpec)
+ {
+ this.timestampSpec = timestampSpec;
+ return this;
+ }
+
+ public Builder withDimensions(DimensionsSpec dimensionsSpec)
+ {
+ this.dimensionsSpec = dimensionsSpec;
+ return this;
+ }
+
+ public Builder withDimensions(List<DimensionSchema> dimensions)
+ {
+ this.dimensionsSpec =
DimensionsSpec.builder().setDimensions(dimensions).build();
+ return this;
+ }
+
+ public Builder withDimensions(DimensionSchema... dimensions)
+ {
+ return withDimensions(Arrays.asList(dimensions));
+ }
+
+ public Builder withAggregators(AggregatorFactory... aggregators)
+ {
+ this.aggregators = aggregators;
+ return this;
+ }
+
+ public Builder withGranularity(GranularitySpec granularitySpec)
+ {
+ this.granularitySpec = granularitySpec;
+ return this;
+ }
+
+ public Builder withTransform(TransformSpec transformSpec)
+ {
+ this.transformSpec = transformSpec;
+ return this;
+ }
+
+ public Builder withObjectMapper(ObjectMapper objectMapper)
Review Comment:
Include `@Deprecated`, since this is only used with the `parserMap`, which
is itself deprecated?
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/destination/SegmentGenerationUtils.java:
##########
@@ -96,14 +96,14 @@ public static DataSchema makeDataSchemaForIngestion(
destination.getDimensionSchemas()
);
- return new DataSchema(
- destination.getDataSource(),
- new TimestampSpec(ColumnHolder.TIME_COLUMN_NAME, "millis", null),
- dimensionsAndAggregators.lhs,
- dimensionsAndAggregators.rhs.toArray(new AggregatorFactory[0]),
- makeGranularitySpecForIngestion(querySpec.getQuery(),
querySpec.getColumnMappings(), isRollupQuery, jsonMapper),
- new TransformSpec(null, Collections.emptyList())
- );
+ return DataSchema.builder()
+ .withDataSource(destination.getDataSource())
+ .withTimestamp(new
TimestampSpec(ColumnHolder.TIME_COLUMN_NAME, "millis", null))
+ .withDimensions(dimensionsAndAggregators.lhs)
+ .withAggregators(dimensionsAndAggregators.rhs.toArray(new
AggregatorFactory[0]))
+
.withGranularity(makeGranularitySpecForIngestion(querySpec.getQuery(),
querySpec.getColumnMappings(), isRollupQuery, jsonMapper))
+ .withTransform(new TransformSpec(null,
Collections.emptyList()))
Review Comment:
Could leave this line out, if the default is a no-op `TransformSpec`.
--
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]