Search in sources :

Example 6 with SQLExceptionCode

use of org.apache.phoenix.exception.SQLExceptionCode in project phoenix by apache.

the class SchemaUtilTest method testExceptionCode.

@Test
public void testExceptionCode() throws Exception {
    SQLExceptionCode code = SQLExceptionCode.fromErrorCode(SQLExceptionCode.AGGREGATE_IN_GROUP_BY.getErrorCode());
    assertEquals(SQLExceptionCode.AGGREGATE_IN_GROUP_BY, code);
}
Also used : SQLExceptionCode(org.apache.phoenix.exception.SQLExceptionCode) Test(org.junit.Test)

Example 7 with SQLExceptionCode

use of org.apache.phoenix.exception.SQLExceptionCode in project phoenix by apache.

the class Sequence method incrementValue.

public long incrementValue(Result result, ValueOp op, long numToAllocate) throws SQLException {
    // before a next val was. Not sure how to prevent that.
    if (result.rawCells().length == 1) {
        Cell errorKV = result.rawCells()[0];
        int errorCode = PInteger.INSTANCE.getCodec().decodeInt(errorKV.getValueArray(), errorKV.getValueOffset(), SortOrder.getDefault());
        SQLExceptionCode code = SQLExceptionCode.fromErrorCode(errorCode);
        // }
        throw new SQLExceptionInfo.Builder(code).setSchemaName(key.getSchemaName()).setTableName(key.getSequenceName()).build().buildException();
    }
    // If we found the sequence, we update our cache with the new value
    SequenceValue value = new SequenceValue(result, op, numToAllocate);
    insertSequenceValue(value);
    return increment(value, op, numToAllocate);
}
Also used : SQLExceptionCode(org.apache.phoenix.exception.SQLExceptionCode) Cell(org.apache.hadoop.hbase.Cell)

Example 8 with SQLExceptionCode

use of org.apache.phoenix.exception.SQLExceptionCode in project phoenix by apache.

the class ServerUtil method parseRemoteException.

private static SQLException parseRemoteException(Throwable t) {
    String message = t.getLocalizedMessage();
    if (message != null) {
        // If the message matches the standard pattern, recover the SQLException and throw it.
        Matcher matcher = PATTERN.matcher(t.getLocalizedMessage());
        if (matcher.find()) {
            int statusCode = Integer.parseInt(matcher.group(1));
            SQLExceptionCode code = SQLExceptionCode.fromErrorCode(statusCode);
            return new SQLExceptionInfo.Builder(code).setMessage(matcher.group()).setRootCause(t).build().buildException();
        }
    }
    return null;
}
Also used : SQLExceptionCode(org.apache.phoenix.exception.SQLExceptionCode) Matcher(java.util.regex.Matcher)

Aggregations

SQLExceptionCode (org.apache.phoenix.exception.SQLExceptionCode)8 Cell (org.apache.hadoop.hbase.Cell)4 SQLException (java.sql.SQLException)1 Matcher (java.util.regex.Matcher)1 SQLExceptionInfo (org.apache.phoenix.exception.SQLExceptionInfo)1 SequenceAllocation (org.apache.phoenix.schema.SequenceAllocation)1 SequenceInfo (org.apache.phoenix.schema.SequenceInfo)1 SequenceKey (org.apache.phoenix.schema.SequenceKey)1 SequenceNotFoundException (org.apache.phoenix.schema.SequenceNotFoundException)1 Test (org.junit.Test)1