tuple = new HashMap<String, ByteIterator>(); ColumnDefinitions cd = row.getColumnDefinitions();
ColumnDefinitions cd = row.getColumnDefinitions();
private static void formatMissingOrNullColumn(Row peerRow, String columnName, StringBuilder sb) { if (!peerRow.getColumnDefinitions().contains(columnName)) sb.append(", missing ").append(columnName); else if (peerRow.isNull(columnName)) sb.append(", ").append(columnName).append("=null"); }
private static boolean isNullOrAbsent(Row row, String name) { return row.getColumnDefinitions().getIndexOf(name) < 0 || row.isNull(name); }
void populateObjectFromRow(EntityMetadata metadata, MetamodelImpl metaModel, EntityType entityType, List results, Map<String, Object> relationalValues, Object entity, Row row) { ColumnDefinitions columnDefs = row.getColumnDefinitions(); Iterator<Definition> columnDefIter = columnDefs.iterator(); entity = iteratorColumns(metadata, metaModel, entityType, relationalValues, entity, row, columnDefIter); if (entity != null && entity.getClass().isAssignableFrom(metadata.getEntityClazz())) { Object rowKey = PropertyAccessorHelper.getId(entity, metadata); // populate secondary tables data if there is any. populateSecondaryTableData(rowKey, entity, metaModel, metadata); if (!relationalValues.isEmpty()) { results.add(new EnhanceEntity(entity, rowKey, relationalValues)); } else { results.add(entity); } } else if (entity != null) { results.add(entity); } }
@Override public <E> List<E> getColumnsById(String schemaName, String tableName, String pKeyColumnName, String columnName, Object pKeyColumnValue, Class columnJavaType) { // select columnName from tableName where pKeyColumnName = // pKeyColumnValue List results = new ArrayList(); CQLTranslator translator = new CQLTranslator(); String selectQuery = translator.SELECT_QUERY; selectQuery = StringUtils.replace(selectQuery, CQLTranslator.COLUMN_FAMILY, translator.ensureCase(new StringBuilder(), tableName, false).toString()); selectQuery = StringUtils.replace(selectQuery, CQLTranslator.COLUMNS, translator.ensureCase(new StringBuilder(), columnName, false).toString()); StringBuilder selectQueryBuilder = new StringBuilder(selectQuery); selectQueryBuilder.append(CQLTranslator.ADD_WHERE_CLAUSE); translator.buildWhereClause(selectQueryBuilder, columnJavaType, pKeyColumnName, pKeyColumnValue, CQLTranslator.EQ_CLAUSE, false); selectQueryBuilder.delete(selectQueryBuilder.lastIndexOf(CQLTranslator.AND_CLAUSE), selectQueryBuilder.length()); ResultSet rSet = execute(selectQueryBuilder.toString(), null); Iterator<Row> rowIter = rSet.iterator(); while (rowIter.hasNext()) { Row row = rowIter.next(); DataType dataType = row.getColumnDefinitions().getType(columnName); Object columnValue = DSClientUtilities.assign(row, null, null, dataType.getName(), null, columnName, null, null); results.add(columnValue); } return results; }
final Row row = rowIter.next(); final ColumnDefinitions columnDefs = row.getColumnDefinitions();
/** * Iterate and return. * * @param rSet * the r set * @return the list */ private List iterateAndReturn(ResultSet rSet) { Iterator<Row> rowIter = rSet.iterator(); List results = new ArrayList(); while (rowIter.hasNext()) { Row row = rowIter.next(); ColumnDefinitions columnDefs = row.getColumnDefinitions(); Iterator<Definition> columnDefIter = columnDefs.iterator(); Map rowData = new HashMap(); while (columnDefIter.hasNext()) { Definition columnDef = columnDefIter.next(); rowData.put(columnDef.getName(), DSClientUtilities.assign(row, null, null, columnDef.getType().getName(), null, columnDef.getName(), null, null)); } results.add(rowData); } return results; }
private boolean isValidPeer(Row peerRow, boolean logIfInvalid) { boolean isValid = isPeersV2 ? peerRow.getColumnDefinitions().contains("native_address") && peerRow.getColumnDefinitions().contains("native_port") && !peerRow.isNull("native_address") && !peerRow.isNull("native_port") : peerRow.getColumnDefinitions().contains("rpc_address") && !peerRow.isNull("rpc_address"); if (EXTENDED_PEER_CHECK) { isValid &= peerRow.getColumnDefinitions().contains("host_id") && !peerRow.isNull("host_id") && peerRow.getColumnDefinitions().contains("data_center") && !peerRow.isNull("data_center") && peerRow.getColumnDefinitions().contains("rack") && !peerRow.isNull("rack") && peerRow.getColumnDefinitions().contains("tokens") && !peerRow.isNull("tokens"); } if (!isValid && logIfInvalid) logger.warn( "Found invalid row in system.peers: {}. " + "This is likely a gossip or snitch issue, this host will be ignored.", formatInvalidPeer(peerRow)); return isValid; }
private static InetSocketAddress nativeAddressForPeerHost( Row peersRow, InetSocketAddress connectedHost, Cluster.Manager cluster) { if (peersRow.getColumnDefinitions().contains("native_address")) { InetAddress nativeAddress = peersRow.getInet("native_address"); int nativePort = peersRow.getInt("native_port");
public RawNumericMetric map(Row row) { RawNumericMetric metricRow = new RawNumericMetric(row.getString(0), row.getString(1), row.getDate(2).getTime(), row.getInt(3)); ColumnDefinitions columeDef = row.getColumnDefinitions(); List<Definition> columeDefList = columeDef.asList(); Map<String, String> tagMap = new HashMap<String, String>(); for(Definition def: columeDefList){ if(def.getName().startsWith("tag_")){ tagMap.put(def.getName(), row.getString(def.getName())); } } if(tagMap.size()>0){ metricRow.setTagMap(tagMap); } return metricRow; }
@Override public Tuple apply(Row input) { Object[] cols = new Object[input.getColumnDefinitions().size()]; for (int i = 0; i < input.getColumnDefinitions().size(); i++) { cols[i] = input.getObject(i); } return new Tuple(cols); } };
private static CassandraBackendEntry row2Entry(HugeType type, Row row) { CassandraBackendEntry entry = new CassandraBackendEntry(type); List<Definition> cols = row.getColumnDefinitions().asList(); for (Definition col : cols) { String name = col.getName(); Object value = row.getObject(name); entry.column(CassandraTable.parseKey(name), value); } return entry; }
if (row.getColumnDefinitions().contains("peer")) { // system.peers int broadcastPort = row.getColumnDefinitions().contains("peer_port") ? row.getInt("peer_port") : 0; broadcastAddress = new InetSocketAddress(row.getInet("peer"), broadcastPort); } else if (row.getColumnDefinitions().contains("broadcast_address")) { // system.local int broadcastPort = row.getColumnDefinitions().contains("broadcast_port") ? row.getInt("broadcast_port") : 0; broadcastAddress = new InetSocketAddress(row.getInet("broadcast_address"), broadcastPort); if (row.getColumnDefinitions().contains("listen_address")) { int listenPort = row.getColumnDefinitions().contains("listen_port") ? row.getInt("listen_port") : 0; listenAddress = new InetSocketAddress(row.getInet("listen_address"), listenPort); if (row.getColumnDefinitions().contains("workload")) { String dseWorkload = row.getString("workload"); host.setDseWorkload(dseWorkload); if (row.getColumnDefinitions().contains("graph")) { boolean isDseGraph = row.getBool("graph"); host.setDseGraphEnabled(isDseGraph); if (row.getColumnDefinitions().contains("dse_version")) { String dseVersion = row.getString("dse_version"); host.setDseVersion(dseVersion);
/** * Populates data form secondary tables of entity for given row key. * * @param rowId * the row id * @param entity * the entity * @param metaModel * the meta model * @param metadata * the metadata */ private void populateSecondaryTableData(Object rowId, Object entity, MetamodelImpl metaModel, EntityMetadata metadata) { AbstractManagedType managedType = (AbstractManagedType) metaModel.entity(metadata.getEntityClazz()); List<String> secondaryTables = ((DefaultEntityAnnotationProcessor) managedType.getEntityAnnotation()).getSecondaryTablesName(); for (String tableName : secondaryTables) { StringBuilder builder = createSelectQuery(rowId, metadata, tableName); ResultSet rSet = this.execute(builder.toString(), null); Iterator<Row> rowIter = rSet.iterator(); Row row = rowIter.next(); ColumnDefinitions columnDefs = row.getColumnDefinitions(); Iterator<Definition> columnDefIter = columnDefs.iterator(); entity = iteratorColumns(metadata, metaModel, metaModel.entity(metadata.getEntityClazz()), new HashMap<String, Object>(), entity, row, columnDefIter); } }
/** * Validates that columns using collections of custom types are properly handled by the driver. * * @jira_ticket JAVA-1034 * @test_category metadata */ @Test(groups = "short") public void should_serialize_and_deserialize_collections_of_custom_types() { TestUtils.compactStorageSupportCheck(ccm()); TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("test_collection"); assertThat(table.getColumn("c1")).hasType(DataType.list(CUSTOM_DYNAMIC_COMPOSITE)); assertThat(table.getColumn("c2")) .hasType(DataType.map(CUSTOM_DYNAMIC_COMPOSITE, CUSTOM_DYNAMIC_COMPOSITE)); session() .execute( "INSERT INTO test_collection(k, c1, c2) VALUES (0, [ 's@foo:i@32' ], { 's@foo:i@32': 's@bar:i@42' })"); Row r = session().execute("SELECT * FROM test_collection").one(); assertThat(r.getColumnDefinitions().getType("c1")) .isEqualTo(DataType.list(CUSTOM_DYNAMIC_COMPOSITE)); List<ByteBuffer> c1 = r.getList("c1", ByteBuffer.class); assertThat(c1.get(0)).isEqualTo(serializeForDynamicCompositeType("foo", 32)); assertThat(r.getColumnDefinitions().getType("c2")) .isEqualTo(DataType.map(CUSTOM_DYNAMIC_COMPOSITE, CUSTOM_DYNAMIC_COMPOSITE)); Map<ByteBuffer, ByteBuffer> c2 = r.getMap("c2", ByteBuffer.class, ByteBuffer.class); Map.Entry<ByteBuffer, ByteBuffer> entry = c2.entrySet().iterator().next(); assertThat(entry.getKey()).isEqualTo(serializeForDynamicCompositeType("foo", 32)); assertThat(entry.getValue()).isEqualTo(serializeForDynamicCompositeType("bar", 42)); }
if (row.getColumnDefinitions().contains(str) && !row.isNull(str)) c.indexColumns.put(str, row.getString(str));
assertThat(r.getColumnDefinitions().getType("c1")).isEqualTo(CUSTOM_DYNAMIC_COMPOSITE); assertThat(r.getColumnDefinitions().getType("c2")).isEqualTo(CUSTOM_COMPOSITE); assertThat(r.getColumnDefinitions().getType("c3")).isEqualTo(cint());
assertThat(row.getColumnDefinitions().getType("iavg")).isEqualTo(DataType.cfloat()); Float f = row.getFloat("iavg");
assertThat(row.getColumnDefinitions().getType("k")).isEqualTo(cint()); assertThat(row.getColumnDefinitions().getType("v")).isEqualTo(custom_udt);