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

x33g5p2x  于2022-01-30 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(102)

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

TypeCodec.parse介绍

[英]Parse the given CQL literal into an instance of the Java type handled by this codec.

Implementors should take care of unquoting and unescaping the given CQL string where applicable. Null values and empty Strings should be accepted, as well as the string "NULL"; in most cases, implementations should interpret these inputs has equivalent to a nullreference.

Implementing this method is not strictly mandatory: internally, the driver only uses it to parse the INITCOND when building the metadata of an aggregate function (and in most cases it will use a built-in codec, unless the INITCOND has a custom type).
[中]将给定的CQL文本解析为该编解码器处理的Java类型的实例。
在适用的情况下,实现者应该注意取消引用和取消跳过给定的CQL字符串。应接受空值和空字符串,以及字符串“Null”;在大多数情况下,实现应该解释这些输入相当于一个空引用。
实现此方法并不是严格必需的:在内部,驱动程序在构建聚合函数的元数据时仅使用它来解析INITCOND(在大多数情况下,它将使用内置编解码器,除非INITCOND具有自定义类型)。

代码示例

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

statement.setBool(paramIndex, (boolean) typeCodec.parse(paramValue));
statement.setInt(paramIndex, (int) typeCodec.parse(paramValue));
statement.setLong(paramIndex, (long) typeCodec.parse(paramValue));
statement.setFloat(paramIndex, (float) typeCodec.parse(paramValue));
statement.setDouble(paramIndex, (double) typeCodec.parse(paramValue));
statement.setBytes(paramIndex, (ByteBuffer) typeCodec.parse(paramValue));
statement.setTimestamp(paramIndex, (Date) typeCodec.parse(paramValue));
    DataType secondParamType = getPrimitiveDataTypeFromString(secondParamTypeName);
    DataType mapType = DataType.map(firstParamType, secondParamType);
    statement.setMap(paramIndex, (Map) codecRegistry.codecFor(mapType).parse(paramValue));
    return;
    statement.setSet(paramIndex, (Set) codecRegistry.codecFor(setType).parse(paramValue));
    return;
  } else if (DataType.Name.LIST.toString().equalsIgnoreCase(mainTypeString)) {
    DataType listType = DataType.list(firstParamType);
    statement.setList(paramIndex, (List) codecRegistry.codecFor(listType).parse(paramValue));
    return;

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

@Override
public O parse(String value) throws InvalidTypeException {
 return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")
   ? null
   : deserialize(innerCodec.parse(value));
}

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

@Override
public NumberBox<T> parse(String value) throws InvalidTypeException {
 return new NumberBox<T>(numberCodec.parse(value));
}

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

@Override
 protected TupleValue parseAndSetField(String input, TupleValue target, int index) {
  DataType elementType = definition.getComponentTypes().get(index);
  TypeCodec<Object> codec = definition.getCodecRegistry().codecFor(elementType);
  target.set(index, codec.parse(input), codec.getJavaType());
  return target;
 }
}

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

K k = keyCodec.parse(value.substring(idx, n));
idx = n;
V v = valueCodec.parse(value.substring(idx, n));
idx = n;

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

l.add(eltCodec.parse(value.substring(idx, n)));
idx = n;

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

@Override
 protected UDTValue parseAndSetField(String input, UDTValue target, String fieldName) {
  DataType elementType = definition.getFieldType(fieldName);
  TypeCodec<Object> codec = definition.getCodecRegistry().codecFor(elementType);
  target.set(fieldName, codec.parse(input), codec.getJavaType());
  return target;
 }
}

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

@Test(groups = "unit")
public void parseFormatListTest() {
 String toParse = "['Foo','Bar','Foo''bar']";
 List<String> toFormat = Arrays.asList("Foo", "Bar", "Foo'bar");
 DataType dt = DataType.list(DataType.text());
 assertEquals(codecRegistry.codecFor(dt).parse(toParse), toFormat);
 assertEquals(codecRegistry.codecFor(dt).format(toFormat), toParse);
}

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

