@Override public RangeEndpoint append(Object value, Equality equality) { ComponentSerializer<?> serializer = components.get(position); position++; // First, serialize the ByteBuffer for this component ByteBuffer cb; try { cb = serializer.serializeValue(value); } catch (Exception e) { throw new RuntimeException(e); } if (cb == null) { cb = EMPTY_BYTE_BUFFER; } if (cb.limit() + COMPONENT_OVERHEAD > out.remaining()) { int exponent = (int) Math.ceil(Math.log((double) (cb.limit() + COMPONENT_OVERHEAD) / (double) out.limit()) / Math.log(2)); int newBufferSize = out.limit() * (int) Math.pow(2, exponent); ByteBuffer temp = ByteBuffer.allocate(newBufferSize); out.flip(); temp.put(out); out = temp; } // Write the data: <length><data><0> out.putShort((short) cb.remaining()); out.put(cb.slice()); out.put(equality.toByte()); return this; }
break; default: throw new RuntimeException("Cannot recognize operator: " + op.getOperator().name());
protected Where addWhereClauseForCompositeColumnRange(Where stmt, CompositeByteBufferRange compositeRange) { List<RangeQueryRecord> records = compositeRange.getRecords(); int componentIndex = 0; for (RangeQueryRecord record : records) { for (RangeQueryOp op : record.getOps()) { String columnName = clusteringKeyCols.get(componentIndex).getName(); switch (op.getOperator()) { case EQUAL: stmt.and(eq(columnName, BIND_MARKER)); componentIndex++; break; case LESS_THAN : stmt.and(lt(columnName, BIND_MARKER)); break; case LESS_THAN_EQUALS: stmt.and(lte(columnName, BIND_MARKER)); break; case GREATER_THAN: stmt.and(gt(columnName, BIND_MARKER)); break; case GREATER_THAN_EQUALS: stmt.and(gte(columnName, BIND_MARKER)); break; default: throw new RuntimeException("Cannot recognize operator: " + op.getOperator().name()); }; // end of switch stmt } // end of inner for for ops for each range query record } return stmt; }
public void append(ByteBufferOutputStream out, Object value, Equality equality) { ComponentSerializer<?> serializer = components.get(position); // First, serialize the ByteBuffer for this component ByteBuffer cb; try { cb = serializer.serializeValue(value); } catch (Exception e) { throw new RuntimeException(e); } if (cb == null) { cb = EMPTY_BYTE_BUFFER; } // Write the data: <length><data><0> out.writeShort((short) cb.remaining()); out.write(cb.slice()); out.write(equality.toByte()); } };