LuciferYang commented on code in PR #13204: URL: https://github.com/apache/gluten/pull/13204#discussion_r4190348132
########## backends-velox/src/test/scala/org/apache/gluten/execution/FileSourceScanOptionsSuite.scala: ########## @@ -0,0 +1,89 @@ +/* + * 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.gluten.execution + +import org.apache.spark.network.util.JavaUtils +import org.apache.spark.sql.catalyst.expressions.AttributeReference +import org.apache.spark.sql.catalyst.util.CaseInsensitiveMap +import org.apache.spark.sql.execution.datasources.{HadoopFsRelation, InMemoryFileIndex} +import org.apache.spark.sql.execution.datasources.csv.CSVFileFormat +import org.apache.spark.sql.types.{StringType, StructField, StructType} + +import org.apache.hadoop.fs.Path + +import java.nio.file.Files + +class FileSourceScanOptionsSuite extends VeloxWholeStageTransformerSuite { + override protected val resourcePath: String = "" + override protected val fileFormat: String = "csv" + + private lazy val dir = Files.createTempDirectory("csv-options").toFile + + override def afterAll(): Unit = { + try JavaUtils.deleteRecursively(dir) + finally super.afterAll() + } + + private def scan(options: Map[String, String]): FileSourceScanExecTransformer = { + val schema = StructType(Seq(StructField("a", StringType, nullable = true))) + val relation = HadoopFsRelation( + new InMemoryFileIndex(spark, Seq(new Path(dir.toURI)), Map.empty, None), + StructType(Nil), + schema, + None, + new CSVFileFormat(), + CaseInsensitiveMap(options))(spark) + val attr = AttributeReference("a", StringType)() + FileSourceScanExecTransformer(relation, None, Seq(attr), schema, Nil, None, None, Nil, None) + } + + private def scanProperties(options: Map[String, String]): Map[String, String] = + scan(options).getProperties + + test("csv sep option maps to the native field delimiter") { Review Comment: Added "read csv with the sep option" to `GlutenClickHouseExcelFormatSuite` in 68e2aefc1. It writes `|`- and tab-separated files, reads them with `option("sep", "|")` and with the escaped `option("sep", "\\t")`, on both the default and the Excel text reader, compares against vanilla Spark, and checks the scan is a `FileSourceScanExecTransformer`. I put it in the ClickHouse suite rather than `gluten-ut` so it does not depend on un-excluding Spark's alias test, which also asserts charset handling. -- 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]
