morningman commented on code in PR #48041:
URL: https://github.com/apache/doris/pull/48041#discussion_r1961585513


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/InternalSchemaInitializer.java:
##########
@@ -358,7 +358,45 @@ private boolean created() {
 
         // 3. check audit table
         optionalStatsTbl = db.getTable(AuditLoader.AUDIT_LOG_TABLE);
-        return optionalStatsTbl.isPresent();
-    }
+        if (!optionalStatsTbl.isPresent()) {
+            return false;
+        }
 
+        // 4. check and update audit table schema
+        OlapTable auditTable = (OlapTable) optionalStatsTbl.get();
+        List<ColumnDef> expectedSchema = InternalSchema.AUDIT_SCHEMA;
+
+        // 5. check if we need to add new columns
+        List<AlterClause> alterClauses = Lists.newArrayList();
+        for (ColumnDef def : expectedSchema) {
+            if (auditTable.getColumn(def.getName()) == null) {
+                // add column if it doesn't exist
+                try {
+                    ColumnDef columnDef = new ColumnDef(def.getName(),
+                            def.getTypeDef(), def.isAllowNull());
+                    ModifyColumnClause clause = new 
ModifyColumnClause(columnDef, null, null,

Review Comment:
   1. We should add new column to exact place, not just append to the end.
   2. Better find a way to cover this logic by unit test



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