Jackie-Jiang commented on code in PR #19270:
URL: https://github.com/apache/pinot/pull/19270#discussion_r4730150106


##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java:
##########
@@ -1760,6 +1767,116 @@ public void updateSchema(Schema schema, boolean reload, 
boolean forceTableSchema
     }
   }
 
+  /// Updates an existing schema with optimistic concurrency and refreshes its 
servers only after a successful write.
+  /// Returns false for an unchanged schema, a stale version, a deleted 
schema, or a rejected persistence operation.
+  public boolean updateSchema(Schema schema, int expectedVersion)
+      throws SchemaBackwardIncompatibleException {
+    Schema oldSchema = getSchemaForVersionedUpdate(schema.getSchemaName(), 
expectedVersion);
+    if (oldSchema == null) {
+      return false;
+    }
+    schema.validate();
+    if (!updateSchema(schema, oldSchema, false, expectedVersion)) {
+      return false;
+    }
+    refreshTablesUsingSchema(schema.getSchemaName());
+    return true;
+  }
+
+  /// Finds every stored physical table sharing a schema, including configs 
that cannot currently be read or decorated.
+  /// Migration must validate all of these records before removing shared 
schema transforms.
+  public List<String> getTableNamesForSchemaMigration(String schemaName)
+      throws TableNotFoundException {
+    List<String> tableNames = new ArrayList<>(2);
+    for (TableType tableType : List.of(TableType.OFFLINE, TableType.REALTIME)) 
{
+      String tableName = 
TableNameBuilder.forType(tableType).tableNameWithType(schemaName);
+      if (ZKMetadataProvider.isTableConfigExists(_propertyStore, tableName)) {
+        tableNames.add(tableName);
+      }
+    }
+    if (tableNames.isEmpty()) {
+      throw new TableNotFoundException("Table '" + schemaName + "' not 
found.");
+    }
+    return tableNames;
+  }
+
+  /// Atomically updates affected table configs before removing their shared 
schema's legacy transforms.
+  /// Every table version is checked, including tables whose existing 
overrides require no config change.
+  /// Stale/deleted records leave all definitions unchanged, and refreshes are 
sent only after the transaction succeeds.
+  public boolean updateSchemaAndTableConfigs(Schema schema, int 
expectedSchemaVersion,
+      Map<String, Pair<TableConfig, Integer>> tableConfigs)
+      throws SchemaBackwardIncompatibleException, 
TableConfigBackwardIncompatibleException, TableNotFoundException,
+      IOException, KeeperException {
+    Schema oldSchema = getSchemaForVersionedUpdate(schema.getSchemaName(), 
expectedSchemaVersion);
+    if (oldSchema == null || !validateSchemaUpdate(schema, oldSchema, false)) {
+      return false;
+    }
+    ZkMultiWriteBuilder transaction = multiWriteZK();
+    List<TableConfig> effectiveConfigs = new ArrayList<>(tableConfigs.size());
+    List<TableConfig> changedConfigs = new ArrayList<>(tableConfigs.size());
+    for (Map.Entry<String, Pair<TableConfig, Integer>> entry : 
tableConfigs.entrySet()) {
+      String tableName = entry.getKey();
+      TableConfig rawConfig = entry.getValue().getLeft();
+      int expectedVersion = entry.getValue().getRight();
+      Preconditions.checkArgument(expectedVersion >= 0 && 
tableName.equals(rawConfig.getTableName())
+              && 
schema.getSchemaName().equals(TableNameBuilder.extractRawTableName(tableName)),
+          "Expected a versioned physical table using schema: %s", 
schema.getSchemaName());
+      Pair<TableConfig, Integer> original =
+          ZKMetadataProvider.getTableConfigWithVersion(_propertyStore, 
tableName, false, false);
+      if (original == null || original.getRight() != expectedVersion) {
+        return false;
+      }
+      TableConfig effective = TableConfigDecoratorRegistry.applyDecorator(
+          
ConfigUtils.applyConfigWithEnvVariablesAndSystemProperties(rawConfig));
+      TableConfig existingEffective = 
TableConfigDecoratorRegistry.applyDecorator(
+          
ConfigUtils.applyConfigWithEnvVariablesAndSystemProperties(original.getLeft()));
+      TableConfigUtils.validate(effective, schema, null, existingEffective);
+      TableConfigValidatorRegistry.validate(effective, schema);
+      validateExistingTableConfig(rawConfig, effective, expectedVersion, 
false, true);
+      effectiveConfigs.add(effective);
+      String path = 
ZKMetadataProvider.constructPropertyStorePathForResourceConfig(tableName);
+      transaction.check(path, expectedVersion);
+      if 
(!JsonUtils.objectToJsonNode(rawConfig).equals(JsonUtils.objectToJsonNode(original.getLeft())))
 {
+        transaction.set(path, TableConfigSerDeUtils.toZNRecord(rawConfig), 
expectedVersion);
+        changedConfigs.add(effective);
+      }
+    }
+    SchemaUtils.validate(schema, effectiveConfigs, false, oldSchema);
+    if (!new 
HashSet<>(getTableNamesForSchemaMigration(schema.getSchemaName())).equals(tableConfigs.keySet()))
 {
+      return false;
+    }
+    
transaction.set(ZKMetadataProvider.constructPropertyStorePathForSchema(schema.getSchemaName()),
+        SchemaSerDeUtils.toZNRecord(schema), expectedSchemaVersion);
+    try {
+      transaction.execute();

Review Comment:
   [P1] Fence concurrent table updates against migration
   
   A `PUT /tables/{tableName}` can validate a retention-only update against the 
old schema, pause while this transaction moves its transforms into the table 
config, then overwrite that migrated config. 
`PinotTableRestletResource.updateTableConfig()` reads the schema at lines 
794–797 before calling the resource manager at line 808; the normal 
`updateTableConfig()` path still writes with `expectedVersion=-1` (line 2680). 
After that PUT completes, neither definition contains the transform, so 
subsequent ingestion silently loses derived values.
   
   Please carry the schema/table versions captured during validation through 
ordinary table writes and reject or rebuild stale candidates when migration 
wins the race.



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/migration/LegacyTimeFieldSchemaMigrator.java:
##########
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.utils.migration;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Preconditions;
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.config.migration.SchemaMigrator;
+import org.apache.pinot.spi.data.DateTimeFieldSpec;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.data.TimeFieldSpec;
+import org.apache.pinot.spi.data.TimeGranularitySpec;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+/// Replaces legacy TIME fields with equivalent DATE_TIME fields, retaining 
their common field attributes.
+/// The existing schema conversion supplies the time format, granularity, and 
any required ingestion transform.
+/// This stateless migrator is safe to invoke concurrently on distinct schema 
copies.
+// Legacy TIME and transform APIs are intentionally read to migrate existing 
stored schemas.
+@SuppressWarnings("deprecation")
+public class LegacyTimeFieldSchemaMigrator implements SchemaMigrator {
+  @Override
+  public int fromVersion() {
+    return 0;
+  }
+
+  @Override
+  public Schema migrate(Schema input) {
+    TimeFieldSpec timeFieldSpec = input.getTimeFieldSpec();
+    if (timeFieldSpec == null) {
+      return input;
+    }
+    TimeGranularitySpec incoming = timeFieldSpec.getIncomingGranularitySpec();
+    TimeGranularitySpec outgoing = timeFieldSpec.getOutgoingGranularitySpec();
+    // An empty transform still selects the legacy time converter, but the 
helper would copy it as an identity.
+    Preconditions.checkState(!"".equals(timeFieldSpec.getTransformFunction()) 
|| incoming.equals(outgoing),
+        "Cannot automatically migrate time field with empty conversion 
transform: %s", timeFieldSpec.getName());
+    boolean nonUnitMillis = incoming.getTimeType() == TimeUnit.MILLISECONDS && 
incoming.getTimeUnitSize() != 1
+        || outgoing.getTimeType() == TimeUnit.MILLISECONDS && 
outgoing.getTimeUnitSize() != 1;
+    // The conversion helper does not multiply/divide non-unit millisecond 
values when generating a transform.
+    Preconditions.checkState(
+        !nonUnitMillis || incoming.equals(outgoing) || 
timeFieldSpec.getTransformFunction() != null,
+        "Cannot automatically migrate time field with non-unit millisecond 
conversion: %s", timeFieldSpec.getName());
+    DateTimeFieldSpec converted = 
Schema.convertToDateTimeFieldSpec(timeFieldSpec);

Review Comment:
   [P1] Quote source identifiers in generated TIME transforms
   
   `Schema.convertToDateTimeFieldSpec()` interpolates the incoming column name 
without quoting it. A valid legacy millisecond source named `foo-bar`, 
converted to outgoing seconds, becomes `toEpochSeconds(foo-bar)`, which parses 
as subtraction of two columns. The legacy `TimeSpecFunctionEvaluator` reads the 
literal `foo-bar` key. Validation accepts the generated expression because 
transform source columns need not exist in the schema, so migration can replace 
correct timestamps with null or incorrect values.
   
   Please quote and escape the source identifier when generating the 
expression, or skip automatic conversion for names that cannot be preserved 
safely, and add coverage for a source name containing `-`.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java:
##########
@@ -2103,6 +2233,56 @@ public void addTable(TableConfig tableConfig, 
List<StreamMetadata> streamMetadat
     LOGGER.info("Adding table {}: Successfully added table", 
tableNameWithType);
   }
 
+  /// Fences schema cleanup against new physical tables by changing the schema 
data version in the same transaction.
+  /// The exact stored record is retained, including fields unknown to this 
controller.
+  @VisibleForTesting
+  void createTableConfigWithSchemaVersion(TableConfig tableConfig)
+      throws IOException {
+    String tableName = tableConfig.getTableName();
+    String schemaPath = ZKMetadataProvider.constructPropertyStorePathForSchema(
+        TableNameBuilder.extractRawTableName(tableName));
+    String tablePath = 
ZKMetadataProvider.constructPropertyStorePathForResourceConfig(tableName);
+    String tableParent = tablePath.substring(0, tablePath.lastIndexOf('/'));
+    for (int attempt = 0; attempt < 3; attempt++) {
+      Stat stat = new Stat();
+      ZNRecord schemaRecord = _propertyStore.get(schemaPath, stat, 
AccessOption.PERSISTENT);
+      if (schemaRecord == null) {
+        throw new InvalidTableConfigException("No schema defined for table: " 
+ tableName);
+      }
+      try {
+        
Preconditions.checkNotNull(SchemaSerDeUtils.fromZNRecord(schemaRecord));
+      } catch (Exception e) {
+        throw new InvalidTableConfigException("Invalid schema defined for 
table: " + tableName, e);
+      }
+      if (!_propertyStore.exists(tableParent, AccessOption.PERSISTENT)) {
+        _propertyStore.create(tableParent, new ZNRecord("TABLE"), 
AccessOption.PERSISTENT);

Review Comment:
   [P2] Create the table parent in the current storage root
   
   `AutoFallbackPropertyStore.exists()` returns true when `/CONFIGS/TABLE` 
exists only under `HELIX_PROPERTYSTORE`. This skips creating the parent under 
`PROPERTYSTORE`, where `multiWriteZK()` exclusively writes. Table creation then 
repeatedly fails with `NoNodeException`; the retry promotes only the schema and 
never creates the missing table parent. The previous 
`propertyStore.create(tableConfigPath, ...)` path recursively created missing 
parents, so this is a regression even when automatic migration is disabled.
   
   Please ensure the parent exists specifically in the current root—for 
example, attempt current-root parent creation regardless of the fallback-aware 
existence check.



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/periodictask/ConfigMigrationManager.java:
##########
@@ -0,0 +1,323 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.controller.helix.core.periodictask;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.helix.store.zk.ZkHelixPropertyStore;
+import org.apache.helix.zookeeper.datamodel.ZNRecord;
+import org.apache.pinot.common.metadata.ZKMetadataProvider;
+import org.apache.pinot.common.metrics.ControllerMeter;
+import org.apache.pinot.common.metrics.ControllerMetrics;
+import org.apache.pinot.controller.ControllerConf;
+import org.apache.pinot.controller.ControllerConf.ControllerPeriodicTasksConf;
+import org.apache.pinot.controller.LeadControllerManager;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import org.apache.pinot.segment.local.utils.SchemaUtils;
+import org.apache.pinot.segment.local.utils.TableConfigUtils;
+import org.apache.pinot.spi.config.ConfigUtils;
+import org.apache.pinot.spi.config.migration.ConfigMigrationRegistry;
+import org.apache.pinot.spi.config.migration.ConfigMigrationUtils;
+import org.apache.pinot.spi.config.migration.MigrationResult;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableConfigValidatorRegistry;
+import org.apache.pinot.spi.config.table.ingestion.IngestionConfig;
+import org.apache.pinot.spi.config.table.ingestion.TransformConfig;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.TableConfigDecoratorRegistry;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/// Inspects stored table definitions and recommends available schema and 
table-config migrations.
+/// By default only warnings and recommendation meters are emitted. Explicitly 
enabling
+/// the cluster config `controller.config.migration.auto.update.enabled` also 
persists validated candidates with the
+/// captured ZooKeeper version and refreshes caches through the resource 
manager.
+///
+/// Schema transforms move to all affected table configs before being removed, 
using one version-checked transaction.
+/// Raw templates are retained for storage; a separate resolved table config 
is used for validation and
+/// runtime side effects. Table leadership and sequential per-run processing 
are provided by [ControllerPeriodicTask].
+public class ConfigMigrationManager extends 
ControllerPeriodicTask<ConfigMigrationManager.Context> {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(ConfigMigrationManager.class);
+  public static final String TASK_NAME = 
ConfigMigrationManager.class.getSimpleName();
+
+  private final ConfigMigrationRegistry _migrationRegistry;
+  private volatile boolean _autoUpdateEnabled =
+      ControllerPeriodicTasksConf.DEFAULT_CONFIG_MIGRATION_AUTO_UPDATE_ENABLED;
+
+  public ConfigMigrationManager(PinotHelixResourceManager helixResourceManager,
+      LeadControllerManager leadControllerManager, ControllerConf config, 
ControllerMetrics controllerMetrics,
+      ConfigMigrationRegistry migrationRegistry) {
+    super(TASK_NAME, config.getConfigMigrationFrequencyInSeconds(), 
config.getConfigMigrationInitialDelaySeconds(),
+        config.getConfigMigrationCronExpression(), helixResourceManager, 
leadControllerManager, controllerMetrics);
+    _migrationRegistry = migrationRegistry;
+  }
+
+  @Override
+  public void onChange(Set<String> changedConfigs, Map<String, String> 
clusterConfigs) {
+    if 
(changedConfigs.contains(ControllerPeriodicTasksConf.CONFIG_MIGRATION_AUTO_UPDATE_ENABLED))
 {
+      _autoUpdateEnabled = Boolean.parseBoolean(clusterConfigs.getOrDefault(
+          ControllerPeriodicTasksConf.CONFIG_MIGRATION_AUTO_UPDATE_ENABLED,
+          
Boolean.toString(ControllerPeriodicTasksConf.DEFAULT_CONFIG_MIGRATION_AUTO_UPDATE_ENABLED)));
+    }
+  }
+
+  /// Tracks shared schemas so a hybrid table's OFFLINE/REALTIME halves report 
and update it once per run.
+  public static class Context {
+    private final Set<String> _processedSchemas = new HashSet<>();
+    private final Set<String> _processedTables = new HashSet<>();
+  }
+
+  @Override
+  protected Context preprocess(Properties periodicTaskProperties) {
+    return new Context();
+  }
+
+  @Override
+  protected void processTable(String tableNameWithType, Context context) {
+    if (_migrationRegistry.getCurrentTableConfigVersion() == 0 && 
_migrationRegistry.getCurrentSchemaVersion() == 0) {
+      return;
+    }
+    ZkHelixPropertyStore<ZNRecord> propertyStore = 
_pinotHelixResourceManager.getPropertyStore();
+    String schemaName = 
TableNameBuilder.extractRawTableName(tableNameWithType);
+    ImmutablePair<Schema, Integer> schemaAndVersion =
+        ZKMetadataProvider.getSchemaWithVersion(propertyStore, schemaName);
+    Schema schema = schemaAndVersion != null ? schemaAndVersion.getLeft() : 
null;
+    if (_migrationRegistry.getCurrentSchemaVersion() > 0 && schemaAndVersion 
!= null
+        && context._processedSchemas.add(schemaName)) {
+      schema = migrateSchema(schema, schemaAndVersion.getRight(), context);
+    }
+    if (_migrationRegistry.getCurrentTableConfigVersion() > 0 && 
context._processedTables.add(tableNameWithType)) {
+      migrateTableConfig(propertyStore, tableNameWithType, schema);
+    }
+  }
+
+  private void migrateTableConfig(ZkHelixPropertyStore<ZNRecord> 
propertyStore, String tableNameWithType,
+      @Nullable Schema schema) {
+    try {
+      ImmutablePair<TableConfig, Integer> configAndVersion =
+          ZKMetadataProvider.getTableConfigWithVersion(propertyStore, 
tableNameWithType, false, false);
+      if (configAndVersion == null) {
+        return;
+      }
+      TableConfig original = configAndVersion.getLeft();
+      MigrationResult<TableConfig> result = 
_migrationRegistry.migrateTableConfig(original);
+      if (!result.isChanged()) {
+        return;
+      }
+      LOGGER.warn("Table: {} has legacy configuration; recommend updating to 
config migration version: {}. "
+          + "Automatic updates enabled: {}", tableNameWithType, 
result.getVersion(), _autoUpdateEnabled);
+      _controllerMetrics.addMeteredTableValue(tableNameWithType, 
ControllerMeter.CONFIG_MIGRATION_RECOMMENDED, 1L);
+      if (schema == null) {
+        return;
+      }
+      TableConfig migrated = result.getConfig();
+      TableConfig effective = TableConfigDecoratorRegistry.applyDecorator(
+          
ConfigUtils.applyConfigWithEnvVariablesAndSystemProperties(migrated));
+      TableConfig existingEffective = 
TableConfigDecoratorRegistry.applyDecorator(
+          
ConfigUtils.applyConfigWithEnvVariablesAndSystemProperties(original));
+      TableConfigUtils.validate(effective, schema, null, existingEffective);
+      TableConfigValidatorRegistry.validate(effective, schema);
+      if (!_autoUpdateEnabled) {
+        return;
+      }
+      _pinotHelixResourceManager.setExistingTableConfig(migrated, effective, 
configAndVersion.getRight(), false);
+      LOGGER.info("Updated table config for table: {} to migration version: 
{}", tableNameWithType,
+          result.getVersion());
+      _controllerMetrics.addMeteredTableValue(tableNameWithType, 
ControllerMeter.CONFIG_MIGRATION_SUCCESS, 1L);
+    } catch (Exception e) {
+      // Exception messages can contain resolved config values; report only 
the type, never the config payload.
+      LOGGER.warn("Could not complete table config migration for table: {}; 
will recheck next scan ({})",
+          tableNameWithType, e.getClass().getSimpleName());
+      _controllerMetrics.addMeteredTableValue(tableNameWithType, 
ControllerMeter.CONFIG_MIGRATION_FAILURE, 1L);
+    }
+  }
+
+  private Schema migrateSchema(Schema original, int expectedVersion, Context 
context) {
+    String schemaName = original.getSchemaName();
+    try {
+      if (ConfigMigrationUtils.getSchemaVersion(original) > 
_migrationRegistry.getCurrentSchemaVersion()) {
+        return original;
+      }
+      MigrationResult<Schema> result = 
_migrationRegistry.migrateSchema(original);
+      Schema migrated = result.getConfig();
+      Map<String, String> transforms = getSchemaTransforms(migrated);
+      if (!result.isChanged() && transforms.isEmpty()) {
+        return original;
+      }
+      LOGGER.warn("Schema: {} has legacy configuration; recommend updating to 
schema migration version: {}. "
+          + "Automatic updates enabled: {}", schemaName, result.getVersion(), 
_autoUpdateEnabled);
+      _controllerMetrics.addMeteredTableValue(schemaName, 
ControllerMeter.SCHEMA_MIGRATION_RECOMMENDED, 1L);
+      if (!transforms.isEmpty()) {
+        return migrateSchemaTransforms(original, migrated, expectedVersion, 
transforms, context);
+      }
+      List<TableConfig> tableConfigs = new ArrayList<>();
+      for (String tableName : 
_pinotHelixResourceManager.getTableNamesForSchemaMigration(schemaName)) {
+        TableConfig config = 
_pinotHelixResourceManager.getTableConfig(tableName);
+        if (config == null) {
+          throw new IllegalStateException("Table config unavailable for schema 
migration");
+        }
+        tableConfigs.add(config);
+      }
+      SchemaUtils.validate(migrated, tableConfigs, false, original);
+      if (!_autoUpdateEnabled) {
+        return original;
+      }
+      if (!_pinotHelixResourceManager.updateSchema(migrated, expectedVersion)) 
{
+        _controllerMetrics.addMeteredTableValue(schemaName, 
ControllerMeter.CONFIG_MIGRATION_FAILURE, 1L);
+        return original;
+      }
+      LOGGER.info("Updated schema: {} to migration version: {}", schemaName, 
result.getVersion());
+      _controllerMetrics.addMeteredTableValue(schemaName, 
ControllerMeter.CONFIG_MIGRATION_SUCCESS, 1L);
+      return migrated;
+    } catch (Exception e) {
+      LOGGER.warn("Could not complete schema migration: {}; will recheck next 
scan ({})",
+          schemaName, e.getClass().getSimpleName());
+      _controllerMetrics.addMeteredTableValue(schemaName, 
ControllerMeter.CONFIG_MIGRATION_FAILURE, 1L);
+      return original;
+    }
+  }
+
+  // Read legacy schema transforms deliberately; empty and virtual transforms 
have different runtime semantics.
+  @SuppressWarnings("deprecation")
+  private static Map<String, String> getSchemaTransforms(Schema schema) {
+    Map<String, String> transforms = new LinkedHashMap<>();
+    for (FieldSpec field : schema.getAllFieldSpecs()) {
+      String transform = field.getTransformFunction();
+      if (!field.isVirtualColumn() && transform != null && 
!transform.isEmpty()) {
+        transforms.put(field.getName(), transform);
+      }
+    }
+    return transforms;
+  }
+
+  // Clear deprecated schema properties only in a copy whose table 
replacements are committed atomically.
+  @SuppressWarnings("deprecation")
+  private Schema migrateSchemaTransforms(Schema original, Schema candidate, 
int expectedVersion,
+      Map<String, String> transforms, Context context)
+      throws Exception {
+    String schemaName = original.getSchemaName();
+    Schema migrated = Schema.fromString(candidate.toSingleLineJsonString());
+    for (String column : transforms.keySet()) {
+      migrated.getFieldSpecFor(column).setTransformFunction(null);

Review Comment:
   [P1] Reorder the remaining controller ingestion reader
   
   `PinotIngestionRestletResource.ingestData()` still reads the table config 
first (line 224) and the schema second (line 229). If migration commits between 
those reads, `/ingestFromFile` or `/ingestFromURI` receives an old table 
without the copied transforms and a new schema with them cleared here. 
`FileIngestionHelper` then builds and uploads a segment with missing derived 
values defaulted. For example, a schema transform `derived = lower(raw)` 
disappears from the effective ingestion pipeline.
   
   Please fetch the schema before the table config in this reader, matching the 
server/minion changes, and cover the interleaving.



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