-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Some optimizations for constant blocks #132456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
af6a820
afe3608
e63235e
7e0ef8f
1753831
9505aff
276759a
8f21547
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 132456 | ||
summary: Some optimizations for constant blocks | ||
area: ES|QL | ||
type: enhancement | ||
issues: [] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import org.elasticsearch.compute.data.BytesRefBlock; | ||
import org.elasticsearch.compute.data.BytesRefVector; | ||
import org.elasticsearch.compute.data.IntBlock; | ||
import org.elasticsearch.compute.data.IntVector; | ||
import org.elasticsearch.compute.data.OrdinalBytesRefBlock; | ||
import org.elasticsearch.compute.operator.BreakingBytesRefBuilder; | ||
import org.elasticsearch.core.Releasable; | ||
|
@@ -64,6 +65,41 @@ public SingletonOrdinalsBuilder endPositionEntry() { | |
throw new UnsupportedOperationException("should only have one value per doc"); | ||
} | ||
|
||
BytesRefBlock tryBuildConstantBlock() { | ||
if (minOrd == maxOrd) { | ||
boolean seenNulls = false; | ||
for (int ord : ords) { | ||
if (ord == -1) { | ||
seenNulls = true; | ||
break; | ||
} | ||
} | ||
if (seenNulls == false) { | ||
final BytesRef v; | ||
try { | ||
v = BytesRef.deepCopyOf(docValues.lookupOrd(minOrd)); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException("failed to lookup ordinals", e); | ||
} | ||
BytesRefVector bytes = null; | ||
IntVector ordinals = null; | ||
boolean success = false; | ||
try { | ||
bytes = blockFactory.newConstantBytesRefVector(v, 1); | ||
ordinals = blockFactory.newConstantIntVector(0, ords.length); | ||
final var result = new OrdinalBytesRefBlock(ordinals.asBlock(), bytes); | ||
|
||
success = true; | ||
return result; | ||
} finally { | ||
if (success == false) { | ||
Releasables.close(bytes, ordinals); | ||
} | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
BytesRefBlock buildOrdinal() { | ||
int valueCount = maxOrd - minOrd + 1; | ||
long breakerSize = ordsSize(valueCount); | ||
|
@@ -172,6 +208,10 @@ public long estimatedBytes() { | |
|
||
@Override | ||
public BytesRefBlock build() { | ||
var constantBlock = tryBuildConstantBlock(); | ||
if (constantBlock != null) { | ||
return constantBlock; | ||
} | ||
return shouldBuildOrdinalsBlock() ? buildOrdinal() : buildRegularBlock(); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.