org.apache.cassandra.db.marshal.LongType Java Examples

The following examples show how to use org.apache.cassandra.db.marshal.LongType. 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 vote down vote up
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: CompactionHistoryTabularData.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public static TabularData from(UntypedResultSet resultSet) throws OpenDataException
{
    TabularDataSupport result = new TabularDataSupport(TABULAR_TYPE);
    for (UntypedResultSet.Row row : resultSet)
    {
        UUID id = row.getUUID(ITEM_NAMES[0]);
        String ksName = row.getString(ITEM_NAMES[1]);
        String cfName = row.getString(ITEM_NAMES[2]);
        long compactedAt = row.getLong(ITEM_NAMES[3]);
        long bytesIn = row.getLong(ITEM_NAMES[4]);
        long bytesOut = row.getLong(ITEM_NAMES[5]);
        Map<Integer, Long> rowMerged = row.getMap(ITEM_NAMES[6], Int32Type.instance, LongType.instance);

        result.put(new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
                   new Object[]{ id.toString(), ksName, cfName, compactedAt, bytesIn, bytesOut,
                                 "{" + FBUtilities.toString(rowMerged) + "}" }));
    }
    return result;
}
 
Example #3
Source File: Constants.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
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: Attributes.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public long getTimestamp(long now, QueryOptions options) throws InvalidRequestException
{
    if (timestamp == null)
        return now;

    ByteBuffer tval = timestamp.bindAndGet(options);
    if (tval == null)
        throw new InvalidRequestException("Invalid null value of timestamp");

    try
    {
        LongType.instance.validate(tval);
    }
    catch (MarshalException e)
    {
        throw new InvalidRequestException("Invalid timestamp value");
    }

    return LongType.instance.compose(tval);
}
 
Example #5
Source File: CellValidatorTest.java    From deep-spark with Apache License 2.0 6 votes vote down vote up
public void testValidatorClassToKind() {
    assertEquals(Kind.validatorClassToKind(null), Kind.NOT_A_COLLECTION);
    assertEquals(Kind.validatorClassToKind(TimeUUIDType.class), Kind.NOT_A_COLLECTION);
    assertEquals(Kind.validatorClassToKind(UTF8Type.class), Kind.NOT_A_COLLECTION);
    assertEquals(Kind.validatorClassToKind(Int32Type.class), Kind.NOT_A_COLLECTION);

    assertEquals(Kind.validatorClassToKind(BooleanType.class), Kind.NOT_A_COLLECTION);
    assertEquals(Kind.validatorClassToKind(TimestampType.class), Kind.NOT_A_COLLECTION);
    assertEquals(Kind.validatorClassToKind(DecimalType.class), Kind.NOT_A_COLLECTION);
    assertEquals(Kind.validatorClassToKind(LongType.class), Kind.NOT_A_COLLECTION);
    assertEquals(Kind.validatorClassToKind(DoubleType.class), Kind.NOT_A_COLLECTION);

    assertEquals(Kind.validatorClassToKind(FloatType.class), Kind.NOT_A_COLLECTION);
    assertEquals(Kind.validatorClassToKind(InetAddressType.class), Kind.NOT_A_COLLECTION);
    assertEquals(Kind.validatorClassToKind(IntegerType.class), Kind.NOT_A_COLLECTION);
    assertEquals(Kind.validatorClassToKind(UUIDType.class), Kind.NOT_A_COLLECTION);

    assertEquals(Kind.validatorClassToKind(SetType.class), Kind.SET);
    assertEquals(Kind.validatorClassToKind(ListType.class), Kind.LIST);
    assertEquals(Kind.validatorClassToKind(MapType.class), Kind.MAP);
}
 
Example #6
Source File: OnDiskIndexTest.java    From sasi with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuperBlockRetrieval() throws Exception
{
    OnDiskIndexBuilder builder = new OnDiskIndexBuilder(UTF8Type.instance, LongType.instance, OnDiskIndexBuilder.Mode.SPARSE);
    for (long i = 0; i < 100000; i++)
        builder.add(LongType.instance.decompose(i), keyAt(i), i);

    File index = File.createTempFile("on-disk-sa-multi-superblock-match", ".db");
    index.deleteOnExit();

    builder.finish(index);

    OnDiskIndex onDiskIndex = new OnDiskIndex(index, LongType.instance, new KeyConverter());

    testSearchRangeWithSuperBlocks(onDiskIndex, 0, 500);
    testSearchRangeWithSuperBlocks(onDiskIndex, 300, 93456);
    testSearchRangeWithSuperBlocks(onDiskIndex, 210, 1700);
    testSearchRangeWithSuperBlocks(onDiskIndex, 530, 3200);

    Random random = new Random(0xdeadbeef);
    for (int i = 0; i < 100000; i += random.nextInt(1500)) // random steps with max of 1500 elements
    {
        for (int j = 0; j < 3; j++)
            testSearchRangeWithSuperBlocks(onDiskIndex, i, ThreadLocalRandom.current().nextInt(i, 100000));
    }
}
 
