@Override public Object toObject(Object object, PDataType actualType) { Long v = (Long) PLong.INSTANCE.toObject(object, actualType); throwIfNonNegativeNumber(v); return v; }
@Override public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { Long v = (Long) PLong.INSTANCE.toObject(b, o, l, actualType, sortOrder); throwIfNonNegativeNumber(v); return v; }
@Override public Object toObject(Object object, PDataType actualType) { Object o = PLong.INSTANCE.toObject(object, actualType); if (!(o instanceof Long) || o == null) { return o; } long l = (Long)o; if (l < Short.MIN_VALUE || l > Short.MAX_VALUE) { throw newIllegalDataException(actualType + " value " + l + " cannot be cast to Short without changing its value"); } short s = (short)l; return s; }
@Override public Object toObject(Object object, PDataType actualType) { Object o = PLong.INSTANCE.toObject(object, actualType); if (!(o instanceof Long) || o == null) { return o; } long l = (Long) o; if (l < Byte.MIN_VALUE || l > Byte.MAX_VALUE) { throw newIllegalDataException( actualType + " value " + l + " cannot be cast to Byte without changing its value"); } return (byte) l; }
@Override public Object toObject(Object object, PDataType actualType) { Object o = PLong.INSTANCE.toObject(object, actualType); if (!(o instanceof Long) || o == null) { return o; } long l = (Long) o; if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) { throw newIllegalDataException( actualType + " value " + l + " cannot be cast to Integer without changing its value"); } int v = (int) l; return v; }
private long nextValueFor(long startWith, long incrementBy) { long hstartWith = Bytes.toLong(PLong.INSTANCE.toBytes(startWith)); hstartWith += incrementBy; return (Long) PLong.INSTANCE.toObject(Bytes.toBytes(hstartWith)); }
private long evalExpression(CreateSequenceStatement sequence, StatementContext context, Expression expression, SQLExceptionCode code) throws SQLException { ImmutableBytesWritable ptr = context.getTempPtr(); expression.evaluate(null, ptr); if (ptr.getLength() == 0 || !expression.getDataType().isCoercibleTo(PLong.INSTANCE)) { TableName sequenceName = sequence.getSequenceName(); throw SequenceUtil.getException(sequenceName.getSchemaName(), sequenceName.getTableName(), code); } return (Long) PLong.INSTANCE.toObject(ptr, expression.getDataType()); }
Long la = 4L; byte[] b = PLong.INSTANCE.toBytes(la); Long lb = (Long) PLong.INSTANCE.toObject(b); assertEquals(la,lb); Object obj = PLong.INSTANCE.toObject(value, PInteger.INSTANCE); assertTrue(obj instanceof Long); assertEquals(100, ((Long)obj).longValue()); Object longObj = PLong.INSTANCE.toObject(longValue, PLong.INSTANCE); assertTrue(longObj instanceof Long); assertEquals(100, ((Long)longObj).longValue()); Object lo = PLong.INSTANCE.toObject(d, PDouble.INSTANCE); assertEquals(-2L, ((Long)lo).longValue()); lo = PLong.INSTANCE.toObject(bytes,0, bytes.length, PDouble.INSTANCE); assertEquals(-2L, ((Long)lo).longValue()); lo = PLong.INSTANCE.toObject(f, PFloat.INSTANCE); assertEquals(-2L, ((Long)lo).longValue()); lo = PLong.INSTANCE.toObject(bytes,0, bytes.length, PFloat.INSTANCE); assertEquals(-2L, ((Long)lo).longValue());
long newDisableTimeStamp = 0; if ((currentDisableTimeStamp != null && currentDisableTimeStamp.getValueLength() > 0)) { curTimeStampVal = (Long) PLong.INSTANCE.toObject(currentDisableTimeStamp.getValueArray(), currentDisableTimeStamp.getValueOffset(), currentDisableTimeStamp.getValueLength()); return; newDisableTimeStamp = (Long) PLong.INSTANCE.toObject(newDisableTimeStampCell.getValueArray(), newDisableTimeStampCell.getValueOffset(), newDisableTimeStampCell.getValueLength());
@Override public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { Long v = (Long) PLong.INSTANCE.toObject(b, o, l, actualType, sortOrder); throwIfNonNegativeNumber(v); return v; }
@Override public Object toObject(Object object, PDataType actualType) { Long v = (Long) PLong.INSTANCE.toObject(object, actualType); throwIfNonNegativeNumber(v); return v; }
@Override public Object toObject(Object object, PDataType actualType) { Object o = PLong.INSTANCE.toObject(object, actualType); if (!(o instanceof Long) || o == null) { return o; } long l = (Long)o; if (l < Short.MIN_VALUE || l > Short.MAX_VALUE) { throw newIllegalDataException(actualType + " value " + l + " cannot be cast to Short without changing its value"); } short s = (short)l; return s; }
@Override public Object toObject(Object object, PDataType actualType) { Long v = (Long) PLong.INSTANCE.toObject(object, actualType); throwIfNonNegativeNumber(v); return v; }
@Override public Object toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { Long v = (Long) PLong.INSTANCE.toObject(b, o, l, actualType, sortOrder); throwIfNonNegativeNumber(v); return v; }
@Override public Object toObject(Object object, PDataType actualType) { Object o = PLong.INSTANCE.toObject(object, actualType); if (!(o instanceof Long) || o == null) { return o; } long l = (Long) o; if (l < Byte.MIN_VALUE || l > Byte.MAX_VALUE) { throw newIllegalDataException( actualType + " value " + l + " cannot be cast to Byte without changing its value"); } return (byte) l; }
@Test public void testLongArrayWithIndex() { Long[] longArr = new Long[4]; longArr[0] = 1l; longArr[1] = 2l; longArr[2] = 4l; longArr[3] = 5l; PhoenixArray arr = PArrayDataType.instantiatePhoenixArray( PLong.INSTANCE, longArr); PLongArray.INSTANCE.toObject(arr, PLongArray.INSTANCE); byte[] bytes = PLongArray.INSTANCE.toBytes(arr); ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes); PArrayDataTypeDecoder.positionAtArrayElement(ptr, 2, PLong.INSTANCE, PLong.INSTANCE.getByteSize()); int offset = ptr.getOffset(); int length = ptr.getLength(); byte[] bs = ptr.get(); byte[] res = new byte[length]; System.arraycopy(bs, offset, res, 0, length); long result = (Long) PLong.INSTANCE.toObject(res); assertEquals(4l, result); }
long numToAllocate = (long) PLong.INSTANCE.toObject(ptr, expression.getDataType()); if (numToAllocate < 1) { throw SequenceUtil.getException(sequenceName.getSchemaName(), sequenceName.getTableName(), SQLExceptionCode.NUM_SEQ_TO_ALLOCATE_MUST_BE_CONSTANT);
false, PNameFactory.newName("9223372036854775806"), PLong.INSTANCE.toBytes(PLong.INSTANCE.toObject("9223372036854775806")) });
private long evalExpression(CreateSequenceStatement sequence, StatementContext context, Expression expression, SQLExceptionCode code) throws SQLException { ImmutableBytesWritable ptr = context.getTempPtr(); expression.evaluate(null, ptr); if (ptr.getLength() == 0 || !expression.getDataType().isCoercibleTo(PLong.INSTANCE)) { TableName sequenceName = sequence.getSequenceName(); throw SequenceUtil.getException(sequenceName.getSchemaName(), sequenceName.getTableName(), code); } return (Long) PLong.INSTANCE.toObject(ptr, expression.getDataType()); }
private long evalExpression(CreateSequenceStatement sequence, StatementContext context, Expression expression, SQLExceptionCode code) throws SQLException { ImmutableBytesWritable ptr = context.getTempPtr(); expression.evaluate(null, ptr); if (ptr.getLength() == 0 || !expression.getDataType().isCoercibleTo(PLong.INSTANCE)) { TableName sequenceName = sequence.getSequenceName(); throw SequenceUtil.getException(sequenceName.getSchemaName(), sequenceName.getTableName(), code); } return (Long) PLong.INSTANCE.toObject(ptr, expression.getDataType()); }