org.apache.cassandra.db.marshal.BytesType Java Examples
The following examples show how to use
org.apache.cassandra.db.marshal.BytesType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LazyCassandraUtils.java From Hive-Cassandra with Apache License 2.0 | 6 votes |
public static AbstractType getCassandraType(PrimitiveObjectInspector oi) { switch (oi.getPrimitiveCategory()) { case BOOLEAN: return BooleanType.instance; case INT: return Int32Type.instance; case LONG: return LongType.instance; case FLOAT: return FloatType.instance; case DOUBLE: return DoubleType.instance; case STRING: return UTF8Type.instance; case BYTE: case SHORT: case BINARY: return BytesType.instance; case TIMESTAMP: return DateType.instance; default: throw new RuntimeException("Hive internal error."); } }
Example #2
Source File: SSTableExportTest.java From stratio-cassandra with Apache License 2.0 | 6 votes |
@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")); }
Example #3
Source File: Constants.java From stratio-cassandra with Apache License 2.0 | 6 votes |
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()); } }
Example #4
Source File: BytesConversionFcts.java From stratio-cassandra with Apache License 2.0 | 6 votes |
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())); } } }; }
Example #5
Source File: AutoSavingCache.java From stratio-cassandra with Apache License 2.0 | 6 votes |
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"); }
Example #6
Source File: MvccLogEntrySerializationStrategyV1Impl.java From usergrid with Apache License 2.0 | 5 votes |
@Override public Collection<MultiTenantColumnFamilyDefinition> getColumnFamilies() { //create the CF entity data. We want it reversed b/c we want the most recent version at the top of the //row for fast seeks MultiTenantColumnFamilyDefinition cf = new MultiTenantColumnFamilyDefinition( CF_ENTITY_LOG, BytesType.class.getSimpleName(), ReversedType.class.getSimpleName() + "(" + UUIDType.class.getSimpleName() + ")", IntegerType.class.getSimpleName(), MultiTenantColumnFamilyDefinition.CacheOption.KEYS ); return Collections.singleton( cf ); }
Example #7
Source File: CassandraTypeConverterTest.java From debezium-incubator with Apache License 2.0 | 5 votes |
@Test public void testBlob() { DataType blobType = DataType.blob(); AbstractType<?> convertedType = CassandraTypeConverter.convert(blobType); BytesType expectedType = BytesType.instance; Assert.assertEquals(expectedType, convertedType); }
Example #8
Source File: JsonOutputFormat.java From aegisthus with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private AbstractType<ByteBuffer> getConverter(Configuration conf, String key) { String converterType = conf.get(key); if (Strings.isNullOrEmpty(key)) { return BytesType.instance; } try { return (AbstractType<ByteBuffer>) TypeParser.parse(converterType); } catch (SyntaxException | ConfigurationException e) { throw Throwables.propagate(e); } }
Example #9
Source File: SSTableColumnScanner.java From aegisthus with Apache License 2.0 | 5 votes |
private String keyToString(byte[] rowKey) { if (rowKey == null) { return "null"; } String str = BytesType.instance.getString(ByteBuffer.wrap(rowKey)); return StringUtils.left(str, 32); }
Example #10
Source File: MvccEntitySerializationStrategyImpl.java From usergrid with Apache License 2.0 | 5 votes |
@Override public java.util.Collection getColumnFamilies() { //create the CF entity data. We want it reversed b/c we want the most recent version at the top of the //row for fast seeks MultiTenantColumnFamilyDefinition cf = new MultiTenantColumnFamilyDefinition( columnFamily, BytesType.class.getSimpleName(), ReversedType.class.getSimpleName() + "(" + UUIDType.class.getSimpleName() + ")", BytesType.class.getSimpleName(), MultiTenantColumnFamilyDefinition.CacheOption.KEYS ); return Collections.singleton( cf ); }
Example #11
Source File: MvccEntitySerializationStrategyV3Impl.java From usergrid with Apache License 2.0 | 5 votes |
@Override public java.util.Collection getColumnFamilies() { //create the CF entity data. We want it reversed b/c we want the most recent version at the top of the //row for fast seeks MultiTenantColumnFamilyDefinition cf = new MultiTenantColumnFamilyDefinition( CF_ENTITY_DATA, BytesType.class.getSimpleName(), BooleanType.class.getSimpleName() , BytesType.class.getSimpleName(), MultiTenantColumnFamilyDefinition.CacheOption.KEYS ); return Collections.singleton( cf ); }
Example #12
Source File: MvccLogEntrySerializationStrategyV2Impl.java From usergrid with Apache License 2.0 | 5 votes |
@Override public Collection<MultiTenantColumnFamilyDefinition> getColumnFamilies() { //create the CF entity data. We want it reversed b/c we want the most recent version at the top of the //row for fast seeks MultiTenantColumnFamilyDefinition cf = new MultiTenantColumnFamilyDefinition( CF_ENTITY_LOG_V2, BytesType.class.getSimpleName(), ReversedType.class.getSimpleName() + "(" + UUIDType.class.getSimpleName() + ")", IntegerType.class.getSimpleName(), MultiTenantColumnFamilyDefinition.CacheOption.KEYS ); return Collections.singleton( cf ); }
Example #13
Source File: JsonColumnParser.java From hadoop-sstable with Apache License 2.0 | 5 votes |
private void serializeColumns(StringBuilder sb, SSTableIdentityIterator rowIterator, Mapper.Context context) { while (rowIterator.hasNext()) { OnDiskAtom atom = rowIterator.next(); if (atom instanceof IColumn) { IColumn column = (IColumn) atom; String cn = getColumnName(column.name(), columnNameConverter); sb.append("[\""); sb.append(cn); sb.append("\", \""); sb.append(JSONObject.escape(getColumnValueConvertor(handleCompositeColumnName(cn), BytesType.instance).getString(column.value()))); sb.append("\", "); sb.append(column.timestamp()); if (column instanceof DeletedColumn) { sb.append(", "); sb.append("\"d\""); } else if (column instanceof ExpiringColumn) { sb.append(", "); sb.append("\"e\""); sb.append(", "); sb.append(((ExpiringColumn) column).getTimeToLive()); sb.append(", "); sb.append(column.getLocalDeletionTime()); } else if (column instanceof CounterColumn) { sb.append(", "); sb.append("\"c\""); sb.append(", "); sb.append(((CounterColumn) column).timestampOfLastDelete()); } sb.append("]"); if (rowIterator.hasNext()) { sb.append(", "); } } else if (atom instanceof RangeTombstone) { context.getCounter("Columns", "Range Tombstone Found").increment(1L); } } }
Example #14
Source File: MigrationInfoSerializationImpl.java From usergrid with Apache License 2.0 | 5 votes |
@Override public Collection<MultiTenantColumnFamilyDefinition> getColumnFamilies() { return Collections.singletonList( new MultiTenantColumnFamilyDefinition( CF_MIGRATION_INFO, BytesType.class.getSimpleName(), UTF8Type.class.getSimpleName(), BytesType.class.getSimpleName(), MultiTenantColumnFamilyDefinition.CacheOption.KEYS ) ); }
Example #15
Source File: NodeSerializationImpl.java From usergrid with Apache License 2.0 | 5 votes |
@Override public Collection<MultiTenantColumnFamilyDefinition> getColumnFamilies() { return Collections.singleton( new MultiTenantColumnFamilyDefinition( GRAPH_DELETE, BytesType.class.getSimpleName(), BooleanType.class.getSimpleName(), BytesType.class.getSimpleName(), MultiTenantColumnFamilyDefinition.CacheOption.ALL ) ); }
Example #16
Source File: EdgeShardSerializationImpl.java From usergrid with Apache License 2.0 | 5 votes |
@Override public Collection<MultiTenantColumnFamilyDefinition> getColumnFamilies() { return Collections.singleton( new MultiTenantColumnFamilyDefinition( EDGE_SHARDS, BytesType.class.getSimpleName(), ColumnTypes.LONG_TYPE_REVERSED, BytesType.class.getSimpleName(), MultiTenantColumnFamilyDefinition.CacheOption.KEYS ) ); }
Example #17
Source File: SizebasedEdgeColumnFamilies.java From usergrid with Apache License 2.0 | 5 votes |
@Override public Collection<MultiTenantColumnFamilyDefinition> getColumnFamilies() { return Arrays .asList( graphCf( SOURCE_NODE_EDGES ), graphCf( TARGET_NODE_EDGES ), graphCf( SOURCE_NODE_TARGET_TYPE ), graphCf( TARGET_NODE_SOURCE_TYPE ), new MultiTenantColumnFamilyDefinition( EDGE_VERSIONS, BytesType.class.getSimpleName(), ColumnTypes.LONG_TYPE_REVERSED, BytesType.class.getSimpleName(), MultiTenantColumnFamilyDefinition.CacheOption.ALL ) ); }
Example #18
Source File: CrunchBulkRecordWriter.java From hdfs2cass with Apache License 2.0 | 5 votes |
private void prepareWriter() { String columnFamily = CrunchConfigHelper.getOutputColumnFamily(conf); String keyspace = ConfigHelper.getOutputKeyspace(conf); if (outputdir == null) { // dir must be named by ks/cf for the loader outputdir = Paths.get(getOutputLocation(), keyspace, columnFamily).toFile(); outputdir.mkdirs(); } if (writer == null) { AbstractType<?> subcomparator = null; if (cfType == CFType.SUPER) subcomparator = BytesType.instance; this.writer = new SSTableSimpleWriter( outputdir, ConfigHelper.getOutputPartitioner(conf), keyspace, columnFamily, BytesType.instance, subcomparator); ExternalSSTableLoaderClient externalClient = new ExternalSSTableLoaderClient( ConfigHelper.getOutputInitialAddress(conf), ConfigHelper.getOutputRpcPort(conf), ConfigHelper.getOutputKeyspaceUserName(conf), ConfigHelper.getOutputKeyspacePassword(conf)); this.loader = new SSTableLoader(outputdir, externalClient, new OutputHandler.SystemOutput(true, true)); } }
Example #19
Source File: CassandraTypeDeserializerTest.java From debezium-incubator with Apache License 2.0 | 5 votes |
@Test public void testBytes() { ByteBuffer expectedBytes = ByteBuffer.wrap("some random stuff here".getBytes(CHARSET)); // Pretty sure this is a no-op, but for consistency... ByteBuffer serializedBytes = BytesType.instance.decompose(expectedBytes); Object deserializedBytes = CassandraTypeDeserializer.deserialize(BytesType.instance, serializedBytes); Assert.assertEquals(expectedBytes, deserializedBytes); }
Example #20
Source File: SSTableExportTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Tests CASSANDRA-6892 (key aliases being used improperly for validation) */ @Test public void testColumnNameEqualToDefaultKeyAlias() throws IOException, ParseException { File tempSS = tempSSTableFile("Keyspace1", "UUIDKeys"); ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create("Keyspace1", "UUIDKeys"); SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2, ActiveRepairService.UNREPAIRED_SSTABLE); // Add a row cfamily.addColumn(column(CFMetaData.DEFAULT_KEY_ALIAS, "not a uuid", 1L)); writer.append(Util.dk(ByteBufferUtil.bytes(UUIDGen.getTimeUUID())), cfamily); SSTableReader reader = writer.closeAndOpenReader(); // Export to JSON and verify File tempJson = File.createTempFile("CFWithColumnNameEqualToDefaultKeyAlias", ".json"); SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[0], CFMetaData.sparseCFMetaData("Keyspace1", "UUIDKeys", BytesType.instance)); JSONArray json = (JSONArray)JSONValue.parseWithException(new FileReader(tempJson)); assertEquals(1, json.size()); JSONObject row = (JSONObject)json.get(0); JSONArray cols = (JSONArray) row.get("cells"); assertEquals(1, cols.size()); // check column name and value JSONArray col = (JSONArray) cols.get(0); assertEquals(CFMetaData.DEFAULT_KEY_ALIAS, ByteBufferUtil.string(hexToBytes((String) col.get(0)))); assertEquals("not a uuid", ByteBufferUtil.string(hexToBytes((String) col.get(1)))); }
Example #21
Source File: CellValidatorTest.java From deep-spark with Apache License 2.0 | 5 votes |
public void testBlobDataType() { CellValidator cv = cellValidator(DataType.blob()); assertNotNull(cv); assertEquals(cv.getValidatorClassName(), BytesType.class.getName()); assertNull(cv.getValidatorTypes()); assertNotNull(cv.getAbstractType()); assertEquals(cv.getAbstractType(), BytesType.instance); }
Example #22
Source File: BytesConversionFcts.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public static Function makeToBlobFunction(AbstractType<?> fromType) { String name = fromType.asCQL3Type() + "asblob"; return new AbstractFunction(name, BytesType.instance, fromType) { public ByteBuffer execute(List<ByteBuffer> parameters) { return parameters.get(0); } }; }
Example #23
Source File: CompressedRandomAccessReaderTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void test6791() throws IOException, ConfigurationException { File f = File.createTempFile("compressed6791_", "3"); String filename = f.getAbsolutePath(); try { MetadataCollector sstableMetadataCollector = new MetadataCollector(new SimpleDenseCellNameType(BytesType.instance)); CompressedSequentialWriter writer = new CompressedSequentialWriter(f, filename + ".metadata", new CompressionParameters(SnappyCompressor.instance, 32, Collections.<String, String>emptyMap()), sstableMetadataCollector); for (int i = 0; i < 20; i++) writer.write("x".getBytes()); FileMark mark = writer.mark(); // write enough garbage to create new chunks: for (int i = 0; i < 40; ++i) writer.write("y".getBytes()); writer.resetAndTruncate(mark); for (int i = 0; i < 20; i++) writer.write("x".getBytes()); writer.close(); CompressedRandomAccessReader reader = CompressedRandomAccessReader.open(filename, new CompressionMetadata(filename + ".metadata", f.length(), true)); String res = reader.readLine(); assertEquals(res, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); assertEquals(40, res.length()); } finally { // cleanup if (f.exists()) f.delete(); File metadata = new File(filename+ ".metadata"); if (metadata.exists()) metadata.delete(); } }
Example #24
Source File: SSTableImport.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Get key validator for column family * @param columnFamily column family instance * @return key validator for given column family */ private AbstractType<?> getKeyValidator(ColumnFamily columnFamily) { // this is a fix to support backward compatibility // which allows to skip the current key validator // please, take a look onto CASSANDRA-7498 for more details if ("true".equals(System.getProperty("skip.key.validator", "false"))) { return BytesType.instance; } return columnFamily.metadata().getKeyValidator(); }
Example #25
Source File: ColumnMapperBlob.java From stratio-cassandra with Apache License 2.0 | 4 votes |
/** * Builds a new {@link ColumnMapperBlob}. */ @JsonCreator public ColumnMapperBlob() { super(new AbstractType<?>[]{AsciiType.instance, UTF8Type.instance, BytesType.instance}, new AbstractType[]{}); }
Example #26
Source File: SizebasedEdgeColumnFamilies.java From usergrid with Apache License 2.0 | 4 votes |
/** * Helper to generate an edge definition by the type */ private MultiTenantColumnFamilyDefinition graphCf(MultiTenantColumnFamily cf ) { return new MultiTenantColumnFamilyDefinition( cf, BytesType.class.getSimpleName(), EDGE_DYNAMIC_COMPOSITE_TYPE, BytesType.class.getSimpleName(), MultiTenantColumnFamilyDefinition.CacheOption.ALL ); }
Example #27
Source File: CassandraEmbeddedStoreManager.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
private void ensureColumnFamilyExists(String ksName, String cfName) throws BackendException { ensureColumnFamilyExists(ksName, cfName, BytesType.instance); }
Example #28
Source File: EdgeMetadataSerializationV1Impl.java From usergrid with Apache License 2.0 | 4 votes |
/** * Helper to generate an edge definition by the type */ private MultiTenantColumnFamilyDefinition graphCf(MultiTenantColumnFamily cf ) { return new MultiTenantColumnFamilyDefinition( cf, BytesType.class.getSimpleName(), UTF8Type.class.getSimpleName(), BytesType.class.getSimpleName(), MultiTenantColumnFamilyDefinition.CacheOption.KEYS ); }
Example #29
Source File: EdgeMetadataSerializationV2Impl.java From usergrid with Apache License 2.0 | 4 votes |
/** * Helper to generate an edge definition by the type */ private MultiTenantColumnFamilyDefinition graphCf(MultiTenantColumnFamily cf ) { return new MultiTenantColumnFamilyDefinition( cf, BytesType.class.getSimpleName(), UTF8Type.class.getSimpleName(), BytesType.class.getSimpleName(), MultiTenantColumnFamilyDefinition.CacheOption.KEYS ); }
Example #30
Source File: AbstractByteOrderedPartitioner.java From stratio-cassandra with Apache License 2.0 | 4 votes |
public AbstractType<?> getTokenValidator() { return BytesType.instance; }