log.debug("Found CqlResult: {}", result); switch (result.getType()) { case VOID: rows = new CqlRows<K, N, V>(); if ( result.getRowsSize() > 0 ) { LinkedHashMap<ByteBuffer, List<Column>> ret = new LinkedHashMap<ByteBuffer, List<Column>>(result.getRowsSize()); int keyColumnIndex = -1; for (Iterator<CqlRow> rowsIter = result.getRowsIterator(); rowsIter.hasNext(); ) { CqlRow row = rowsIter.next(); ByteBuffer kbb = ByteBuffer.wrap(row.getKey()); List<Column> rowcolumns = row.getColumns(); for (Column c: rowcolumns) { keyColumnIndex++; String name = StringSerializer.get().fromBytes(c.getName()); if (name.toUpperCase().equals("KEY")) { kbb = ByteBuffer.wrap(c.getValue()); break; kbb = ByteBuffer.wrap(row.getColumns().get(keyColumnIndex).getValue());
@Test public void passesCqlQueriesAndResultsToAndFromDelegate() throws TException { ByteBuffer byteBuffer = ByteBuffer.allocate(1); CqlResult standardCqlResult = new CqlResult(CqlResultType.ROWS) .setRows(ImmutableList.of(new CqlRow(byteBuffer, ImmutableList.of(new Column(byteBuffer))))); setDelegateResponseToCqlQuery(standardCqlResult); assertThat(executeCqlQuery()).isEqualTo(standardCqlResult); verifyCqlQueryWasExecuted(); }
private List<Column> filterKeyColumn(CqlRow row) { if ( suppressKeyInColumns && row.isSetColumns() && row.columns.size() > 0) { Iterator<Column> columnsIterator = row.getColumnsIterator(); Column column = columnsIterator.next(); if ( column.name.duplicate().equals(KEY_BB) ) { columnsIterator.remove(); } } return row.getColumns(); }
private static long getCqlRowSize(CqlRow cqlRow) { if (cqlRow == null) { return getNullSize(); } return getByteArraySize(cqlRow.getKey()) + getCollectionSize(cqlRow.getColumns(), ThriftObjectSizeUtils::getColumnSize); }
for (int i = 0; i < metadata.columnCount; i++) Column col = new Column(ByteBufferUtil.bytes(metadata.names.get(i).name.toString())); col.setValue(row.get(i)); thriftCols.add(col); cqlRows.add(new CqlRow(ByteBufferUtil.EMPTY_BYTE_BUFFER, thriftCols)); CqlResult res = new CqlResult(CqlResultType.ROWS); res.setRows(cqlRows).setSchema(schema); return res;
Column c = new Column(); c.setName("acol".getBytes()); c.setValue((i+"").getBytes()); c.setTimestamp(System.nanoTime()); changes.add( c ); String s = new String(res.rows.get(0).getColumns().get(2).getValue());
keyspace = clientState.getKeyspace(); CqlResult result = new CqlResult(); "AsciiType", "LongType"); List<Column> columns = Collections.singletonList(new Column(countBytes).setValue(ByteBufferUtil.bytes((long) rows.size()))); result.rows = Collections.singletonList(new CqlRow(countBytes, columns)); return result; thriftColumns.add(new Column(keyName).setValue(row.key.getKey()).setTimestamp(-1)); result.schema.name_types.put(keyName, TypeParser.getShortName(AsciiType.instance)); result.schema.value_types.put(keyName, TypeParser.getShortName(metadata.getKeyValidator())); CqlRow cqlRow = new CqlRow(); cqlRow.key = row.key.getKey(); cqlRow.columns = thriftColumns;
if (cqlResult != null && (cqlResult.getRows() != null || cqlResult.getRowsSize() > 0)) { results = new ArrayList<Object>(cqlResult.getRowsSize()); Iterator<CqlRow> iter = cqlResult.getRowsIterator(); while (iter.hasNext()) { for (Column column : row.getColumns()) { if (column != null) { String thriftColumnName = PropertyAccessorFactory.STRING.fromBytes(String.class, column.getName()); if (column.getValue() == null) { entity.put(thriftColumnName, null); } else { entity.put(thriftColumnName, composeColumnValue(cqlResult.getSchema(), column.getValue(), column.getName()));
private static boolean isResultSuccessful(CqlRow cqlRow) { Column appliedColumn = cqlRow.getColumns() .stream() .filter(column -> APPLIED_COLUMN.equals(decodeCqlColumnName(column))) .findFirst() .orElseThrow(() -> new IllegalStateException("CQL row " + cqlRow + " was missing an [applied] column")); return Arrays.equals(SUCCESSFUL_OPERATION, appliedColumn.getValue()); }
setCqlMetadata(result.getSchema()); if (result != null && (result.getRows() != null || result.getRowsSize() > 0)) { returnedEntities = new ArrayList<Object>(result.getRowsSize()); Iterator<CqlRow> iter = result.getRowsIterator(); thriftRow = new ThriftRow(rowKey, entityMetadata.getTableName(), row.getColumns(), new ArrayList<SuperColumn>(0), new ArrayList<CounterColumn>(0), new ArrayList<CounterSuperColumn>(0)); returnedEntities.add(e); } else if (isNative) { returnedEntities.add(row.getColumns().get(0));
Assert.assertEquals("keyspace_name", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(0).getName()))); Assert.assertEquals(keyspaceName, ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(0).getValue()))); Assert.assertEquals("durable_writes", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(1).getName()))); Assert.assertEquals(false, Boolean.getBoolean(ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(1).getValue())))); Assert.assertEquals("replication", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(2).getName()))); if ("CASSANDRAUSERXYZ".equals(ByteBuffer.wrap(cqlRow.getColumns().get(1).getValue()))) Assert.assertEquals("comment", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(5).getName()))); Assert.assertTrue(ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(5).getValue())).isEmpty()); Assert.assertEquals("comparator", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(8).getName()))); Assert.assertEquals(UTF8Type.class.getName(), ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(8).getValue()))); Assert.assertEquals("default_validator", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(10).getName()))); Assert.assertEquals(BytesType.class.getName(), Boolean.getBoolean(ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(10).getValue())))); Assert.assertEquals("max_compaction_threshold", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(17).getName()))); Assert.assertEquals(16, ByteBufferUtil.toInt(ByteBuffer.wrap(cqlRow.getColumns().get(17).getValue()))); Assert.assertEquals("min_compaction_threshold", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(18).getName()))); Assert.assertEquals(64, ByteBufferUtil.toInt(ByteBuffer.wrap(cqlRow.getColumns().get(18).getValue()))); Assert.assertEquals("replicate_on_write", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(21).getName()))); Assert.assertEquals("true", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(21).getValue()))); Assert.assertEquals("subcomparator", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(22).getName()))); Assert.assertNull(ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(22).getValue()))); Assert.assertEquals("type", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(23).getName()))); Assert.assertEquals("Standard", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(23).getValue()))); else if ("CassandraDefaultUser".equals(ByteBuffer.wrap(cqlRow.getColumns().get(1).getValue()))) Assert.assertEquals("comment", ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(5).getName()))); Assert.assertTrue(ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.getColumns().get(5).getValue())).isEmpty());
/** * Performs a deep copy on <i>other</i>. */ public CqlRow(CqlRow other) { if (other.isSetKey()) { this.key = org.apache.thrift.TBaseHelper.copyBinary(other.key); ; } if (other.isSetColumns()) { List<Column> __this__columns = new ArrayList<Column>(other.columns.size()); for (Column other_element : other.columns) { __this__columns.add(new Column(other_element)); } this.columns = __this__columns; } }
Iterator<CqlRow> rowIter = cqlResult.getRows().iterator(); while (rowIter.hasNext()) { CqlRow row = rowIter.next(); if (!row.getColumns().isEmpty()) { Column column = row.getColumns().get(0); Object columnValue = CassandraDataTranslator.decompose(columnJavaType, column.getValue(), true); results.add(columnValue);
if (schemeField.type == org.apache.thrift.protocol.TType.I32) { struct.type = CqlResultType.findByValue(iprot.readI32()); struct.setTypeIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); _elem194 = new CqlRow(); _elem194.read(iprot); struct.rows.add(_elem194); struct.setRowsIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); if (schemeField.type == org.apache.thrift.protocol.TType.I32) { struct.num = iprot.readI32(); struct.setNumIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
private static boolean isSuccessfullyApplied(CqlResult casResult) { byte[] appliedValue = getNamedColumnValue(casResult.getRows().get(0).getColumns(), APPLIED_COLUMN); return Arrays.equals(appliedValue, CQL_SUCCESS.toByteArray()); }
@Override public Object generate(Client<?> client, String dataType) { CqlResult cqlResult = ((CassandraClientBase) client).execute("SELECT NOW() FROM system_schema.columns LIMIT 1", ((CassandraClientBase) client).getRawClient(SYSTEM)); CqlRow cqlRow = cqlResult.getRowsIterator().next(); TimeUUIDType t = TimeUUIDType.instance; UUID timeUUID = t.compose(ByteBuffer.wrap(cqlRow.getColumns().get(0).getValue())); switch (dataType.toLowerCase()) { case UUID: return timeUUID; default: return java.util.UUID.randomUUID(); } }
/** * Performs a deep copy on <i>other</i>. */ public CqlResult(CqlResult other) { __isset_bitfield = other.__isset_bitfield; if (other.isSetType()) { this.type = other.type; } if (other.isSetRows()) { List<CqlRow> __this__rows = new ArrayList<CqlRow>(other.rows.size()); for (CqlRow other_element : other.rows) { __this__rows.add(new CqlRow(other_element)); } this.rows = __this__rows; } this.num = other.num; if (other.isSetSchema()) { this.schema = new CqlMetadata(other.schema); } }
private static CqlRow createMockCqlRow(List<Column> columns) { CqlRow row = mock(CqlRow.class); when(row.getColumns()).thenReturn(columns); return row; }
log.debug("Found CqlResult: {}", result); switch (result.getType()) { case VOID: rows = new CqlRows<K, N, V>(); if ( result.getRowsSize() > 0 ) { LinkedHashMap<ByteBuffer, List<Column>> ret = new LinkedHashMap<ByteBuffer, List<Column>>(result.getRowsSize()); for (Iterator<CqlRow> rowsIter = result.getRowsIterator(); rowsIter.hasNext(); ) { CqlRow row = rowsIter.next(); ret.put(ByteBuffer.wrap(row.getKey()), filterKeyColumn(row));