org.apache.cassandra.thrift.CqlRow Java Examples
The following examples show how to use
org.apache.cassandra.thrift.CqlRow.
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: CassandraColumnMetaData.java From learning-hadoop with Apache License 2.0 | 6 votes |
/** * Return the decoded key value of a row. Assumes that the supplied row comes * from the column family that this meta data represents!! * * @param row a Cassandra row * @return the decoded key value * @throws KettleException if a deserializer can't be determined */ public Object getKeyValue(CqlRow row) throws KettleException { /* * byte[] key = row.getKey(); * * return getColumnValue(key, m_keyValidator); */ ByteBuffer key = row.bufferForKey(); if (m_keyValidator.indexOf("BytesType") > 0) { return row.getKey(); } return getColumnValue(key, m_keyValidator); }
Example #2
Source File: CqlOperation.java From stratio-cassandra with Apache License 2.0 | 6 votes |
@Override public Function<CqlResult, ByteBuffer[][]> simpleNativeHandler() { return new Function<CqlResult, ByteBuffer[][]>() { @Override public ByteBuffer[][] apply(CqlResult result) { ByteBuffer[][] r = new ByteBuffer[result.getRows().size()][]; for (int i = 0 ; i < r.length ; i++) { CqlRow row = result.getRows().get(i); r[i] = new ByteBuffer[row.getColumns().size()]; for (int j = 0 ; j < r[i].length ; j++) r[i][j] = ByteBuffer.wrap(row.getColumns().get(j).getValue()); } return r; } }; }
Example #3
Source File: CassandraInputData.java From learning-hadoop with Apache License 2.0 | 5 votes |
/** * Converts a cassandra row to a Kettle row * * @param metaData meta data on the cassandra column family being read from * @param cassandraRow a row from the column family * @param outputFormatMap a Map of output field names to indexes in the * outgoing Kettle row structure * @return a Kettle row * @throws KettleException if a problem occurs */ public Object[] cassandraRowToKettle(CassandraColumnMetaData metaData, CqlRow cassandraRow, Map<String, Integer> outputFormatMap) throws KettleException { Object[] outputRowData = RowDataUtil .allocateRowData(m_outputRowMeta.size()); Object key = metaData.getKeyValue(cassandraRow); if (key == null) { throw new KettleException("Unable to obtain a key value for the row!"); } String keyName = metaData.getKeyName(); int keyIndex = m_outputRowMeta.indexOfValue(keyName); if (keyIndex < 0) { throw new KettleException("Unable to find the key field name '" + keyName + "' in the output row meta data!"); } outputRowData[keyIndex] = key; // do the columns List<Column> rowColumns = cassandraRow.getColumns(); for (Column aCol : rowColumns) { String colName = metaData.getColumnName(aCol); Integer outputIndex = outputFormatMap.get(colName); if (outputIndex != null) { Object colValue = metaData.getColumnValue(aCol); outputRowData[outputIndex.intValue()] = colValue; } } return outputRowData; }
Example #4
Source File: CFMetaData.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Create CFMetaData from thrift {@link CqlRow} that contains columns from schema_columnfamilies. * * @param columnsRes CqlRow containing columns from schema_columnfamilies. * @return CFMetaData derived from CqlRow */ public static CFMetaData fromThriftCqlRow(CqlRow cf, CqlResult columnsRes) { UntypedResultSet.Row cfRow = new UntypedResultSet.Row(convertThriftCqlRow(cf)); List<Map<String, ByteBuffer>> cols = new ArrayList<>(columnsRes.rows.size()); for (CqlRow row : columnsRes.rows) cols.add(convertThriftCqlRow(row)); UntypedResultSet colsRow = UntypedResultSet.create(cols); return fromSchemaNoTriggers(cfRow, colsRow); }
Example #5
Source File: CFMetaData.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private static Map<String, ByteBuffer> convertThriftCqlRow(CqlRow row) { Map<String, ByteBuffer> m = new HashMap<>(); for (org.apache.cassandra.thrift.Column column : row.getColumns()) m.put(UTF8Type.instance.getString(column.bufferForName()), column.value); return m; }
Example #6
Source File: CassandraInputData.java From learning-hadoop with Apache License 2.0 | 4 votes |
/** * Converts a cassandra row to a Kettle row in the key, colName, colValue, * timestamp format * * @param metaData meta data on the cassandra column family being read from * @param cassandraRow a row from the column family * @param cassandraColIter an interator over columns for the current row * * @return a Kettle row * @throws KettleException if a problem occurs */ public Object[] cassandraRowToKettleTupleMode( CassandraColumnMetaData metaData, CqlRow cassandraRow, Iterator<Column> cassandraColIter) throws KettleException { Object[] outputRowData = RowDataUtil .allocateRowData(m_outputRowMeta.size()); Object key = metaData.getKeyValue(cassandraRow); if (key == null) { throw new KettleException("Unable to obtain a key value for the row!"); } String keyName = metaData.getKeyName(); int keyIndex = m_outputRowMeta.indexOfValue(keyName); if (keyIndex < 0) { throw new KettleException("Unable to find the key field name '" + keyName + "' in the output row meta data!"); } outputRowData[keyIndex] = key; // advance the iterator to the next column if (cassandraColIter.hasNext()) { Column aCol = cassandraColIter.next(); String colName = metaData.getColumnName(aCol); // skip the key if (colName.equals("KEY")) { if (cassandraColIter.hasNext()) { aCol = cassandraColIter.next(); colName = metaData.getColumnName(aCol); } else { // run out of columns return null; } } // for queries that specify column names we need to check that the value // is not null in this row while (metaData.getColumnValue(aCol) == null) { if (cassandraColIter.hasNext()) { aCol = cassandraColIter.next(); colName = metaData.getColumnName(aCol); } else { return null; } } outputRowData[1] = colName; // do the value (stored as a string) Object colValue = metaData.getColumnValue(aCol); String stringV = colValue.toString(); outputRowData[2] = stringV; if (colValue instanceof Date) { ValueMeta tempDateMeta = new ValueMeta("temp", ValueMetaInterface.TYPE_DATE); stringV = tempDateMeta.getString(colValue); outputRowData[2] = stringV; } else if (colValue instanceof byte[]) { outputRowData[2] = colValue; } // the timestamp as a date object long timestampL = aCol.getTimestamp(); outputRowData[3] = timestampL; } else { return null; // signify no more columns for this row... } return outputRowData; }