rdblue commented on code in PR #3610: URL: https://github.com/apache/parquet-java/pull/3610#discussion_r3562498770
########## parquet-hadoop/src/test/java/org/apache/parquet/statistics/TestInt96TimestampStatistics.java: ########## @@ -0,0 +1,291 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.parquet.statistics; + +import static org.apache.parquet.schema.MessageTypeParser.parseMessageType; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.file.Files; +import java.util.List; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; +import org.apache.parquet.HadoopReadOptions; +import org.apache.parquet.example.data.Group; +import org.apache.parquet.example.data.simple.SimpleGroupFactory; +import org.apache.parquet.format.ColumnChunk; +import org.apache.parquet.format.FileMetaData; +import org.apache.parquet.format.RowGroup; +import org.apache.parquet.format.Statistics; +import org.apache.parquet.format.Type; +import org.apache.parquet.format.TypeDefinedOrder; +import org.apache.parquet.format.Util; +import org.apache.parquet.hadoop.ParquetFileReader; +import org.apache.parquet.hadoop.ParquetFileWriter; +import org.apache.parquet.hadoop.ParquetReader; +import org.apache.parquet.hadoop.ParquetWriter; +import org.apache.parquet.hadoop.example.ExampleParquetWriter; +import org.apache.parquet.hadoop.example.GroupReadSupport; +import org.apache.parquet.hadoop.example.GroupWriteSupport; +import org.apache.parquet.hadoop.metadata.BlockMetaData; +import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData; +import org.apache.parquet.hadoop.metadata.ParquetMetadata; +import org.apache.parquet.hadoop.util.HadoopInputFile; +import org.apache.parquet.internal.column.columnindex.ColumnIndex; +import org.apache.parquet.io.api.Binary; +import org.apache.parquet.schema.ColumnOrder; +import org.apache.parquet.schema.MessageType; +import org.apache.parquet.schema.PrimitiveType; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * Tests for INT96 timestamp statistics support (INT96_TIMESTAMP_ORDER). + */ +public class TestInt96TimestampStatistics { + + private static final MessageType SCHEMA = + parseMessageType("message test { required int96 ts; required int64 id; } "); + + // Chronologically: EARLY < SAME_DAY_EARLY < LATE_IN_DAY < NEXT_DAY. + // Byte-wise lexicographic comparison would order these incorrectly (nanos bytes come first), + // so these values detect a reader/writer using the wrong order. + private static final Binary EARLY = int96(2440000, 123L); // 1968-05-23 00:00:00.000000123 + private static final Binary SAME_DAY_EARLY = int96(2440588, 1_000L); // 1970-01-01 00:00:00.000001 + private static final Binary LATE_IN_DAY = int96(2440588, 86_399_999_999_999L); // 1970-01-01 23:59:59.999... + private static final Binary NEXT_DAY = int96(2440589, 0L); // 1970-01-02 00:00:00 + + private static final List<Binary> VALUES = List.of(LATE_IN_DAY, NEXT_DAY, EARLY, SAME_DAY_EARLY); + private static final Binary EXPECTED_MIN = EARLY; + private static final Binary EXPECTED_MAX = NEXT_DAY; + + @Rule + public TemporaryFolder tmp = new TemporaryFolder(); + + private static Binary int96(int julianDay, long nanosOfDay) { + return Binary.fromConstantByteArray(ByteBuffer.allocate(12) + .order(ByteOrder.LITTLE_ENDIAN) + .putLong(nanosOfDay) + .putInt(julianDay) + .array()); + } + + private File writeFile() throws IOException { + File file = new File(tmp.getRoot(), "int96.parquet"); Review Comment: This should use `tmp.newFile("int96.parquet")` instead of constructing one manually. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
