Class BinarySearchKernelHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancompareConsistentWithEquality(@NotNull Class<?> dataType) WhetherdataTypecompares consistently with equality, meaningObjectComparisons.compare(a, b) == 0exactly whenObjectComparisons.eq(a, b), for every pair of values.static voidregisterConsistentType(@NotNull Class<?> dataType) RegistersdataTypeas ordering consistently with equality, letting a sorted binary search answer a match over a column of that type by ordering alone.
-
Method Details
-
registerConsistentType
RegistersdataTypeas ordering consistently with equality, letting a sorted binary search answer a match over a column of that type by ordering alone. SeecompareConsistentWithEquality(Class)for what that decides.The property is not verified; registering a type that lacks it will produce incorrect filter, as-of join, range join, sorted first or last, minimum, maximum, median, percentile, count distinct, distinct and unique results.
Registration is additive and idempotent, and a type cannot be withdrawn. Register types during startup: a search already under way keeps the set it started with.
- Parameters:
dataType- the column data type to register- Throws:
IllegalArgumentException- ifdataTypeis notComparable, sinceObjectComparisons.compare(Object, Object)could not order it at all
-
compareConsistentWithEquality
WhetherdataTypecompares consistently with equality, meaningObjectComparisons.compare(a, b) == 0exactly whenObjectComparisons.eq(a, b), for every pair of values.This decides how a sorted binary search may answer a match. The search navigates by
ObjectComparisons.compare(Object, Object), which isComparable.compareTo(Object), while a match is decided byObjectComparisons.eq(Object, Object), which isObjects.equals(Object, Object)-- the same relation the chunk filter uses. When the two agree, the ordering-equal run the search locates is exactly the set of matching rows and the search can answer the match outright. When they disagree --BigDecimalat differing scales, for one -- that run is only a superset, and the matches have to be picked out of it by equality. Sorted pushdown therefore matches a column of a type for which this holds withObjectRegionBinarySearchKernel.binarySearchMatchWithConsistentEquality(io.deephaven.engine.table.impl.sources.regioned.ColumnRegionObject<?, ?>, long, long, io.deephaven.api.SortColumn, java.lang.Object[])orObjectColumnBinarySearchKernel.binarySearchMatchWithConsistentEquality(io.deephaven.engine.table.ElementSource<?>, io.deephaven.engine.rowset.RowSet, io.deephaven.api.SortColumn, java.lang.Object[], boolean), and a column of any other type withObjectRegionBinarySearchKernel.binarySearchMatchWithGeneralEquality(io.deephaven.engine.table.impl.sources.regioned.ColumnRegionObject<?, ?>, long, long, io.deephaven.api.SortColumn, java.lang.Object[])orObjectColumnBinarySearchKernel.binarySearchMatchWithGeneralEquality(io.deephaven.engine.table.ColumnSource<?>, io.deephaven.engine.rowset.RowSet, io.deephaven.api.SortColumn, java.lang.Object[], boolean).BigDecimalis the exception: its match filter matches byBigDecimal.compareTo(java.math.BigDecimal), as the query language's==does, so sorted pushdown matches it by ordering alone too, checking for it by type before consulting this method.Only this stronger both-ways guarantee is checked, and only where documented, since
BigDecimalis a common counterexample. Afalseanswer still assumes the weakereq(a, b) implies compare(a, b) == 0, whichComparablerecommends and without which a type is unusable in any sorted context. An enum qualifies because its ordering is by ordinal and its equality is identity.The same answer selects between the EqualsConsistentObject and Object segmented sorted array, SSA stamp, duplicate compaction, compaction, segmented sorted multiset, and compact modifications classes, which test equality with
equalsand withObjectComparisons.compareEquals(Object, Object)respectively.The engine's own types are answered here; a type it does not know is answered
falseuntilregisterConsistentType(Class)says otherwise, so an unrecognized type costs speed rather than correctness.- Parameters:
dataType- the column's data type- Returns:
trueif a search by ordering alone decides a match for this type
-