|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.gluten.backendsapi.velox |
| 18 | + |
| 19 | +import org.apache.gluten.execution.{GlutenPartition, WholeStageTransformContext} |
| 20 | +import org.apache.gluten.substrait.plan.PlanBuilder |
| 21 | + |
| 22 | +import org.apache.spark.sql.test.SharedSparkSession |
| 23 | + |
| 24 | +/** |
| 25 | + * Tests that [[VeloxIteratorApi.genPartitions]] captures fs.azure.*, fs.s3a.*, and fs.gs.* keys |
| 26 | + * from the driver-side Hadoop configuration and embeds them in [[GlutenPartition.fsConf]], so they |
| 27 | + * are available on executors where Spark's SQLConf propagation does not reach "fs.*" keys. |
| 28 | + */ |
| 29 | +class VeloxIteratorApiFsConfSuite extends SharedSparkSession { |
| 30 | + |
| 31 | + private val api = new VeloxIteratorApi |
| 32 | + |
| 33 | + /** |
| 34 | + * Build a minimal WholeStageTransformContext backed by an empty Substrait plan. |
| 35 | + * genPartitions only calls wsCtx.root.toProtobuf.toByteArray, so a plan with no relations is |
| 36 | + * sufficient for the purpose of this test. |
| 37 | + */ |
| 38 | + private def emptyWsCtx: WholeStageTransformContext = |
| 39 | + WholeStageTransformContext(PlanBuilder.empty()) |
| 40 | + |
| 41 | + test("genPartitions embeds fs.azure.* keys from Hadoop conf into GlutenPartition.fsConf") { |
| 42 | + val hadoopConf = spark.sparkContext.hadoopConfiguration |
| 43 | + hadoopConf.set("fs.azure.account.auth.type.myaccount.dfs.core.windows.net", "OAuth") |
| 44 | + hadoopConf.set("fs.azure.account.oauth.provider.type", "ClientCredentials") |
| 45 | + try { |
| 46 | + val partitions = api.genPartitions(emptyWsCtx, Seq(Seq.empty), Seq.empty) |
| 47 | + assert(partitions.size == 1) |
| 48 | + val fsConf = partitions.head.asInstanceOf[GlutenPartition].fsConf |
| 49 | + assert( |
| 50 | + fsConf.contains("fs.azure.account.auth.type.myaccount.dfs.core.windows.net"), |
| 51 | + s"Expected fs.azure key not found; got: $fsConf") |
| 52 | + assert( |
| 53 | + fsConf("fs.azure.account.auth.type.myaccount.dfs.core.windows.net") == "OAuth") |
| 54 | + assert( |
| 55 | + fsConf.contains("fs.azure.account.oauth.provider.type"), |
| 56 | + s"Expected fs.azure key not found; got: $fsConf") |
| 57 | + } finally { |
| 58 | + hadoopConf.unset("fs.azure.account.auth.type.myaccount.dfs.core.windows.net") |
| 59 | + hadoopConf.unset("fs.azure.account.oauth.provider.type") |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + test("genPartitions embeds fs.s3a.* keys from Hadoop conf into GlutenPartition.fsConf") { |
| 64 | + val hadoopConf = spark.sparkContext.hadoopConfiguration |
| 65 | + hadoopConf.set("fs.s3a.access.key", "AKIAIOSFODNN7EXAMPLE") |
| 66 | + hadoopConf.set("fs.s3a.secret.key", "wJalrXUtnFEMI") |
| 67 | + try { |
| 68 | + val partitions = api.genPartitions(emptyWsCtx, Seq(Seq.empty), Seq.empty) |
| 69 | + assert(partitions.size == 1) |
| 70 | + val fsConf = partitions.head.asInstanceOf[GlutenPartition].fsConf |
| 71 | + assert(fsConf.contains("fs.s3a.access.key"), s"Expected fs.s3a key not found; got: $fsConf") |
| 72 | + assert(fsConf("fs.s3a.access.key") == "AKIAIOSFODNN7EXAMPLE") |
| 73 | + assert(fsConf.contains("fs.s3a.secret.key")) |
| 74 | + } finally { |
| 75 | + hadoopConf.unset("fs.s3a.access.key") |
| 76 | + hadoopConf.unset("fs.s3a.secret.key") |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + test("genPartitions embeds fs.gs.* keys from Hadoop conf into GlutenPartition.fsConf") { |
| 81 | + val hadoopConf = spark.sparkContext.hadoopConfiguration |
| 82 | + hadoopConf.set("fs.gs.auth.service.account.json.keyfile", "/tmp/sa.json") |
| 83 | + try { |
| 84 | + val partitions = api.genPartitions(emptyWsCtx, Seq(Seq.empty), Seq.empty) |
| 85 | + assert(partitions.size == 1) |
| 86 | + val fsConf = partitions.head.asInstanceOf[GlutenPartition].fsConf |
| 87 | + assert( |
| 88 | + fsConf.contains("fs.gs.auth.service.account.json.keyfile"), |
| 89 | + s"Expected fs.gs key not found; got: $fsConf") |
| 90 | + assert(fsConf("fs.gs.auth.service.account.json.keyfile") == "/tmp/sa.json") |
| 91 | + } finally { |
| 92 | + hadoopConf.unset("fs.gs.auth.service.account.json.keyfile") |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + test("genPartitions does not include non-fs.* keys in GlutenPartition.fsConf") { |
| 97 | + val hadoopConf = spark.sparkContext.hadoopConfiguration |
| 98 | + hadoopConf.set("fs.s3a.access.key", "KEY") |
| 99 | + hadoopConf.set("spark.some.conf", "value") |
| 100 | + hadoopConf.set("mapreduce.input.fileinputformat.split.maxsize", "128000000") |
| 101 | + try { |
| 102 | + val partitions = api.genPartitions(emptyWsCtx, Seq(Seq.empty), Seq.empty) |
| 103 | + val fsConf = partitions.head.asInstanceOf[GlutenPartition].fsConf |
| 104 | + assert(!fsConf.contains("spark.some.conf"), "Non-fs key must not appear in fsConf") |
| 105 | + assert( |
| 106 | + !fsConf.contains("mapreduce.input.fileinputformat.split.maxsize"), |
| 107 | + "Non-fs key must not appear in fsConf") |
| 108 | + assert(fsConf.contains("fs.s3a.access.key")) |
| 109 | + } finally { |
| 110 | + hadoopConf.unset("fs.s3a.access.key") |
| 111 | + hadoopConf.unset("spark.some.conf") |
| 112 | + hadoopConf.unset("mapreduce.input.fileinputformat.split.maxsize") |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + test("genPartitions produces empty fsConf when no fs.* keys are set") { |
| 117 | + // Use a key guaranteed not to exist in the Hadoop conf under any test profile. |
| 118 | + val hadoopConf = spark.sparkContext.hadoopConfiguration |
| 119 | + val uniqueKey = "fs.azure.__test_only_unique_key__" |
| 120 | + hadoopConf.unset(uniqueKey) |
| 121 | + // Count only keys matching our prefixes. |
| 122 | + val partitions = api.genPartitions(emptyWsCtx, Seq(Seq.empty), Seq.empty) |
| 123 | + val fsConf = partitions.head.asInstanceOf[GlutenPartition].fsConf |
| 124 | + assert(!fsConf.contains(uniqueKey)) |
| 125 | + } |
| 126 | +} |
0 commit comments