druid icon indicating copy to clipboard operation
druid copied to clipboard

Indexer does not merge properly when dimensions are provided in non-lexicographic order

Open gianm opened this issue 12 years ago • 13 comments

If you give the indexer dimensions in some arbitrary order, the IncrementalIndex will sort its rows based on the values of dimensions in that order. Then, when the IndexMerger merges multiple indexes, it uses a MergeIterable that assumes rows are sorted on values of dimensions in lexicographic order instead of the order the underlying segments actually use. This causes the rowboats to come in out of order and not get combined properly, and the resulting segments have more rows than they should.

Workarounds include: Supply dimensions in lexicographic order in the indexer config. Avoid indexing with dimensionless schemas.

I can think of two possible fixes:

  • IndexMerger could try to use arbitrary dimension orders from the underlying segment when possible. I think this is not possible in general while both getting correct rollup and avoiding re-sorting rows, since the underlying segments could use different row comparators. But it will be possible in many situations. The IndexMerger can also decide to sort rows in situations where it would need to.
  • IncrementalIndex could sort rows based on dimensions in lexicographic order instead of arbitrary order. This makes the IndexMerger's job easier but it means we can't control the row comparator, which could be useful if we ever decide to mess with it in order to do something like optimize size of the inverted indices.

gianm avatar Aug 05 '14 18:08 gianm

Does arbitrary order make sense, if you want your commonly queried dimensions to be sorted next to each other, indexed and merged together ?

srini-mp avatar Oct 31 '14 20:10 srini-mp

@srini-mp If you are specifying the dimensions, then no, this is not a problem. It becomes a problem when you are ingesting data in a schema-less fashion and the sets of dimensions seen don't always happen in the same order.

cheddar avatar Dec 29 '14 18:12 cheddar

@gianm @cheddar I'm trying to understand this one and looking at the code. though I could understand the problem and both proposed solutions. but, I am having hard time understanding the problem with implementing option-2 that is "optimize size of inverted indices" . can u pls explain this a bit more?

himanshug avatar Mar 22 '15 17:03 himanshug

@himanshug I think nobody actually does this, but, in principle you could choose a dimension ordering that creates more runs in the earlier columns and that would make compression work better for those columns.

gianm avatar Mar 23 '15 14:03 gianm

For example, if you have some low cardinality columns, you can get their bitmaps to compress really well by grouping them together. High cardinality columns should have pretty sparse bitmaps anyways, so I wouldn't expect them to benefit much from grouping together.

drcrallen avatar May 28 '15 18:05 drcrallen

https://github.com/druid-io/druid-api/pull/68 removed a workaround for this so I'm tagging it with 0.9.0

drcrallen avatar Jan 21 '16 23:01 drcrallen

@gianm can we close this?

fjy avatar Jan 21 '16 23:01 fjy

Do we have tests that reproduce the bug? that would be a great indicator if we can close it.

drcrallen avatar Jan 21 '16 23:01 drcrallen

I believe @jon-wei added some tests as part of #2006 & #2306.

gianm avatar Jan 21 '16 23:01 gianm

@jon-wei can you confirm if this has proper unit tests in place that pass?

drcrallen avatar Jan 21 '16 23:01 drcrallen

@drcrallen @gianm

In IndexMergerTest, I added two tests that use non-lexicographic dimension ordering: testNonLexicographicDimOrderMerge() testMergeWithSupersetOrdering()

I also added one test to both IndexGeneratorJobTest and RealtimePlumberSchoolTest that verifies that these classes can pass the non-lexicographic dim order across indexes

jon-wei avatar Jan 21 '16 23:01 jon-wei

@jon-wei if your stuff fixed this issue then close it down :)

drcrallen avatar Jan 21 '16 23:01 drcrallen

Alright, I'll close this with the note that:

If indexes to be merged have incompatible dimension orders (e.g., A,B,C,D) and (C,B,D,A,) for some reason, the merger will fallback to using lexicographic order, PR #2006, #2306 will not attempt to resort the rows in that case.

i.e., this adopts the first approach suggested by @gianm

jon-wei avatar Jan 21 '16 23:01 jon-wei