FrankChen021 commented on code in PR #19597:
URL: https://github.com/apache/druid/pull/19597#discussion_r3435732319


##########
multi-stage-query/src/main/java/org/apache/druid/msq/indexing/destination/SegmentGenerationUtils.java:
##########
@@ -112,6 +99,34 @@ public static DataSchema makeDataSchemaForIngestion(
     } else {
       transformSpec = null;
     }
+
+    // base-table mode, the destination supplies the base-table shape
+    if (destination.getBaseTable() != null) {
+      final Granularity queryGranularity =
+          
query.context().getGranularity(DruidSqlInsert.SQL_INSERT_QUERY_GRANULARITY, 
jsonMapper);
+      final BaseTableProjectionSpec baseTable =
+          destination.getBaseTable().withQueryGranularity(queryGranularity);
+      return DataSchema.builder()
+                       .withDataSource(destination.getDataSource())
+                       .withTimestamp(new 
TimestampSpec(ColumnHolder.TIME_COLUMN_NAME, "millis", null))
+                       .withTransform(transformSpec)
+                       .withBaseTable(baseTable)

Review Comment:
   [P1] Carry projections into base-table segment generation
   
   The baseTable branch builds the worker DataSchema without 
withProjections(destination.getProjections()), unlike the legacy branch. 
MSQCompactionRunner passes projections through DataSourceMSQDestination, but 
they are dropped before segment generation, so baseTable compaction configured 
with projections writes segments without them and stores 
lastCompactionState.projections as null; CompactionStatus then keeps scheduling 
the same compaction. Add the projections to this builder path and cover 
baseTable+projections.



##########
processing/src/main/java/org/apache/druid/data/input/impl/ClusteredValueGroupsBaseTableProjectionSpec.java:
##########
@@ -170,6 +172,73 @@ public DimensionsSpec getDimensionsSpec()
     return dimensionsSpec;
   }
 
+  /**
+   * Returns a copy of this spec with a new {@code queryGranularity}, 
expressed as a
+   * {@link Granularities#GRANULARITY_VIRTUAL_COLUMN_NAME} virtual column 
added to {@link #getVirtualColumns()}. A
+   * {@code null}, {@code NONE}, or {@code ALL} granularity is a no-op, so 
this returns {@code this} unchanged.
+   * <p>
+   * Idempotent: if the spec already declares a query-granularity virtual 
column, that one is authoritative and this is
+   * a no-op. (The compaction path attaches the virtual column up front; the 
MSQ generation path then calls this again
+   * with the query-derived granularity, which must not double-add.)
+   */
+  @Override
+  public ClusteredValueGroupsBaseTableProjectionSpec 
withQueryGranularity(@Nullable Granularity queryGranularity)
+  {
+    if (queryGranularity == null
+        || Granularities.NONE.equals(queryGranularity)
+        || Granularities.ALL.equals(queryGranularity)

Review Comment:
   [P1] Do not erase ALL query granularity
   
   Treating Granularities.ALL as a no-op makes baseTable compaction report an 
effective query granularity of NONE. That bypasses MSQCompactionRunner's 
existing ALL handling, which assigns rows to the interval start timestamp, so 
queryGranularity=ALL produces incorrectly timestamped clustered segments; the 
later status check also compares configured ALL to stored NONE and can 
recompact forever. Preserve or reject ALL explicitly instead of silently 
normalizing it away.



-- 
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]

Reply via email to