com.datastax.driver.core.Row.getMap()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(86)

本文整理了Java中com.datastax.driver.core.Row.getMap方法的一些代码示例,展示了Row.getMap的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Row.getMap方法的具体详情如下:
包路径:com.datastax.driver.core.Row
类名称:Row
方法名:getMap

Row.getMap介绍

[英]Returns the ith value of this row as a map.
[中]以映射形式返回此行的第i个值。

代码示例

代码示例来源:origin: prestodb/presto

private static String buildMapValue(Row row, int i, CassandraType keyType, CassandraType valueType)
{
  StringBuilder sb = new StringBuilder();
  sb.append("{");
  for (Map.Entry<?, ?> entry : row.getMap(i, keyType.javaType, valueType.javaType).entrySet()) {
    if (sb.length() > 1) {
      sb.append(",");
    }
    sb.append(objectToString(entry.getKey(), keyType));
    sb.append(":");
    sb.append(objectToString(entry.getValue(), valueType));
  }
  sb.append("}");
  return sb.toString();
}

代码示例来源:origin: kairosdb/kairosdb

record.getString(1), new TreeMap<String, String>(record.getMap(2, String.class, String.class)));

代码示例来源:origin: jooby-project/jooby

@Override
public Session get(final Builder builder) {
 ResultSet rs = session
   .execute(new BoundStatement(selectSQL.apply(tableName)).bind(builder.sessionId()));
 return Optional.ofNullable(rs.one())
   .map(row -> {
    long createdAt = row.getTimestamp(CREATED_AT).getTime();
    long accessedAt = row.getTimestamp(ACCESSED_AT).getTime();
    long savedAt = row.getTimestamp(SAVED_AT).getTime();
    Map<String, String> attributes = row.getMap(ATTRIBUTES, String.class, String.class);
    Session session = builder
      .accessedAt(accessedAt)
      .createdAt(createdAt)
      .savedAt(savedAt)
      .set(attributes)
      .build();
    // touch ttl
    if (timeout > 0) {
     save(session);
    }
    return session;
   })
   .orElse(null);
}

代码示例来源:origin: apache/nifi

