Search in sources :

Example 16 with Value

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();
}
Also used : Value(com.cinchapi.concourse.server.model.Value)

Example 17 with Value

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;
}
Also used : Value(com.cinchapi.concourse.server.model.Value) Range(com.google.common.collect.Range)

Example 18 with Value

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));
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text) TableRecord(com.cinchapi.concourse.server.storage.db.TableRecord) Test(org.junit.Test)

Example 19 with 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
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value) ExecutorService(java.util.concurrent.ExecutorService) Text(com.cinchapi.concourse.server.model.Text) Test(org.junit.Test)

Example 20 with Value

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);
}
Also used : Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text) Test(org.junit.Test)

Aggregations

Value (com.cinchapi.concourse.server.model.Value)73 Text (com.cinchapi.concourse.server.model.Text)60 Test (org.junit.Test)43 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)34 Identifier (com.cinchapi.concourse.server.model.Identifier)25 CountDownLatch (java.util.concurrent.CountDownLatch)22 Set (java.util.Set)14 Operator (com.cinchapi.concourse.thrift.Operator)10 Action (com.cinchapi.concourse.server.storage.Action)6 Range (com.google.common.collect.Range)6 LinkedHashSet (java.util.LinkedHashSet)6 TObject (com.cinchapi.concourse.thrift.TObject)5 LazyTransformSet (com.cinchapi.common.collect.lazy.LazyTransformSet)3 RangeToken (com.cinchapi.concourse.server.concurrent.RangeToken)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 ByteBuffer (java.nio.ByteBuffer)3 Path (java.nio.file.Path)3 NavigableSet (java.util.NavigableSet)3 CoalescableTreeMap (com.cinchapi.common.collect.CoalescableTreeMap)2 Position (com.cinchapi.concourse.server.model.Position)2