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

Parquet: Support reading INT96 column in row group filter #8988

Merged
merged 1 commit into from Jan 8, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -21,6 +21,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import java.util.function.Function;
Expand Down Expand Up @@ -112,6 +113,10 @@ static Function<Object, Object> converterFromParquet(PrimitiveType type) {
case FIXED_LEN_BYTE_ARRAY:
case BINARY:
return binary -> ByteBuffer.wrap(((Binary) binary).getBytes());
case INT96:
return binary ->
ParquetUtil.extractTimestampInt96(
ByteBuffer.wrap(((Binary) binary).getBytes()).order(ByteOrder.LITTLE_ENDIAN));
manuzhang marked this conversation as resolved.
Show resolved Hide resolved
default:
}

Expand Down
Expand Up @@ -453,6 +453,9 @@ private <T> Set<T> dict(int id, Comparator<T> comparator) {
case DOUBLE:
dictSet.add((T) conversion.apply(dict.decodeToDouble(i)));
break;
case INT96:
dictSet.add((T) conversion.apply(dict.decodeToBinary(i)));
break;
default:
throw new IllegalArgumentException(
"Cannot decode dictionary of type: "
Expand Down
Expand Up @@ -2156,22 +2156,32 @@ public void testTableWithInt96Timestamp() throws IOException {
stagingLocation);

// validate we get the expected results back
List<Row> expected = spark.table("parquet_table").select("tmp_col").collectAsList();
List<Row> actual =
spark
.read()
.format("iceberg")
.load(loadLocation(tableIdentifier))
.select("tmp_col")
.collectAsList();
Assertions.assertThat(actual)
.as("Rows must match")
.containsExactlyInAnyOrderElementsOf(expected);
testWithFilter("tmp_col < to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
testWithFilter("tmp_col <= to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
testWithFilter("tmp_col == to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
testWithFilter("tmp_col > to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
testWithFilter("tmp_col >= to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
dropTable(tableIdentifier);
}
}
}

private void testWithFilter(String filterExpr, TableIdentifier tableIdentifier) {
List<Row> expected =
spark.table("parquet_table").select("tmp_col").filter(filterExpr).collectAsList();
List<Row> actual =
spark
.read()
.format("iceberg")
.load(loadLocation(tableIdentifier))
.select("tmp_col")
.filter(filterExpr)
.collectAsList();
Assertions.assertThat(actual)
.as("Rows must match")
.containsExactlyInAnyOrderElementsOf(expected);
}

private GenericData.Record manifestRecord(
Table manifestTable, Long referenceSnapshotId, ManifestFile manifest) {
GenericRecordBuilder builder =
Expand Down
Expand Up @@ -2154,22 +2154,32 @@ public void testTableWithInt96Timestamp() throws IOException {
stagingLocation);

// validate we get the expected results back
List<Row> expected = spark.table("parquet_table").select("tmp_col").collectAsList();
List<Row> actual =
spark
.read()
.format("iceberg")
.load(loadLocation(tableIdentifier))
.select("tmp_col")
.collectAsList();
Assertions.assertThat(actual)
.as("Rows must match")
.containsExactlyInAnyOrderElementsOf(expected);
testWithFilter("tmp_col < to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
testWithFilter("tmp_col <= to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
testWithFilter("tmp_col == to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
testWithFilter("tmp_col > to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
testWithFilter("tmp_col >= to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
dropTable(tableIdentifier);
}
}
}

private void testWithFilter(String filterExpr, TableIdentifier tableIdentifier) {
List<Row> expected =
spark.table("parquet_table").select("tmp_col").filter(filterExpr).collectAsList();
List<Row> actual =
spark
.read()
.format("iceberg")
.load(loadLocation(tableIdentifier))
.select("tmp_col")
.filter(filterExpr)
.collectAsList();
Assertions.assertThat(actual)
.as("Rows must match")
.containsExactlyInAnyOrderElementsOf(expected);
}

private GenericData.Record manifestRecord(
Table manifestTable, Long referenceSnapshotId, ManifestFile manifest) {
GenericRecordBuilder builder =
Expand Down
Expand Up @@ -2181,20 +2181,30 @@ public void testTableWithInt96Timestamp() throws IOException {
stagingLocation);

// validate we get the expected results back
List<Row> expected = spark.table("parquet_table").select("tmp_col").collectAsList();
List<Row> actual =
spark
.read()
.format("iceberg")
.load(loadLocation(tableIdentifier))
.select("tmp_col")
.collectAsList();
assertThat(actual).as("Rows must match").containsExactlyInAnyOrderElementsOf(expected);
testWithFilter("tmp_col < to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
manuzhang marked this conversation as resolved.
Show resolved Hide resolved
testWithFilter("tmp_col <= to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
testWithFilter("tmp_col == to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
testWithFilter("tmp_col > to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
testWithFilter("tmp_col >= to_timestamp('2000-01-31 08:30:00')", tableIdentifier);
dropTable(tableIdentifier);
}
}
}

private void testWithFilter(String filterExpr, TableIdentifier tableIdentifier) {
List<Row> expected =
spark.table("parquet_table").select("tmp_col").filter(filterExpr).collectAsList();
List<Row> actual =
spark
.read()
.format("iceberg")
.load(loadLocation(tableIdentifier))
.select("tmp_col")
.filter(filterExpr)
.collectAsList();
assertThat(actual).as("Rows must match").containsExactlyInAnyOrderElementsOf(expected);
}

private GenericData.Record manifestRecord(
Table manifestTable, Long referenceSnapshotId, ManifestFile manifest) {
GenericRecordBuilder builder =
Expand Down