Example #7
Source File: OnDiskIndexTest.java    From sasi with Apache License 2.0 5 votes vote down vote up
private static Expression expressionFor(long lower, boolean lowerInclusive, long upper, boolean upperInclusive)
{
    Expression expression = new Expression(ByteBufferUtil.EMPTY_BYTE_BUFFER, LongType.instance);
    expression.add(lowerInclusive ? IndexOperator.GTE : IndexOperator.GT, LongType.instance.decompose(lower));
    expression.add(upperInclusive ? IndexOperator.LTE : IndexOperator.LT, LongType.instance.decompose(upper));
    return expression;
}
 
Example #8
Source File: OnDiskIndexTest.java    From sasi with Apache License 2.0 5 votes vote down vote up
private static Expression rangeWithExclusions(long lower, boolean lowerInclusive, long upper, boolean upperInclusive, Set<Long> exclusions)
{
    Expression expression = expressionFor(lower, lowerInclusive, upper, upperInclusive);
    for (long e : exclusions)
        expression.add(IndexOperator.NOT_EQ, LongType.instance.decompose(e));

    return expression;
}
 
Example #9
Source File: ColumnTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testToStringFromDecomposedWithoutSufix() {
    String name = "my_column";
    LongType type = LongType.instance;
    Long composedValue = 5L;
    ByteBuffer decomposedValue = type.decompose(composedValue);
    Column<Long> column = Column.fromDecomposed(name, decomposedValue, type);
    Assert.assertEquals("Column{fullName=my_column, composedValue=5, type=LongType}",
                        column.toString());
}
 
Example #10
Source File: ColumnTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testToStringFromDecomposedWithSufix() {
    String name = "my";
    String sufix = "column";
    LongType type = LongType.instance;
    Long composedValue = 5L;
    ByteBuffer decomposedValue = type.decompose(composedValue);
    Column<Long> column = Column.fromDecomposed(name, sufix, decomposedValue, type);
    Assert.assertEquals("Column{fullName=my.column, composedValue=5, type=LongType}",
                        column.toString());
}
 
Example #11
Source File: ColumnTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateFromComposedWithSufix() {
    String name = "my";
    String sufix = "column";
    LongType type = LongType.instance;
    Long composedValue = 5L;
    ByteBuffer decomposedValue = type.decompose(composedValue);
    Column<Long> column = Column.fromComposed(name, sufix, composedValue, type);
    Assert.assertEquals(name, column.getName());
    Assert.assertEquals("my.column", column.getFullName());
    Assert.assertEquals(type, column.getType());
    Assert.assertEquals(composedValue, column.getComposedValue());
    Assert.assertEquals(decomposedValue, column.getDecomposedValue());
}
 
Example #12
Source File: MappedBufferTest.java    From sasi with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompareToPage() throws IOException
{
    long numValues = 100;
    int typeSize = 8;

    try (MappedBuffer buffer = createTestFile(numValues))
    {
        for (long i = 0; i < numValues * typeSize; i += typeSize)
        {
            long value = i / typeSize;
            Assert.assertEquals(0, buffer.comparePageTo(i, typeSize, LongType.instance, LongType.instance.decompose(value)));
        }
    }
}
 
Example #13
Source File: Selection.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private static ColumnSpecification makeWritetimeOrTTLSpec(CFMetaData cfm, Selectable.WritetimeOrTTL tot, ColumnIdentifier alias)
{
    return new ColumnSpecification(cfm.ksName,
                                   cfm.cfName,
                                   alias == null ? new ColumnIdentifier(tot.toString(), true) : alias,
                                   tot.isWritetime ? LongType.instance : Int32Type.instance);
}
 
Example #14
Source File: CassandraTypeConverterTest.java    From debezium-incubator with Apache License 2.0 5 votes vote down vote up
@Test
public void testBigInt() {
    DataType bigIntType = DataType.bigint();
    AbstractType<?> convertedType = CassandraTypeConverter.convert(bigIntType);

    LongType expectedType = LongType.instance;

    Assert.assertEquals(expectedType, convertedType);
}
 
