Skip to content

Commit

Permalink
Merge 7ce866e into 7584bf7
Browse files Browse the repository at this point in the history
  • Loading branch information
kunal642 authored Nov 27, 2018
2 parents 7584bf7 + 7ce866e commit 2d0729e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -332,13 +334,45 @@ public void clear() {
}
SegmentPropertiesAndSchemaHolder.SegmentPropertiesWrapper other =
(SegmentPropertiesAndSchemaHolder.SegmentPropertiesWrapper) obj;
return tableIdentifier.equals(other.tableIdentifier) && columnsInTable
.equals(other.columnsInTable) && Arrays
return tableIdentifier.equals(other.tableIdentifier) && checkColumnSchemaEquality(
columnsInTable, other.columnsInTable) && Arrays
.equals(columnCardinality, other.columnCardinality);
}

private boolean checkColumnSchemaEquality(List<ColumnSchema> obj1, List<ColumnSchema> obj2) {
if (obj1.size() != obj2.size()) {
return false;
}
List<ColumnSchema> clonedObj1 = new ArrayList<>(obj1);
List<ColumnSchema> clonedObj2 = new ArrayList<>(obj2);
clonedObj1.addAll(obj1);
clonedObj2.addAll(obj2);
Collections.sort(clonedObj1, new Comparator<ColumnSchema>() {
@Override public int compare(ColumnSchema o1, ColumnSchema o2) {
return o1.getColumnUniqueId().compareTo(o2.getColumnUniqueId());
}
});
Collections.sort(clonedObj2, new Comparator<ColumnSchema>() {
@Override public int compare(ColumnSchema o1, ColumnSchema o2) {
return o1.getColumnUniqueId().compareTo(o2.getColumnUniqueId());
}
});
boolean exists = true;
for (int i = 0; i < obj1.size(); i++) {
if (!clonedObj1.get(i).equalsWithStrictCheck(clonedObj2.get(i))) {
exists = false;
break;
}
}
return exists;
}

@Override public int hashCode() {
return tableIdentifier.hashCode() + columnsInTable.hashCode() + Arrays
int allColumnsHashCode = 0;
for (ColumnSchema columnSchema: columnsInTable) {
allColumnsHashCode = 31 * allColumnsHashCode + columnSchema.strictHashCode();
}
return tableIdentifier.hashCode() + allColumnsHashCode + Arrays
.hashCode(columnCardinality);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ public void setParentColumnTableRelations(
return result;
}

public int strictHashCode() {
return hashCode() + columnUniqueId.hashCode() + encodingList.hashCode();
}

/**
* Overridden equals method for columnSchema
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ test("Creation of partition table should fail if the colname in table schema and
test("validate data in partition table after dropping and adding a column") {
sql("drop table if exists par")
sql("create table par(name string) partitioned by (age double) stored by " +
"'carbondata'")
"'carbondata' TBLPROPERTIES('cache_level'='blocklet')")
sql(s"load data local inpath '$resourcesPath/uniqwithoutheader.csv' into table par options" +
s"('header'='false')")
sql("alter table par drop columns(name)")
Expand Down

0 comments on commit 2d0729e

Please sign in to comment.