deephaven / deephaven-core

Deephaven Community Core
Other
250 stars 80 forks source link

Enforce stream assumptions in BaseTable, like flat or add-only #1322

Open rcaudy opened 2 years ago

rcaudy commented 2 years ago

Do the equivalent to:

        if (isFlat()) {
            Assert.assertion(getIndex().isFlat(), "getIndex().isFlat()", getIndex(), "getIndex()");
        }
        if (isAddOnly()) {
            Assert.assertion(update.removed.empty(), "update.removed.empty()");
            Assert.assertion(update.modified.empty(), "update.modified.empty()");
            Assert.assertion(update.shifted.empty(), "update.shifted.empty()");
        }
nbauernfeind commented 2 years ago

I've had a related idea that I think you will love.

I believe that, similar to TableUpdateValidator that we can write up a light-weight TableAttributeValidator that incrementally proves invariants. Such as TABLE_IS_FLAT, TABLE_IS_ADD_ONLY. It would be nice to extend these to columns like COLUMN_IS_SORTED, COLUMN_IS_SINGLETON_ROW (this yields a very performant optimization for CROSS_JOIN -- which is a useful feature when exploring mathematical models. EDIT: consider this optimization a key-less naturalJoin -- we can always use the leftTable's index or an emptyIndex without maintaining any join state at all).

I'm sure there are even more interesting invariants that are cheap to verify incrementally.

Using these attributes we could make future optimizations -- such as don't sort, if it's already sorted (or reverse, if it's sorted in the wrong direction).

nbauernfeind commented 2 years ago

We could potentially have a "cheap" validation version of COLUMN_IS_UNIQUE using a bloom filter to warn on a potential duplicate value. That is, on warning, a user could: