List of usage examples for org.apache.cassandra.cql3 ColumnIdentifier toString
@Override
public String toString()
From source file:com.dse.pig.udfs.AbstractCassandraStorage.java
License:Apache License
/** return the CfInf for the column family */ protected CfInfo getCfInfo(Cassandra.Client client) throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException, NotFoundException, org.apache.cassandra.exceptions.InvalidRequestException, ConfigurationException, IOException { // get CF meta data String query = "SELECT type," + " comparator," + " subcomparator," + " default_validator," + " key_validator," + " key_aliases " + "FROM system.schema_columnfamilies " + "WHERE keyspace_name = '%s' " + " AND columnfamily_name = '%s' "; CqlResult result = client.execute_cql3_query( ByteBufferUtil.bytes(String.format(query, keyspace, column_family)), Compression.NONE, ConsistencyLevel.ONE);/*from w w w. j a v a2s. c om*/ if (result == null || result.rows == null || result.rows.isEmpty()) return null; Iterator<CqlRow> iteraRow = result.rows.iterator(); CfDef cfDef = new CfDef(); cfDef.keyspace = keyspace; cfDef.name = column_family; boolean cql3Table = false; if (iteraRow.hasNext()) { CqlRow cqlRow = iteraRow.next(); cfDef.column_type = ByteBufferUtil.string(cqlRow.columns.get(0).value); cfDef.comparator_type = ByteBufferUtil.string(cqlRow.columns.get(1).value); ByteBuffer subComparator = cqlRow.columns.get(2).value; if (subComparator != null) cfDef.subcomparator_type = ByteBufferUtil.string(subComparator); cfDef.default_validation_class = ByteBufferUtil.string(cqlRow.columns.get(3).value); cfDef.key_validation_class = ByteBufferUtil.string(cqlRow.columns.get(4).value); String keyAliases = ByteBufferUtil.string(cqlRow.columns.get(5).value); List<String> keys = FBUtilities.fromJsonList(keyAliases); // classis thrift tables if (keys.size() == 0) { CFDefinition cfDefinition = getCfDefinition(keyspace, column_family, client); for (ColumnIdentifier column : cfDefinition.keys.keySet()) { String key = column.toString(); String type = cfDefinition.keys.get(column).type.toString(); logger.debug("name: {}, type: {} ", key, type); keys.add(key); } } else cql3Table = true; } cfDef.column_metadata = getColumnMetadata(client); CfInfo cfInfo = new CfInfo(); cfInfo.cfDef = cfDef; if (cql3Table && !(parseType(cfDef.comparator_type) instanceof AbstractCompositeType)) cfInfo.compactCqlTable = true; if (cql3Table) cfInfo.cql3Table = true; return cfInfo; }
From source file:com.dse.pig.udfs.AbstractCassandraStorage.java
License:Apache License
/** get column meta data */ protected List<ColumnDef> getColumnMeta(Cassandra.Client client, boolean cassandraStorage, boolean includeCompactValueColumn) throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException, CharacterCodingException, org.apache.cassandra.exceptions.InvalidRequestException, ConfigurationException, NotFoundException { String query = "SELECT column_name, " + " validator, " + " index_type " + "FROM system.schema_columns " + "WHERE keyspace_name = '%s' " + " AND columnfamily_name = '%s'"; CqlResult result = client.execute_cql3_query( ByteBufferUtil.bytes(String.format(query, keyspace, column_family)), Compression.NONE, ConsistencyLevel.ONE);//from w w w . j a v a 2 s .co m List<CqlRow> rows = result.rows; List<ColumnDef> columnDefs = new ArrayList<ColumnDef>(); if (rows == null || rows.isEmpty()) { // if CassandraStorage, just return the empty list if (cassandraStorage) return columnDefs; // otherwise for CqlStorage, check metadata for classic thrift tables CFDefinition cfDefinition = getCfDefinition(keyspace, column_family, client); for (ColumnIdentifier column : cfDefinition.metadata.keySet()) { ColumnDef cDef = new ColumnDef(); String columnName = column.toString(); String type = cfDefinition.metadata.get(column).type.toString(); logger.debug("name: {}, type: {} ", columnName, type); cDef.name = ByteBufferUtil.bytes(columnName); cDef.validation_class = type; columnDefs.add(cDef); } // we may not need to include the value column for compact tables as we // could have already processed it as schema_columnfamilies.value_alias if (columnDefs.size() == 0 && includeCompactValueColumn) { String value = cfDefinition.value != null ? cfDefinition.value.toString() : null; if ("value".equals(value)) { ColumnDef cDef = new ColumnDef(); cDef.name = ByteBufferUtil.bytes(value); cDef.validation_class = cfDefinition.value.type.toString(); columnDefs.add(cDef); } } return columnDefs; } Iterator<CqlRow> iterator = rows.iterator(); while (iterator.hasNext()) { CqlRow row = iterator.next(); ColumnDef cDef = new ColumnDef(); cDef.setName(ByteBufferUtil.clone(row.getColumns().get(0).value)); cDef.validation_class = ByteBufferUtil.string(row.getColumns().get(1).value); ByteBuffer indexType = row.getColumns().get(2).value; if (indexType != null) cDef.index_type = getIndexType(ByteBufferUtil.string(indexType)); columnDefs.add(cDef); } return columnDefs; }
From source file:com.dse.pig.udfs.CqlStorage.java
License:Apache License
/** get keys meta data */ protected List<ColumnDef> getKeysMeta(Cassandra.Client client) throws Exception { String query = "SELECT key_aliases, " + " column_aliases, " + " key_validator, " + " comparator, " + " keyspace_name, " + " value_alias, " + " default_validator " + "FROM system.schema_columnfamilies " + "WHERE keyspace_name = '%s'" + " AND columnfamily_name = '%s' "; CqlResult result = client.execute_cql3_query( ByteBufferUtil.bytes(String.format(query, keyspace, column_family)), Compression.NONE, ConsistencyLevel.ONE);/*from www .j a v a 2s . c o m*/ if (result == null || result.rows == null || result.rows.isEmpty()) return null; Iterator<CqlRow> iteraRow = result.rows.iterator(); List<ColumnDef> keys = new ArrayList<ColumnDef>(); if (iteraRow.hasNext()) { CqlRow cqlRow = iteraRow.next(); String name = ByteBufferUtil.string(cqlRow.columns.get(4).value); logger.debug("Found ksDef name: {}", name); String keyString = ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.columns.get(0).getValue())); logger.debug("partition keys: {}", keyString); List<String> keyNames = FBUtilities.fromJsonList(keyString); Iterator<String> iterator = keyNames.iterator(); while (iterator.hasNext()) { ColumnDef cDef = new ColumnDef(); cDef.name = ByteBufferUtil.bytes(iterator.next()); keys.add(cDef); } // classic thrift tables if (keys.size() == 0) { CFDefinition cfDefinition = getCfDefinition(keyspace, column_family, client); for (ColumnIdentifier column : cfDefinition.keys.keySet()) { String key = column.toString(); logger.debug("name: {} ", key); ColumnDef cDef = new ColumnDef(); cDef.name = ByteBufferUtil.bytes(key); keys.add(cDef); } for (ColumnIdentifier column : cfDefinition.columns.keySet()) { String key = column.toString(); logger.debug("name: {} ", key); ColumnDef cDef = new ColumnDef(); cDef.name = ByteBufferUtil.bytes(key); keys.add(cDef); } } keyString = ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.columns.get(1).getValue())); logger.debug("cluster keys: {}", keyString); keyNames = FBUtilities.fromJsonList(keyString); iterator = keyNames.iterator(); while (iterator.hasNext()) { ColumnDef cDef = new ColumnDef(); cDef.name = ByteBufferUtil.bytes(iterator.next()); keys.add(cDef); } String validator = ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.columns.get(2).getValue())); logger.debug("row key validator: {}", validator); AbstractType<?> keyValidator = parseType(validator); Iterator<ColumnDef> keyItera = keys.iterator(); if (keyValidator instanceof CompositeType) { Iterator<AbstractType<?>> typeItera = ((CompositeType) keyValidator).types.iterator(); while (typeItera.hasNext()) keyItera.next().validation_class = typeItera.next().toString(); } else keyItera.next().validation_class = keyValidator.toString(); validator = ByteBufferUtil.string(ByteBuffer.wrap(cqlRow.columns.get(3).getValue())); logger.debug("cluster key validator: {}", validator); if (keyItera.hasNext() && validator != null && !validator.isEmpty()) { AbstractType<?> clusterKeyValidator = parseType(validator); if (clusterKeyValidator instanceof CompositeType) { Iterator<AbstractType<?>> typeItera = ((CompositeType) clusterKeyValidator).types.iterator(); while (keyItera.hasNext()) keyItera.next().validation_class = typeItera.next().toString(); } else keyItera.next().validation_class = clusterKeyValidator.toString(); } // compact value_alias column if (cqlRow.columns.get(5).value != null) { try { String compactValidator = ByteBufferUtil .string(ByteBuffer.wrap(cqlRow.columns.get(6).getValue())); logger.debug("default validator: {}", compactValidator); AbstractType<?> defaultValidator = parseType(compactValidator); ColumnDef cDef = new ColumnDef(); cDef.name = cqlRow.columns.get(5).value; cDef.validation_class = defaultValidator.toString(); keys.add(cDef); hasCompactValueAlias = true; } catch (Exception e) { // no compact column at value_alias } } } return keys; }
From source file:com.tuplejump.stargate.cassandra.RowFetcher.java
License:Apache License
private ColumnFamily scored(Float score, ColumnFamily data) { ColumnFamily cleanColumnFamily = data.getFactory().create(table.metadata); String indexColumnName = resultMapper.tableMapper.primaryColumnName(); boolean metaColReplaced = false; Cell firstColumn = null;/*from w ww . j a v a2s. co m*/ for (Cell column : data) { if (firstColumn == null) firstColumn = column; ColumnIdentifier cellName = column.name().cql3ColumnName(table.metadata); String thisColName = cellName.toString(); boolean isIndexColumn = indexColumnName.equals(thisColName); if (isIndexColumn) { Cell scoreColumn = new BufferCell(column.name(), UTF8Type.instance.decompose("{\"score\":" + score.toString() + "}")); cleanColumnFamily.addColumn(scoreColumn); metaColReplaced = true; } else { cleanColumnFamily.addColumn(column); } } if (!metaColReplaced && firstColumn != null) { Cell newColumn = getMetaColumn(firstColumn, score); cleanColumnFamily.addColumn(newColumn); } return cleanColumnFamily; }