use of com.apple.foundationdb.record.metadata.IndexAggregateFunction in project fdb-record-layer by FoundationDB.
the class IndexFunctionHelperTest method filterIndexForBindAggregateFunction.
@Test
void filterIndexForBindAggregateFunction() {
final GroupingKeyExpression group = concat(field("str_value_indexed"), field("num_value_2")).group(1);
RecordMetaDataHook hook = metaData -> {
metaData.addIndex("MySimpleRecord", new Index("filtered_sum_value2", group, Index.EMPTY_VALUE, IndexTypes.SUM, Map.of()));
};
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, hook);
recordStore.deleteAllRecords();
final IndexAggregateFunction indexAggregateFunction = new IndexAggregateFunction("sum", group, null);
final Optional<IndexAggregateFunction> expected = Optional.of(new IndexAggregateFunction("sum", group, "filtered_sum_value2"));
assertEquals(expected, IndexFunctionHelper.bindAggregateFunction(recordStore, indexAggregateFunction, List.of("MySimpleRecord"), IndexQueryabilityFilter.TRUE));
assertEquals(Optional.empty(), IndexFunctionHelper.bindAggregateFunction(recordStore, indexAggregateFunction, List.of("MySimpleRecord"), IndexQueryabilityFilter.FALSE));
commit(context);
}
}
use of com.apple.foundationdb.record.metadata.IndexAggregateFunction in project fdb-record-layer by FoundationDB.
the class RankIndexTest method checkRankForScore.
@Test
public void checkRankForScore() throws Exception {
IndexAggregateFunction function = new IndexAggregateFunction(FunctionNames.RANK_FOR_SCORE, Key.Expressions.field("score").groupBy(Key.Expressions.field("gender")), null);
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
assertEquals(1L, recordStore.evaluateAggregateFunction(Collections.singletonList("BasicRankedRecord"), function, Key.Evaluated.concatenate("M", 100), IsolationLevel.SERIALIZABLE).join().getLong(0));
// Nobody has this score: this is the rank they would have with it.
assertEquals(2L, recordStore.evaluateAggregateFunction(Collections.singletonList("BasicRankedRecord"), function, Key.Evaluated.concatenate("M", 101), IsolationLevel.SERIALIZABLE).join().getLong(0));
commit(context);
}
}
use of com.apple.foundationdb.record.metadata.IndexAggregateFunction in project fdb-record-layer by FoundationDB.
the class RankIndexTest method checkScoreForRank.
@Test
public void checkScoreForRank() throws Exception {
IndexAggregateFunction function = new IndexAggregateFunction(FunctionNames.SCORE_FOR_RANK, Key.Expressions.field("score").groupBy(Key.Expressions.field("gender")), null);
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
assertEquals(100, recordStore.evaluateAggregateFunction(Collections.singletonList("BasicRankedRecord"), function, Key.Evaluated.concatenate("M", 1L), IsolationLevel.SERIALIZABLE).join().getLong(0));
commit(context);
}
}
use of com.apple.foundationdb.record.metadata.IndexAggregateFunction in project fdb-record-layer by FoundationDB.
the class RankIndexTest method countDistinct.
@Test
public void countDistinct() throws Exception {
final IndexAggregateFunction countByGender = new IndexAggregateFunction(FunctionNames.COUNT_DISTINCT, Key.Expressions.field("score").groupBy(Key.Expressions.field("gender")), null);
final List<String> types = Collections.singletonList("BasicRankedRecord");
try (FDBRecordContext context = openContext()) {
openRecordStore(context);
assertEquals(2, recordStore.evaluateAggregateFunction(types, countByGender, Key.Evaluated.scalar("M"), IsolationLevel.SERIALIZABLE).join().getLong(0));
assertEquals(2, recordStore.evaluateAggregateFunction(types, countByGender, Key.Evaluated.scalar("F"), IsolationLevel.SERIALIZABLE).join().getLong(0));
commit(context);
}
}
use of com.apple.foundationdb.record.metadata.IndexAggregateFunction in project fdb-record-layer by FoundationDB.
the class BitmapValueIndexTest method aggregateFunction.
@Test
void aggregateFunction() {
try (FDBRecordContext context = openContext()) {
createOrOpenRecordStore(context, metaData(REC_NO_BY_STR_NUMS_HOOK));
saveRecords(100, 200);
commit(context);
}
try (FDBRecordContext context = openContext()) {
createOrOpenRecordStore(context, metaData(REC_NO_BY_STR_NUMS_HOOK));
final IndexAggregateFunction aggregateFunction = new IndexAggregateFunction(FunctionNames.BITMAP_VALUE, REC_NO_BY_STR_NUM3, null);
assertThat(collectOnBits(recordStore.evaluateAggregateFunction(Collections.singletonList("MySimpleRecord"), aggregateFunction, TupleRange.allOf(Tuple.from("odd", 3)), IsolationLevel.SERIALIZABLE).join().getBytes(0), 0), equalTo(IntStream.range(100, 200).boxed().filter(i -> (i & 1) == 1).filter(i -> (i % 5) == 3).collect(Collectors.toList())));
assertThat(collectOnBits(recordStore.evaluateAggregateFunction(Collections.singletonList("MySimpleRecord"), aggregateFunction, TupleRange.between(Tuple.from("odd", 3, 160), Tuple.from("odd", 3, 180)), IsolationLevel.SERIALIZABLE).join().getBytes(0), 160), equalTo(IntStream.range(160, 180).boxed().filter(i -> (i & 1) == 1).filter(i -> (i % 5) == 3).collect(Collectors.toList())));
}
}
Aggregations