Example #15
Source File: ColumnTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateFromComposedWithoutSufix() {
    String name = "my_column";
    LongType type = LongType.instance;
    Long composedValue = 5L;
    ByteBuffer decomposedValue = type.decompose(composedValue);
    Column<Long> column = Column.fromComposed(name, composedValue, type);
    Assert.assertEquals(name, column.getName());
    Assert.assertEquals(name, column.getFullName());
    Assert.assertEquals(type, column.getType());
    Assert.assertEquals(composedValue, column.getComposedValue());
    Assert.assertEquals(decomposedValue, column.getDecomposedValue());
}
 
Example #16
Source File: CqlRecordWriter.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private AbstractType<?> parseType(String type) throws ConfigurationException
{
    try
    {
        // always treat counters like longs, specifically CCT.serialize is not what we need
        if (type != null && type.equals("org.apache.cassandra.db.marshal.CounterColumnType"))
            return LongType.instance;
        return TypeParser.parse(type);
    }
    catch (SyntaxException e)
    {
        throw new ConfigurationException(e.getMessage(), e);
    }
}
 
Example #17
Source File: ColumnTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateFromDecomposedWithSufix() {
    String name = "my";
    String sufix = "column";
    LongType type = LongType.instance;
    Long composedValue = 5L;
    ByteBuffer decomposedValue = type.decompose(composedValue);
    Column<Long> column = Column.fromDecomposed(name, sufix, decomposedValue, type);
    Assert.assertEquals(name, column.getName());
    Assert.assertEquals("my.column", column.getFullName());
    Assert.assertEquals(type, column.getType());
    Assert.assertEquals(composedValue, column.getComposedValue());
    Assert.assertEquals(decomposedValue, column.getDecomposedValue());
}
 
Example #18
Source File: ColumnTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateFromDecomposedWithoutSufix() {
    String name = "my_column";
    LongType type = LongType.instance;
    Long composedValue = 5L;
    ByteBuffer decomposedValue = type.decompose(composedValue);
    Column<Long> column = Column.fromDecomposed(name, decomposedValue, type);
    Assert.assertEquals(name, column.getName());
    Assert.assertEquals(name, column.getFullName());
    Assert.assertEquals(type, column.getType());
    Assert.assertEquals(composedValue, column.getComposedValue());
    Assert.assertEquals(decomposedValue, column.getDecomposedValue());
}
 
Example #19
Source File: Selection.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public AbstractType<?> getType()
{
    return isWritetime ? LongType.instance : Int32Type.instance;
}
 
Example #20
Source File: Longs.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public Longs(String name, GeneratorConfig config)
{
    super(LongType.instance, config, name, Long.class);
}
 
Example #21
Source File: Murmur3Partitioner.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public AbstractType<?> getTokenValidator()
{
    return LongType.instance;
}
 
Example #22
Source File: ResultSet.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public static ResultSet.Metadata makeCountMetadata(String ksName, String cfName, ColumnIdentifier alias)
{
    ColumnSpecification spec = new ColumnSpecification(ksName, cfName, alias == null ? COUNT_COLUMN : alias, LongType.instance);
    return new Metadata(Collections.singletonList(spec));
}
 
Example #23
Source File: Attributes.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
private ColumnSpecification timestampReceiver(String ksName, String cfName)
{
    return new ColumnSpecification(ksName, cfName, new ColumnIdentifier("[timestamp]", true), LongType.instance);
}
 
Example #24
Source File: TokenTreeTest.java    From sasi with Apache License 2.0 4 votes vote down vote up
@Test
public void testTokenMerge() throws Exception
{
    final long min = 0, max = 1000;

    // two different trees with the same offsets
    TokenTree treeA = generateTree(min, max);
    TokenTree treeB = generateTree(min, max);

    RangeIterator<Long, Token> a = treeA.iterator(new KeyConverter());
    RangeIterator<Long, Token> b = treeB.iterator(new KeyConverter());

    long count = min;
    while (a.hasNext() && b.hasNext())
    {
        final Token tokenA = a.next();
        final Token tokenB = b.next();

        // merging of two OnDiskToken
        tokenA.merge(tokenB);
        // merging with RAM Token with different offset
        tokenA.merge(new TokenWithOffsets(tokenA.get(), convert(count + 1)));
        // and RAM token with the same offset
        tokenA.merge(new TokenWithOffsets(tokenA.get(), convert(count)));

        // should fail when trying to merge different tokens
        try
        {
            tokenA.merge(new TokenWithOffsets(tokenA.get() + 1, convert(count)));
            Assert.fail();
        }
        catch (IllegalArgumentException e)
        {
            // expected
        }

        final Set<Long> offsets = new TreeSet<>();
        for (DecoratedKey key : tokenA)
             offsets.add(LongType.instance.compose(key.key));

        Set<Long> expected = new TreeSet<>();
        {
            expected.add(count);
            expected.add(count + 1);
        }

        Assert.assertEquals(expected, offsets);
        count++;
    }

    Assert.assertEquals(max, count - 1);
}
 
