Skip to content

Commit

Permalink
[format] Fix ParquetFilters cannot handle tinyint and smallint correc…
Browse files Browse the repository at this point in the history
…tly (apache#4365)
  • Loading branch information
yuzelin authored Oct 23, 2024
1 parent f427fca commit e1fa0b0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.apache.flink.types.Row;
import org.junit.jupiter.api.Test;

import java.util.concurrent.ThreadLocalRandom;

import static org.assertj.core.api.Assertions.assertThat;

/** Predicate ITCase. */
Expand Down Expand Up @@ -50,6 +52,42 @@ public void testAppendFilterBucket() throws Exception {
innerTestAllFields();
}

@Test
public void testIntegerFilter() {
int rand = ThreadLocalRandom.current().nextInt(3);
String fileFormat;
if (rand == 0) {
fileFormat = "avro";
} else if (rand == 1) {
fileFormat = "parquet";
} else {
fileFormat = "orc";
}

sql(
"CREATE TABLE T ("
+ "a TINYINT,"
+ "b SMALLINT,"
+ "c INT,"
+ "d BIGINT"
+ ") WITH ("
+ "'file.format' = '%s'"
+ ")",
fileFormat);
sql(
"INSERT INTO T VALUES (CAST (1 AS TINYINT), CAST (1 AS SMALLINT), 1, 1), "
+ "(CAST (2 AS TINYINT), CAST (2 AS SMALLINT), 2, 2)");

Row expectedResult = Row.of((byte) 1, (short) 1, 1, 1L);
assertThat(sql("SELECT * FROM T WHERE a = CAST (1 AS TINYINT)"))
.containsExactly(expectedResult);
assertThat(sql("SELECT * FROM T WHERE b = CAST (1 AS SMALLINT)"))
.containsExactly(expectedResult);
assertThat(sql("SELECT * FROM T WHERE c = 1")).containsExactly(expectedResult);
assertThat(sql("SELECT * FROM T WHERE d = CAST (1 AS BIGINT)"))
.containsExactly(expectedResult);
}

private void writeRecords() throws Exception {
sql("INSERT INTO T VALUES (1, 2), (3, 4), (5, 6), (7, 8), (9, 10)");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ private static Comparable<?> toParquetObject(Object value) {
}

if (value instanceof Number) {
if (value instanceof Byte) {
return ((Byte) value).intValue();
} else if (value instanceof Short) {
return ((Short) value).intValue();
}
return (Comparable<?>) value;
} else if (value instanceof String) {
return Binary.fromString((String) value);
Expand Down

0 comments on commit e1fa0b0

Please sign in to comment.