-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add support for DATE predicate pushdown with Parquet via min/max and … #10181
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,7 @@ | |
| import static com.facebook.presto.parquet.predicate.PredicateUtils.isStatisticsOverflow; | ||
| import static com.facebook.presto.spi.type.BigintType.BIGINT; | ||
| import static com.facebook.presto.spi.type.BooleanType.BOOLEAN; | ||
| import static com.facebook.presto.spi.type.DateType.DATE; | ||
| import static com.facebook.presto.spi.type.DoubleType.DOUBLE; | ||
| import static com.facebook.presto.spi.type.IntegerType.INTEGER; | ||
| import static com.facebook.presto.spi.type.RealType.REAL; | ||
|
|
@@ -200,6 +201,15 @@ else if (isVarcharType(type) && statistics instanceof BinaryStatistics) { | |
| ParquetStringStatistics parquetStringStatistics = new ParquetStringStatistics(minSlice, maxSlice); | ||
| return createDomain(type, hasNullValue, parquetStringStatistics); | ||
| } | ||
| else if (type.equals(DATE) && statistics instanceof IntStatistics) { | ||
| IntStatistics intStatistics = (IntStatistics) statistics; | ||
| // ignore corrupted statistics | ||
| if (intStatistics.genericGetMin() > intStatistics.genericGetMax()) { | ||
| return Domain.create(ValueSet.all(type), hasNullValue); | ||
|
||
| } | ||
| ParquetIntegerStatistics parquetIntegerStatistics = new ParquetIntegerStatistics((long) intStatistics.getMin(), (long) intStatistics.getMax()); | ||
| return createDomain(type, hasNullValue, parquetIntegerStatistics); | ||
| } | ||
| return Domain.create(ValueSet.all(type), hasNullValue); | ||
| } | ||
|
|
||
|
|
@@ -235,7 +245,7 @@ public static Domain getDomain(Type type, DictionaryDescriptor dictionaryDescrip | |
| domains.add(Domain.onlyNull(type)); | ||
| return Domain.union(domains); | ||
| } | ||
| else if (type.equals(BIGINT) && columnDescriptor.getType() == PrimitiveTypeName.INT32) { | ||
| else if ((type.equals(BIGINT) || type.equals(DATE)) && columnDescriptor.getType() == PrimitiveTypeName.INT32) { | ||
| List<Domain> domains = new ArrayList<>(); | ||
| for (int i = 0; i < dictionarySize; i++) { | ||
| domains.add(Domain.singleValue(type, (long) dictionary.decodeToInt(i))); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.facebook.presto.parquet; | ||
|
|
||
| import com.facebook.presto.spi.predicate.TupleDomain; | ||
| import org.testng.annotations.Test; | ||
| import parquet.column.ColumnDescriptor; | ||
| import parquet.schema.OriginalType; | ||
| import parquet.schema.PrimitiveType; | ||
| import parquet.schema.PrimitiveType.PrimitiveTypeName; | ||
|
|
||
| import static com.facebook.presto.parquet.ParquetTypeUtils.getPrestoType; | ||
| import static com.facebook.presto.spi.type.DateType.DATE; | ||
| import static com.facebook.presto.spi.type.IntegerType.INTEGER; | ||
| import static org.testng.Assert.assertEquals; | ||
| import static parquet.schema.Type.Repetition.OPTIONAL; | ||
|
|
||
| public class TestParquetTypeUtils | ||
| { | ||
| @Test | ||
| public void testMapInt32ToPrestoInteger() | ||
| { | ||
| PrimitiveType intType = new PrimitiveType(OPTIONAL, PrimitiveTypeName.INT32, "int_col", OriginalType.INT_32); | ||
| ColumnDescriptor columnDescriptor = new ColumnDescriptor(new String[]{"int_col"}, PrimitiveTypeName.INT32, 0, 1); | ||
| RichColumnDescriptor intColumn = new RichColumnDescriptor(columnDescriptor, intType); | ||
| assertEquals(getPrestoType(TupleDomain.all(), intColumn), INTEGER); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMapInt32WithoutOriginalTypeToPrestoInteger() | ||
| { | ||
| // int32 primitive should default to Presto integer if original type metadata isn't available | ||
| PrimitiveType intType = new PrimitiveType(OPTIONAL, PrimitiveTypeName.INT32, "int_col"); | ||
| ColumnDescriptor columnDescriptor = new ColumnDescriptor(new String[]{"int_col"}, PrimitiveTypeName.INT32, 0, 1); | ||
| RichColumnDescriptor intColumn = new RichColumnDescriptor(columnDescriptor, intType); | ||
| assertEquals(getPrestoType(TupleDomain.all(), intColumn), INTEGER); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMapInt32ToPrestoDate() | ||
| { | ||
| // int32 primitive with original type of date should map to a Presto date | ||
| PrimitiveType dateType = new PrimitiveType(OPTIONAL, PrimitiveTypeName.INT32, "date_col", OriginalType.DATE); | ||
| ColumnDescriptor columnDescriptor = new ColumnDescriptor(new String[]{"date_col"}, PrimitiveTypeName.INT32, 0, 1); | ||
| RichColumnDescriptor dateColumn = new RichColumnDescriptor(columnDescriptor, dateType); | ||
| assertEquals(getPrestoType(TupleDomain.all(), dateColumn), DATE); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why
INT64andINT32cases are handled differently now?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because Parquet has Logical Types where additional metadata in
originalTypedetermines how anint32can be interpreted. In this case, it's checking if the int32 was configured to be interpreted as a date (number of days since Unix epoch which matches the semantics of the PrestoDatetype).Before this change if I had a query like:
The query would fail with a type mismatch exception about comparing a
datevalue tointegerbecause the logical type wasn't considered. There's a similar issue related to this here - #11118 - which is more involved as I was only targeting thedatepushdown currently.I backed out the timestamp changes but the case statement for
int64in the future would be adjusted in a similar way to consider logical types e.g. an int64 can be logically typed as atimestampwhere the value is in epoch millis, micro or nanos.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this, #11118 actually solves this differently by adding the
HiveTypetoRichColumnDescriptorthen determining the mapped Presto type for anint32based on that hereThe outcome should be the same though.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some unit tests in 1f78d8e3c0dfa4ac8e9ad7a8e2b9f53409a55e05 for this in case this changes in the future.