-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Support reading time millis columns in optimized parquet #18535
Merged
+222
−53
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
lib/trino-parquet/src/test/java/io/trino/parquet/reader/FileParquetDataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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 io.trino.parquet.reader; | ||
|
||
import io.trino.parquet.AbstractParquetDataSource; | ||
import io.trino.parquet.ParquetDataSourceId; | ||
import io.trino.parquet.ParquetReaderOptions; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.RandomAccessFile; | ||
|
||
public class FileParquetDataSource | ||
extends AbstractParquetDataSource | ||
{ | ||
private final RandomAccessFile input; | ||
|
||
public FileParquetDataSource(File path, ParquetReaderOptions options) | ||
throws FileNotFoundException | ||
{ | ||
super(new ParquetDataSourceId(path.getPath()), path.length(), options); | ||
this.input = new RandomAccessFile(path, "r"); | ||
} | ||
|
||
@Override | ||
public void close() | ||
throws IOException | ||
{ | ||
super.close(); | ||
input.close(); | ||
raunaqmorarka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Override | ||
protected void readInternal(long position, byte[] buffer, int bufferOffset, int bufferLength) | ||
throws IOException | ||
{ | ||
input.seek(position); | ||
input.readFully(buffer, bufferOffset, bufferLength); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
lib/trino-parquet/src/test/java/io/trino/parquet/reader/TestTimeMillis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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 io.trino.parquet.reader; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.io.Resources; | ||
import io.trino.parquet.ParquetDataSource; | ||
import io.trino.parquet.ParquetReaderOptions; | ||
import io.trino.spi.Page; | ||
import io.trino.spi.block.Block; | ||
import io.trino.spi.type.SqlTime; | ||
import io.trino.spi.type.TimeType; | ||
import io.trino.spi.type.Type; | ||
import org.apache.parquet.hadoop.metadata.ParquetMetadata; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
import static io.trino.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext; | ||
import static io.trino.parquet.ParquetTestUtils.createParquetReader; | ||
import static io.trino.spi.type.TimeType.TIME_MICROS; | ||
import static io.trino.spi.type.TimeType.TIME_MILLIS; | ||
import static io.trino.spi.type.TimeType.TIME_NANOS; | ||
import static io.trino.spi.type.TimeType.TIME_SECONDS; | ||
import static io.trino.testing.DataProviders.toDataProvider; | ||
import static io.trino.testing.TestingConnectorSession.SESSION; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class TestTimeMillis | ||
{ | ||
@Test(dataProvider = "timeTypeProvider") | ||
public void testTimeMillsInt32(TimeType timeType) | ||
throws Exception | ||
{ | ||
List<String> columnNames = ImmutableList.of("COLUMN1", "COLUMN2"); | ||
List<Type> types = ImmutableList.of(timeType, timeType); | ||
int precision = timeType.getPrecision(); | ||
|
||
ParquetDataSource dataSource = new FileParquetDataSource( | ||
new File(Resources.getResource("time_millis_int32.snappy.parquet").toURI()), | ||
new ParquetReaderOptions()); | ||
ParquetMetadata parquetMetadata = MetadataReader.readFooter(dataSource, Optional.empty()); | ||
ParquetReader reader = createParquetReader(dataSource, parquetMetadata, newSimpleAggregatedMemoryContext(), types, columnNames); | ||
|
||
Page page = reader.nextPage(); | ||
Block block = page.getBlock(0).getLoadedBlock(); | ||
assertThat(block.getPositionCount()).isEqualTo(1); | ||
// TIME '15:03:00' | ||
assertThat(timeType.getObjectValue(SESSION, block, 0)) | ||
.isEqualTo(SqlTime.newInstance(precision, 54180000000000000L)); | ||
|
||
// TIME '23:59:59.999' | ||
block = page.getBlock(1).getLoadedBlock(); | ||
assertThat(block.getPositionCount()).isEqualTo(1); | ||
// Rounded up to 0 if precision < 3 | ||
assertThat(timeType.getObjectValue(SESSION, block, 0)) | ||
.isEqualTo(SqlTime.newInstance(precision, timeType == TIME_SECONDS ? 0L : 86399999000000000L)); | ||
} | ||
|
||
@DataProvider | ||
public static Object[][] timeTypeProvider() | ||
{ | ||
return Stream.of(TIME_SECONDS, TIME_MILLIS, TIME_MICROS, TIME_NANOS) | ||
.collect(toDataProvider()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+608 Bytes
lib/trino-parquet/src/test/resources/time_millis_int32.snappy.parquet
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should we have similar rounding for
getTimeMicrosDecoder
where trino type is lower than precision than 6?(or assertion that type is 6 if only time(6) is supported)
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.
Yes, I'm planning to tackle that separately by adding rounding on lower precision. In practise we're only supporting time(6) in iceberg right now, so it's not a problem yet. But from parquet reader perspective it is better to assume such a scenario might arise in future and support it correctly.