Example #1
0
 /**
  * Imperfect estimate of row size given a PTable TODO: keep row count in stats table and use total
  * size / row count instead
  *
  * @param table
  * @return estimate of size in bytes of a row
  */
 public static long estimateRowSize(PTable table) {
   int keyLength = estimateKeyLength(table);
   long rowSize = 0;
   for (PColumn column : table.getColumns()) {
     if (!SchemaUtil.isPKColumn(column)) {
       PDataType type = column.getDataType();
       Integer maxLength = column.getMaxLength();
       int valueLength =
           !type.isFixedWidth()
               ? VAR_KV_LENGTH_ESTIMATE
               : maxLength == null ? type.getByteSize() : maxLength;
       rowSize +=
           KeyValue.getKeyValueDataStructureSize(
               keyLength,
               column.getFamilyName().getBytes().length,
               column.getName().getBytes().length,
               valueLength);
     }
   }
   // Empty key value
   rowSize +=
       KeyValue.getKeyValueDataStructureSize(
           keyLength,
           getEmptyColumnFamily(table).length,
           QueryConstants.EMPTY_COLUMN_BYTES.length,
           0);
   return rowSize;
 }
Example #2
0
 /**
  * Estimate the max key length in bytes of the PK for a given table
  *
  * @param table the table
  * @return the max PK length
  */
 public static int estimateKeyLength(PTable table) {
   int maxKeyLength = 0;
   // Calculate the max length of a key (each part must currently be of a fixed width)
   int i = 0;
   List<PColumn> columns = table.getPKColumns();
   while (i < columns.size()) {
     PColumn keyColumn = columns.get(i++);
     PDataType type = keyColumn.getDataType();
     Integer maxLength = keyColumn.getMaxLength();
     maxKeyLength +=
         !type.isFixedWidth()
             ? VAR_LENGTH_ESTIMATE
             : maxLength == null ? type.getByteSize() : maxLength;
   }
   return maxKeyLength;
 }
 @Override
 public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
   Expression arg = getChildren().get(0);
   if (!arg.evaluate(tuple, ptr)) {
     return false;
   }
   if (ptr.getLength() == 0) {
     return true;
   }
   long dateTime = inputCodec.decodeLong(ptr, arg.getSortOrder());
   DateTime jodaDT = new DateTime(dateTime);
   int day = jodaDT.getDayOfYear();
   PDataType returnDataType = getDataType();
   byte[] byteValue = new byte[returnDataType.getByteSize()];
   returnDataType.getCodec().encodeInt(day, byteValue, 0);
   ptr.set(byteValue);
   return true;
 }