@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { Expression child = children.get(0); if (!child.evaluate(tuple, ptr)) { return false; } if (ptr.getLength() == 0) { return true; } int code = PTinyint.INSTANCE.getCodec().decodeByte(ptr, child.getSortOrder()); TransactionFactory.Provider provider = TransactionFactory.Provider.fromCode(code); ptr.set(PVarchar.INSTANCE.toBytes(provider.name())); return true; }
PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) { return BigDecimal.valueOf(actualType.getCodec().decodeLong(b, o, sortOrder)); } else if (equalsAny(actualType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE)) { return BigDecimal.valueOf(actualType.getCodec().decodeFloat(b, o, sortOrder)); } else if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) { return BigDecimal.valueOf(actualType.getCodec().decodeDouble(b, o, sortOrder)); } else if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) { long millisPart = DateUtil.getCodecFor(actualType).decodeLong(b, o, sortOrder); int nanoPart = PUnsignedInt.INSTANCE.getCodec().decodeInt(b, o + Bytes.SIZEOF_LONG, sortOrder); BigDecimal nanosPart = BigDecimal.valueOf( (nanoPart % QueryConstants.MILLIS_TO_NANOS_CONVERTOR)
@Test public void testAllShortValues() throws Exception { int curr = Short.MIN_VALUE; List<Expression> children = Lists.newArrayListWithExpectedSize(1); List<Integer> failedValues = Lists.newArrayList(); while (curr <= Short.MAX_VALUE) { children.add(LiteralExpression.newConstant(curr, PSmallint.INSTANCE)); ImmutableBytesPtr ptr = evaluate(children); ColumnValueDecoder decoder = immutableStorageScheme.getDecoder(); assertTrue(decoder.decode(ptr, 0)); if (ptr.getLength() == 0) { failedValues.add(curr); } else { if (curr != PSmallint.INSTANCE.getCodec().decodeShort(ptr.copyBytesIfNecessary(), 0, SortOrder.ASC)) { failedValues.add(curr); } } children.remove(0); curr++; } // in v1, we can't distinguish a null from two short values if (serializationVersion == IMMUTABLE_SERIALIZATION_VERSION) { assertTrue(failedValues.size() + " values were not properly decoded: " + failedValues, failedValues.size() == 2); } else { assertTrue(failedValues.size() + " values were not properly decoded: " + failedValues, failedValues.size() == 0); } }
Cell tableSeqNumKv = tableKeyValues[TABLE_SEQ_NUM_INDEX]; long tableSeqNum = PLong.INSTANCE.getCodec().decodeLong(tableSeqNumKv.getValueArray(), tableSeqNumKv.getValueOffset(), SortOrder.getDefault()); Cell columnCountKv = tableKeyValues[COLUMN_COUNT_INDEX]; int columnCount = PInteger.INSTANCE.getCodec().decodeInt(columnCountKv.getValueArray(), columnCountKv.getValueOffset(), SortOrder.getDefault()); Cell pkNameKv = tableKeyValues[PK_NAME_INDEX]; Cell saltBucketNumKv = tableKeyValues[SALT_BUCKETS_INDEX]; Integer saltBucketNum = saltBucketNumKv != null ? (Integer) PInteger.INSTANCE.getCodec().decodeInt( saltBucketNumKv.getValueArray(), saltBucketNumKv.getValueOffset(), SortOrder.getDefault()) : null; if (saltBucketNum != null && saltBucketNum.intValue() == 0) { PTinyint.INSTANCE.getCodec().decodeByte( transactionProviderKv.getValueArray(), transactionProviderKv.getValueOffset(), IndexType indexType = indexTypeKv == null ? null : IndexType.fromSerializedValue(indexTypeKv.getValueArray()[indexTypeKv.getValueOffset()]); Cell baseColumnCountKv = tableKeyValues[BASE_COLUMN_COUNT_INDEX]; int baseColumnCount = baseColumnCountKv == null ? 0 : PInteger.INSTANCE.getCodec().decodeInt(baseColumnCountKv.getValueArray(), baseColumnCountKv.getValueOffset(), SortOrder.getDefault()); Cell rowKeyOrderOptimizableKv = tableKeyValues[ROW_KEY_ORDER_OPTIMIZABLE_INDEX]; Cell updateCacheFrequencyKv = tableKeyValues[UPDATE_CACHE_FREQUENCY_INDEX]; long updateCacheFrequency = updateCacheFrequencyKv == null ? 0 : PLong.INSTANCE.getCodec().decodeLong(updateCacheFrequencyKv.getValueArray(),
Cell tableSeqNumKv = tableKeyValues[TABLE_SEQ_NUM_INDEX]; long tableSeqNum = PLong.INSTANCE.getCodec().decodeLong(tableSeqNumKv.getValueArray(), tableSeqNumKv.getValueOffset(), SortOrder.getDefault()); Cell columnCountKv = tableKeyValues[COLUMN_COUNT_INDEX]; int columnCount = PInteger.INSTANCE.getCodec().decodeInt(columnCountKv.getValueArray(), columnCountKv.getValueOffset(), SortOrder.getDefault()); Cell pkNameKv = tableKeyValues[PK_NAME_INDEX]; Cell saltBucketNumKv = tableKeyValues[SALT_BUCKETS_INDEX]; Integer saltBucketNum = saltBucketNumKv != null ? (Integer) PInteger.INSTANCE.getCodec().decodeInt( saltBucketNumKv.getValueArray(), saltBucketNumKv.getValueOffset(), SortOrder.getDefault()) : null; if (saltBucketNum != null && saltBucketNum.intValue() == 0) { PTinyint.INSTANCE.getCodec().decodeByte( transactionProviderKv.getValueArray(), transactionProviderKv.getValueOffset(), ViewType viewType = viewTypeKv == null ? null : ViewType.fromSerializedValue(viewTypeKv.getValueArray()[viewTypeKv.getValueOffset()]); Cell viewIndexIdKv = tableKeyValues[VIEW_INDEX_ID_INDEX]; Short viewIndexId = viewIndexIdKv == null ? null : (Short)MetaDataUtil.getViewIndexIdDataType().getCodec().decodeShort(viewIndexIdKv.getValueArray(), viewIndexIdKv.getValueOffset(), SortOrder.getDefault()); Cell indexTypeKv = tableKeyValues[INDEX_TYPE_INDEX]; IndexType indexType = indexTypeKv == null ? null : IndexType.fromSerializedValue(indexTypeKv.getValueArray()[indexTypeKv.getValueOffset()]); Cell baseColumnCountKv = tableKeyValues[BASE_COLUMN_COUNT_INDEX]; int baseColumnCount = baseColumnCountKv == null ? 0 : PInteger.INSTANCE.getCodec().decodeInt(baseColumnCountKv.getValueArray(), baseColumnCountKv.getValueOffset(), SortOrder.getDefault()); Cell rowKeyOrderOptimizableKv = tableKeyValues[ROW_KEY_ORDER_OPTIMIZABLE_INDEX];
return Longs.compare(this.getCodec().decodeLong(lhs, lhsOffset, lhsSortOrder), rhsType.getCodec() .decodeLong(rhs, rhsOffset, rhsSortOrder)); } else if (isDoubleOrFloat(this) && isDoubleOrFloat(rhsType)) { // native double to double comparison return Doubles.compare(this.getCodec().decodeDouble(lhs, lhsOffset, lhsSortOrder), rhsType.getCodec() .decodeDouble(rhs, rhsOffset, rhsSortOrder)); } else { // native float/double to long comparison float fvalue = 0.0F; lvalue = this.getCodec().decodeLong(lhs, lhsOffset, lhsSortOrder); } else if (this.getClass() == PFloat.class) { isFloat = true; fvalue = this.getCodec().decodeFloat(lhs, lhsOffset, lhsSortOrder); } else if (this.isCoercibleTo(PDouble.INSTANCE)) { dvalue = this.getCodec().decodeDouble(lhs, lhsOffset, lhsSortOrder); lvalue = rhsType.getCodec().decodeLong(rhs, rhsOffset, rhsSortOrder); } else if (rhsType == PFloat.INSTANCE) { invert = -1; isFloat = true; fvalue = rhsType.getCodec().decodeFloat(rhs, rhsOffset, rhsSortOrder); } else if (rhsType.isCoercibleTo(PDouble.INSTANCE)) { invert = -1; dvalue = rhsType.getCodec().decodeDouble(rhs, rhsOffset, rhsSortOrder);
return Longs.compare(this.getCodec().decodeLong(lhs, lhsOffset, lhsSortOrder), rhsType.getCodec() .decodeLong(rhs, rhsOffset, rhsSortOrder)); } else if (isDoubleOrFloat(this) && isDoubleOrFloat(rhsType)) { // native double to double comparison return Doubles.compare(this.getCodec().decodeDouble(lhs, lhsOffset, lhsSortOrder), rhsType.getCodec() .decodeDouble(rhs, rhsOffset, rhsSortOrder)); } else { // native float/double to long comparison float fvalue = 0.0F; lvalue = this.getCodec().decodeLong(lhs, lhsOffset, lhsSortOrder); } else if (this.getClass() == PFloat.class) { isFloat = true; fvalue = this.getCodec().decodeFloat(lhs, lhsOffset, lhsSortOrder); } else if (this.isCoercibleTo(PDouble.INSTANCE)) { dvalue = this.getCodec().decodeDouble(lhs, lhsOffset, lhsSortOrder); lvalue = rhsType.getCodec().decodeLong(rhs, rhsOffset, rhsSortOrder); } else if (rhsType == PFloat.INSTANCE) { invert = -1; isFloat = true; fvalue = rhsType.getCodec().decodeFloat(rhs, rhsOffset, rhsSortOrder); } else if (rhsType.isCoercibleTo(PDouble.INSTANCE)) { invert = -1; dvalue = rhsType.getCodec().decodeDouble(rhs, rhsOffset, rhsSortOrder);
PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) { return BigDecimal.valueOf(actualType.getCodec().decodeLong(b, o, sortOrder)); } else if (equalsAny(actualType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE)) { return BigDecimal.valueOf(actualType.getCodec().decodeFloat(b, o, sortOrder)); } else if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) { return BigDecimal.valueOf(actualType.getCodec().decodeDouble(b, o, sortOrder)); } else if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) { long millisPart = DateUtil.getCodecFor(actualType).decodeLong(b, o, sortOrder); int nanoPart = PUnsignedInt.INSTANCE.getCodec().decodeInt(b, o + Bytes.SIZEOF_LONG, sortOrder); BigDecimal nanosPart = BigDecimal.valueOf( (nanoPart % QueryConstants.MILLIS_TO_NANOS_CONVERTOR)
PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) { return BigDecimal.valueOf(actualType.getCodec().decodeLong(b, o, sortOrder)); } else if (equalsAny(actualType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE)) { return BigDecimal.valueOf(actualType.getCodec().decodeFloat(b, o, sortOrder)); } else if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) { return BigDecimal.valueOf(actualType.getCodec().decodeDouble(b, o, sortOrder)); } else if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) { long millisPart = DateUtil.getCodecFor(actualType).decodeLong(b, o, sortOrder); int nanoPart = PUnsignedInt.INSTANCE.getCodec().decodeInt(b, o + Bytes.SIZEOF_LONG, sortOrder); BigDecimal nanosPart = BigDecimal.valueOf( (nanoPart % QueryConstants.MILLIS_TO_NANOS_CONVERTOR)
@Override public Byte toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { if (l == 0) { return null; } if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE, PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) { return actualType.getCodec().decodeByte(b, o, sortOrder); } else if (actualType == PDecimal.INSTANCE) { BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder); return bd.byteValueExact(); } throwConstraintViolationException(actualType, this); return null; }
@Override public Byte toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { if (l == 0) { return null; } if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE, PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) { return actualType.getCodec().decodeByte(b, o, sortOrder); } else if (actualType == PDecimal.INSTANCE) { BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder); return bd.byteValueExact(); } throwConstraintViolationException(actualType, this); return null; }
@Override public Short toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { if (l == 0) { return null; } if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE, PUnsignedInt.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) { return actualType.getCodec().decodeShort(b, o, sortOrder); } else if (actualType == PDecimal.INSTANCE) { BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder); return bd.shortValueExact(); } throwConstraintViolationException(actualType,this); return null; }
@Override public Float toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { if (l <= 0) { return null; } if (equalsAny(actualType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE, PUnsignedDouble.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE, PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) { return actualType.getCodec().decodeFloat(b, o, sortOrder); } else if (actualType == PDecimal.INSTANCE) { BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder); return bd.floatValue(); } throwConstraintViolationException(actualType, this); return null; }
@Override public Float toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { if (l <= 0) { return null; } if (equalsAny(actualType, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE, PUnsignedDouble.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE, PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) { return actualType.getCodec().decodeFloat(b, o, sortOrder); } else if (actualType == PDecimal.INSTANCE) { BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder); return bd.floatValue(); } throwConstraintViolationException(actualType, this); return null; }
@Override public Short toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { if (l == 0) { return null; } if (equalsAny(actualType, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE, PUnsignedInt.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) { return actualType.getCodec().decodeShort(b, o, sortOrder); } else if (actualType == PDecimal.INSTANCE) { BigDecimal bd = (BigDecimal)actualType.toObject(b, o, l, actualType, sortOrder); return bd.shortValueExact(); } throwConstraintViolationException(actualType,this); return null; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { Expression child = children.get(0); if (!child.evaluate(tuple, ptr)) { return false; } if (ptr.getLength() == 0) { return true; } int code = PTinyint.INSTANCE.getCodec().decodeByte(ptr, child.getSortOrder()); TransactionFactory.Provider provider = TransactionFactory.Provider.fromCode(code); ptr.set(PVarchar.INSTANCE.toBytes(provider.name())); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { Expression child = children.get(0); if (!child.evaluate(tuple, ptr)) { return false; } if (ptr.getLength() == 0) { return true; } int code = PTinyint.INSTANCE.getCodec().decodeByte(ptr, child.getSortOrder()); TransactionFactory.Provider provider = TransactionFactory.Provider.fromCode(code); ptr.set(PVarchar.INSTANCE.toBytes(provider.name())); return true; }
public static LinkType getLinkType(Mutation tableMutation) { List<Cell> kvs = tableMutation.getFamilyCellMap().get(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES); if (kvs != null) { for (Cell kv : kvs) { if (Bytes.compareTo(kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength(), PhoenixDatabaseMetaData.LINK_TYPE_BYTES, 0, PhoenixDatabaseMetaData.LINK_TYPE_BYTES.length) == 0) { return LinkType .fromSerializedValue(PUnsignedTinyint.INSTANCE.getCodec().decodeByte(kv.getValueArray(), kv.getValueOffset(), SortOrder.getDefault())); } } } return null; }
@Override public int toBytes(Object object, byte[] bytes, int offset) { if (object == null) { throw newIllegalDataException(this + " may not be null"); } return this.getCodec().encodeFloat(((Number) object).floatValue(), bytes, offset); }
@Override public int toBytes(Object object, byte[] bytes, int offset) { if (object == null) { throw newIllegalDataException(this + " may not be null"); } return this.getCodec().encodeByte(((Number) object).byteValue(), bytes, offset); }