use of org.apache.hadoop.hive.ql.metadata.UniqueConstraint.UniqueConstraintCol in project hive by apache.
the class MetaDataFormatUtils method getUniqueConstraintRelInformation.
private static void getUniqueConstraintRelInformation(StringBuilder constraintsInfo, String constraintName, List<UniqueConstraintCol> ukRel) {
formatOutput("Constraint Name:", constraintName, constraintsInfo);
if (ukRel != null && ukRel.size() > 0) {
for (UniqueConstraintCol ukc : ukRel) {
getUniqueConstraintColInformation(constraintsInfo, ukc);
}
}
constraintsInfo.append(LINE_DELIM);
}
use of org.apache.hadoop.hive.ql.metadata.UniqueConstraint.UniqueConstraintCol in project hive by apache.
the class RelOptHiveTable method generateKeys.
private Pair<List<ImmutableBitSet>, List<ImmutableBitSet>> generateKeys() {
final PrimaryKeyInfo primaryKeyInfo = hiveTblMetadata.getPrimaryKeyInfo();
final UniqueConstraint uniqueKeyInfo = hiveTblMetadata.getUniqueKeyInfo();
ImmutableList.Builder<ImmutableBitSet> builder = ImmutableList.builder();
ImmutableList.Builder<ImmutableBitSet> nonNullbuilder = ImmutableList.builder();
// First PK
if (primaryKeyInfo != null && !primaryKeyInfo.getColNames().isEmpty()) {
ImmutableBitSet.Builder keys = ImmutableBitSet.builder();
for (String pkColName : primaryKeyInfo.getColNames().values()) {
int pkPos;
for (pkPos = 0; pkPos < rowType.getFieldNames().size(); pkPos++) {
String colName = rowType.getFieldNames().get(pkPos);
if (pkColName.equals(colName)) {
break;
}
}
if (pkPos == rowType.getFieldNames().size()) {
LOG.error("Column for primary key definition " + pkColName + " not found");
}
keys.set(pkPos);
}
ImmutableBitSet key = keys.build();
builder.add(key);
nonNullbuilder.add(key);
}
// Then UKs
if (uniqueKeyInfo != null && !uniqueKeyInfo.getUniqueConstraints().isEmpty()) {
for (List<UniqueConstraintCol> ukCols : uniqueKeyInfo.getUniqueConstraints().values()) {
ImmutableBitSet.Builder keys = ImmutableBitSet.builder();
boolean isNonNullable = true;
for (UniqueConstraintCol ukCol : ukCols) {
int ukPos;
for (ukPos = 0; ukPos < rowType.getFieldNames().size(); ukPos++) {
String colName = rowType.getFieldNames().get(ukPos);
if (ukCol.colName.equals(colName)) {
if (rowType.getFieldList().get(ukPos).getType().isNullable()) {
// they should all be nullable
isNonNullable = false;
}
break;
}
}
if (ukPos == rowType.getFieldNames().size()) {
LOG.error("Column for unique constraint definition " + ukCol.colName + " not found");
}
keys.set(ukPos);
}
ImmutableBitSet key = keys.build();
builder.add(key);
if (isNonNullable) {
nonNullbuilder.add(key);
}
}
}
return new Pair<>(builder.build(), nonNullbuilder.build());
}
use of org.apache.hadoop.hive.ql.metadata.UniqueConstraint.UniqueConstraintCol in project hive by apache.
the class TextDescTableFormatter method getUniqueConstraintRelInformation.
private void getUniqueConstraintRelInformation(StringBuilder constraintsInfo, String constraintName, List<UniqueConstraintCol> columns) {
formatOutput("Constraint Name:", constraintName, constraintsInfo);
if (CollectionUtils.isNotEmpty(columns)) {
for (UniqueConstraintCol column : columns) {
String[] fields = new String[2];
fields[0] = "Column Name:" + column.colName;
fields[1] = "Key Sequence:" + column.position;
formatOutput(fields, constraintsInfo);
}
}
constraintsInfo.append(LINE_DELIM);
}
Aggregations