You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/12/01 05:01:16 UTC

[GitHub] [spark] dchvn commented on a change in pull request #34673: [SPARK-37343][SQL] Implement createIndex, IndexExists and dropIndex in JDBC (Postgres dialect)

dchvn commented on a change in pull request #34673:
URL: https://github.com/apache/spark/pull/34673#discussion_r759855352



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
##########
@@ -1078,26 +1080,50 @@ object JdbcUtils extends Logging with SQLConfHelper {
    */
   def checkIfIndexExists(
       conn: Connection,
-      indexName: String,
       sql: String,
-      indexColumnName: String,
       options: JDBCOptions): Boolean = {
     val statement = conn.createStatement
     try {
       statement.setQueryTimeout(options.queryTimeout)
       val rs = statement.executeQuery(sql)
-      while (rs.next()) {
-        val retrievedIndexName = rs.getString(indexColumnName)
-        if (conf.resolver(retrievedIndexName, indexName)) {
-          return true
-        }
-      }
-      false
+      rs.next
+    } catch {
+      case _: Exception =>
+        logWarning("Cannot retrieved index info.")
+        false
     } finally {
       statement.close()
     }
   }
 
+  /**
+   * Process index properties and return tuple of indexType and list of the other index properties.
+   */
+  def processIndexProperties(
+      properties: util.Map[String, String],
+      options: JDBCOptions
+    ): (String, Array[String]) = {
+    val dialect = JdbcDialects.get(options.url)
+    var indexType = ""
+    var indexPropertyList: Array[String] = Array.empty
+
+    if (!properties.isEmpty) {
+      properties.asScala.foreach { case (k, v) =>
+        if (k.equals(SupportsIndex.PROP_TYPE)) {
+          if (v.equalsIgnoreCase("BTREE") || v.equalsIgnoreCase("HASH")) {
+            indexType = s"USING $v"
+          } else {
+            throw new UnsupportedOperationException(s"Index Type $v is not supported." +
+              " The supported Index Types are: BTREE and HASH")

Review comment:
       @huaxingao, `GIST` and `GIN` index types in PostgreSQL are used for specific types: `tsvector` and `tsquery`, which are not supported types in Spark. Also for `SP-GIST` are used for the `point` type. Should we ignore these index types or something else? [GIST and GIN index type](https://www.postgresql.org/docs/9.1/textsearch-indexes.html) for details.




-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org