rdblue commented on a change in pull request #1266: URL: https://github.com/apache/iceberg/pull/1266#discussion_r469417642
########## File path: flink/src/test/java/org/apache/iceberg/flink/data/TestHelpers.java ########## @@ -0,0 +1,198 @@ +/* + * 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.iceberg.flink.data; + +import java.math.BigDecimal; +import java.nio.ByteBuffer; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.temporal.ChronoUnit; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.function.Supplier; +import org.apache.flink.table.data.ArrayData; +import org.apache.flink.table.data.DecimalData; +import org.apache.flink.table.data.MapData; +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.data.TimestampData; +import org.apache.flink.table.types.logical.ArrayType; +import org.apache.flink.table.types.logical.LogicalType; +import org.apache.flink.table.types.logical.MapType; +import org.apache.flink.table.types.logical.RowType; +import org.apache.iceberg.data.Record; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; +import org.junit.Assert; + +public class TestHelpers { + private TestHelpers() {} + + private static final OffsetDateTime EPOCH = Instant.ofEpochMilli(0L).atOffset(ZoneOffset.UTC); + private static final LocalDate EPOCH_DAY = EPOCH.toLocalDate(); + + public static void assertRowData(Type type, LogicalType rowType, Record expectedRecord, RowData actualRowData) { + if (expectedRecord == null && actualRowData == null) { + return; + } + + Assert.assertTrue("expected Record and actual RowData should be both null or not null", + expectedRecord != null && actualRowData != null); + + List<Type> types = Lists.newArrayList(); + for (Types.NestedField field : type.asStructType().fields()) { + types.add(field.type()); + } + + for (int i = 0; i < types.size(); i += 1) { + if (expectedRecord.get(i) == null) { + Assert.assertTrue(actualRowData.isNullAt(i)); + continue; + } + + Object expected = expectedRecord.get(i); + LogicalType logicalType = ((RowType) rowType).getTypeAt(i); + + final int fieldPos = i; + assertEquals(types.get(i), logicalType, expected, + () -> RowData.createFieldGetter(logicalType, fieldPos).getFieldOrNull(actualRowData)); + } + } + + private static void assertEquals(Type type, LogicalType logicalType, Object expected, Supplier<Object> supplier) { Review comment: Why call `supplier.get()` in every case when you could pass an object instead of a supplier? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
