Skip to content

Commit

Permalink
[core][common][format] Remove useless codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
guanshi committed Nov 8, 2024
1 parent 6843bb2 commit a6ec503
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,13 @@ public FileIndexResult evaluate(@Nullable Predicate predicate) {
Set<String> requiredFieldNames = getRequiredNames(predicate);
Map<String, Collection<FileIndexReader>> indexReaders = new HashMap<>();
requiredFieldNames.forEach(name -> indexReaders.put(name, reader.readColumnIndex(name)));
return new FileIndexPredicateTest(indexReaders).test(predicate);
}

public boolean testPredicate(@Nullable Predicate filePredicate) {
if (filePredicate == null) {
return true;
}

Set<String> requiredFieldNames = getRequiredNames(filePredicate);

Map<String, Collection<FileIndexReader>> indexReaders = new HashMap<>();
requiredFieldNames.forEach(name -> indexReaders.put(name, reader.readColumnIndex(name)));
if (!new FileIndexPredicateTest(indexReaders).test(filePredicate).remain()) {
FileIndexResult result = new FileIndexPredicateTest(indexReaders).test(predicate);
if (!result.remain()) {
LOG.debug(
"One file has been filtered: "
+ (path == null ? "in scan stage" : path.toString()));
return false;
}
return true;
return result;
}

private Set<String> getRequiredNames(Predicate filePredicate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,25 @@
import org.apache.paimon.fs.Path;
import org.apache.paimon.reader.RecordReader;

import javax.annotation.Nullable;

/** the context for creating RecordReader {@link RecordReader}. */
public class FormatReaderContext implements FormatReaderFactory.Context {

private final FileIO fileIO;
private final Path file;
private final long fileSize;
private FileIndexResult fileIndexResult;
@Nullable private final FileIndexResult fileIndexResult;

public FormatReaderContext(FileIO fileIO, Path file, long fileSize) {
this(fileIO, file, fileSize, null);
}

public FormatReaderContext(
FileIO fileIO, Path file, long fileSize, @Nullable FileIndexResult fileIndexResult) {
this.fileIO = fileIO;
this.file = file;
this.fileSize = fileSize;
}

public void setFileIndexResult(FileIndexResult fileIndexResult) {
this.fileIndexResult = fileIndexResult;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private boolean testFileIndex(@Nullable byte[] embeddedIndexBytes, ManifestEntry

try (FileIndexPredicate predicate =
new FileIndexPredicate(embeddedIndexBytes, dataRowType)) {
return predicate.testPredicate(dataPredicate);
return predicate.evaluate(dataPredicate).remain();
} catch (IOException e) {
throw new RuntimeException("Exception happens while checking predicate.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private boolean filterByFileIndex(@Nullable byte[] embeddedIndexBytes, ManifestE
id ->
fieldValueStatsConverters.convertFilter(
entry.file().schemaId(), valueFilter));
return predicate.testPredicate(dataPredicate);
return predicate.evaluate(dataPredicate).remain();
} catch (IOException e) {
throw new RuntimeException("Exception happens while checking fileIndex predicate.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ private RecordReader<InternalRow> createFileReader(

FormatReaderContext formatReaderContext =
new FormatReaderContext(
fileIO, dataFilePathFactory.toPath(file.fileName()), file.fileSize());
formatReaderContext.setFileIndexResult(fileIndexResult);
fileIO,
dataFilePathFactory.toPath(file.fileName()),
file.fileSize(),
fileIndexResult);
FileRecordReader fileRecordReader =
new FileRecordReader(
bulkFormatMapping.getReaderFactory(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.paimon.format.parquet;

import org.apache.paimon.fileindex.FileIndexResult;
import org.apache.paimon.format.SimpleStatsExtractor;
import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;
Expand Down Expand Up @@ -48,7 +49,7 @@ public class ParquetUtil {
*/
public static Pair<Map<String, Statistics<?>>, SimpleStatsExtractor.FileInfo>
extractColumnStats(FileIO fileIO, Path path) throws IOException {
try (ParquetFileReader reader = getParquetReader(fileIO, path)) {
try (ParquetFileReader reader = getParquetReader(fileIO, path, null)) {
ParquetMetadata parquetMetadata = reader.getFooter();
List<BlockMetaData> blockMetaDataList = parquetMetadata.getBlocks();
Map<String, Statistics<?>> resultStats = new HashMap<>();
Expand Down Expand Up @@ -77,11 +78,12 @@ public class ParquetUtil {
* @param path the path of parquet files to be read
* @return parquet reader, used for reading footer, status, etc.
*/
public static ParquetFileReader getParquetReader(FileIO fileIO, Path path) throws IOException {
public static ParquetFileReader getParquetReader(
FileIO fileIO, Path path, FileIndexResult fileIndexResult) throws IOException {
return new ParquetFileReader(
ParquetInputFile.fromPath(fileIO, path),
ParquetReadOptions.builder().build(),
null);
fileIndexResult);
}

static void assertStatsClass(
Expand Down

0 comments on commit a6ec503

Please sign in to comment.