public boolean isPrimitiveType() { return this.baseType.getCodec() != null; }
protected PDataCodec getKeyRangeCodec(PDataType columnDataType) { return columnDataType.getCodec(); }
public CurrentDateFunction(long timeStamp) { getDataType().getCodec().encodeLong(timeStamp, currentDate); }
public CurrentTimeFunction(long timeStamp) { getDataType().getCodec().encodeLong(timeStamp, currentDate); }
@Override public void aggregate(Tuple tuple, ImmutableBytesWritable ptr) { double value = getInputDataType().getCodec().decodeDouble(ptr, sortOrder); sum += value; if (buffer == null) { initBuffer(); } }
@Override public void aggregate(Tuple tuple, ImmutableBytesWritable ptr) { // Get either IntNative or LongNative depending on input type long value = getInputDataType().getCodec().decodeLong(ptr, sortOrder); sum += value; if (buffer == null) { initBuffer(); } }
@NotNull public static PDataCodec getCodecFor(PDataType type) { PDataCodec codec = type.getCodec(); if (codec != null) { return codec; } if (type == PTimestamp.INSTANCE) { return PDate.INSTANCE.getCodec(); } else if (type == PUnsignedTimestamp.INSTANCE) { return PUnsignedDate.INSTANCE.getCodec(); } else { throw new RuntimeException(TypeMismatchException.newException(PTimestamp.INSTANCE, type)); } }
/** * Returns viewIndexId based on its underlying data type * * @param viewIndexIdKv * @param viewIndexIdType * @return */ private Long decodeViewIndexId(Cell viewIndexIdKv, PDataType viewIndexIdType) { return viewIndexIdType.getCodec().decodeLong(viewIndexIdKv.getValueArray(), viewIndexIdKv.getValueOffset(), SortOrder.getDefault()); }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { long finalResult=0; for(int i=0;i<children.size();i++) { Expression child = children.get(i); if (!child.evaluate(tuple, ptr) || ptr.getLength() == 0) { return false; } long childvalue = child.getDataType().getCodec().decodeLong(ptr, child.getSortOrder()); finalResult += childvalue; } byte[] resultPtr=new byte[PLong.INSTANCE.getByteSize()]; getDataType().getCodec().encodeLong(finalResult, resultPtr, 0); ptr.set(resultPtr); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (children.get(0).evaluate(tuple, ptr)) { if (ptr.getLength() == 0) { return true; // child evaluated to null } PDataType dataType = getDataType(); long time = dataType.getCodec().decodeLong(ptr, children.get(0).getSortOrder()); long value = roundTime(time); Date d = new Date(value); byte[] byteValue = dataType.toBytes(d); ptr.set(byteValue); return true; } return false; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (children.get(0).evaluate(tuple, ptr)) { if (ptr.getLength() == 0) { return true; // child evaluated to null } PDataType dataType = getDataType(); long time = dataType.getCodec().decodeLong(ptr, children.get(0).getSortOrder()); DateTime dt = new DateTime(time,ISOChronology.getInstanceUTC()); long value = roundDateTime(dt); Date d = new Date(value); byte[] byteValue = dataType.toBytes(d); ptr.set(byteValue); return true; } return false; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (buffer == null) { if (isNullable()) { return false; } initBuffer(); } getDataType().getCodec().encodeDouble(sum, buffer, 0); ptr.set(buffer); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (buffer == null) { if (isNullable()) { return false; } initBuffer(); } getDataType().getCodec().encodeLong(sum, buffer, 0); ptr.set(buffer); return true; }
static double getArg(Expression exp, ImmutableBytesWritable ptr) { if (exp.getDataType() == PDecimal.INSTANCE) { return ((BigDecimal) exp.getDataType().toObject(ptr, exp.getSortOrder())).doubleValue(); } else { return exp.getDataType().getCodec().decodeDouble(ptr, exp.getSortOrder()); } }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (buffer == null) { buffer = new byte[getDataType().getByteSize()]; } getDataType().getCodec().encodeLong(count, buffer, 0); ptr.set(buffer); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { PDataType returnType = getDataType(); Expression arg1Expr = children.get(0); if (!arg1Expr.evaluate(tuple, ptr)) return false; if (ptr.getLength() == 0) return true; double arg1 = getArg(arg1Expr, ptr); ptr.set(new byte[returnType.getByteSize()]); returnType.getCodec().encodeDouble(compute(arg1), ptr); return true; }
@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 expression = getChildExpression(); if (!expression.evaluate(tuple, ptr)) { return false; } if ( ptr.getLength() == 0) { return true; //means null } long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder()); int hour = (int)(((dateTime/1000) % (24*3600))/3600); PDataType returnType = getDataType(); byte[] byteValue = new byte[returnType.getByteSize()]; returnType.getCodec().encodeInt(hour, byteValue, 0); ptr.set(byteValue); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { Expression expression = getChildExpression(); if (!expression.evaluate(tuple, ptr)) { return false; } if ( ptr.getLength() == 0) { return true; //means null } long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder()); int sec = (int)((dateTime/1000) % 60); PDataType returnType = getDataType(); byte[] byteValue = new byte[returnType.getByteSize()]; returnType.getCodec().encodeInt(sec, byteValue, 0); ptr.set(byteValue); return true; }