Github user manishgupta88 commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/2990#discussion_r242870325
  
    --- Diff: 
integration/spark2/src/main/scala/org/apache/spark/sql/hive/CarbonFileMetastore.scala
 ---
    @@ -318,15 +322,27 @@ class CarbonFileMetastore extends CarbonMetaStore {
        */
       def revertTableSchemaInAlterFailure(carbonTableIdentifier: 
CarbonTableIdentifier,
           thriftTableInfo: org.apache.carbondata.format.TableInfo,
    -      absoluteTableIdentifier: AbsoluteTableIdentifier)(sparkSession: 
SparkSession): String = {
    +      absoluteTableIdentifier: AbsoluteTableIdentifier,
    +      timeStamp: Long)(sparkSession: SparkSession): String = {
         val schemaConverter = new ThriftWrapperSchemaConverterImpl
         val wrapperTableInfo = schemaConverter.fromExternalToWrapperTableInfo(
           thriftTableInfo,
           carbonTableIdentifier.getDatabaseName,
           carbonTableIdentifier.getTableName,
           absoluteTableIdentifier.getTablePath)
         val evolutionEntries = 
thriftTableInfo.fact_table.schema_evolution.schema_evolution_history
    -    evolutionEntries.remove(evolutionEntries.size() - 1)
    +    // we may need to remove two evolution entries if the operation is 
both col rename and datatype
    +    // change operation
    +    if (evolutionEntries.size() > 1 &&
    +        (evolutionEntries.get(evolutionEntries.size() - 1).time_stamp ==
    +        evolutionEntries.get(evolutionEntries.size() - 2).time_stamp)) {
    +      evolutionEntries.remove(evolutionEntries.size() - 1)
    +      evolutionEntries.remove(evolutionEntries.size() - 2)
    +    } else {
    +      if (evolutionEntries.get(evolutionEntries.size() - 1).time_stamp == 
timeStamp) {
    +        evolutionEntries.remove(evolutionEntries.size() - 1)
    +      }
    --- End diff --
    
    Better not toi harcode the entries. Iterate and compare the entries and 
remove till timestamps are equal


---

Reply via email to