|
| 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 | + |
| 18 | +package org.apache.spark.sql.execution |
| 19 | + |
| 20 | +import org.apache.spark.sql.{DataFrame, QueryTest} |
| 21 | +import org.apache.spark.sql.test.SharedSQLContext |
| 22 | + |
| 23 | +/** |
| 24 | + * Tests for the sameResult function for [[SparkPlan]]s. |
| 25 | + */ |
| 26 | +class SameResultSuite extends QueryTest with SharedSQLContext { |
| 27 | + |
| 28 | + test("FileSourceScanExec: different orders of data filters and partition filters") { |
| 29 | + withTempPath { path => |
| 30 | + val tmpDir = path.getCanonicalPath |
| 31 | + spark.range(10) |
| 32 | + .selectExpr("id as a", "id + 1 as b", "id + 2 as c", "id + 3 as d") |
| 33 | + .write |
| 34 | + .partitionBy("a", "b") |
| 35 | + .parquet(tmpDir) |
| 36 | + val df = spark.read.parquet(tmpDir) |
| 37 | + // partition filters: a > 1 AND b < 9 |
| 38 | + // data filters: c > 1 AND d < 9 |
| 39 | + val plan1 = getFileSourceScanExec(df.where("a > 1 AND b < 9 AND c > 1 AND d < 9")) |
| 40 | + val plan2 = getFileSourceScanExec(df.where("b < 9 AND a > 1 AND d < 9 AND c > 1")) |
| 41 | + assert(plan1.sameResult(plan2)) |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + private def getFileSourceScanExec(df: DataFrame): FileSourceScanExec = { |
| 46 | + df.queryExecution.sparkPlan.find(_.isInstanceOf[FileSourceScanExec]).get |
| 47 | + .asInstanceOf[FileSourceScanExec] |
| 48 | + } |
| 49 | +} |
0 commit comments