use of com.cinchapi.concourse.Tag in project concourse by cinchapi.
the class Convert method javaToThrift.
/**
* Return the Thrift Object that represents {@code object}.
*
* @param object
* @return the TObject
*/
public static TObject javaToThrift(Object object) {
if (object == null) {
return TObject.NULL;
} else {
ByteBuffer bytes;
Type type = null;
if (object instanceof Boolean) {
bytes = ByteBuffer.allocate(1);
bytes.put((boolean) object ? (byte) 1 : (byte) 0);
type = Type.BOOLEAN;
} else if (object instanceof Double) {
bytes = ByteBuffer.allocate(8);
bytes.putDouble((double) object);
type = Type.DOUBLE;
} else if (object instanceof Float) {
bytes = ByteBuffer.allocate(4);
bytes.putFloat((float) object);
type = Type.FLOAT;
} else if (object instanceof Link) {
bytes = ByteBuffer.allocate(8);
bytes.putLong(((Link) object).longValue());
type = Type.LINK;
} else if (object instanceof Long) {
bytes = ByteBuffer.allocate(8);
bytes.putLong((long) object);
type = Type.LONG;
} else if (object instanceof Integer) {
bytes = ByteBuffer.allocate(4);
bytes.putInt((int) object);
type = Type.INTEGER;
} else if (object instanceof BigDecimal) {
bytes = ByteBuffer.allocate(8);
bytes.putDouble((double) ((BigDecimal) object).doubleValue());
type = Type.DOUBLE;
} else if (object instanceof Tag) {
bytes = ByteBuffer.wrap(object.toString().getBytes(StandardCharsets.UTF_8));
type = Type.TAG;
} else if (object instanceof Timestamp) {
try {
bytes = ByteBuffer.allocate(8);
bytes.putLong(((Timestamp) object).getMicros());
type = Type.TIMESTAMP;
} catch (IllegalStateException e) {
throw new UnsupportedOperationException("Cannot convert string based Timestamp to a TObject");
}
} else if (object instanceof Function) {
type = Type.FUNCTION;
Function function = (Function) object;
byte[] nameBytes = function.operation().getBytes(StandardCharsets.UTF_8);
byte[] keyBytes = function.key().getBytes(StandardCharsets.UTF_8);
if (function instanceof IndexFunction) {
/*
* Schema:
* | type (1) | timestamp(8) | nameLength (4) | name
* (nameLength) | key |
*/
bytes = ByteBuffer.allocate(1 + 8 + 4 + nameBytes.length + keyBytes.length);
bytes.put((byte) FunctionType.INDEX.ordinal());
bytes.putLong(((TemporalFunction) function).timestamp());
bytes.putInt(nameBytes.length);
bytes.put(nameBytes);
bytes.put(keyBytes);
} else if (function instanceof KeyRecordsFunction) {
/*
* Schema:
* | type (1) | timestamp(8) | nameLength (4) | name
* (nameLength) | keyLength (4) | key (keyLength) | records
* (8 each) |
*/
KeyRecordsFunction func = (KeyRecordsFunction) function;
bytes = ByteBuffer.allocate(1 + 8 + 4 + nameBytes.length + 4 + keyBytes.length + 8 * func.source().size());
bytes.put((byte) FunctionType.KEY_RECORDS.ordinal());
bytes.putLong(((TemporalFunction) function).timestamp());
bytes.putInt(nameBytes.length);
bytes.put(nameBytes);
bytes.putInt(keyBytes.length);
bytes.put(keyBytes);
for (long record : func.source()) {
bytes.putLong(record);
}
} else if (function instanceof KeyConditionFunction) {
/*
* Schema:
* | type (1) | timestamp(8) | nameLength (4) | name
* (nameLength) | keyLength (4) | key (keyLength) |
* condition |
*/
KeyConditionFunction func = (KeyConditionFunction) function;
String condition = ConcourseCompiler.get().tokenize(func.source()).stream().map(Symbol::toString).collect(Collectors.joining(" "));
bytes = ByteBuffer.allocate(1 + 9 + 4 + nameBytes.length + 4 + keyBytes.length + condition.length());
bytes.put((byte) FunctionType.KEY_CONDITION.ordinal());
bytes.putLong(((TemporalFunction) function).timestamp());
bytes.putInt(nameBytes.length);
bytes.put(nameBytes);
bytes.putInt(keyBytes.length);
bytes.put(keyBytes);
bytes.put(condition.getBytes(StandardCharsets.UTF_8));
} else {
throw new UnsupportedOperationException("Cannot convert the following function to a TObject: " + function);
}
} else {
bytes = ByteBuffer.wrap(object.toString().getBytes(StandardCharsets.UTF_8));
type = Type.STRING;
}
bytes.rewind();
return new TObject(bytes, type).setJavaFormat(object);
}
}
use of com.cinchapi.concourse.Tag in project concourse by cinchapi.
the class StoreTest method testSearchThatRecordWithValueAsTagIsNotIncludedInResultSetReproCON_129.
@Test
public void testSearchThatRecordWithValueAsTagIsNotIncludedInResultSetReproCON_129() {
String key = "yy2mf7yveeprn5u1znljubdmld8r2w";
Tag value = Tag.create("1");
Long tagRecord = -2641333647249146582L;
add(key, Convert.javaToThrift("btq0adgux53hjckphjeux7x1sxemyfpsdzipvy032n7t9daxkmw1h7r7zyl60ks5t06zjdjuj4iooq"), 285009080280006567L);
add(key, Convert.javaToThrift("7pu1v97xoz5063p9cuq2qoks"), -7352212869558049531L);
add(key, Convert.javaToThrift(false), 388620935878197713L);
add(key, Convert.javaToThrift("2m5lwamprzq4msvvs2wnv08zcqzi4newhl745qodce22h9yy812"), 1548639509905032340L);
add(key, Convert.javaToThrift("e ysho"), -765676142204325002L);
add(key, Convert.javaToThrift("jzfttlm258jejhsuapeqybe2j8fej3t7fgb2t6lqbbj"), 2679248400003802470L);
add(key, Convert.javaToThrift("s4i0ite7fep"), -2412570382637653495L);
add(key, Convert.javaToThrift("6o42czhg72u4u9w2gqfvrnc6c7tm3kp1811u6oi04ri8it5pomhxqx3h71omavvk5pmu4hgl10v00549e"), -1087503013401908104L);
add(key, Convert.javaToThrift("ob4yhyvk076c0 ock"), -9186255645112595336L);
add(key, Convert.javaToThrift("4n8c8bfiyjv0q6niyd6wa2l2s01s2g9jkq9y2dqbkz08zjcrmnbtf5vnyzflwthqcfxp o"), 8074263650552255137L);
add(key, Convert.javaToThrift(false), -1122802924122720425L);
add(key, Convert.javaToThrift(0.6491074), 8257322177342234041L);
add(key, Convert.javaToThrift(false), 2670863628024031952L);
add(key, Convert.javaToThrift(0.7184745217075929), 6804414020539721485L);
add(key, Convert.javaToThrift(value), tagRecord);
Set<Long> searchResult = store.search(key, value.toString());
Variables.register("searchResult", searchResult);
// "1" does get indexed
Assert.assertFalse(searchResult.isEmpty());
// from other values
}
use of com.cinchapi.concourse.Tag in project concourse by cinchapi.
the class StoreTest method testSearchThatRecordWithValueAsTagIsNotIncludedInResultSet.
@Test
public void testSearchThatRecordWithValueAsTagIsNotIncludedInResultSet() {
String key = Variables.register("key", TestData.getSimpleString());
Tag value = Variables.register("value", Tag.create(TestData.getString()));
Set<Long> records = addRecords(key, value, Operator.NOT_EQUALS);
Long tagRecord = null;
while (tagRecord == null || records.contains(tagRecord)) {
tagRecord = Variables.register("tagRecord", TestData.getLong());
}
add(key, Convert.javaToThrift(value), tagRecord);
Assert.assertFalse(store.search(key, value.toString()).contains(tagRecord));
}
use of com.cinchapi.concourse.Tag in project concourse by cinchapi.
the class StoreTest method testFindThatRecordWithValueAsTagIsIncludedInResultSet.
@Test
public void testFindThatRecordWithValueAsTagIsIncludedInResultSet() {
String key = TestData.getSimpleString();
Tag value = Tag.create(TestData.getString());
Set<Long> records = addRecords(key, value, Operator.NOT_EQUALS);
Long tagRecord = null;
while (tagRecord == null || records.contains(tagRecord)) {
tagRecord = TestData.getLong();
}
Set<Long> resultRecords = Sets.newHashSet();
resultRecords.add(tagRecord);
add(key, Convert.javaToThrift(value), tagRecord);
Assert.assertEquals(resultRecords, store.find(key, Operator.EQUALS, Convert.javaToThrift(value)));
}
use of com.cinchapi.concourse.Tag in project concourse by cinchapi.
the class CON672 method reproTag.
@Test
public void reproTag() {
Tag value = Tag.create("a=b");
Criteria criteria = Criteria.where().key("foo").operator(Operator.EQUALS).value(value);
System.out.println(criteria.ccl());
client.find(criteria);
// lack of Exception means the test passes
Assert.assertTrue(true);
}
Aggregations