4040import java .util .Arrays ;
4141import java .util .List ;
4242import java .util .Map ;
43+ import java .util .stream .Collectors ;
4344
4445@ JsonTypeInfo (use = JsonTypeInfo .Id .NAME , property = "type" , defaultImpl = InlineSchemaDataSourceCompactionConfig .class )
4546@ JsonSubTypes (value = {
@@ -101,34 +102,39 @@ public interface DataSourceCompactionConfig
101102
102103 /**
103104 * Converts this compaction config to a {@link CompactionState}.
105+ * <p>
106+ * For IndexSpec and DimensionsSpec, we convert to their effective specs so that the fingerprint and associated state
107+ * reflect the actual layout of the segments after compaction (with all missing defaults not included in the compaction
108+ * config filled in). This is consistent with how {@link org.apache.druid.timeline.DataSegment#lastCompactionState }
109+ * has been computed historically.
104110 */
105111 default CompactionState toCompactionState ()
106112 {
107113 ClientCompactionTaskQueryTuningConfig tuningConfig = ClientCompactionTaskQueryTuningConfig .from (this );
108114
109- // 1. PartitionsSpec - reuse existing method
110115 PartitionsSpec partitionsSpec = CompactionStatus .findPartitionsSpecFromConfig (tuningConfig );
111116
112- // 2. DimensionsSpec
117+ IndexSpec indexSpec = tuningConfig .getIndexSpec () == null
118+ ? IndexSpec .getDefault ().getEffectiveSpec ()
119+ : tuningConfig .getIndexSpec ().getEffectiveSpec ();
120+
113121 DimensionsSpec dimensionsSpec = null ;
114122 if (getDimensionsSpec () != null && getDimensionsSpec ().getDimensions () != null ) {
115- dimensionsSpec = new DimensionsSpec (getDimensionsSpec ().getDimensions ());
123+ dimensionsSpec = DimensionsSpec .builder ()
124+ .setDimensions (
125+ getDimensionsSpec ().getDimensions ()
126+ .stream ()
127+ .map (dim -> dim .getEffectiveSchema (indexSpec ))
128+ .collect (Collectors .toList ())
129+ ).build ();
116130 }
117131
118- // 3. Metrics
119132 List <AggregatorFactory > metricsSpec = getMetricsSpec () == null
120133 ? null
121134 : Arrays .asList (getMetricsSpec ());
122135
123- // 4. Transform
124136 CompactionTransformSpec transformSpec = getTransformSpec ();
125137
126- // 5. IndexSpec
127- IndexSpec indexSpec = tuningConfig .getIndexSpec () == null
128- ? IndexSpec .getDefault ()
129- : tuningConfig .getIndexSpec ();
130-
131- // 6. GranularitySpec
132138 GranularitySpec granularitySpec = null ;
133139 if (getGranularitySpec () != null ) {
134140 UserCompactionTaskGranularityConfig userGranularityConfig = getGranularitySpec ();
@@ -140,7 +146,6 @@ default CompactionState toCompactionState()
140146 );
141147 }
142148
143- // 7. Projections
144149 List <AggregateProjectionSpec > projections = getProjections ();
145150
146151 return new CompactionState (
0 commit comments