|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.iceberg.spark; |
| 20 | + |
| 21 | +import static org.assertj.core.api.Assertions.assertThat; |
| 22 | +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; |
| 23 | + |
| 24 | +import org.apache.iceberg.ParameterizedTestExtension; |
| 25 | +import org.apache.iceberg.Table; |
| 26 | +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; |
| 27 | +import org.apache.spark.sql.internal.SQLConf; |
| 28 | +import org.apache.spark.sql.util.CaseInsensitiveStringMap; |
| 29 | +import org.junit.jupiter.api.AfterEach; |
| 30 | +import org.junit.jupiter.api.BeforeEach; |
| 31 | +import org.junit.jupiter.api.TestTemplate; |
| 32 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 33 | + |
| 34 | +@ExtendWith(ParameterizedTestExtension.class) |
| 35 | +public class TestSparkReadConf extends TestBaseWithCatalog { |
| 36 | + |
| 37 | + @BeforeEach |
| 38 | + public void before() { |
| 39 | + super.before(); |
| 40 | + sql("CREATE TABLE %s (id BIGINT, data STRING) USING iceberg", tableName); |
| 41 | + } |
| 42 | + |
| 43 | + @AfterEach |
| 44 | + public void after() { |
| 45 | + sql("DROP TABLE IF EXISTS %s", tableName); |
| 46 | + } |
| 47 | + |
| 48 | + @TestTemplate |
| 49 | + public void testSplitParallelismDefault() { |
| 50 | + Table table = validationCatalog.loadTable(tableIdent); |
| 51 | + SparkReadConf conf = new SparkReadConf(spark, table, CaseInsensitiveStringMap.empty()); |
| 52 | + assertThat(conf.splitParallelism()).isEqualTo(conf.parallelism()); |
| 53 | + } |
| 54 | + |
| 55 | + @TestTemplate |
| 56 | + public void testSplitParallelismSessionConf() { |
| 57 | + Table table = validationCatalog.loadTable(tableIdent); |
| 58 | + withSQLConf( |
| 59 | + ImmutableMap.of( |
| 60 | + SQLConf.SHUFFLE_PARTITIONS().key(), |
| 61 | + "999", |
| 62 | + SparkSQLProperties.READ_ADAPTIVE_SPLIT_SIZE_PARALLELISM, |
| 63 | + "42"), |
| 64 | + () -> { |
| 65 | + SparkReadConf conf = new SparkReadConf(spark, table, CaseInsensitiveStringMap.empty()); |
| 66 | + assertThat(conf.splitParallelism()).isEqualTo(42); |
| 67 | + }); |
| 68 | + } |
| 69 | + |
| 70 | + @TestTemplate |
| 71 | + public void testSplitParallelismRejectsZero() { |
| 72 | + Table table = validationCatalog.loadTable(tableIdent); |
| 73 | + withSQLConf( |
| 74 | + ImmutableMap.of(SparkSQLProperties.READ_ADAPTIVE_SPLIT_SIZE_PARALLELISM, "0"), |
| 75 | + () -> { |
| 76 | + SparkReadConf conf = new SparkReadConf(spark, table, CaseInsensitiveStringMap.empty()); |
| 77 | + assertThatIllegalArgumentException() |
| 78 | + .isThrownBy(conf::splitParallelism) |
| 79 | + .withMessageContaining("Split parallelism must be > 0"); |
| 80 | + }); |
| 81 | + } |
| 82 | + |
| 83 | + @TestTemplate |
| 84 | + public void testSplitParallelismRejectsNegative() { |
| 85 | + Table table = validationCatalog.loadTable(tableIdent); |
| 86 | + withSQLConf( |
| 87 | + ImmutableMap.of(SparkSQLProperties.READ_ADAPTIVE_SPLIT_SIZE_PARALLELISM, "-5"), |
| 88 | + () -> { |
| 89 | + SparkReadConf conf = new SparkReadConf(spark, table, CaseInsensitiveStringMap.empty()); |
| 90 | + assertThatIllegalArgumentException() |
| 91 | + .isThrownBy(conf::splitParallelism) |
| 92 | + .withMessageContaining("Split parallelism must be > 0"); |
| 93 | + }); |
| 94 | + } |
| 95 | +} |
0 commit comments