urosstan-db commented on code in PR #51519:
URL: https://github.com/apache/spark/pull/51519#discussion_r2213670789


##########
sql/core/src/test/scala/org/apache/spark/sql/jdbc/v2/JDBCJoinPushdownIntegrationSuite.scala:
##########
@@ -0,0 +1,511 @@
+/*
+ * 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.jdbc.v2
+
+import java.sql.{Connection, DriverManager}
+import java.util.Properties
+
+import org.apache.spark.sql.QueryTest
+import org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.jdbc.JdbcDialect
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types.{DataType, DataTypes}
+
+trait JDBCJoinPushdownIntegrationSuite
+  extends QueryTest
+  with SharedSparkSession
+  with V2JDBCPushdownTestUtils {
+  val catalogName: String
+  def namespaceOpt: Option[String] = None
+  val url: String
+
+  val joinTableName1: String = "join_table_1"
+  val joinTableName2: String = "join_table_2"
+
+  val jdbcDialect: JdbcDialect
+
+  private def catalogAndNamespace =
+    namespaceOpt.map(namespace => 
s"$catalogName.$namespace").getOrElse(catalogName)
+
+  def qualifyTableName(tableName: String): String = namespaceOpt
+    .map(namespace => s"$namespace.$tableName").getOrElse(tableName)
+
+  private val fullyQualifiedTableName1: String = 
qualifyTableName(joinTableName1)
+
+  private val fullyQualifiedTableName2: String = 
qualifyTableName(joinTableName2)
+
+  protected def getJDBCTypeString(dt: DataType): String = {
+    JdbcUtils.getJdbcType(dt, jdbcDialect).databaseTypeDefinition.toUpperCase()
+  }
+
+  protected def caseConvert(tableName: String): String = tableName
+
+  protected def withConnection[T](f: Connection => T): T = {
+    val conn = DriverManager.getConnection(url, new Properties())
+    try {
+      f(conn)
+    } finally {
+      conn.close()
+    }
+  }
+
+  def dataPreparation(connection: Connection): Unit = {
+    schemaPreparation(connection)
+    tablePreparation(connection)
+    fillJoinTables(connection)
+  }
+
+  def schemaPreparation(connection: Connection): Unit = {
+    connection.prepareStatement(s"CREATE SCHEMA IF NOT EXISTS 
${namespaceOpt.get}").executeUpdate()
+  }
+
+  def tablePreparation(connection: Connection): Unit = {
+    connection.prepareStatement(
+      s"""CREATE TABLE $fullyQualifiedTableName1 (
+         |  ID ${getJDBCTypeString(DataTypes.IntegerType)},
+         |  AMOUNT ${getJDBCTypeString(DataTypes.createDecimalType(10, 2))},
+         |  ADDRESS ${getJDBCTypeString(DataTypes.StringType)}
+         |)""".stripMargin
+    ).executeUpdate()
+
+    connection.prepareStatement(
+      s"""CREATE TABLE $fullyQualifiedTableName2 (
+         |  ID ${getJDBCTypeString(DataTypes.IntegerType)},
+         |  NEXT_ID ${getJDBCTypeString(DataTypes.IntegerType)},
+         |  SALARY ${getJDBCTypeString(DataTypes.createDecimalType(10, 2))},
+         |  SURNAME ${getJDBCTypeString(DataTypes.StringType)}
+         |)""".stripMargin
+    ).executeUpdate()
+  }
+
+  def fillJoinTables(connection: Connection): Unit = {
+    val random = new java.util.Random(42)
+    val table1Data = (1 to 100).map { i =>
+      val id = i % 11
+      val amount = BigDecimal.valueOf(random.nextDouble() * 10000)
+        .setScale(2, BigDecimal.RoundingMode.HALF_UP)
+      val address = s"address_$i"
+      (id, amount, address)
+    }
+    val table2Data = (1 to 100).map { i =>
+      val id = (i % 17)
+      val next_id = (id + 1) % 17
+      val salary = BigDecimal.valueOf(random.nextDouble() * 50000)
+        .setScale(2, BigDecimal.RoundingMode.HALF_UP)
+      val surname = s"surname_$i"
+      (id, next_id, salary, surname)
+    }

Review Comment:
   Is 42 seed of Random function?



-- 
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]

Reply via email to