Skip to content

Commit

Permalink
[refactor](paimon)paimon scanner code optimization (#42606)
Browse files Browse the repository at this point in the history
paimon scanner code optimization
  • Loading branch information
zddr authored and Your Name committed Oct 28, 2024
1 parent 5174c9a commit c5937ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ private int[] getProjected() {
}

private List<Predicate> getPredicates() {
List<Predicate> predicates = PaimonScannerUtils.decodeStringToObject(paimonPredicate);
List<Predicate> predicates = PaimonUtils.deserialize(paimonPredicate);
if (LOG.isDebugEnabled()) {
LOG.debug("predicates:{}", predicates);
}
return predicates;
}

private Split getSplit() {
Split split = PaimonScannerUtils.decodeStringToObject(paimonSplit);
Split split = PaimonUtils.deserialize(paimonSplit);
if (LOG.isDebugEnabled()) {
LOG.debug("split:{}", split);
}
Expand Down Expand Up @@ -224,7 +224,7 @@ private void initTable() {
tableExt = PaimonTableCache.getTable(key);
}
this.table = tableExt.getTable();
paimonAllFieldNames = PaimonScannerUtils.fieldNames(this.table.rowType());
paimonAllFieldNames = PaimonUtils.getFieldNames(this.table.rowType());
if (LOG.isDebugEnabled()) {
LOG.debug("paimonAllFieldNames:{}", paimonAllFieldNames);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,23 @@
import java.util.List;
import java.util.stream.Collectors;

public class PaimonScannerUtils {
private static final Base64.Decoder BASE64_DECODER = Base64.getUrlDecoder();
public class PaimonUtils {
private static final Base64.Decoder DECODER = Base64.getUrlDecoder();

public static <T> T decodeStringToObject(String encodedStr) {
final byte[] bytes = BASE64_DECODER.decode(encodedStr.getBytes(java.nio.charset.StandardCharsets.UTF_8));
try {
return InstantiationUtil.deserializeObject(bytes, PaimonScannerUtils.class.getClassLoader());
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public static List<String> fieldNames(RowType rowType) {
public static List<String> getFieldNames(RowType rowType) {
return rowType.getFields().stream()
.map(DataField::name)
.map(String::toLowerCase)
.collect(Collectors.toList());
}

public static <T> T deserialize(String encodedStr) {
try {
return InstantiationUtil.deserializeObject(
DECODER.decode(encodedStr.getBytes(java.nio.charset.StandardCharsets.UTF_8)),
PaimonUtils.class.getClassLoader());
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit c5937ad

Please sign in to comment.