package com.splicemachine.db.impl.sql.compile;

import java.util.Iterator;

public class ColumnMappingUtils {

    /**
     * Updates the result set number and the column id of columns found in colRefsToUpdate to
     * the value found at that column name in colsToUpdateFrom.
     *
     * @param colsToUpdateFrom
     * @param colRefsToUpdate
     */
    public static void updateColumnMappings(ResultColumnList colsToUpdateFrom, Iterator colRefsToUpdate) {

        while(colRefsToUpdate.hasNext()){

            ColumnReference colRef = (ColumnReference) colRefsToUpdate.next();
            ResultColumn rcToUpdate = colRef.getSource();

            if(rcToUpdate != null){
                // TODO: handle column name collision
                ResultColumn updateFromRC = colsToUpdateFrom.getResultColumnFullName(rcToUpdate.getFullName(), true);
                rcToUpdate.setResultSetNumber(updateFromRC.getResultSetNumber());
                rcToUpdate.setVirtualColumnId(updateFromRC.getVirtualColumnId());
            }
        }
    }
}

@@ -675,62 +675,8 @@
 l)%7B%0A
-                // TODO: handle column name collision%0A
     
@@ -789,16 +789,62 @@
  true);%0A
+                if(updateFromRC != null)%7B%0A    
         
@@ -913,24 +913,28 @@
 tNumber());%0A
+    
             
@@ -999,24 +999,43 @@
 olumnId());%0A
+                %7D%0A%0A
             

handle when getResultColumnFullName returns null