Example #25
Source File: OnDiskIndexTest.java    From sasi with Apache License 2.0 4 votes vote down vote up
@Test
public void testRangeQueryWithExclusions() throws Exception
{
    final long lower = 0;
    final long upper = 100000;

    OnDiskIndexBuilder builder = new OnDiskIndexBuilder(UTF8Type.instance, LongType.instance, OnDiskIndexBuilder.Mode.SPARSE);
    for (long i = lower; i <= upper; i++)
        builder.add(LongType.instance.decompose(i), keyAt(i), i);

    File index = File.createTempFile("on-disk-sa-except-long-ranges", "db");
    index.deleteOnExit();

    builder.finish(index);

    OnDiskIndex onDisk = new OnDiskIndex(index, LongType.instance, new KeyConverter());

    ThreadLocalRandom random = ThreadLocalRandom.current();

    // single exclusion

    // let's do small range first to figure out if searchPoint works properly
    validateExclusions(onDisk, lower, 50, Sets.newHashSet(42L));
    // now let's do whole data set to test SPARSE searching
    validateExclusions(onDisk, lower, upper, Sets.newHashSet(31337L));

    // pair of exclusions which would generate a split

    validateExclusions(onDisk, lower, random.nextInt(400, 800), Sets.newHashSet(42L, 154L));
    validateExclusions(onDisk, lower, upper, Sets.newHashSet(31337L, 54631L));

    // 3 exclusions which would generate a split and change bounds

    validateExclusions(onDisk, lower, random.nextInt(400, 800), Sets.newHashSet(42L, 154L));
    validateExclusions(onDisk, lower, upper, Sets.newHashSet(31337L, 54631L));

    validateExclusions(onDisk, lower, random.nextLong(400, upper), Sets.newHashSet(42L, 55L));
    validateExclusions(onDisk, lower, random.nextLong(400, upper), Sets.newHashSet(42L, 55L, 93L));
    validateExclusions(onDisk, lower, random.nextLong(400, upper), Sets.newHashSet(42L, 55L, 93L, 205L));

    Set<Long> exclusions = Sets.newHashSet(3L, 12L, 13L, 14L, 27L, 54L, 81L, 125L, 384L, 771L, 1054L, 2048L, 78834L);

    // test that exclusions are properly bound by lower/upper of the expression
    Assert.assertEquals(392, validateExclusions(onDisk, lower, 400, exclusions, false));
    Assert.assertEquals(101, validateExclusions(onDisk, lower, 100, Sets.newHashSet(-10L, -5L, -1L), false));

    validateExclusions(onDisk, lower, upper, exclusions);

    Assert.assertEquals(100000, convert(onDisk.search(new Expression(ByteBufferUtil.EMPTY_BYTE_BUFFER, LongType.instance)
                                                .add(IndexOperator.NOT_EQ, LongType.instance.decompose(100L)))).size());

    Assert.assertEquals(49, convert(onDisk.search(new Expression(ByteBufferUtil.EMPTY_BYTE_BUFFER, LongType.instance)
                                                .add(IndexOperator.LT, LongType.instance.decompose(50L))
                                                .add(IndexOperator.NOT_EQ, LongType.instance.decompose(10L)))).size());

    Assert.assertEquals(99998, convert(onDisk.search(new Expression(ByteBufferUtil.EMPTY_BYTE_BUFFER, LongType.instance)
                                                .add(IndexOperator.GT, LongType.instance.decompose(1L))
                                                .add(IndexOperator.NOT_EQ, LongType.instance.decompose(20L)))).size());

    onDisk.close();
}
 
Example #26
Source File: CassandraTypeDeserializerTest.java    From debezium-incubator with Apache License 2.0 3 votes vote down vote up
@Test
public void testLongType() {
    Long expectedLong = 8L;

    ByteBuffer serializedLong = LongType.instance.decompose(expectedLong);

    Object deserializedLong = CassandraTypeDeserializer.deserialize(LongType.instance, serializedLong);

    Assert.assertEquals(expectedLong, deserializedLong);
}