Skip to content

Commit

Permalink
[core] Pass null value to file index (apache#3766)
Browse files Browse the repository at this point in the history
  • Loading branch information
leaves12138 authored Jul 19, 2024
1 parent 375ffb8 commit b7e11d7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ public abstract class FileIndexWriter {
private boolean empty = true;

public void writeRecord(Object key) {
if (key != null) {
empty = false;
write(key);
}
empty = false;
write(key);
}

public abstract void write(Object key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public Writer(DataType type, int items, double fpp) {

@Override
public void write(Object key) {
filter.addHash(hashFunction.hash(key));
if (key != null) {
filter.addHash(hashFunction.hash(key));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
import java.io.OutputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/** Index file writer for a data file. */
public final class DataFileIndexWriter implements Closeable {
Expand Down Expand Up @@ -303,18 +305,30 @@ public MapFileIndexMaintainer(
}

public void write(InternalRow row) {
if (row.isNullAt(position)) {
indexWritersMap.values().forEach(write -> write.writeRecord(null));
return;
}
InternalMap internalMap = row.getMap(position);
InternalArray keyArray = internalMap.keyArray();
InternalArray valueArray = internalMap.valueArray();

Set<String> writedKeys = new HashSet<>();
for (int i = 0; i < keyArray.size(); i++) {
String key = keyArray.getString(i).toString();
org.apache.paimon.fileindex.FileIndexWriter writer =
indexWritersMap.getOrDefault(key, null);
if (writer != null) {
writedKeys.add(key);
writer.writeRecord(valueElementGetter.getElementOrNull(valueArray, i));
}
}

for (Map.Entry<String, FileIndexWriter> writerEntry : indexWritersMap.entrySet()) {
if (!writedKeys.contains(writerEntry.getKey())) {
writerEntry.getValue().writeRecord(null);
}
}
}

public void add(String nestedKey, Options nestedOptions) {
Expand Down

0 comments on commit b7e11d7

Please sign in to comment.