Search in sources :

Example 11 with SQLNotNullConstraint

use of org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint in project hive by apache.

the class ObjectStore method getNotNullConstraintsViaJdo.

private List<SQLNotNullConstraint> getNotNullConstraintsViaJdo(String db_name, String tbl_name) throws MetaException {
    boolean commited = false;
    List<SQLNotNullConstraint> notNullConstraints = null;
    Query query = null;
    try {
        openTransaction();
        query = pm.newQuery(MConstraint.class, "parentTable.tableName == tbl_name && parentTable.database.name == db_name &&" + " constraintType == MConstraint.NOT_NULL_CONSTRAINT");
        query.declareParameters("java.lang.String tbl_name, java.lang.String db_name");
        Collection<?> constraints = (Collection<?>) query.execute(tbl_name, db_name);
        pm.retrieveAll(constraints);
        notNullConstraints = new ArrayList<>();
        for (Iterator<?> i = constraints.iterator(); i.hasNext(); ) {
            MConstraint currConstraint = (MConstraint) i.next();
            List<MFieldSchema> cols = currConstraint.getParentColumn() != null ? currConstraint.getParentColumn().getCols() : currConstraint.getParentTable().getPartitionKeys();
            int enableValidateRely = currConstraint.getEnableValidateRely();
            boolean enable = (enableValidateRely & 4) != 0;
            boolean validate = (enableValidateRely & 2) != 0;
            boolean rely = (enableValidateRely & 1) != 0;
            notNullConstraints.add(new SQLNotNullConstraint(db_name, tbl_name, cols.get(currConstraint.getParentIntegerIndex()).getName(), currConstraint.getConstraintName(), enable, validate, rely));
        }
        commited = commitTransaction();
    } finally {
        rollbackAndCleanup(commited, query);
    }
    return notNullConstraints;
}
Also used : SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) Query(javax.jdo.Query) MFieldSchema(org.apache.hadoop.hive.metastore.model.MFieldSchema) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) Collection(java.util.Collection) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) SQLDefaultConstraint(org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint) SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)

Aggregations

SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)11 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)10 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)8 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)8 SQLForeignKey (org.apache.hadoop.hive.metastore.api.SQLForeignKey)6 SQLPrimaryKey (org.apache.hadoop.hive.metastore.api.SQLPrimaryKey)6 ArrayList (java.util.ArrayList)5 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)3 Table (org.apache.hadoop.hive.ql.metadata.Table)3 DDLWork (org.apache.hadoop.hive.ql.plan.DDLWork)3 Query (javax.jdo.Query)2 Path (org.apache.hadoop.fs.Path)2 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)2 DefaultConstraint (org.apache.hadoop.hive.ql.metadata.DefaultConstraint)2 NotNullConstraint (org.apache.hadoop.hive.ql.metadata.NotNullConstraint)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1