in adb3client/src/main/java/com/alibaba/cloud/analyticdb/adb3client/model/TableSchema.java [207:286]
public void calculateProperties() {
if (columnNameToIndexMapping == null) {
columnNameToIndexMapping = new HashMap<>();
List<String> primaryKeyNames = new ArrayList<>();
for (int i = 0; i < columns.length; ++i) {
Column column = columns[i];
columnNameToIndexMapping.put(column.getName(), i);
if (column.getPrimaryKey()) {
primaryKeyNames.add(column.getName());
}
}
// The JDBC spec says when you have duplicate columns names,
// the first one should be returned. So load the map in
// reverse order so the first ones will overwrite later ones.
lowerColumnNameToIndexMapping = new HashMap<>();
for (int i = columns.length - 1; i > -1; --i) {
Column column = columns[i];
lowerColumnNameToIndexMapping.put(column.getName().toLowerCase(Locale.US), i);
}
if (partitionIndex > -2) {
if (partitionIndex == -1) {
partitionInfo = null;
} else {
partitionInfo = columns[partitionIndex].getName();
}
} else {
if (null != partitionInfo && partitionInfo.length() > 0) {
partitionIndex = columnNameToIndexMapping.get(partitionInfo);
} else {
partitionIndex = -1;
}
}
primaryKeys = primaryKeyNames.toArray(new String[]{});
keyIndex = new int[primaryKeys.length];
if (primaryKeys.length > 0) {
primaryKeySet = new HashSet<>();
}
for (int i = 0; i < primaryKeys.length; ++i) {
keyIndex[i] = columnNameToIndexMapping.get(primaryKeys[i]);
if (primaryKeySet != null) {
primaryKeySet.add(primaryKeys[i]);
}
}
if (distributionKeys == null) {
distributionKeys = new String[]{};
}
distributionKeyIndex = new int[distributionKeys.length];
for (int i = 0; i < distributionKeyIndex.length; ++i) {
distributionKeyIndex[i] = columnNameToIndexMapping.get(distributionKeys[i]);
}
String[] typeNamesTemp = new String[columns.length];
for (int i = 0; i < columns.length; ++i) {
typeNamesTemp[i] = columns[i].getTypeName();
}
this.typeNames = typeNamesTemp;
int[] columnTypesTemp = new int[columns.length];
for (int i = 0; i < columns.length; ++i) {
columnTypesTemp[i] = columns[i].getType();
}
this.columnTypes = columnTypesTemp;
String[] columnNamesTemp = new String[columns.length];
for (int i = 0; i < columns.length; ++i) {
columnNamesTemp[i] = columns[i].getName();
}
this.columnNames = columnNamesTemp;
}
if (tableId == null) {
tableId = tableName.fullName;
}
if (schemaVersion == null) {
schemaVersion = "";
}
}