Search in sources :

Example 6 with ConstraintViolationException

use of org.apache.phoenix.schema.ConstraintViolationException in project phoenix by apache.

the class VariableLengthPKIT method testTooShortKVColumn.

@Test
public void testTooShortKVColumn() throws Exception {
    long ts = nextTimestamp();
    ensureTableCreated(getUrl(), BTABLE_NAME, BTABLE_NAME, null, ts - 2, null);
    // Insert at timestamp 0
    String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + ts;
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(url, props);
    conn.setAutoCommit(true);
    // Insert all rows at ts
    PreparedStatement stmt = conn.prepareStatement("upsert into " + "BTABLE(" + "    A_STRING, " + "    A_ID," + "    B_STRING," + "    A_INTEGER," + "    C_STRING," + "    E_STRING)" + "VALUES (?, ?, ?, ?, ?, ?)");
    stmt.setString(1, "abc");
    stmt.setString(2, "123");
    stmt.setString(3, "x");
    stmt.setInt(4, 1);
    stmt.setString(5, "ab");
    stmt.setString(6, "01234");
    try {
        stmt.execute();
    } catch (ConstraintViolationException e) {
        fail("Constraint voilation Exception should not be thrown, the characters have to be padded");
    } finally {
        conn.close();
    }
}
Also used : Connection(java.sql.Connection) ConstraintViolationException(org.apache.phoenix.schema.ConstraintViolationException) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

ConstraintViolationException (org.apache.phoenix.schema.ConstraintViolationException)6 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 Properties (java.util.Properties)3 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)2 Pair (org.apache.hadoop.hbase.util.Pair)2 SQLExceptionInfo (org.apache.phoenix.exception.SQLExceptionInfo)2 Expression (org.apache.phoenix.expression.Expression)2 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)2 DataOutputStream (java.io.DataOutputStream)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 Cell (org.apache.hadoop.hbase.Cell)1 Scan (org.apache.hadoop.hbase.client.Scan)1 ExpressionCompiler (org.apache.phoenix.compile.ExpressionCompiler)1 AggregatePlan (org.apache.phoenix.execute.AggregatePlan)1 MutationState (org.apache.phoenix.execute.MutationState)1 RowMutationState (org.apache.phoenix.execute.MutationState.RowMutationState)1 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)1