Java Code Examples for org.apache.phoenix.exception.SQLExceptionCode#fromErrorCode()

The following examples show how to use org.apache.phoenix.exception.SQLExceptionCode#fromErrorCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerUtil.java    From phoenix with Apache License 2.0 6 votes vote down vote up
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;
            try {
                code = SQLExceptionCode.fromErrorCode(statusCode);
            } catch (SQLException e) {
                return e;
            }
            return new SQLExceptionInfo.Builder(code).setMessage(matcher.group()).build().buildException();
        }
    	}
    return null;
}
 
Example 2
Source File: Sequence.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public long incrementValue(Result result, ValueOp op) throws SQLException {
    // In this case, we don't definitely know the timestamp of the deleted sequence,
    // but we know anything older is likely deleted. Worse case, we remove a sequence
    // from the cache that we shouldn't have which will cause a gap in sequence values.
    // In that case, we might get an error that a curr value was done on a sequence
    // 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);
        // TODO: We could have the server return the timestamps of the
        // delete markers and we could insert them here, but this seems
        // like overkill.
        // if (code == SQLExceptionCode.SEQUENCE_UNDEFINED) {
        // }
        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);
    insertSequenceValue(value);
    return increment(value, op);
}
 
Example 3
Source File: Sequence.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public boolean returnValue(Result result) throws SQLException {
    Cell statusKV = result.rawCells()[0];
    if (statusKV.getValueLength() == 0) { // No error, but unable to return sequence values
        return false;
    }
    long timestamp = statusKV.getTimestamp();
    int statusCode = PInteger.INSTANCE.getCodec().decodeInt(statusKV.getValueArray(), statusKV.getValueOffset(), SortOrder.getDefault());
    if (statusCode == SUCCESS) {  // Success - update nextValue down to currentValue
        SequenceValue value = findSequenceValue(timestamp);
        if (value == null) {
            throw new EmptySequenceCacheException(key.getSchemaName(),key.getSequenceName());
        }
        return true;
    }
    SQLExceptionCode code = SQLExceptionCode.fromErrorCode(statusCode);
    // TODO: We could have the server return the timestamps of the
    // delete markers and we could insert them here, but this seems
    // like overkill.
    // if (code == SQLExceptionCode.SEQUENCE_UNDEFINED) {
    // }
    throw new SQLExceptionInfo.Builder(code)
        .setSchemaName(key.getSchemaName())
        .setTableName(key.getSequenceName())
        .build().buildException();
}
 
Example 4
Source File: Sequence.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public long dropSequence(Result result) throws SQLException {
    Cell statusKV = result.rawCells()[0];
    long timestamp = statusKV.getTimestamp();
    int statusCode = PInteger.INSTANCE.getCodec().decodeInt(statusKV.getValueArray(), statusKV.getValueOffset(), SortOrder.getDefault());
    SQLExceptionCode code = statusCode == 0 ? null : SQLExceptionCode.fromErrorCode(statusCode);
    if (code == null) {
        // Insert delete marker so that point-in-time sequences work
        insertSequenceValue(new SequenceValue(timestamp, true));
        return timestamp;
    }
    // TODO: We could have the server return the timestamps of the
    // delete markers and we could insert them here, but this seems
    // like overkill.
    // if (code == SQLExceptionCode.SEQUENCE_UNDEFINED) {
    // }
    throw new SQLExceptionInfo.Builder(code)
        .setSchemaName(key.getSchemaName())
        .setTableName(key.getSequenceName())
        .build().buildException();
}
 
Example 5
Source File: ServerUtil.java    From phoenix with Apache License 2.0 6 votes vote down vote up
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);
            if(code.equals(SQLExceptionCode.HASH_JOIN_CACHE_NOT_FOUND)){
                Matcher m = HASH_JOIN_EXCEPTION_PATTERN.matcher(t.getLocalizedMessage());
                if (m.find()) { return new HashJoinCacheNotFoundException(Long.parseLong(m.group(1))); }
            }
            return new SQLExceptionInfo.Builder(code).setMessage(matcher.group()).setRootCause(t).build().buildException();
        }
    }
    return null;
}
 
Example 6
Source File: Sequence.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public long incrementValue(Result result, ValueOp op, long numToAllocate) throws SQLException {
    // In this case, we don't definitely know the timestamp of the deleted sequence,
    // but we know anything older is likely deleted. Worse case, we remove a sequence
    // from the cache that we shouldn't have which will cause a gap in sequence values.
    // In that case, we might get an error that a curr value was done on a sequence
    // 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);
        // TODO: We could have the server return the timestamps of the
        // delete markers and we could insert them here, but this seems
        // like overkill.
        // if (code == SQLExceptionCode.SEQUENCE_UNDEFINED) {
        // }
        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);
}
 