private void assertCodec(String input, Duration expected) {
  // serialize + deserialize
  ByteBuffer bytes = TypeCodec.duration().serialize(Duration.from(input), V4);
  Duration actual = TypeCodec.duration().deserialize(bytes, V4);
  assertThat(actual).isEqualTo(expected);
  // format + parse
  String format = TypeCodec.duration().format(Duration.from(input));
  actual = TypeCodec.duration().parse(format);
  assertThat(actual).isEqualTo(expected);
  // parse alone
  actual = TypeCodec.duration().parse(input);
  assertThat(actual).isEqualTo(expected);
 }
}

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

@SuppressWarnings("deprecation")
@Test(groups = "unit")
public void parseFormatTupleTest() {
 String toParse = "(1,'foo',1.0)";
 TupleType t =
   new TupleType(
     newArrayList(DataType.cint(), DataType.text(), DataType.cfloat()),
     protocolVersion,
     codecRegistry);
 TupleValue toFormat = t.newValue(1, "foo", 1.0f);
 assertEquals(codecRegistry.codecFor(t).parse(toParse), toFormat);
 assertEquals(codecRegistry.codecFor(t).format(toFormat), toParse);
}

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

@Test(groups = "unit")
public void parseNativeTest() {
 for (DataType dt : DataType.allPrimitiveTypes()) {
  if (exclude(dt)) continue;
  for (TestValue value : primitiveTestValues(dt))
   assertThat(codecRegistry.codecFor(dt).parse(value.cqlInputString))
     .as("Parsing input %s to a %s", value.cqlInputString, dt)
     .isEqualTo(value.javaObject);
 }
}

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

@SuppressWarnings("serial")
@Test(groups = "unit")
public void parseFormatSetTest() {
 String toParse = "{'Foo','Bar','Foo''bar'}";
 Set<String> toFormat =
   new LinkedHashSet<String>() {
    {
     add("Foo");
     add("Bar");
     add("Foo'bar");
    }
   };
 DataType dt = DataType.set(DataType.text());
 assertEquals(codecRegistry.codecFor(dt).parse(toParse), toFormat);
 assertEquals(codecRegistry.codecFor(dt).format(toFormat), toParse);
}

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

@SuppressWarnings("serial")
@Test(groups = "unit")
public void parseFormatMapTest() {
 String toParse = "{'Foo':3,'Bar':42,'Foo''bar':-24}";
 Map<String, Integer> toFormat =
   new LinkedHashMap<String, Integer>() {
    {
     put("Foo", 3);
     put("Bar", 42);
     put("Foo'bar", -24);
    }
   };
 DataType dt = DataType.map(DataType.text(), DataType.cint());
 assertEquals(codecRegistry.codecFor(dt).parse(toParse), toFormat);
 assertEquals(codecRegistry.codecFor(dt).format(toFormat), toParse);
}

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

@Override
public O parse(String value) throws InvalidTypeException {
 return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")
   ? null
   : deserialize(innerCodec.parse(value));
}

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

@Override
public T parse(String value) throws InvalidTypeException {
 return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")
   ? null
   : fromString(innerCodec.parse(value));
}

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

} else {
 try {
  initCond = codecRegistry.codecFor(stateType).parse(rawInitCond);
 } catch (RuntimeException e) {
  LOGGER.warn(

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

assertEquals(codecRegistry.codecFor(udt2).parse(toParse), toFormat);
assertEquals(codecRegistry.codecFor(udt2).format(toFormat), toParse);

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

@Override
public O parse(String value) throws InvalidTypeException {
 return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")
   ? null
   : deserialize(innerCodec.parse(value));
}

代码示例来源:origin: io.prestosql.cassandra/cassandra-driver

@Override
protected TupleValue parseAndSetField(String input, TupleValue target, int index) {
  DataType elementType = definition.getComponentTypes().get(index);
  TypeCodec<Object> codec = definition.getCodecRegistry().codecFor(elementType);
  target.set(index, codec.parse(input), codec.getJavaType());
  return target;
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver

@Override
  protected UDTValue parseAndSetField(String input, UDTValue target, String fieldName) {
    DataType elementType = definition.getFieldType(fieldName);
    TypeCodec<Object> codec = definition.getCodecRegistry().codecFor(elementType);
    target.set(fieldName, codec.parse(input), codec.getJavaType());
    return target;
  }
}

相关文章