Search in sources :

Example 1 with DataConstraintViolationError

use of org.apache.hadoop.hive.ql.exec.errors.DataConstraintViolationError in project hive by apache.

the class TestConstraintsMerge method testUpdateInMergeViolatesCheckConstraint.

@Test
public void testUpdateInMergeViolatesCheckConstraint() throws Exception {
    HiveConf confForTez = new HiveConf(hiveConf);
    confForTez.setBoolVar(HiveConf.ConfVars.HIVE_EXPLAIN_USER, false);
    setupTez(confForTez);
    runStatementOnDriver("insert into " + Table.TBL_CHECK_MERGE + "(name, age, gpa) values " + "('student1', 16, 2.0)", confForTez);
    Throwable error = null;
    try {
        runStatementOnDriver("merge into " + Table.TBL_CHECK_MERGE + " using (select age from table_source) source\n" + "on source.age=table_check_merge.age\n" + "when matched then update set gpa=6", confForTez);
    } catch (Throwable t) {
        error = t;
    }
    assertTrue(error instanceof DataConstraintViolationError);
    assertTrue(error.getMessage().contains("Either CHECK or NOT NULL constraint violated!"));
}
Also used : DataConstraintViolationError(org.apache.hadoop.hive.ql.exec.errors.DataConstraintViolationError) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Test(org.junit.Test)

Example 2 with DataConstraintViolationError

use of org.apache.hadoop.hive.ql.exec.errors.DataConstraintViolationError in project hive by apache.

the class TestGenericUDFEnforceConstraint method testNull.

@Test
public void testNull() throws HiveException {
    try {
        GenericUDFEnforceConstraint udf = new GenericUDFEnforceConstraint();
        ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
        ObjectInspector[] arguments = { valueOI };
        udf.initialize(arguments);
        BooleanWritable input = new BooleanWritable(false);
        GenericUDF.DeferredObject[] args = { new GenericUDF.DeferredJavaObject(input) };
        udf.evaluate(args);
        fail("Unreachable line");
    } catch (DataConstraintViolationError e) {
        // DataConstraintViolationError is expected
        assertTrue(e.getMessage().contains("NOT NULL constraint violated!"));
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DataConstraintViolationError(org.apache.hadoop.hive.ql.exec.errors.DataConstraintViolationError) BooleanWritable(org.apache.hadoop.io.BooleanWritable) Test(org.junit.Test)

Aggregations

DataConstraintViolationError (org.apache.hadoop.hive.ql.exec.errors.DataConstraintViolationError)2 Test (org.junit.Test)2 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)1 BooleanWritable (org.apache.hadoop.io.BooleanWritable)1