You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2022/10/31 12:29:43 UTC

[GitHub] [hudi] leesf commented on a diff in pull request #6442: [HUDI-4449] Support DataSourceV2 Read for Spark3.2

leesf commented on code in PR #6442:
URL: https://github.com/apache/hudi/pull/6442#discussion_r1009358207


##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestQueryTable.scala:
##########
@@ -0,0 +1,415 @@
+/*
+ * 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.spark.sql.hudi
+
+import org.apache.commons.lang3.StringUtils
+import org.apache.hudi.HoodieSparkUtils
+import org.apache.hudi.exception.{HoodieDuplicateKeyException, HoodieException}
+import org.apache.spark.sql.functions.lit
+
+class TestQueryTable extends HoodieSparkSqlTestBase {
+
+  test("Test PruneColumns") {
+    withTempDir { tmp =>
+      val tableName = generateTableName
+      // Create a partitioned table
+      spark.sql(
+        s"""
+           |create table $tableName (
+           |  id int,
+           |  name string,
+           |  price double,
+           |  ts long,
+           |  dt string
+           |) using hudi
+           | tblproperties (primaryKey = 'id')
+           | partitioned by (dt)
+           | location '${tmp.getCanonicalPath}/$tableName'
+       """.stripMargin)
+      //  Insert overwrite dynamic partition
+      spark.sql(
+        s"""
+           | insert overwrite table $tableName
+           | select 1 as id, 'a1' as name, 10 as price, 1000 as ts, '2021-01-05' as dt
+        """.stripMargin)
+
+      //  Insert overwrite dynamic partition
+      spark.sql(
+        s"""
+           | insert overwrite table $tableName
+           | select 2 as id, 'a2' as name, 10 as price, 1000 as ts, '2021-01-06' as dt
+        """.stripMargin)
+
+      // Insert overwrite static partition
+      spark.sql(
+        s"""
+           | insert into table $tableName partition(dt = '2021-01-05')
+           | select * from (select 2 , 'a2', 12, 1000) limit 10
+        """.stripMargin)
+
+      spark.sql(s"set hoodie.datasource.v2.read.enable=true")
+
+      val query = s"select id, name from $tableName " +
+        s"where dt ='2021-01-05' and id = 1"
+
+      spark.sql(query).explain(true)
+
+      checkAnswer(query)(
+        Seq(1, "a1")
+      )
+      spark.sql(s"set hoodie.datasource.v2.read.enable=false")
+
+    }
+
+  }
+
+  test("Test RuntimeFiltering") {
+    withTempDir { tmp =>
+      val tableName = generateTableName
+      // Create a partitioned table
+      println(spark.version)
+      spark.sql(
+        s"""
+           |create table $tableName (
+           |  id int,
+           |  name string,
+           |  price double,
+           |  ts long,
+           |  dt string
+           |) using hudi
+           | tblproperties (primaryKey = 'id', type = 'cow')
+           | partitioned by (name)
+           | location '${tmp.getCanonicalPath}'
+       """.stripMargin)
+      // Insert into dynamic partition
+      spark.sql(
+        s"""
+           | insert into $tableName
+           | select 1 as id, 'a1' as name, 10 as price, 1000 as ts, '2021-01-05' as dt
+        """.stripMargin)
+
+      spark.sql(
+        s"""
+           | insert into $tableName
+           | select 10 as id, 'a10' as name, 100 as price, 10000 as ts, '2021-01-06' as dt
+        """.stripMargin)
+
+
+      spark.sql(
+        s"""
+           | insert into $tableName
+           | select 2 as id, 'a2' as name, 20 as price, 2000 as ts, '2021-02-05' as dt
+        """.stripMargin)
+
+      val dimDf = spark.range(1, 4)
+        .withColumn("name", lit("a1"))
+        .select("id", "name")
+
+      dimDf.show(false)
+
+      spark.sql("CREATE TABLE dim (id int, name string) USING parquet")
+      dimDf.coalesce(1).write.mode("append").insertInto("dim")
+
+
+      spark.sql(s"set hoodie.datasource.v2.read.enable=true")
+
+      val query =String.format("SELECT f.id, f.price, f.ts, f.dt, f.name FROM %s f JOIN dim d ON f.name = d.name AND d.id = 1 ORDER BY id", tableName)

Review Comment:
   `= String`



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org