use of com.cinchapi.concourse.server.model.Value in project concourse by cinchapi.
the class RangeToken method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(key);
sb.append(operator != null ? " " + operator : " AS");
for (Value value : values) {
sb.append(" " + value);
}
return sb.toString();
}
use of com.cinchapi.concourse.server.model.Value in project concourse by cinchapi.
the class RangeTokens method convertToRange.
/**
* Convert the specified range {@code token} to one or more {@link Range
* ranges} that provide the appropriate coverage.
*
* @param token
* @return the Ranges
*/
public static Iterable<Range<Value>> convertToRange(RangeToken token) {
List<Range<Value>> ranges = Lists.newArrayListWithCapacity(1);
if (token.getOperator() == Operator.EQUALS || token.getOperator() == null) {
// null operator means
// the range token is for
// writing
ranges.add(Range.singleton(token.getValues()[0]));
} else if (token.getOperator() == Operator.NOT_EQUALS) {
ranges.add(Range.lessThan(token.getValues()[0]));
ranges.add(Range.greaterThan(token.getValues()[0]));
} else if (token.getOperator() == Operator.GREATER_THAN) {
ranges.add(Range.greaterThan(token.getValues()[0]));
} else if (token.getOperator() == Operator.GREATER_THAN_OR_EQUALS) {
ranges.add(Range.atLeast(token.getValues()[0]));
} else if (token.getOperator() == Operator.LESS_THAN) {
ranges.add(Range.lessThan(token.getValues()[0]));
} else if (token.getOperator() == Operator.LESS_THAN_OR_EQUALS) {
ranges.add(Range.atMost(token.getValues()[0]));
} else if (token.getOperator() == Operator.BETWEEN) {
Value a = token.getValues()[0];
Value b = token.getValues()[1];
if (a == Value.NEGATIVE_INFINITY && b == Value.POSITIVE_INFINITY) {
ranges.add(Range.<Value>all());
} else if (token.getValues().length == 3) {
ranges.add(Range.open(a, b));
} else if (token.getValues().length == 4) {
ranges.add(Range.closed(a, b));
} else if (token.getValues().length == 5) {
ranges.add(Range.openClosed(a, b));
} else {
ranges.add(Range.closedOpen(a, b));
}
} else if (token.getOperator() == Operator.REGEX || token.getOperator() == Operator.NOT_REGEX) {
ranges.add(Range.<Value>all());
} else {
throw new UnsupportedOperationException();
}
return ranges;
}
use of com.cinchapi.concourse.server.model.Value in project concourse by cinchapi.
the class TableChunkTest method testInsertLocatorWithTrailingWhiteSpace.
@Test
public void testInsertLocatorWithTrailingWhiteSpace() {
Identifier locator = Identifier.of(1);
Text key = Text.wrap("Youtube Embed Link ");
Value value = Value.wrap(Convert.javaToThrift("http://youtube.com"));
chunk.insert(locator, key, value, Time.now(), Action.ADD);
TableRecord record = TableRecord.createPartial(locator, key);
chunk.transfer(file);
chunk = load(file, filter, chunk.manifest());
chunk.seek(Composite.create(locator, key), record);
Assert.assertTrue(record.get(key).contains(value));
}
use of com.cinchapi.concourse.server.model.Value in project concourse by cinchapi.
the class CorpusChunkTest method testAsyncInsert.
@Test
public void testAsyncInsert() {
// Verify that inserting data serially and
// asynchronously produces a CorpusChunk with
// the same content
final Text aKey = Variables.register("aKey", TestData.getText());
final Value aValue = Variables.register("aValue", // force
Value.wrap(Convert.javaToThrift(TestData.getString())));
// string
final Identifier aRecord = Variables.register("aRecord", getRecord());
final long aTimestamp = Time.now();
final Text bKey = Variables.register("bKey", TestData.getText());
final Value bValue = Variables.register("bValue", // force
Value.wrap(Convert.javaToThrift(TestData.getString())));
// string
final Identifier bRecord = Variables.register("bRecord", getRecord());
final long bTimestamp = Time.now();
CorpusChunk serial = (CorpusChunk) create(BloomFilter.create(100));
serial.insert(aKey, aValue, aRecord, aTimestamp, Action.ADD);
serial.insert(bKey, bValue, bRecord, bTimestamp, Action.ADD);
final CorpusChunk async = (CorpusChunk) chunk;
Runnable a = new Runnable() {
@Override
public void run() {
async.insert(aKey, aValue, aRecord, aTimestamp, Action.ADD);
}
};
Runnable b = new Runnable() {
@Override
public void run() {
async.insert(bKey, bValue, bRecord, bTimestamp, Action.ADD);
}
};
ExecutorService executor = Executors.newFixedThreadPool(2);
executor.execute(a);
executor.execute(b);
executor.shutdown();
while (!executor.isTerminated()) {
continue;
}
Assert.assertEquals(serial.dump().split("\n")[1], // must ignore the first line of
async.dump().split("\n")[1]);
// dump output which contains the
// chunk id
}
use of com.cinchapi.concourse.server.model.Value in project concourse by cinchapi.
the class CorpusChunkTest method testMightContainLocatorKeyValue.
@Override
@Test
public void testMightContainLocatorKeyValue() {
Value value = null;
Text term = null;
int position = 0;
while (term == null) {
value = Value.wrap(Convert.javaToThrift(TestData.getString()));
position = 0;
for (String string : value.getObject().toString().split(TStrings.REGEX_GROUP_OF_ONE_OR_MORE_WHITESPACE_CHARS)) {
if (!GlobalState.STOPWORDS.contains(string) && !Strings.isNullOrEmpty(string)) {
term = Text.wrap(string);
break;
} else {
position++;
continue;
}
}
}
doTestMightContainLocatorKeyValue(getLocator(), value, term, getRecord(), position);
}
Aggregations