Search in sources :

Example 1 with ValuePickerValue

use of com.apple.foundationdb.record.query.predicates.ValuePickerValue in project fdb-record-layer by FoundationDB.

the class FDBSelectorPlanTest method testPlanValues.

@DualPlannerTest
void testPlanValues() throws Throwable {
    complexQuerySetup(NO_HOOK);
    RecordQuery query1 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").build();
    RecordQuery query2 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("num_value_2").equalsValue(1)).build();
    RecordQueryPlan plan = RecordQuerySelectorPlan.from(plan(query1, query2), List.of(50, 50));
    List<? extends Value> resultValues = plan.getResultValues();
    assertThat(resultValues.size(), is(1));
    ValuePickerValue value = (ValuePickerValue) resultValues.get(0);
    List<Value> subValues = ImmutableList.copyOf(value.getChildren());
    assertThat(subValues.size(), is(2));
    assertThat(subValues.get(0), is(plan.getQuantifiers().get(0).getFlowedValues().get(0)));
    assertThat(subValues.get(1), is(plan.getQuantifiers().get(1).getFlowedValues().get(0)));
}
Also used : ValuePickerValue(com.apple.foundationdb.record.query.predicates.ValuePickerValue) ValuePickerValue(com.apple.foundationdb.record.query.predicates.ValuePickerValue) Value(com.apple.foundationdb.record.query.predicates.Value) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) DualPlannerTest(com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest)

Example 2 with ValuePickerValue

use of com.apple.foundationdb.record.query.predicates.ValuePickerValue in project fdb-record-layer by FoundationDB.

the class RecordQueryChooserPlanBase method calculateChildrenValues.

/**
 * This utility calculates the list of values that are returned by the plan. The plan returns a list of
 * {@link ValuePickerValue} that each represent the values returned by one of the child plans.
 * Each {@link ValuePickerValue} holds a "selected index" that determines which of the sub-values it references, so
 * that, in all, when the same "selected index" is chosen for all picker value, one would get back a consistent set
 * of values, representing one of the child plans for this plan.
 *
 * @return list of {@link ValuePickerValue} representing all the values from all the sub plans
 */
private List<? extends Value> calculateChildrenValues() {
    // Store all values in a multimap, indexed by the ordinal of the value in the returned list
    // Each list represents all the i'th Value from each of the sub plans
    ImmutableListMultimap.Builder<Integer, Value> mapBuilder = ImmutableListMultimap.builder();
    quantifiers.forEach(quantifier -> {
        List<? extends Value> values = quantifier.getFlowedValues();
        for (int i = 0; i < values.size(); i++) {
            mapBuilder.put(i, values.get(i));
        }
    });
    ImmutableListMultimap<Integer, ? extends Value> valuesMap = mapBuilder.build();
    ImmutableList.Builder<ValuePickerValue> resultBuilder = ImmutableList.builder();
    for (int i = 0; i < valuesMap.keySet().size(); i++) {
        ImmutableList<? extends Value> subValues = valuesMap.get(i);
        // For now, fix all the picker values to return the first sub value
        resultBuilder.add(new ValuePickerValue(0, subValues));
    }
    return resultBuilder.build();
}
Also used : ValuePickerValue(com.apple.foundationdb.record.query.predicates.ValuePickerValue) ImmutableList(com.google.common.collect.ImmutableList) ValuePickerValue(com.apple.foundationdb.record.query.predicates.ValuePickerValue) Value(com.apple.foundationdb.record.query.predicates.Value) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap)

Aggregations

Value (com.apple.foundationdb.record.query.predicates.Value)2 ValuePickerValue (com.apple.foundationdb.record.query.predicates.ValuePickerValue)2 DualPlannerTest (com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest)1 RecordQuery (com.apple.foundationdb.record.query.RecordQuery)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1