the-other-tim-brown commented on code in PR #14344: URL: https://github.com/apache/hudi/pull/14344#discussion_r2561008888
########## hudi-sync/hudi-hive-sync/src/test/java/org/apache/hudi/hive/TestSparkSchemaUtils.java: ########## @@ -0,0 +1,135 @@ +/* + * 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.hudi.hive; + +import org.apache.hudi.common.schema.HoodieSchema; +import org.apache.hudi.common.schema.HoodieSchemaField; +import org.apache.hudi.common.schema.HoodieSchemaType; +import org.apache.hudi.sync.common.util.SparkSchemaUtils; + +import org.apache.spark.sql.execution.SparkSqlParser; +import org.apache.spark.sql.internal.SQLConf; +import org.apache.spark.sql.types.ArrayType; +import org.apache.spark.sql.types.IntegerType$; +import org.apache.spark.sql.types.MapType; +import org.apache.spark.sql.types.Metadata; +import org.apache.spark.sql.types.StringType$; +import org.apache.spark.sql.types.StructField; +import org.apache.spark.sql.types.StructType; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestSparkSchemaUtils { + private final SparkSqlParser parser = createSqlParser(); + + private static SparkSqlParser createSqlParser() { + try { + return SparkSqlParser.class.getDeclaredConstructor(SQLConf.class).newInstance(new SQLConf()); + } catch (Exception ne) { + try { // For spark 3.1, there is no constructor with SQLConf, use the default constructor + return SparkSqlParser.class.getDeclaredConstructor().newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + @Test + public void testConvertPrimitiveType() { + StructType sparkSchema = parser.parseTableSchema( + "f0 int, f1 string, f3 bigint," + + " f4 decimal(5,2), f5 timestamp, f6 date," + + " f7 timestamp_ntz, f8 float, f9 double, f10 binary," + + " f11 binary, f12 boolean, f13 string"); Review Comment: The previous testing covered maps with non-string keys, short, and byte types for integers. None of those are currently supported by Hudi so the test is altered to only include types we support. -- 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]
