@@ -470,6 +470,12 @@ protected void setRoutineLoadDesc(RoutineLoadDesc routineLoadDesc) {
470470 }
471471
472472 public void validateTargetTable (Database db , OlapTable targetTable ) throws UserException {
473+ validateTargetTable (db , targetTable , Maps .newHashMap (), uniqueKeyUpdateMode );
474+ }
475+
476+ public void validateTargetTable (Database db , OlapTable targetTable ,
477+ Map <String , String > alteredJobProperties , TUniqueKeyUpdateMode effectiveUniqueKeyUpdateMode )
478+ throws UserException {
473479 if (isMultiTable ) {
474480 throw new AnalysisException ("ALTER ROUTINE LOAD target table change only supports single-table job" );
475481 }
@@ -479,17 +485,75 @@ public void validateTargetTable(Database db, OlapTable targetTable) throws UserE
479485 }
480486 checkMeta (targetTable , new RoutineLoadDesc (columnSeparator , lineDelimiter , columnsInfo , precedingFilter ,
481487 whereExpr , partitionNamesInfo , deleteCondition , mergeType , sequenceCol ));
488+ validateAlterJobProperties (targetTable , alteredJobProperties , effectiveUniqueKeyUpdateMode );
482489
483490 targetTable .readLock ();
484491 try {
485- NereidsStreamLoadPlanner planner = new NereidsStreamLoadPlanner (db , targetTable ,
486- toNereidsRoutineLoadTaskInfo ());
492+ NereidsRoutineLoadTaskInfo taskInfo = toNereidsRoutineLoadTaskInfo ();
493+ taskInfo .applyAlterPropertiesForValidation (alteredJobProperties , effectiveUniqueKeyUpdateMode );
494+ NereidsStreamLoadPlanner planner = new NereidsStreamLoadPlanner (db , targetTable , taskInfo );
487495 planner .plan (new TUniqueId (0 , 0 ));
488496 } finally {
489497 targetTable .readUnlock ();
490498 }
491499 }
492500
501+ public void validateAlterJobProperties (OlapTable targetTable , Map <String , String > alteredJobProperties ,
502+ TUniqueKeyUpdateMode effectiveUniqueKeyUpdateMode ) throws UserException {
503+ if (effectiveUniqueKeyUpdateMode == TUniqueKeyUpdateMode .UPSERT ) {
504+ return ;
505+ }
506+ if (isMultiTable ) {
507+ throw new AnalysisException ("Partial update is not supported in multi-table load." );
508+ }
509+ if (effectiveUniqueKeyUpdateMode == TUniqueKeyUpdateMode .UPDATE_FIXED_COLUMNS ) {
510+ if (!targetTable .getEnableUniqueKeyMergeOnWrite ()) {
511+ throw new AnalysisException ("load by PARTIAL_COLUMNS is only supported in unique table MoW" );
512+ }
513+ return ;
514+ }
515+ Preconditions .checkState (effectiveUniqueKeyUpdateMode == TUniqueKeyUpdateMode .UPDATE_FLEXIBLE_COLUMNS ,
516+ effectiveUniqueKeyUpdateMode );
517+ validateFlexiblePartialUpdateForAlter (targetTable , alteredJobProperties );
518+ }
519+
520+ public static TUniqueKeyUpdateMode getEffectiveUniqueKeyUpdateMode (TUniqueKeyUpdateMode currentUniqueKeyUpdateMode ,
521+ Map <String , String > alteredJobProperties ) {
522+ if (alteredJobProperties .containsKey (CreateRoutineLoadInfo .UNIQUE_KEY_UPDATE_MODE )) {
523+ return TUniqueKeyUpdateMode .valueOf (
524+ alteredJobProperties .get (CreateRoutineLoadInfo .UNIQUE_KEY_UPDATE_MODE ));
525+ }
526+ if (alteredJobProperties .containsKey (CreateRoutineLoadInfo .PARTIAL_COLUMNS )
527+ && Boolean .parseBoolean (alteredJobProperties .get (CreateRoutineLoadInfo .PARTIAL_COLUMNS ))
528+ && currentUniqueKeyUpdateMode == TUniqueKeyUpdateMode .UPSERT ) {
529+ return TUniqueKeyUpdateMode .UPDATE_FIXED_COLUMNS ;
530+ }
531+ return currentUniqueKeyUpdateMode ;
532+ }
533+
534+ protected void validateAlterJobPropertiesForMutation (AlterRoutineLoadCommand command ) throws UserException {
535+ Map <String , String > alteredJobProperties = command .getAnalyzedJobProperties ();
536+ TUniqueKeyUpdateMode effectiveUniqueKeyUpdateMode = getEffectiveUniqueKeyUpdateMode (
537+ uniqueKeyUpdateMode , alteredJobProperties );
538+ if (effectiveUniqueKeyUpdateMode == TUniqueKeyUpdateMode .UPSERT ) {
539+ return ;
540+ }
541+
542+ Database db = Env .getCurrentInternalCatalog ().getDbNullable (dbId );
543+ if (db == null ) {
544+ throw new DdlException ("Database not found: " + dbId );
545+ }
546+ long effectiveTableId = command .hasTargetTable () ? command .getTargetTableId () : tableId ;
547+ Table table = db .getTableNullable (effectiveTableId );
548+ if (table == null ) {
549+ throw new DdlException ("Table not found: " + effectiveTableId );
550+ }
551+ if (!(table instanceof OlapTable )) {
552+ throw new DdlException ("Partial update is only supported for OLAP tables" );
553+ }
554+ validateAlterJobProperties ((OlapTable ) table , alteredJobProperties , effectiveUniqueKeyUpdateMode );
555+ }
556+
493557 @ Override
494558 public long getId () {
495559 return id ;
@@ -2093,10 +2157,6 @@ protected void modifyCommonJobProperties(Map<String, String> jobProperties) thro
20932157 if (hasExplicitUniqueKeyUpdateMode ) {
20942158 String modeStr = jobProperties .remove (CreateRoutineLoadInfo .UNIQUE_KEY_UPDATE_MODE );
20952159 TUniqueKeyUpdateMode newMode = CreateRoutineLoadInfo .parseAndValidateUniqueKeyUpdateMode (modeStr );
2096- // Validate flexible partial update constraints when changing to UPDATE_FLEXIBLE_COLUMNS
2097- if (newMode == TUniqueKeyUpdateMode .UPDATE_FLEXIBLE_COLUMNS ) {
2098- validateFlexiblePartialUpdateForAlter ();
2099- }
21002160 this .uniqueKeyUpdateMode = newMode ;
21012161 this .isPartialUpdate = (uniqueKeyUpdateMode == TUniqueKeyUpdateMode .UPDATE_FIXED_COLUMNS );
21022162 this .jobProperties .put (CreateRoutineLoadInfo .UNIQUE_KEY_UPDATE_MODE , uniqueKeyUpdateMode .name ());
@@ -2120,43 +2180,27 @@ protected void modifyCommonJobProperties(Map<String, String> jobProperties) thro
21202180 /**
21212181 * Validate flexible partial update constraints when altering routine load job.
21222182 */
2123- private void validateFlexiblePartialUpdateForAlter () throws UserException {
2124- // Multi-table load does not support flexible partial update
2125- if (isMultiTable ) {
2126- throw new DdlException ("Flexible partial update is not supported in multi-table load" );
2127- }
2128-
2129- // Get the table to check table-level constraints
2130- Database db = Env .getCurrentInternalCatalog ().getDbNullable (dbId );
2131- if (db == null ) {
2132- throw new DdlException ("Database not found: " + dbId );
2133- }
2134- Table table = db .getTableNullable (tableId );
2135- if (table == null ) {
2136- throw new DdlException ("Table not found: " + tableId );
2137- }
2138- if (!(table instanceof OlapTable )) {
2139- throw new DdlException ("Flexible partial update is only supported for OLAP tables" );
2140- }
2141- OlapTable olapTable = (OlapTable ) table ;
2142-
2183+ private void validateFlexiblePartialUpdateForAlter (OlapTable targetTable ,
2184+ Map <String , String > alteredJobProperties ) throws UserException {
21432185 // Validate table-level constraints (MoW, skip_bitmap, light_schema_change, variant columns)
2144- olapTable .validateForFlexiblePartialUpdate ();
2186+ targetTable .validateForFlexiblePartialUpdate ();
2187+ Map <String , String > effectiveJobProperties = Maps .newHashMap (jobProperties );
2188+ effectiveJobProperties .putAll (alteredJobProperties );
21452189
21462190 // Routine load specific validations
21472191 // Must use JSON format
2148- String format = this . jobProperties .getOrDefault (FileFormatProperties .PROP_FORMAT , "csv" );
2192+ String format = effectiveJobProperties .getOrDefault (FileFormatProperties .PROP_FORMAT , "csv" );
21492193 if (!"json" .equalsIgnoreCase (format )) {
21502194 throw new DdlException ("Flexible partial update only supports JSON format, but current job uses: "
21512195 + format );
21522196 }
21532197 // Cannot use fuzzy_parse
2154- if (Boolean .parseBoolean (this . jobProperties .getOrDefault (
2198+ if (Boolean .parseBoolean (effectiveJobProperties .getOrDefault (
21552199 JsonFileFormatProperties .PROP_FUZZY_PARSE , "false" ))) {
21562200 throw new DdlException ("Flexible partial update does not support fuzzy_parse" );
21572201 }
21582202 // Cannot use jsonpaths
2159- String jsonPaths = getJsonPaths ( );
2203+ String jsonPaths = effectiveJobProperties . get ( JsonFileFormatProperties . PROP_JSON_PATHS );
21602204 if (jsonPaths != null && !jsonPaths .isEmpty ()) {
21612205 throw new DdlException ("Flexible partial update does not support jsonpaths" );
21622206 }
0 commit comments