Example 7
Source File: Sequence.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public boolean returnValue(Result result) throws SQLException {
    Cell statusKV = result.rawCells()[0];
    if (statusKV.getValueLength() == 0) { // No error, but unable to return sequence values
        return false;
    }
    long timestamp = statusKV.getTimestamp();
    int statusCode = PInteger.INSTANCE.getCodec().decodeInt(statusKV.getValueArray(), statusKV.getValueOffset(), SortOrder.getDefault());
    if (statusCode == SUCCESS) {  // Success - update nextValue down to currentValue
        SequenceValue value = findSequenceValue(timestamp);
        if (value == null) {
            throw new EmptySequenceCacheException(key.getSchemaName(),key.getSequenceName());
        }
        return true;
    }
    SQLExceptionCode code = SQLExceptionCode.fromErrorCode(statusCode);
    // TODO: We could have the server return the timestamps of the
    // delete markers and we could insert them here, but this seems
    // like overkill.
    // if (code == SQLExceptionCode.SEQUENCE_UNDEFINED) {
    // }
    throw new SQLExceptionInfo.Builder(code)
        .setSchemaName(key.getSchemaName())
        .setTableName(key.getSequenceName())
        .build().buildException();
}
 
Example 8
Source File: Sequence.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public long dropSequence(Result result) throws SQLException {
    Cell statusKV = result.rawCells()[0];
    long timestamp = statusKV.getTimestamp();
    int statusCode = PInteger.INSTANCE.getCodec().decodeInt(statusKV.getValueArray(), statusKV.getValueOffset(), SortOrder.getDefault());
    SQLExceptionCode code = statusCode == 0 ? null : SQLExceptionCode.fromErrorCode(statusCode);
    if (code == null) {
        // Insert delete marker so that point-in-time sequences work
        insertSequenceValue(new SequenceValue(timestamp, true));
        return timestamp;
    }
    // TODO: We could have the server return the timestamps of the
    // delete markers and we could insert them here, but this seems
    // like overkill.
    // if (code == SQLExceptionCode.SEQUENCE_UNDEFINED) {
    // }
    throw new SQLExceptionInfo.Builder(code)
        .setSchemaName(key.getSchemaName())
        .setTableName(key.getSequenceName())
        .build().buildException();
}
 
Example 9
Source File: Sequence.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public long createSequence(Result result, long minValue, long maxValue, boolean cycle) throws SQLException {
    Cell statusKV = result.rawCells()[0];
    long timestamp = statusKV.getTimestamp();
    int statusCode = PInteger.INSTANCE.getCodec().decodeInt(statusKV.getValueArray(), statusKV.getValueOffset(), SortOrder.getDefault());
    if (statusCode == 0) {  // Success - add sequence value and return timestamp
        SequenceValue value = new SequenceValue(timestamp, minValue, maxValue, cycle);
        insertSequenceValue(value);
        return timestamp;
    }
    SQLExceptionCode code = SQLExceptionCode.fromErrorCode(statusCode);
    throw new SQLExceptionInfo.Builder(code)
        .setSchemaName(key.getSchemaName())
        .setTableName(key.getSequenceName())
        .build().buildException();
}
 
Example 10
Source File: Sequence.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public long createSequence(Result result, long minValue, long maxValue, boolean cycle) throws SQLException {
    Cell statusKV = result.rawCells()[0];
    long timestamp = statusKV.getTimestamp();
    int statusCode = PInteger.INSTANCE.getCodec().decodeInt(statusKV.getValueArray(), statusKV.getValueOffset(), SortOrder.getDefault());
    if (statusCode == 0) {  // Success - add sequence value and return timestamp
        SequenceValue value = new SequenceValue(timestamp, minValue, maxValue, cycle);
        insertSequenceValue(value);
        return timestamp;
    }
    SQLExceptionCode code = SQLExceptionCode.fromErrorCode(statusCode);
    throw new SQLExceptionInfo.Builder(code)
        .setSchemaName(key.getSchemaName())
        .setTableName(key.getSequenceName())
        .build().buildException();
}
 
Example 11
Source File: SchemaUtilTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Test
public void testExceptionCode() throws Exception {
    SQLExceptionCode code = SQLExceptionCode.fromErrorCode(SQLExceptionCode.AGGREGATE_IN_GROUP_BY.getErrorCode());
    assertEquals(SQLExceptionCode.AGGREGATE_IN_GROUP_BY, code);
}
 
Example 12
Source File: SchemaUtilTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Test
public void testExceptionCode() throws Exception {
    SQLExceptionCode code = SQLExceptionCode.fromErrorCode(SQLExceptionCode.AGGREGATE_IN_GROUP_BY.getErrorCode());
    assertEquals(SQLExceptionCode.AGGREGATE_IN_GROUP_BY, code);
}