final ColumnDefinitions columnDefinitions = rs.getColumnDefinitions(); final int nrOfColumns = (columnDefinitions == null ? 0 : columnDefinitions.size()); String tableName = "NiFi_Cassandra_Query_Record"; if (nrOfColumns > 0) { String tableNameFromMeta = columnDefinitions.getTable(0); if (!StringUtils.isBlank(tableNameFromMeta)) { tableName = tableNameFromMeta; for (int i = 0; i < nrOfColumns; i++) { DataType dataType = columnDefinitions.getType(i); if (dataType == null) { throw new IllegalArgumentException("No data type for column[" + i + "] with name " + columnDefinitions.getName(i)); if (dataType.equals(DataType.set(firstArg)) || dataType.equals(DataType.list(firstArg))) { builder.name(columnDefinitions.getName(i)).type().unionOf().nullBuilder().endNull().and().array() .items(getUnionFieldType(getPrimitiveAvroTypeFromCassandraType(firstArg))).endUnion().noDefault(); } else { if (dataType.equals(DataType.map(firstArg, secondArg))) { builder.name(columnDefinitions.getName(i)).type().unionOf().nullBuilder().endNull().and().map().values( getUnionFieldType(getPrimitiveAvroTypeFromCassandraType(secondArg))).endUnion().noDefault(); builder.name(columnDefinitions.getName(i)) .type(getUnionFieldType(getPrimitiveAvroTypeFromCassandraType(dataType))).noDefault();
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; }
if (iterator.getColumnDefinitions().contains("row_time")) newIndex = true; while (!iterator.isExhausted()) Row record = iterator.one(); if (record.getString(1) == null) continue; //empty row rowKey = new DataPointsRowKey(m_metricName, m_clusterName, record.getTimestamp(0).getTime(), record.getString(1), new TreeMap<String, String>(record.getMap(2, String.class, String.class)));
final ColumnDefinitions columnDefinitions = rs.getColumnDefinitions(); long nrOfRows = 0; if (columnDefinitions != null) { int rowsAvailableWithoutFetching = rs.getAvailableWithoutFetching(); if (rowsAvailableWithoutFetching == 0) { rs.fetchMoreResults().get(); } else { rs.fetchMoreResults().get(timeout, timeUnit); for (int i = 0; i < columnDefinitions.size(); i++) { final DataType dataType = columnDefinitions.getType(i); final String colName = columnDefinitions.getName(i); if (i != 0) { outStream.write(",".getBytes(charset)); if (row.isNull(i)) { outStream.write(("\"" + colName + "\"" + ":null").getBytes(charset)); } else {
String version = row.getString("release_version"); 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);
static Raw fromRow(Row row, VersionNumber version) { String name = row.getString(COLUMN_NAME); kind = Kind.REGULAR; } else if (version.getMajor() < 3) { kind = row.isNull(KIND_V2) ? Kind.REGULAR : Kind.fromStringV2(row.getString(KIND_V2)); } else { kind = row.isNull(KIND_V3) ? Kind.REGULAR : Kind.fromStringV3(row.getString(KIND_V3)); if (row.getColumnDefinitions().contains(str) && !row.isNull(str)) c.indexColumns.put(str, row.getString(str));
.hasType(CUSTOM_COMPOSITE) .hasClusteringOrder(ClusteringOrder.DESC); assertThat(table.getColumn("c3")).hasType(cint()); Row r = rs.one(); 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(r.getInt("k")).isEqualTo(0); assertThat(r.getInt("c3")).isEqualTo(3); r = rs.one(); assertThat(r.getInt("k")).isEqualTo(0); assertThat(r.getBytesUnsafe("c1")).isEqualTo(serializeForDynamicCompositeType(42)); assertThat(r.getInt("c3")).isEqualTo(2); r = rs.one(); assertThat(r.getInt("k")).isEqualTo(0); assertThat(r.getBytesUnsafe("c1")).isEqualTo(serializeForDynamicCompositeType("foo", 32));
/** * 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)); }
.execute( select() .fcall("avg", cast(column("i"), DataType.cfloat())) .as("iavg") .from(TABLE2) .where(eq("k", "cast_t"))); assertThat(ar.getAvailableWithoutFetching()).isEqualTo(1); Row row = ar.one(); assertThat(row.getColumnDefinitions().getType("iavg")).isEqualTo(DataType.cfloat()); Float f = row.getFloat("iavg");
public int getColumnType(int column) throws SQLException { DataType type = null; if(currentRow!=null){ type = currentRow.getColumnDefinitions().getType(column-1); }else{ type = driverResultSet.getColumnDefinitions().asList().get(column-1).getType(); } return TypesMap.getTypeForComparator(type.toString()).getJdbcType(); }
assertThat(custom_udt.getFieldType("regular")).isEqualTo(cint()); assertThat(custom_udt.getFieldType("c2")).isEqualTo(DataType.bigint()); Row row = session().execute("select * from custom_udt_tbl").one(); assertThat(row.getColumnDefinitions().getType("k")).isEqualTo(cint()); assertThat(row.getColumnDefinitions().getType("v")).isEqualTo(custom_udt); UDTValue value = row.getUDTValue("v"); assertThat(value.getInt("regular")).isEqualTo(5); assertThat(value.getBytes("c1")).isEqualTo(serializeForDynamicCompositeType("hello", 93));
@Override public Map<String, Object> convert(Row row) { ColumnDefinitions cols = row.getColumnDefinitions(); Map<String, Object> map = new HashMap<>(cols.size()); cols.asList().stream().map(Definition::getName) .forEach(name -> map.put(name, row.isNull(name) ? null : row.getObject(name))); return map; } }
final Iterator<Row> rowIter = rSet.iterator(); final List results = new ArrayList(); final List item = new ArrayList<>(); final boolean isSingle = (rSet.getColumnDefinitions().size() == 1); final ColumnDefinitions columnDefs = row.getColumnDefinitions(); final Iterator<Definition> columnDefIter = columnDefs.iterator(); final Definition columnDef = columnDefIter.next(); item.add(DSClientUtilities.assign(row, null, null, columnDef.getType().getName(), null, columnDef.getName(), null, null));
@Override protected T wrapResultSet(ResultSet resultSet) { Row row = resultSet.one(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("got {} row for {} modify {}", row != null ? "1" : "no", mode, entity.type); } if (tracer != null) { tracer.onModifyWrapResultSet(persistenceSession, entity, mode, resultSet); } if (row != null) { int idx = row.getColumnDefinitions().getIndexOf("[applied]"); if (idx != -1 && !row.getBool(idx)) { throw new CasNotAppliedException(entity, instance, mode, row); } } persistenceSession.modified(binder, mode, entity, instance); Interceptors postModify = mode == PersistMode.DELETE ? entity.postDelete : entity.postPersist; if (postModify != null) { postModify.invoke(instance, entity, mode); } return null; }
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); }
.execute( select() .cast("f", DataType.cint()) .as("fint") .column("i") .where(eq("k", "cast_t"))); assertThat(r.getAvailableWithoutFetching()).isEqualTo(4); for (Row row : r) { Integer i = row.getInt("i"); assertThat(row.getColumnDefinitions().getType("fint")).isEqualTo(DataType.cint()); Integer f = row.getInt("fint"); switch (i) { case 1:
@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; }
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"); return cluster.translateAddress(new InetSocketAddress(nativeAddress, nativePort)); } else {