TypeCodec secondCodec = codecRegistry.codecFor(secondArg);
if (dataType.equals(DataType.map(firstArg, secondArg))) {
  return row.getMap(i, firstCodec.getJavaType(), secondCodec.getJavaType());

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/** Build an IndexMetadata from a system_schema.indexes row. */
static IndexMetadata fromRow(TableMetadata table, Row indexRow) {
 String name = indexRow.getString(NAME);
 Kind kind = Kind.valueOf(indexRow.getString(KIND));
 Map<String, String> options = indexRow.getMap(OPTIONS, String.class, String.class);
 String target = options.get(TARGET_OPTION_NAME);
 return new IndexMetadata(table, name, kind, target, options);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

static KeyspaceMetadata build(Row row, VersionNumber cassandraVersion) {
 if (cassandraVersion.getMajor() <= 2) {
  String name = row.getString(KS_NAME);
  boolean durableWrites = row.getBool(DURABLE_WRITES);
  Map<String, String> replicationOptions;
  replicationOptions = new HashMap<String, String>();
  replicationOptions.put("class", row.getString(STRATEGY_CLASS));
  replicationOptions.putAll(SimpleJSONParser.parseStringMap(row.getString(STRATEGY_OPTIONS)));
  return new KeyspaceMetadata(name, durableWrites, replicationOptions, false);
 } else {
  String name = row.getString(KS_NAME);
  boolean durableWrites = row.getBool(DURABLE_WRITES);
  return new KeyspaceMetadata(
    name, durableWrites, row.getMap(REPLICATION, String.class, String.class), false);
 }
}

代码示例来源:origin: Impetus/Kundera

retVal = row.getMap(columnName, mapGenericClasses.get(0).isAssignableFrom(byte[].class) ? ByteBuffer.class
    : mapGenericClasses.get(0), mapValueClazz);

代码示例来源:origin: org.apache.cassandra/cassandra-all

@Override
public <K, V> Map<K, V> getMap(String name, Class<K> keysClass, Class<V> valuesClass)
{
  return row.getMap(name, keysClass, valuesClass);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

parameters =
   Collections.unmodifiableMap(
     sessRow.getMap("parameters", String.class, String.class));
startedAt = sessRow.getTimestamp("started_at").getTime();

代码示例来源:origin: org.apache.cassandra/cassandra-all

@Override
public <K, V> Map<K, V> getMap(int i, Class<K> keysClass, Class<V> valuesClass)
{
  return row.getMap(i, keysClass, valuesClass);
}

代码示例来源:origin: jsevellec/cassandra-unit

@Override
public <K, V> Map<K, V> getMap(int i, TypeToken<K> typeToken, TypeToken<V> typeToken1)
{
  return row.getMap(i, typeToken, typeToken1);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

private void assertRow(Row row) {
  assertThat(row.getInt(0)).isEqualTo(n_int);
  assertThat(row.getList(1, Integer.class)).isEqualTo(l_int);
  assertThat(row.getList(2, Long.class)).isEqualTo(l_bigint);
  assertThat(row.getSet(3, Float.class)).isEqualTo(s_float);
  assertThat(row.getSet(4, Double.class)).isEqualTo(s_double);
  assertThat(row.getMap(5, Integer.class, BigInteger.class)).isEqualTo(m_varint);
  assertThat(row.getMap(6, Integer.class, BigDecimal.class)).isEqualTo(m_decimal);
  // with get + type
  assertThat(row.get(1, TypeTokens.listOf(Integer.class))).isEqualTo(l_int);
  assertThat(row.get(2, TypeTokens.listOf(Long.class))).isEqualTo(l_bigint);
  assertThat(row.get(3, TypeTokens.setOf(Float.class))).isEqualTo(s_float);
  assertThat(row.get(4, TypeTokens.setOf(Double.class))).isEqualTo(s_double);
  assertThat(row.get(5, TypeTokens.mapOf(Integer.class, BigInteger.class))).isEqualTo(m_varint);
  assertThat(row.get(6, TypeTokens.mapOf(Integer.class, BigDecimal.class))).isEqualTo(m_decimal);
  // with getObject
  assertThat(row.getObject(1)).isEqualTo(l_int);
  assertThat(row.getObject(2)).isEqualTo(l_bigint);
  assertThat(row.getObject(3)).isEqualTo(s_float);
  assertThat(row.getObject(4)).isEqualTo(s_double);
  assertThat(row.getObject(5)).isEqualTo(m_varint);
  assertThat(row.getObject(6)).isEqualTo(m_decimal);
 }
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

this.caching = ImmutableMap.copyOf(row.getMap(CACHING, String.class, String.class));
} else if (is210) {
 this.caching = ImmutableMap.copyOf(SimpleJSONParser.parseStringMap(row.getString(CACHING)));
 this.compaction = ImmutableMap.copyOf(row.getMap(COMPACTION, String.class, String.class));
else {
 this.compaction =
 this.compression = ImmutableMap.copyOf(row.getMap(COMPRESSION, String.class, String.class));
else
 this.compression =
 this.extensions = ImmutableMap.copyOf(row.getMap(EXTENSIONS, String.class, ByteBuffer.class));
else this.extensions = ImmutableMap.of();

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_handle_collections_of_UDT() throws Exception {
 UserType udtType = cluster().getMetadata().getKeyspace(keyspace).getUserType("udt");
 UDTValue udtValue =
   udtType.newValue().setInt("i", 2).setInet("a", InetAddress.getByName("localhost"));
 UDTValue udtValue2 =
   udtType.newValue().setInt("i", 3).setInet("a", InetAddress.getByName("localhost"));
 Statement insert = insertInto("udtTest").value("k", 1).value("l", ImmutableList.of(udtValue));
 assertThat(insert.toString())
   .isEqualTo("INSERT INTO udtTest (k,l) VALUES (1,[{i:2,a:'127.0.0.1'}]);");
 session().execute(insert);
 List<Row> rows = session().execute(select().from("udtTest").where(eq("k", 1))).all();
 assertThat(rows.size()).isEqualTo(1);
 Row r1 = rows.get(0);
 assertThat(r1.getList("l", UDTValue.class).get(0).getInet("a").getHostAddress())
   .isEqualTo("127.0.0.1");
 Map<Integer, UDTValue> map = Maps.newHashMap();
 map.put(0, udtValue);
 map.put(2, udtValue2);
 Statement updateMap = update("udtTest").with(putAll("m", map)).where(eq("k", 1));
 assertThat(updateMap.toString())
   .isEqualTo(
     "UPDATE udtTest SET m=m+{0:{i:2,a:'127.0.0.1'},2:{i:3,a:'127.0.0.1'}} WHERE k=1;");
 session().execute(updateMap);
 rows = session().execute(select().from("udtTest").where(eq("k", 1))).all();
 r1 = rows.get(0);
 assertThat(r1.getMap("m", Integer.class, UDTValue.class)).isEqualTo(map);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_delete_map_entry() throws Exception {
 // given
 session().execute("INSERT INTO test_coll (k, b) VALUES (1, {1:'foo', 2:'bar'})");
 // when
 BuiltStatement statement = delete().mapElt("b", 1).from("test_coll").where(eq("k", 1));
 session().execute(statement);
 // then
 Map<Integer, String> actual =
   session()
     .execute("SELECT b FROM test_coll WHERE k = 1")
     .one()
     .getMap("b", Integer.class, String.class);
 assertThat(actual).containsExactly(entry(2, "bar"));
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_handle_contains_on_map_with_index() {
 PreparedStatement byFeatures =
   session()
     .prepare(
       select("id", "description", "features_values")
         .from("products")
         .where(contains("features_values", bindMarker("feature"))));
 ResultSet results = session().execute(byFeatures.bind().setString("feature", "LED"));
 Row row = results.one();
 assertThat(row).isNotNull();
 assertThat(row.getInt("id")).isEqualTo(29412);
 assertThat(row.getMap("features_values", String.class, String.class))
   .containsEntry("techno", "LED");
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
 public void should_handle_contains_key_on_map_with_index() {
  PreparedStatement byFeatures =
    session()
      .prepare(
        select("id", "description", "features_keys")
          .from("products")
          .where(containsKey("features_keys", bindMarker("feature"))));

  ResultSet results = session().execute(byFeatures.bind().setString("feature", "refresh-rate"));

  Row row = results.one();
  assertThat(row).isNotNull();
  assertThat(row.getInt("id")).isEqualTo(34134);
  assertThat(row.getMap("features_keys", String.class, String.class))
    .containsEntry("refresh-rate", "400hz");
 }
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_delete_map_entry_with_bind_marker() throws Exception {
 // given
 session().execute("INSERT INTO test_coll (k, a, b) VALUES (1, null, {1:'foo', 2:'bar'})");
 // when
 BuiltStatement statement =
   delete().mapElt("b", bindMarker()).from("test_coll").where(eq("k", 1));
 PreparedStatement ps = session().prepare(statement);
 session().execute(ps.bind().setInt(0, 1));
 // then
 Map<Integer, String> actual =
   session()
     .execute("SELECT b FROM test_coll WHERE k = 1")
     .one()
     .getMap("b", Integer.class, String.class);
 assertThat(actual).containsExactly(entry(2, "bar"));
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * 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));
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

assertThat(getValue(row, "v", mapping.outerType, registry)).isEqualTo(mapping.value);
assertThat(row.getList("l", mapping.codec.getJavaType())).isEqualTo(list);
assertThat(row.getMap("m", mapping.codec.getJavaType(), mapping.codec.getJavaType()))
  .isEqualTo(map);
assertThat(row.getMap(2, mapping.codec.getJavaType(), mapping.codec.getJavaType()))
  .isEqualTo(map);

相关文章