@Override public Long getLong( final MapScope scope, final String key ) { ByteBuffer value = getValueCQL( scope, key, cassandraConfig.getDataStaxReadCl()); return value != null ? (Long)DataType.bigint().deserialize(value, ProtocolVersion.NEWEST_SUPPORTED ) : null; }
protected static String getPrimitiveAvroTypeFromCassandraType(DataType dataType) { // Map types from Cassandra to Avro where possible if (dataType.equals(DataType.ascii()) || dataType.equals(DataType.text()) || dataType.equals(DataType.varchar()) // Nonstandard types represented by this processor as a string || dataType.equals(DataType.timestamp()) || dataType.equals(DataType.timeuuid()) || dataType.equals(DataType.uuid()) || dataType.equals(DataType.inet()) || dataType.equals(DataType.varint())) { return "string"; } else if (dataType.equals(DataType.cboolean())) { return "boolean"; } else if (dataType.equals(DataType.cint())) { return "int"; } else if (dataType.equals(DataType.bigint()) || dataType.equals(DataType.counter())) { return "long"; } else if (dataType.equals(DataType.cfloat())) { return "float"; } else if (dataType.equals(DataType.cdouble())) { return "double"; } else if (dataType.equals(DataType.blob())) { return "bytes"; } else { throw new IllegalArgumentException("createSchema: Unknown Cassandra data type " + dataType.getName() + " cannot be converted to Avro type"); } }
return row.getInt(i); } else if (dataType.equals(DataType.bigint()) || dataType.equals(DataType.counter())) { return row.getLong(i);
@Override public void putLong( final MapScope scope, final String key, final Long value ) { Preconditions.checkNotNull( scope, "mapscope is required" ); Preconditions.checkNotNull( key, "key is required" ); Preconditions.checkNotNull( value, "value is required" ); Statement mapEntry = QueryBuilder.insertInto(MAP_ENTRIES_TABLE) .value("key", getMapEntryPartitionKey(scope, key)) .value("column1", DataType.cboolean().serialize(true, ProtocolVersion.NEWEST_SUPPORTED)) .value("value", DataType.bigint().serialize(value, ProtocolVersion.NEWEST_SUPPORTED)); session.execute(mapEntry); final int bucket = BUCKET_LOCATOR.getCurrentBucket( scope.getName() ); Statement mapKey; mapKey = QueryBuilder.insertInto(MAP_KEYS_TABLE) .value("key", getMapKeyPartitionKey(scope, bucket)) .value("column1", DataType.text().serialize(key, ProtocolVersion.NEWEST_SUPPORTED)) .value("value", DataType.cboolean().serialize(true, ProtocolVersion.NEWEST_SUPPORTED)); session.execute(mapKey); }
private Object deserializeColumnValue(final String name, final ByteBuffer bb){ switch (name) { case TOKEN_TYPE: case TOKEN_PRINCIPAL_TYPE: return DataType.text().deserialize(bb, ProtocolVersion.NEWEST_SUPPORTED); case TOKEN_CREATED: case TOKEN_ACCESSED: case TOKEN_INACTIVE: case TOKEN_DURATION: return DataType.bigint().deserialize(bb, ProtocolVersion.NEWEST_SUPPORTED); case TOKEN_ENTITY: case TOKEN_APPLICATION: case TOKEN_WORKFLOW_ORG_ID: case TOKEN_UUID: return DataType.uuid().deserialize(bb, ProtocolVersion.NEWEST_SUPPORTED); case TOKEN_STATE: return fromByteBuffer(bb, Object.class); } return null; }
statement.setInt(paramIndex, (int) typeCodec.parse(paramValue)); } else if (mainType.equals(DataType.bigint()) || mainType.equals(DataType.counter())) { statement.setLong(paramIndex, (long) typeCodec.parse(paramValue));
@Test( groups = "unit", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "The '\\[pk\\]' columns can not be declared as partition keys and clustering keys at the same time") public void should_fail_if_same_partition_and_clustering_column() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addClusteringColumn("pk", DataType.bigint()) .getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "The '\\[cluster\\]' columns can not be declared as clustering keys and static columns at the same time") public void should_fail_if_same_clustering_and_static_column() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addClusteringColumn("cluster", DataType.bigint()) .addStaticColumn("cluster", DataType.text()) .getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "The '\\[pk\\]' columns can not be declared as partition keys and simple columns at the same time") public void should_fail_if_same_partition_and_simple_column() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addColumn("pk", DataType.text()) .getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "The '\\[pk\\]' columns can not be declared as partition keys and static columns at the same time") public void should_fail_if_same_partition_and_static_column() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addStaticColumn("pk", DataType.text()) .getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The partition key name 'ADD' is not allowed because it is a reserved keyword") public void should_fail_if_partition_key_is_a_reserved_keyword() throws Exception { createTable("test") .addPartitionKey("ADD", DataType.bigint()) .addColumn("col", DataType.text()) .getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "The table 'test' cannot declare static columns '\\[stat\\]' without clustering columns") public void should_fail_if_static_column_in_non_clustered_table() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addStaticColumn("stat", DataType.text()) .getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The keyspace name 'ADD' is not allowed because it is a reserved keyword") public void should_fail_if_keyspace_name_is_a_reserved_keyword() throws Exception { createTable("ADD", "test") .addPartitionKey("pk", DataType.bigint()) .addColumn("col", DataType.text()) .getQueryString(); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_read_repair_chance_out_of_bound() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .readRepairChance(1.3); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The column name 'ADD' is not allowed because it is a reserved keyword") public void should_fail_if_simple_column_is_a_reserved_keyword() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addClusteringColumn("cluster", DataType.uuid()) .addColumn("ADD", DataType.text()) .getQueryString(); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_negative_rows_per_partition() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .caching(KeyCaching.ALL, rows(-3)); }
@Test(groups = "unit", expectedExceptions = IllegalStateException.class) public void should_fail_when_both_caching_versions() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .caching(Caching.KEYS_ONLY) .caching(KeyCaching.ALL, allRows()) .getQueryString(); }
@Test(groups = "short") public void should_ignore_whitespace() { assertThat(parse(" int ", cluster(), null, null, null, false, false)).isEqualTo(cint()); assertThat(parse(" set < bigint > ", cluster(), null, null, null, false, false)) .isEqualTo(set(bigint())); assertThat(parse(" map < date , timeuuid > ", cluster(), null, null, null, false, false)) .isEqualTo(map(date(), timeuuid())); }
@Test(groups = "short") public void should_parse_frozen_collection_types() { assertThat(parse("frozen<list<int>>", cluster(), null, null, null, false, false)) .isEqualTo(list(cint(), true)); assertThat(parse("frozen<set<bigint>>", cluster(), null, null, null, false, false)) .isEqualTo(set(bigint(), true)); assertThat(parse("frozen<map<date,timeuuid>>", cluster(), null, null, null, false, false)) .isEqualTo(map(date(), timeuuid(), true)); }
@Test(groups = "short") public void should_parse_collection_types() { assertThat(parse("list<int>", cluster(), null, null, null, false, false)) .isEqualTo(list(cint())); assertThat(parse("set<bigint>", cluster(), null, null, null, false, false)) .isEqualTo(set(bigint())); assertThat(parse("map<date,timeuuid>", cluster(), null, null, null, false, false)) .isEqualTo(map(date(), timeuuid())); }