YannByron commented on code in PR #2219: URL: https://github.com/apache/fluss/pull/2219#discussion_r2647846934
########## fluss-spark/fluss-spark-common/src/main/scala/org/apache/fluss/spark/types/SparkToFlussTypeVisitor.scala: ########## @@ -0,0 +1,96 @@ +/* + * 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.fluss.spark.types + +import org.apache.fluss.types.{ArrayType => FlussArrayType, DataField => FlussDataField, DataType => FlussDataType, MapType => FlussMapType, _} +import org.apache.spark.sql.types.{ArrayType => SparkArrayType, DataType => SparkDataType, MapType => SparkMapType, StructType, UserDefinedType} + +import scala.collection.JavaConverters._ + +object SparkToFlussTypeVisitor { + + def visit(dataType: SparkDataType): FlussDataType = { + dataType match { + case st: StructType => + visitStructType(st) + case mt: SparkMapType => + visitMapType(mt) + case at: SparkArrayType => + visitArrayType(at) + case _: UserDefinedType[_] => + throw new UnsupportedOperationException("User-defined type is not supported"); + case t => + visitPrimitiveType(t) + } + } + + private def visitStructType(st: StructType): RowType = { + val flussDataFields = st.fields.map { + field => + val flussDataType = visit(field.dataType) + new FlussDataField(field.name, flussDataType, field.getComment().orNull) + } + new RowType(flussDataFields.toList.asJava) + } + + private def visitMapType(mt: SparkMapType): FlussMapType = { + new FlussMapType(visit(mt.keyType), visit(mt.valueType).copy(mt.valueContainsNull)) + } + + private def visitArrayType(at: SparkArrayType): FlussArrayType = { + new FlussArrayType(at.containsNull, visit(at.elementType)) Review Comment: Right. I observe `MapType`, but ignore `ArrayType`.Thanks to correct it. -- 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]
