org.apache.cassandra.thrift.ColumnParent Java Examples
The following examples show how to use
org.apache.cassandra.thrift.ColumnParent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThriftCounterGetter.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public void run(final ThriftClient client) throws IOException { final SlicePredicate predicate = select().predicate(); final ByteBuffer key = getKey(); timeWithRetry(new RunOp() { @Override public boolean run() throws Exception { List<?> r = client.get_slice(key, new ColumnParent(type.table), predicate, settings.command.consistencyLevel); return r != null && r.size() > 0; } @Override public int partitionCount() { return 1; } @Override public int rowCount() { return 1; } }); }
Example #2
Source File: AbstractCassandraInputAdapter.java From OpenRate with Apache License 2.0 | 5 votes |
private void insertColumnValue(String parentName, String id, String name, String value, long ts) throws TException, TimedOutException, UnavailableException, InvalidRequestException, UnsupportedEncodingException { ColumnParent parent = new ColumnParent(parentName); Column column = new Column(toByteBuffer(name)); column.setValue(toByteBuffer(value)); column.setTimestamp(ts); getClient().insert(toByteBuffer(id), parent, column, ConsistencyLevel.ONE); }
Example #3
Source File: ThriftReader.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public void run(final ThriftClient client) throws IOException { final ColumnSelection select = select(); final ByteBuffer key = getKey(); final List<ByteBuffer> expect = getColumnValues(select); timeWithRetry(new RunOp() { @Override public boolean run() throws Exception { List<ColumnOrSuperColumn> row = client.get_slice(key, new ColumnParent(type.table), select.predicate(), settings.command.consistencyLevel); if (expect == null) return !row.isEmpty(); if (row == null) return false; if (row.size() != expect.size()) return false; for (int i = 0 ; i < row.size() ; i++) if (!row.get(i).getColumn().bufferForValue().equals(expect.get(i))) return false; return true; } @Override public int partitionCount() { return 1; } @Override public int rowCount() { return 1; } }); }
Example #4
Source File: CassandraInputData.java From learning-hadoop with Apache License 2.0 | 4 votes |
public void sliceModeInit(CassandraColumnMetaData meta, List<String> colNames, int maxRows, int maxCols, int rowBatchSize, int colBatchSize) throws KettleException { m_newSliceQuery = true; m_requestedCols = colNames; m_sliceRowsMax = maxRows; m_sliceColsMax = maxCols; m_sliceRowsBatchSize = rowBatchSize; m_sliceColsBatchSize = colBatchSize; m_rowIndex = 0; m_colIndex = 0; if (m_sliceColsBatchSize <= 0) { m_sliceColsBatchSize = Integer.MAX_VALUE; } if (m_sliceRowsBatchSize <= 0) { m_sliceRowsBatchSize = Integer.MAX_VALUE; } List<ByteBuffer> specificCols = null; if (m_requestedCols != null && m_requestedCols.size() > 0) { specificCols = new ArrayList<ByteBuffer>(); // encode the textual column names for (String colName : m_requestedCols) { ByteBuffer encoded = meta.columnNameToByteBuffer(colName); specificCols.add(encoded); } } m_slicePredicate = new SlicePredicate(); if (specificCols == null) { m_sliceRange = new SliceRange(ByteBuffer.wrap(new byte[0]), ByteBuffer.wrap(new byte[0]), false, m_sliceColsBatchSize); m_slicePredicate.setSlice_range(m_sliceRange); } else { m_slicePredicate.setColumn_names(specificCols); } m_keyRange = new KeyRange(m_sliceRowsBatchSize); m_keyRange.setStart_key(new byte[0]); m_keyRange.setEnd_key(new byte[0]); m_colParent = new ColumnParent(meta.getColumnFamilyName()); m_converted = new ArrayList<Object[]>(); }
Example #5
Source File: TestRingCache.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** * usage: java -cp <configpath> org.apache.cassandra.client.TestRingCache [keyspace row-id-prefix row-id-int] * to test a single keyspace/row, use the parameters. row-id-prefix and row-id-int are appended together to form a * single row id. If you supply now parameters, 'Keyspace1' is assumed and will check 9 rows ('row1' through 'row9'). * @param args * @throws Exception */ public static void main(String[] args) throws Throwable { int minRow; int maxRow; String rowPrefix, keyspace = "Keyspace1"; if (args.length > 0) { keyspace = args[0]; rowPrefix = args[1]; minRow = Integer.parseInt(args[2]); maxRow = minRow + 1; } else { minRow = 1; maxRow = 10; rowPrefix = "row"; } TestRingCache tester = new TestRingCache(keyspace); for (int nRows = minRow; nRows < maxRow; nRows++) { ByteBuffer row = ByteBufferUtil.bytes((rowPrefix + nRows)); ColumnPath col = new ColumnPath("Standard1").setSuper_column((ByteBuffer)null).setColumn("col1".getBytes()); ColumnParent parent = new ColumnParent("Standard1").setSuper_column((ByteBuffer)null); Collection<InetAddress> endpoints = tester.ringCache.getEndpoint(row); InetAddress firstEndpoint = endpoints.iterator().next(); System.out.printf("hosts with key %s : %s; choose %s%n", new String(row.array()), StringUtils.join(endpoints, ","), firstEndpoint); // now, read the row back directly from the host owning the row locally tester.setup(firstEndpoint.getHostAddress(), DatabaseDescriptor.getRpcPort()); tester.thriftClient.set_keyspace(keyspace); tester.thriftClient.insert(row, parent, new Column(ByteBufferUtil.bytes("col1")).setValue(ByteBufferUtil.bytes("val1")).setTimestamp(1), ConsistencyLevel.ONE); Column column = tester.thriftClient.get(row, col, ConsistencyLevel.ONE).column; System.out.println("read row " + new String(row.array()) + " " + new String(column.name.array()) + ":" + new String(column.value.array()) + ":" + column.timestamp); } System.exit(1); }
Example #6
Source File: DBConn.java From Doradus with Apache License 2.0 | 4 votes |
private static String toString(ColumnParent colParent) { return "CF '" + colParent.getColumn_family() + "'"; }
Example #7
Source File: ColumnFamilyWideRowRecordReader.java From Hive-Cassandra with Apache License 2.0 | 4 votes |
private void maybeInit() { // check if we need another row if (rows != null && columnsRead < rowPageSize) { columnsRead = 0; startToken = partitioner.getTokenFactory().toString(partitioner.getToken(rows.get(0).key)); predicate.getSlice_range().setStart(startSlicePredicate); rows = null; prevStartSlice = null; totalRead++; } if (startToken == null) { startToken = split.getStartToken(); } else if (startToken.equals(split.getEndToken()) && rows == null) { // reached end of the split return; } KeyRange keyRange = new KeyRange(batchRowCount) .setStart_token(startToken) .setEnd_token(split.getEndToken()); try { rows = client.get_range_slices(new ColumnParent(cfName), predicate, keyRange, consistencyLevel); // nothing new? reached the end if (rows.isEmpty()) { rows = null; return; } //detect infinite loop if (prevStartSlice != null && ByteBufferUtil.compareUnsigned(prevStartSlice, predicate.slice_range.start) == 0) { rows = null; return; } // prepare for the next slice to be read KeySlice row = rows.get(0); if (row.getColumnsSize() > 0) { ColumnOrSuperColumn cosc = row.getColumns().get(row.getColumnsSize() - 1); prevStartSlice = predicate.slice_range.start; //prepare next slice if (cosc.column != null) { predicate.slice_range.start = cosc.column.name; } if (cosc.super_column != null) { predicate.slice_range.start = cosc.super_column.name; } if (cosc.counter_column != null) { predicate.slice_range.start = cosc.counter_column.name; } if (cosc.counter_super_column != null) { predicate.slice_range.start = cosc.counter_super_column.name; } columnsRead = row.getColumnsSize(); //If we've hit the max columns then rm the last column //to make sure we don't know where to start next without overlap if (columnsRead == rowPageSize) { row.getColumns().remove(columnsRead - 1); } } } catch (Exception e) { throw new RuntimeException(e); } }
Example #8
Source File: CassandraDefs.java From Doradus with Apache License 2.0 | 2 votes |
/** * Return the ColumnParent object for the given ColumnFamily name. * * @param cfName Name of a ColumnFamily. * @return ColumnParent object for the given CF name. */ static ColumnParent columnParent(String cfName) { return new ColumnParent(cfName); }