Indian-boult commented on code in PR #1018: URL: https://github.com/apache/incubator-xtable/pull/1018#discussion_r4638042842
########## xtable-core/src/test/java/org/apache/xtable/kernel/ITDeltaKernelConversionTarget.java: ########## @@ -0,0 +1,156 @@ +/* + * 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.xtable.kernel; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.nio.file.Path; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Collections; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; + +import org.apache.spark.api.java.JavaSparkContext; +import org.apache.spark.sql.SparkSession; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import org.apache.hudi.client.HoodieReadClient; +import org.apache.hudi.common.config.TypedProperties; +import org.apache.hudi.common.model.HoodieTableType; + +import org.apache.xtable.TestJavaHudiTable; +import org.apache.xtable.conversion.ConversionConfig; +import org.apache.xtable.conversion.ConversionController; +import org.apache.xtable.conversion.SourceTable; +import org.apache.xtable.conversion.TargetTable; +import org.apache.xtable.delta.DeltaConversionTargetConfig; +import org.apache.xtable.hudi.HudiConversionSourceProvider; +import org.apache.xtable.hudi.HudiTestUtil; +import org.apache.xtable.model.storage.TableFormat; +import org.apache.xtable.model.sync.SyncMode; +import org.apache.xtable.model.sync.SyncResult; +import org.apache.xtable.model.sync.SyncStatusCode; + +/** + * Writes Delta tables with {@link DeltaKernelConversionTarget} through the normal {@link + * ConversionController} path, then reads them with Spark Delta and compares the result with the + * source and with the Delta Standalone target. + */ +public class ITDeltaKernelConversionTarget { + @TempDir public static Path tempDir; + + private static SparkSession sparkSession; + private static JavaSparkContext jsc; + + @BeforeAll + public static void setupOnce() { + sparkSession = + SparkSession.builder() + .config(HoodieReadClient.addHoodieSupport(HudiTestUtil.getSparkConf(tempDir))) + .getOrCreate(); + jsc = JavaSparkContext.fromSparkContext(sparkSession.sparkContext()); + } + + @AfterAll + public static void teardown() { + if (jsc != null) { + jsc.close(); + } + if (sparkSession != null) { + sparkSession.close(); + } + } + + /** + * A Hudi timestamp-millis column has its stats in millis. Delta readers skip files using the + * min/max stats in the Delta log, so stats written in the wrong unit drop rows from filtered + * reads. + */ + @Test + public void testFilterOnMillisTimestampColumnMatchesSourceAndStandaloneTarget() { + String tableName = "test_table_" + UUID.randomUUID(); + String filter = + String.format( + "timestamp_millis_nullable_field >= timestamp_millis(%d)", + Instant.now().truncatedTo(ChronoUnit.DAYS).minus(2, ChronoUnit.DAYS).toEpochMilli()); + try (TestJavaHudiTable table = Review Comment: Moved it. The round trip is now `ITConversionController#testMillisTimestampFilterDeltaTarget`, next to the other Kernel target tests, and `ITDeltaKernelConversionTarget` is gone since nothing format-local was left in it. It syncs a Hudi table with a `timestamp-millis` column to Delta, once with the Standalone target and once with the Kernel target through `USE_KERNEL`, then compares the source and target rows for a filter on that column. The unit test in `TestDeltaKernelDataFileUpdatesExtractor` stays where it was, since it only needs Delta. Without the fix the Kernel case fails (68 rows from the source, 0 from the Kernel target) and the Standalone case passes. With the fix both pass. -- 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]
