org.apache.cassandra.db.marshal.AbstractType Java Examples
The following examples show how to use
org.apache.cassandra.db.marshal.AbstractType.
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: CassandraTypeDeserializerTest.java From debezium-incubator with Apache License 2.0 | 6 votes |
@Test public void testTupleType() { List<AbstractType<?>> innerAbstractTypes = new ArrayList<>(2); innerAbstractTypes.add(AsciiType.instance); innerAbstractTypes.add(ShortType.instance); TupleType tupleType = new TupleType(innerAbstractTypes); String sourceTupleString = "foo:1"; ByteBuffer serializedTuple = tupleType.fromString(sourceTupleString); Object deserializedTuple = CassandraTypeDeserializer.deserialize(tupleType, serializedTuple); Schema tupleSchema = CassandraTypeDeserializer.getSchemaBuilder(tupleType).build(); Struct expectedTuple = new Struct(tupleSchema) .put("field1", "foo") .put("field2", (short) 1); Assert.assertEquals(expectedTuple, deserializedTuple); }
Example #2
Source File: CellData.java From debezium-incubator with Apache License 2.0 | 6 votes |
static Schema cellSchema(ColumnMetadata cm, boolean optional) { AbstractType<?> convertedType = CassandraTypeConverter.convert(cm.getType()); Schema valueSchema = CassandraTypeDeserializer.getSchemaBuilder(convertedType).optional().build(); if (valueSchema != null) { SchemaBuilder schemaBuilder = SchemaBuilder.struct().name(cm.getName()) .field(CELL_VALUE_KEY, valueSchema) .field(CELL_DELETION_TS_KEY, Schema.OPTIONAL_INT64_SCHEMA) .field(CELL_SET_KEY, Schema.BOOLEAN_SCHEMA); if (optional) { schemaBuilder.optional(); } return schemaBuilder.build(); } else { return null; } }
Example #3
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 #4
Source File: BlobPlacementFactory.java From emodb with Apache License 2.0 | 6 votes |
@Override public Placement newPlacement(String placement) throws ConnectionException { String[] parsed = PlacementUtil.parsePlacement(placement); String keyspaceName = parsed[0]; String cfPrefix = parsed[1]; CassandraKeyspace keyspace = _keyspaceMap.get(keyspaceName); if (keyspace == null) { throw new UnknownPlacementException(format( "Placement string refers to unknown or non-local Cassandra keyspace: %s", keyspaceName), placement); } KeyspaceDefinition keyspaceDef = keyspace.getAstyanaxKeyspace().describeKeyspace(); ColumnFamily<ByteBuffer,Composite> columnFamily = getColumnFamily(keyspaceDef, cfPrefix, "blob", placement, new SpecificCompositeSerializer(CompositeType.getInstance(Arrays.<AbstractType<?>>asList( AsciiType.instance, IntegerType.instance)))); return new BlobPlacement(placement, keyspace, columnFamily); }
Example #5
Source File: ColumnMapper.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * Returns {@code true} if the specified Cassandra type/marshaller is supported, {@code false} otherwise. * * @param type A Cassandra type/marshaller. * @return {@code true} if the specified Cassandra type/marshaller is supported, {@code false} otherwise. */ public boolean supports(final AbstractType<?> type) { AbstractType<?> checkedType = type; if (type.isCollection()) { if (type instanceof MapType<?, ?>) { checkedType = ((MapType<?, ?>) type).getValuesType(); } else if (type instanceof ListType<?>) { checkedType = ((ListType<?>) type).getElementsType(); } else if (type instanceof SetType) { checkedType = ((SetType<?>) type).getElementsType(); } } if (type instanceof ReversedType) { ReversedType reversedType = (ReversedType) type; checkedType = reversedType.baseType; } for (AbstractType<?> n : supportedTypes) { if (checkedType.getClass() == n.getClass()) { return true; } } return false; }
Example #6
Source File: ThriftRangeUtilsTest.java From deep-spark with Apache License 2.0 | 6 votes |
private static <K extends Comparable, T extends Token<K>> void testDeepTokenRanges(IPartitioner<T> partitioner, K startToken, K endToken, List<String> endpoints, List<DeepTokenRange> expectedRanges) { ThriftRangeUtils utils = new ThriftRangeUtils(partitioner, "", 0, "", "", 0); Token.TokenFactory tokenFactory = partitioner.getTokenFactory(); AbstractType tokenType = partitioner.getTokenValidator(); String start = tokenFactory.toString(tokenFactory.fromByteArray(tokenType.decompose(startToken))); String end = tokenFactory.toString(tokenFactory.fromByteArray(tokenType.decompose(endToken))); CfSplit thriftSplit = new CfSplit(start, end, 0); List<DeepTokenRange> actualRanges = utils.deepTokenRanges(Arrays.asList(thriftSplit), endpoints); assertEquals(actualRanges, expectedRanges); }
Example #7
Source File: ColumnIdentifier.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public ColumnIdentifier prepare(CFMetaData cfm) { AbstractType<?> comparator = cfm.comparator.asAbstractType(); if (cfm.getIsDense() || comparator instanceof CompositeType || comparator instanceof UTF8Type) return new ColumnIdentifier(text, true); // We have a Thrift-created table with a non-text comparator. We need to parse column names with the comparator // to get the correct ByteBuffer representation. However, this doesn't apply to key aliases, so we need to // make a special check for those and treat them normally. See CASSANDRA-8178. ByteBuffer bufferName = ByteBufferUtil.bytes(text); for (ColumnDefinition def : cfm.partitionKeyColumns()) { if (def.name.bytes.equals(bufferName)) return new ColumnIdentifier(text, true); } return new ColumnIdentifier(comparator.fromString(rawText), text); }
Example #8
Source File: ColumnFamilyRecordReader.java From stratio-cassandra with Apache License 2.0 | 6 votes |
protected Pair<ByteBuffer, SortedMap<ByteBuffer, Cell>> computeNext() { maybeInit(); if (rows == null) return endOfData(); totalRead++; KeySlice ks = rows.get(i++); AbstractType<?> comp = isSuper ? CompositeType.getInstance(comparator, subComparator) : comparator; SortedMap<ByteBuffer, Cell> map = new TreeMap<ByteBuffer, Cell>(comp); for (ColumnOrSuperColumn cosc : ks.columns) { List<Cell> cells = unthriftify(cosc); for (Cell cell : cells) map.put(cell.name().toByteBuffer(), cell); } return Pair.create(ks.key, map); }
Example #9
Source File: CellValidator.java From deep-spark with Apache License 2.0 | 6 votes |
/** * private constructor. */ private CellValidator(Field field) { Class<?>[] types = AnnotationUtils.getGenericTypes(field); DeepField annotation = field.getAnnotation(DeepField.class); Class<? extends AbstractType> clazz = annotation.validationClass(); this.validatorClassName = annotation.validationClass().getCanonicalName(); this.validatorKind = Kind.validatorClassToKind(clazz); cqlTypeName = MAP_JAVA_TYPE_TO_DATA_TYPE_NAME.get(this.validatorClassName); switch (this.validatorKind) { case SET: case LIST: this.validatorTypes = asList(getCollectionInnerType(types[0])); break; case MAP: this.validatorTypes = asList(getCollectionInnerType(types[0]), getCollectionInnerType(types[1])); break; default: } }
Example #10
Source File: CellValidator.java From deep-spark with Apache License 2.0 | 6 votes |
/** * Generates the cassandra marshaller ({@link org.apache.cassandra.db.marshal.AbstractType}) for this CellValidator. * * @return an instance of the cassandra marshaller for this CellValidator. */ public AbstractType<?> getAbstractType() { if (abstractType != null) { return abstractType; } try { if (validatorKind == Kind.NOT_A_COLLECTION) { abstractType = MAP_ABSTRACT_TYPE_CLASS_TO_ABSTRACT_TYPE.get(forName (validatorClassName)); } else { throw new DeepGenericException("Cannot determine collection kind for " + validatorKind); } } catch (ClassNotFoundException e) { throw new DeepGenericException(e); } return abstractType; }
Example #11
Source File: CombinedTermIterator.java From sasi with Apache License 2.0 | 6 votes |
public CombinedTermIterator(Descriptor d, OnDiskIndex... parts) { descriptor = d; union = OnDiskIndexIterator.union(parts); AbstractType<?> comparator = parts[0].getComparator(); // assumes all SAs have same comparator ByteBuffer minimum = parts[0].minTerm(); ByteBuffer maximum = parts[0].maxTerm(); for (int i = 1; i < parts.length; i++) { OnDiskIndex part = parts[i]; if (part == null) continue; minimum = comparator.compare(minimum, part.minTerm()) > 0 ? part.minTerm() : minimum; maximum = comparator.compare(maximum, part.maxTerm()) < 0 ? part.maxTerm() : maximum; } min = minimum; max = maximum; }
Example #12
Source File: CassandraTypeConverterTest.java From debezium-incubator with Apache License 2.0 | 6 votes |
@Test public void testList() { // list of ints // test non-frozen DataType listType = DataType.list(DataType.cint(), false); AbstractType<?> convertedType = CassandraTypeConverter.convert(listType); ListType<?> expectedType = ListType.getInstance(Int32Type.instance, true); Assert.assertEquals(expectedType, convertedType); // test frozen listType = DataType.list(DataType.cint(), true); convertedType = CassandraTypeConverter.convert(listType); expectedType = ListType.getInstance(Int32Type.instance, false); Assert.assertEquals(expectedType, convertedType); Assert.assertTrue("Expected convertedType to be frozen", convertedType.isFrozenCollection()); }
Example #13
Source File: UserTypeConverter.java From debezium-incubator with Apache License 2.0 | 6 votes |
@Override public UserType convert(DataType dataType) { com.datastax.driver.core.UserType userType = (com.datastax.driver.core.UserType) dataType; String typeNameString = userType.getTypeName(); Collection<String> fieldNames = userType.getFieldNames(); List<AbstractType<?>> innerAbstractTypes = new ArrayList<>(fieldNames.size()); ByteBuffer typeNameBuffer = UTF8Type.instance.fromString(typeNameString); List<FieldIdentifier> fieldIdentifiers = new ArrayList<>(fieldNames.size()); for (String fieldName : fieldNames) { fieldIdentifiers.add(FieldIdentifier.forInternalString(fieldName)); innerAbstractTypes.add((CassandraTypeConverter.convert(userType.getFieldType(fieldName)))); } return new UserType(userType.getKeyspace(), typeNameBuffer, fieldIdentifiers, innerAbstractTypes, !userType.isFrozen()); }
Example #14
Source File: CassandraTypeConverterTest.java From debezium-incubator with Apache License 2.0 | 6 votes |
@Test public void testMap() { // map from ASCII to Double // test non-frozen DataType mapType = DataType.map(DataType.ascii(), DataType.cdouble()); AbstractType<?> convertedType = CassandraTypeConverter.convert(mapType); MapType<?, ?> expectedType = MapType.getInstance(AsciiType.instance, DoubleType.instance, true); Assert.assertEquals(expectedType, convertedType); // test frozen mapType = DataType.map(DataType.ascii(), DataType.cdouble(), true); convertedType = CassandraTypeConverter.convert(mapType); expectedType = MapType.getInstance(AsciiType.instance, DoubleType.instance, false); Assert.assertEquals(expectedType, convertedType); Assert.assertTrue("Expected convertType to be frozen", convertedType.isFrozenCollection()); }
Example #15
Source File: CassandraTypeConverterTest.java From debezium-incubator with Apache License 2.0 | 5 votes |
@Test public void testTinyInt() { DataType tinyInt = DataType.tinyint(); AbstractType<?> convertedType = CassandraTypeConverter.convert(tinyInt); ByteType expectedType = ByteType.instance; Assert.assertEquals(expectedType, convertedType); }
Example #16
Source File: PartitionIterator.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public String getKeyAsString() { StringBuilder sb = new StringBuilder(); int i = 0; for (Object key : partitionKey) { if (i > 0) sb.append("|"); AbstractType type = generator.partitionKey.get(i++).type; sb.append(type.getString(type.decompose(key))); } return sb.toString(); }
Example #17
Source File: CassandraTypeConverterTest.java From debezium-incubator with Apache License 2.0 | 5 votes |
@Test public void testInt() { DataType intType = DataType.cint(); AbstractType<?> convertedType = CassandraTypeConverter.convert(intType); Int32Type expectedType = Int32Type.instance; Assert.assertEquals(expectedType, convertedType); }
Example #18
Source File: CassandraTypeConverterTest.java From debezium-incubator with Apache License 2.0 | 5 votes |
@Test public void testTime() { DataType timeType = DataType.time(); AbstractType<?> convertedType = CassandraTypeConverter.convert(timeType); TimeType expectedType = TimeType.instance; Assert.assertEquals(expectedType, convertedType); }
Example #19
Source File: View.java From sasi with Apache License 2.0 | 5 votes |
public View(ColumnIndex index, AbstractType<?> keyValidator, Collection<SSTableIndex> currentView, Collection<SSTableReader> oldSSTables, Set<SSTableIndex> newIndexes) { Map<Descriptor, SSTableIndex> newView = new HashMap<>(); AbstractType<?> validator = index.getValidator(); TermTree.Builder termTreeBuilder = (validator instanceof AsciiType || validator instanceof UTF8Type) ? new PrefixTermTree.Builder(index.getMode().mode, validator) : new RangeTermTree.Builder(index.getMode().mode, validator); List<Interval<ByteBuffer, SSTableIndex>> keyIntervals = new ArrayList<>(); for (SSTableIndex sstableIndex : Iterables.concat(currentView, newIndexes)) { SSTableReader sstable = sstableIndex.getSSTable(); if (oldSSTables.contains(sstable) || sstable.isMarkedCompacted() || newView.containsKey(sstable.descriptor)) { sstableIndex.release(); continue; } newView.put(sstable.descriptor, sstableIndex); termTreeBuilder.add(sstableIndex); keyIntervals.add(Interval.create(sstableIndex.minKey(), sstableIndex.maxKey(), sstableIndex)); } this.view = newView; this.termTree = termTreeBuilder.build(); this.keyIntervalTree = IntervalTree.build(keyIntervals, keyValidator); if (keyIntervalTree.intervalCount() != termTree.intervalCount()) throw new IllegalStateException(String.format("mismatched sizes for intervals tree for keys vs terms: %d != %d", keyIntervalTree.intervalCount(), termTree.intervalCount())); }
Example #20
Source File: ColumnSliceTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void testDifferentMinMaxLengths() { List<AbstractType<?>> types = new ArrayList<>(); types.add(Int32Type.instance); types.add(Int32Type.instance); types.add(Int32Type.instance); CompoundDenseCellNameType nameType = new CompoundDenseCellNameType(types); // slice does intersect ColumnSlice slice = new ColumnSlice(composite(), composite()); assertTrue(slice.intersects(columnNames(), columnNames(1), nameType, false)); slice = new ColumnSlice(composite(), composite()); assertTrue(slice.intersects(columnNames(1), columnNames(1, 2), nameType, false)); slice = new ColumnSlice(composite(), composite(1)); assertTrue(slice.intersects(columnNames(), columnNames(1), nameType, false)); slice = new ColumnSlice(composite(1), composite()); assertTrue(slice.intersects(columnNames(), columnNames(1), nameType, false)); slice = new ColumnSlice(composite(1), composite(1)); assertTrue(slice.intersects(columnNames(), columnNames(1), nameType, false)); slice = new ColumnSlice(composite(0), composite(1, 2, 3)); assertTrue(slice.intersects(columnNames(), columnNames(1), nameType, false)); slice = new ColumnSlice(composite(1, 2, 3), composite(2)); assertTrue(slice.intersects(columnNames(), columnNames(1), nameType, false)); // slice does not intersect slice = new ColumnSlice(composite(2), composite(3, 4, 5)); assertFalse(slice.intersects(columnNames(), columnNames(1), nameType, false)); slice = new ColumnSlice(composite(0), composite(0, 1, 2)); assertFalse(slice.intersects(columnNames(1), columnNames(1, 2), nameType, false)); }
Example #21
Source File: QueryProcessor.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private static QueryOptions makeInternalOptions(ParsedStatement.Prepared prepared, Object[] values) { if (prepared.boundNames.size() != values.length) throw new IllegalArgumentException(String.format("Invalid number of values. Expecting %d but got %d", prepared.boundNames.size(), values.length)); List<ByteBuffer> boundValues = new ArrayList<ByteBuffer>(values.length); for (int i = 0; i < values.length; i++) { Object value = values[i]; AbstractType type = prepared.boundNames.get(i).type; boundValues.add(value instanceof ByteBuffer || value == null ? (ByteBuffer)value : type.decompose(value)); } return QueryOptions.forInternalCalls(boundValues); }
Example #22
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 #23
Source File: QueryProcessor.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private static void validateSelect(String keyspace, SelectStatement select, List<ByteBuffer> variables) throws InvalidRequestException { select.getConsistencyLevel().validateForRead(keyspace); // Finish key w/o start key (KEY < foo) if (!select.isKeyRange() && (select.getKeyFinish() != null)) throw new InvalidRequestException("Key range clauses must include a start key (i.e. KEY > term)"); // Key range and by-key(s) combined (KEY > foo AND KEY = bar) if (select.isKeyRange() && select.getKeys().size() > 0) throw new InvalidRequestException("You cannot combine key range and by-key clauses in a SELECT"); // Start and finish keys, *and* column relations (KEY > foo AND KEY < bar and name1 = value1). if (select.isKeyRange() && (select.getKeyFinish() != null) && (select.getColumnRelations().size() > 0)) throw new InvalidRequestException("You cannot combine key range and by-column clauses in a SELECT"); // Can't use more than one KEY = if (!select.isMultiKey() && select.getKeys().size() > 1) throw new InvalidRequestException("You cannot use more than one KEY = in a SELECT"); if (select.getColumnRelations().size() > 0) { ColumnFamilyStore cfstore = Keyspace.open(keyspace).getColumnFamilyStore(select.getColumnFamily()); CellNameType comparator = cfstore.metadata.comparator; AbstractType<?> at = comparator.asAbstractType(); SecondaryIndexManager idxManager = cfstore.indexManager; for (Relation relation : select.getColumnRelations()) { ByteBuffer name = relation.getEntity().getByteBuffer(at, variables); if ((relation.operator() == RelationType.EQ) && idxManager.indexes(comparator.cellFromByteBuffer(name))) return; } throw new InvalidRequestException("No indexed columns present in by-columns clause with \"equals\" operator"); } }
Example #24
Source File: Sets.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public boolean equals(SetType st, Value v) { if (elements.size() != v.elements.size()) return false; Iterator<ByteBuffer> thisIter = elements.iterator(); Iterator<ByteBuffer> thatIter = v.elements.iterator(); AbstractType elementsType = st.getElementsType(); while (thisIter.hasNext()) if (elementsType.compare(thisIter.next(), thatIter.next()) != 0) return false; return true; }
Example #25
Source File: CassandraTypeConverterTest.java From debezium-incubator with Apache License 2.0 | 5 votes |
@Test public void testDate() { DataType dateType = DataType.date(); AbstractType<?> convertedType = CassandraTypeConverter.convert(dateType); SimpleDateType expectedType = SimpleDateType.instance; Assert.assertEquals(expectedType, convertedType); }
Example #26
Source File: CassandraTypeConverterTest.java From debezium-incubator with Apache License 2.0 | 5 votes |
@Test public void testDecimal() { DataType decimalType = DataType.decimal(); AbstractType<?> convertedType = CassandraTypeConverter.convert(decimalType); DecimalType expectedType = DecimalType.instance; Assert.assertEquals(expectedType, convertedType); }
Example #27
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 #28
Source File: CassandraTypeConverterTest.java From debezium-incubator with Apache License 2.0 | 5 votes |
@Test public void testDuration() { DataType durationType = DataType.duration(); AbstractType<?> convertedType = CassandraTypeConverter.convert(durationType); DurationType expectedType = DurationType.instance; Assert.assertEquals(expectedType, convertedType); }
Example #29
Source File: CellNames.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public static CellNameType fromAbstractType(AbstractType<?> type, boolean isDense) { if (isDense) { if (type instanceof CompositeType) { return new CompoundDenseCellNameType(((CompositeType)type).types); } else { return new SimpleDenseCellNameType(type); } } else { if (type instanceof CompositeType) { List<AbstractType<?>> types = ((CompositeType)type).types; if (types.get(types.size() - 1) instanceof ColumnToCollectionType) { // We don't allow collection for super columns, so the "name" type *must* be UTF8 assert types.get(types.size() - 2) instanceof UTF8Type; return new CompoundSparseCellNameType.WithCollection(types.subList(0, types.size() - 2), (ColumnToCollectionType)types.get(types.size() - 1)); } else { AbstractType<?> nameType = types.get(types.size() - 1); return new CompoundSparseCellNameType(types.subList(0, types.size() - 1), nameType); } } else { return new SimpleSparseCellNameType(type); } } }
Example #30
Source File: CassandraTypeConverterTest.java From debezium-incubator with Apache License 2.0 | 5 votes |
@Test public void testInet() { DataType inetType = DataType.inet(); AbstractType<?> convertedType = CassandraTypeConverter.convert(inetType); InetAddressType expectedType = InetAddressType.instance; Assert.assertEquals(expectedType, convertedType); }