Skip to content
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

Use record patterns #20345

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import io.trino.spi.block.Block;
import io.trino.spi.block.DictionaryBlock;
import io.trino.spi.block.LazyBlock;
import io.trino.spi.block.RunLengthEncodedBlock;
import io.trino.spi.block.ValueBlock;
import io.trino.type.BlockTypeOperators.BlockPositionIsDistinctFrom;
Expand Down Expand Up @@ -74,35 +75,35 @@ public void append(IntArrayList positions, Block source)
return;
}

if (source instanceof RunLengthEncodedBlock rleBlock) {
appendRle(rleBlock.getValue(), positions.size());
}
else if (source instanceof DictionaryBlock dictionaryBlock) {
ValueBlock dictionary = dictionaryBlock.getDictionary();
if (state == State.UNINITIALIZED) {
state = State.DICTIONARY;
this.dictionary = dictionary;
dictionaryIdsBuilder.appendPositions(positions, dictionaryBlock);
switch (source) {
case RunLengthEncodedBlock rleBlock -> {
findepi marked this conversation as resolved.
Show resolved Hide resolved
appendRle(rleBlock.getValue(), positions.size());
}
else if (state == State.DICTIONARY && this.dictionary == dictionary) {
dictionaryIdsBuilder.appendPositions(positions, dictionaryBlock);
case DictionaryBlock dictionaryBlock -> {
ValueBlock dictionary = dictionaryBlock.getDictionary();
if (state == State.UNINITIALIZED) {
state = State.DICTIONARY;
this.dictionary = dictionary;
dictionaryIdsBuilder.appendPositions(positions, dictionaryBlock);
}
else if (state == State.DICTIONARY && this.dictionary == dictionary) {
dictionaryIdsBuilder.appendPositions(positions, dictionaryBlock);
}
else {
transitionToDirect();

int[] positionArray = new int[positions.size()];
for (int i = 0; i < positions.size(); i++) {
positionArray[i] = dictionaryBlock.getId(positions.getInt(i));
}
delegate.append(IntArrayList.wrap(positionArray), dictionary);
}
}
else {
case ValueBlock valueBlock -> {
transitionToDirect();

int[] positionArray = new int[positions.size()];
for (int i = 0; i < positions.size(); i++) {
positionArray[i] = dictionaryBlock.getId(positions.getInt(i));
}
delegate.append(IntArrayList.wrap(positionArray), dictionary);
delegate.append(positions, valueBlock);
}
}
else if (source instanceof ValueBlock valueBlock) {
transitionToDirect();
delegate.append(positions, valueBlock);
}
else {
throw new IllegalArgumentException("Unsupported block type: " + source.getClass().getSimpleName());
case LazyBlock ignore -> throw new IllegalArgumentException("Unsupported block type: " + source.getClass().getSimpleName());
}
}

Expand Down Expand Up @@ -144,17 +145,11 @@ public void append(int position, Block source)
transitionToDirect();
}

if (source instanceof RunLengthEncodedBlock runLengthEncodedBlock) {
delegate.append(0, runLengthEncodedBlock.getValue());
}
else if (source instanceof DictionaryBlock dictionaryBlock) {
delegate.append(dictionaryBlock.getId(position), dictionaryBlock.getDictionary());
}
else if (source instanceof ValueBlock valueBlock) {
delegate.append(position, valueBlock);
}
else {
throw new IllegalArgumentException("Unsupported block type: " + source.getClass().getSimpleName());
switch (source) {
case RunLengthEncodedBlock runLengthEncodedBlock -> delegate.append(0, runLengthEncodedBlock.getValue());
case DictionaryBlock dictionaryBlock -> delegate.append(dictionaryBlock.getId(position), dictionaryBlock.getDictionary());
case ValueBlock valueBlock -> delegate.append(position, valueBlock);
case LazyBlock ignore -> throw new IllegalArgumentException("Unsupported block type: " + source.getClass().getSimpleName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2984,21 +2984,19 @@ else if (strings.size() != 2) {
else {
snapshotAtRefresh = Optional.of(Long.parseLong(value));
}
TableChangeInfo tableChangeInfo = getTableChangeInfo(session, (IcebergTableHandle) tableHandle, snapshotAtRefresh);
if (tableChangeInfo instanceof NoTableChange) {
// Fresh
}
else if (tableChangeInfo instanceof FirstChangeSnapshot firstChange) {
hasStaleIcebergTables = true;
firstTableChange = firstTableChange
.map(epochMilli -> Math.min(epochMilli, firstChange.snapshot().timestampMillis()));
}
else if (tableChangeInfo instanceof UnknownTableChange) {
hasStaleIcebergTables = true;
firstTableChange = Optional.empty();
}
else {
throw new IllegalStateException("Unhandled table change info " + tableChangeInfo);
switch (getTableChangeInfo(session, (IcebergTableHandle) tableHandle, snapshotAtRefresh)) {
case NoTableChange() -> {
// Fresh
}
case FirstChangeSnapshot(Snapshot snapshot) -> {
findepi marked this conversation as resolved.
Show resolved Hide resolved
hasStaleIcebergTables = true;
firstTableChange = firstTableChange
.map(epochMilli -> Math.min(epochMilli, snapshot.timestampMillis()));
}
case UnknownTableChange() -> {
hasStaleIcebergTables = true;
firstTableChange = Optional.empty();
}
}
}

Expand Down Expand Up @@ -3111,7 +3109,7 @@ private static IcebergTableHandle checkValidTableHandle(ConnectorTableHandle tab
private sealed interface TableChangeInfo
permits NoTableChange, FirstChangeSnapshot, UnknownTableChange {}

private static final class NoTableChange
private record NoTableChange()
implements TableChangeInfo {}

private record FirstChangeSnapshot(Snapshot snapshot)
Expand All @@ -3123,6 +3121,6 @@ private record FirstChangeSnapshot(Snapshot snapshot)
}
}

private static final class UnknownTableChange
private record UnknownTableChange()
implements TableChangeInfo {}
}
Loading