本文整理汇总了Java中org.apache.cassandra.db.marshal.BytesType类的典型用法代码示例。如果您正苦于以下问题:Java BytesType类的具体用法?Java BytesType怎么用?Java BytesType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BytesType类属于org.apache.cassandra.db.marshal包,在下文中一共展示了BytesType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parsedValue
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
private ByteBuffer parsedValue(AbstractType<?> validator) throws InvalidRequestException
{
if (validator instanceof ReversedType<?>)
validator = ((ReversedType<?>) validator).baseType;
try
{
// BytesType doesn't want it's input prefixed by '0x'.
if (type == Type.HEX && validator instanceof BytesType)
return validator.fromString(text.substring(2));
if (validator instanceof CounterColumnType)
return LongType.instance.fromString(text);
return validator.fromString(text);
}
catch (MarshalException e)
{
throw new InvalidRequestException(e.getMessage());
}
}
示例2: makeFromBlobFunction
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
public static Function makeFromBlobFunction(final AbstractType<?> toType)
{
final String name = "blobas" + toType.asCQL3Type();
return new AbstractFunction(name, toType, BytesType.instance)
{
public ByteBuffer execute(List<ByteBuffer> parameters) throws InvalidRequestException
{
ByteBuffer val = parameters.get(0);
try
{
if (val != null)
toType.validate(val);
return val;
}
catch (MarshalException e)
{
throw new InvalidRequestException(String.format("In call to function %s, value 0x%s is not a valid binary representation for type %s",
name, ByteBufferUtil.bytesToHex(val), toType.asCQL3Type()));
}
}
};
}
示例3: Writer
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
protected Writer(int keysToSave)
{
if (keysToSave >= getKeySet().size())
keys = getKeySet();
else
keys = hotKeySet(keysToSave);
OperationType type;
if (cacheType == CacheService.CacheType.KEY_CACHE)
type = OperationType.KEY_CACHE_SAVE;
else if (cacheType == CacheService.CacheType.ROW_CACHE)
type = OperationType.ROW_CACHE_SAVE;
else if (cacheType == CacheService.CacheType.COUNTER_CACHE)
type = OperationType.COUNTER_CACHE_SAVE;
else
type = OperationType.UNKNOWN;
info = new CompactionInfo(CFMetaData.denseCFMetaData(Keyspace.SYSTEM_KS, cacheType.toString(), BytesType.instance),
type,
0,
keys.size(),
"keys");
}
示例4: testAsciiKeyValidator
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
@Test
public void testAsciiKeyValidator() throws IOException, ParseException
{
File tempSS = tempSSTableFile("Keyspace1", "AsciiKeys");
ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create("Keyspace1", "AsciiKeys");
SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2, ActiveRepairService.UNREPAIRED_SSTABLE);
// Add a row
cfamily.addColumn(column("column", "value", 1L));
writer.append(Util.dk("key", AsciiType.instance), cfamily);
SSTableReader reader = writer.closeAndOpenReader();
// Export to JSON and verify
File tempJson = File.createTempFile("CFWithAsciiKeys", ".json");
SSTableExport.export(reader,
new PrintStream(tempJson.getPath()),
new String[0],
CFMetaData.sparseCFMetaData("Keyspace1", "AsciiKeys", BytesType.instance));
JSONArray json = (JSONArray)JSONValue.parseWithException(new FileReader(tempJson));
assertEquals(1, json.size());
JSONObject row = (JSONObject)json.get(0);
// check row key
assertEquals("key", row.get("key"));
}
示例5: Writer
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
protected Writer(int keysToSave)
{
if (keysToSave >= getKeySet().size())
keys = getKeySet();
else
keys = hotKeySet(keysToSave);
OperationType type;
if (cacheType == CacheService.CacheType.KEY_CACHE)
type = OperationType.KEY_CACHE_SAVE;
else if (cacheType == CacheService.CacheType.ROW_CACHE)
type = OperationType.ROW_CACHE_SAVE;
else
type = OperationType.UNKNOWN;
info = new CompactionInfo(new CFMetaData(Keyspace.SYSTEM_KS, cacheType.toString(), ColumnFamilyType.Standard, BytesType.instance, null),
type,
0,
keys.size(),
"keys");
}
示例6: parsedValue
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
private ByteBuffer parsedValue(AbstractType<?> validator) throws InvalidRequestException
{
if (validator instanceof ReversedType<?>)
validator = ((ReversedType<?>) validator).baseType;
try
{
if (type == Type.HEX)
// Note that validator could be BytesType, but it could also be a custom type, so
// we hardcode BytesType (rather than using 'validator') in the call below.
// Further note that BytesType doesn't want it's input prefixed by '0x', hence the substring.
return BytesType.instance.fromString(text.substring(2));
if (validator instanceof CounterColumnType)
return LongType.instance.fromString(text);
return validator.fromString(text);
}
catch (MarshalException e)
{
throw new InvalidRequestException(e.getMessage());
}
}
示例7: makeFromBlobFunction
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
public static Function makeFromBlobFunction(final AbstractType<?> toType)
{
final String name = "blobas" + toType.asCQL3Type();
return new NativeScalarFunction(name, toType, BytesType.instance)
{
public ByteBuffer execute(int protocolVersion, List<ByteBuffer> parameters) throws InvalidRequestException
{
ByteBuffer val = parameters.get(0);
try
{
if (val != null)
toType.validate(val);
return val;
}
catch (MarshalException e)
{
throw new InvalidRequestException(String.format("In call to function %s, value 0x%s is not a valid binary representation for type %s",
name, ByteBufferUtil.bytesToHex(val), toType.asCQL3Type()));
}
}
};
}
示例8: forKeyCache
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
public static SerializationHeader forKeyCache(CFMetaData metadata)
{
// We don't save type information in the key cache (we could change
// that but it's easier right now), so instead we simply use BytesType
// for both serialization and deserialization. Note that we also only
// serializer clustering prefixes in the key cache, so only the clusteringTypes
// really matter.
int size = metadata.clusteringColumns().size();
List<AbstractType<?>> clusteringTypes = new ArrayList<>(size);
for (int i = 0; i < size; i++)
clusteringTypes.add(BytesType.instance);
return new SerializationHeader(false,
BytesType.instance,
clusteringTypes,
PartitionColumns.NONE,
EncodingStats.NO_STATS,
Collections.<ByteBuffer, AbstractType<?>>emptyMap());
}
示例9: testEmptyVariableLengthTypes
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
@Test
public void testEmptyVariableLengthTypes()
{
AbstractType<?>[] types = new AbstractType<?>[]{
AsciiType.instance,
BytesType.instance,
UTF8Type.instance,
new UFTestCustomType()
};
for (AbstractType<?> type : types)
{
Assert.assertFalse("type " + type.getClass().getName(),
UDHelper.isNullOrEmpty(type, ByteBufferUtil.EMPTY_BYTE_BUFFER));
}
}
示例10: testNonTextComparator
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
@Test // test for CASSANDRA-8178
public void testNonTextComparator() throws Throwable
{
ColumnDef column = new ColumnDef();
column.setName(bytes(42))
.setValidation_class(UTF8Type.instance.toString());
CfDef cf = new CfDef("thriftcompat", "JdbcInteger");
cf.setColumn_type("Standard")
.setComparator_type(Int32Type.instance.toString())
.setDefault_validation_class(UTF8Type.instance.toString())
.setKey_validation_class(BytesType.instance.toString())
.setColumn_metadata(Collections.singletonList(column));
SchemaLoader.createKeyspace("thriftcompat", KeyspaceParams.simple(1), ThriftConversion.fromThrift(cf));
// the comparator is IntegerType, and there is a column named 42 with a UTF8Type validation type
execute("INSERT INTO \"thriftcompat\".\"JdbcInteger\" (key, \"42\") VALUES (0x00000001, 'abc')");
execute("UPDATE \"thriftcompat\".\"JdbcInteger\" SET \"42\" = 'abc' WHERE key = 0x00000001");
execute("DELETE \"42\" FROM \"thriftcompat\".\"JdbcInteger\" WHERE key = 0x00000000");
UntypedResultSet results = execute("SELECT key, \"42\" FROM \"thriftcompat\".\"JdbcInteger\"");
assertEquals(1, results.size());
UntypedResultSet.Row row = results.iterator().next();
assertEquals(ByteBufferUtil.bytes(1), row.getBytes("key"));
assertEquals("abc", row.getString("42"));
}
示例11: testComparisonMethod
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
@Test
public void testComparisonMethod()
{
ThreadLocalRandom random = ThreadLocalRandom.current();
byte[] commonBytes = new byte[10];
byte[] aBytes = new byte[16];
byte[] bBytes = new byte[16];
for (int i = 0 ; i < 100000 ; i++)
{
int commonLength = random.nextInt(0, 10);
random.nextBytes(commonBytes);
random.nextBytes(aBytes);
random.nextBytes(bBytes);
System.arraycopy(commonBytes, 0, aBytes, 0, commonLength);
System.arraycopy(commonBytes, 0, bBytes, 0, commonLength);
int aLength = random.nextInt(commonLength, 16);
int bLength = random.nextInt(commonLength, 16);
ColumnIdentifier a = new ColumnIdentifier(ByteBuffer.wrap(aBytes, 0, aLength), BytesType.instance);
ColumnIdentifier b = new ColumnIdentifier(ByteBuffer.wrap(bBytes, 0, bLength), BytesType.instance);
Assert.assertEquals("" + i, compareResult(a.compareTo(b)), compareResult(ByteBufferUtil.compareUnsigned(a.bytes, b.bytes)));
}
}
示例12: defineSchema
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
@BeforeClass
public static void defineSchema() throws ConfigurationException
{
CFMetaData cfMetadata = CFMetaData.Builder.create(KEYSPACE1, CF_STANDARD)
.addPartitionKey("key", BytesType.instance)
.addClusteringColumn("col1", AsciiType.instance)
.addRegularColumn("c1", AsciiType.instance)
.addRegularColumn("c2", AsciiType.instance)
.addRegularColumn("one", AsciiType.instance)
.addRegularColumn("two", AsciiType.instance)
.build();
CFMetaData cfMetaData2 = CFMetaData.Builder.create(KEYSPACE1, CF_COLLECTION)
.addPartitionKey("k", ByteType.instance)
.addRegularColumn("m", MapType.getInstance(IntegerType.instance, IntegerType.instance, true))
.build();
SchemaLoader.prepareServer();
SchemaLoader.createKeyspace(KEYSPACE1,
KeyspaceParams.simple(1),
cfMetadata, cfMetaData2);
}
示例13: defineSchema
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
@BeforeClass
public static void defineSchema() throws ConfigurationException
{
new Random().nextBytes(entropy);
DatabaseDescriptor.setCommitLogCompression(new ParameterizedClass("LZ4Compressor", ImmutableMap.of()));
DatabaseDescriptor.setCommitLogSegmentSize(1);
DatabaseDescriptor.setCommitLogSync(CommitLogSync.periodic);
DatabaseDescriptor.setCommitLogSyncPeriod(10 * 1000);
SchemaLoader.prepareServer();
SchemaLoader.createKeyspace(KEYSPACE1,
KeyspaceParams.simple(1),
SchemaLoader.standardCFMD(KEYSPACE1, STANDARD1, 0, AsciiType.instance, BytesType.instance),
SchemaLoader.standardCFMD(KEYSPACE1, STANDARD2, 0, AsciiType.instance, BytesType.instance));
CompactionManager.instance.disableAutoCompaction();
}
示例14: makeFromBlobFunction
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
public static Function makeFromBlobFunction(final AbstractType<?> toType)
{
final String name = "blobas" + toType.asCQL3Type();
return new NativeFunction(name, toType, BytesType.instance)
{
public ByteBuffer execute(List<ByteBuffer> parameters) throws InvalidRequestException
{
ByteBuffer val = parameters.get(0);
try
{
if (val != null)
toType.validate(val);
return val;
}
catch (MarshalException e)
{
throw new InvalidRequestException(String.format("In call to function %s, value 0x%s is not a valid binary representation for type %s",
name, ByteBufferUtil.bytesToHex(val), toType.asCQL3Type()));
}
}
};
}
示例15: defineSchema
import org.apache.cassandra.db.marshal.BytesType; //导入依赖的package包/类
@BeforeClass
public static void defineSchema() throws ConfigurationException
{
Map<String, String> compactionOptions = new HashMap<>();
compactionOptions.put("tombstone_compaction_interval", "1");
SchemaLoader.prepareServer();
SchemaLoader.createKeyspace(KEYSPACE1,
SimpleStrategy.class,
KSMetaData.optsWithRF(1),
SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD1).compactionStrategyOptions(compactionOptions),
SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD2),
SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD3),
SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD4),
SchemaLoader.superCFMD(KEYSPACE1, CF_SUPER1, LongType.instance),
SchemaLoader.superCFMD(KEYSPACE1, CF_SUPER5, BytesType.instance),
SchemaLoader.superCFMD(KEYSPACE1, CF_SUPERGC, BytesType.instance).gcGraceSeconds(0));
}