Search in sources :

Example 1 with UniqueConstraintCol

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);
}
Also used : UniqueConstraintCol(org.apache.hadoop.hive.ql.metadata.UniqueConstraint.UniqueConstraintCol)

Example 2 with UniqueConstraintCol

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());
}
Also used : UniqueConstraintCol(org.apache.hadoop.hive.ql.metadata.UniqueConstraint.UniqueConstraintCol) PrimaryKeyInfo(org.apache.hadoop.hive.ql.metadata.PrimaryKeyInfo) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) ImmutableList(com.google.common.collect.ImmutableList) UniqueConstraint(org.apache.hadoop.hive.ql.metadata.UniqueConstraint) UniqueConstraint(org.apache.hadoop.hive.ql.metadata.UniqueConstraint) RelReferentialConstraint(org.apache.calcite.rel.RelReferentialConstraint) IntPair(org.apache.calcite.util.mapping.IntPair) Pair(org.apache.calcite.util.Pair)

Example 3 with UniqueConstraintCol

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);
}
Also used : UniqueConstraintCol(org.apache.hadoop.hive.ql.metadata.UniqueConstraint.UniqueConstraintCol)

Aggregations

UniqueConstraintCol (org.apache.hadoop.hive.ql.metadata.UniqueConstraint.UniqueConstraintCol)3 ImmutableList (com.google.common.collect.ImmutableList)1 RelReferentialConstraint (org.apache.calcite.rel.RelReferentialConstraint)1 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)1 Pair (org.apache.calcite.util.Pair)1 IntPair (org.apache.calcite.util.mapping.IntPair)1 PrimaryKeyInfo (org.apache.hadoop.hive.ql.metadata.PrimaryKeyInfo)1 UniqueConstraint (org.apache.hadoop.hive.ql.metadata.UniqueConstraint)1