Esempio n. 1
0
 @Override
 public List<Mutation>
     toRowMutations() { // TODO: change to List<Mutation> once it implements Row
   List<Mutation> mutations = new ArrayList<Mutation>(3);
   if (deleteRow != null) {
     // Include only deleteRow mutation if present because it takes precedence over all others
     mutations.add(deleteRow);
   } else {
     // Because we cannot enforce a not null constraint on a KV column (since we don't know if
     // the row exists when
     // we upsert it), se instead add a KV that is always emtpy. This allows us to imitate SQL
     // semantics given the
     // way HBase works.
     setValues.add(
         SchemaUtil.getEmptyColumnFamily(getColumnFamilies()),
         QueryConstants.EMPTY_COLUMN_BYTES,
         ts,
         ByteUtil.EMPTY_BYTE_ARRAY);
     mutations.add(setValues);
     if (!unsetValues.isEmpty()) {
       mutations.add(unsetValues);
     }
   }
   return mutations;
 }
Esempio n. 2
0
 @Override
 public void setValue(PColumn column, byte[] byteValue) {
   deleteRow = null;
   byte[] family = column.getFamilyName().getBytes();
   byte[] qualifier = column.getName().getBytes();
   PDataType type = column.getDataType();
   // Check null, since some types have no byte representation for null
   if (byteValue == null || byteValue.length == 0) {
     if (!column.isNullable()) {
       throw new ConstraintViolationException(
           name.getString() + "." + column.getName().getString() + " may not be null");
     }
     removeIfPresent(setValues, family, qualifier);
     unsetValues.deleteColumns(family, qualifier, ts);
   } else {
     Integer byteSize = column.getByteSize();
     if (type.isFixedWidth()) { // TODO: handle multi-byte characters
       if (byteValue.length != byteSize) {
         throw new ConstraintViolationException(
             name.getString()
                 + "."
                 + column.getName().getString()
                 + " must be "
                 + byteSize
                 + " bytes ("
                 + type.toObject(byteValue)
                 + ")");
       }
     } else if (byteSize != null && byteValue.length > byteSize) {
       throw new ConstraintViolationException(
           name.getString()
               + "."
               + column.getName().getString()
               + " may not exceed "
               + byteSize
               + " bytes ("
               + type.toObject(byteValue)
               + ")");
     }
     removeIfPresent(unsetValues, family, qualifier);
     setValues.add(family, qualifier, ts, byteValue);
   }
 }