Skip to content

[SPARK-39759][SQL] Implement listIndexes in JDBC (H2 dialect) - #37172

Closed
panbingkun wants to merge 2 commits into
apache:masterfrom
panbingkun:h2dialect_listindex_dev
Closed

[SPARK-39759][SQL] Implement listIndexes in JDBC (H2 dialect)#37172
panbingkun wants to merge 2 commits into
apache:masterfrom
panbingkun:h2dialect_listindex_dev

Conversation

@panbingkun

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Implementing listIndexes in DS V2 JDBC for H2 dialect.

Why are the changes needed?

This is a subtask of the V2 Index support(https://issues.apache.org/jira/browse/SPARK-36525).
It can better test the index interface locally.

This PR implements listIndexes in H2 dialect.

Does this PR introduce any user-facing change?

Yes, listIndexes in DS V2 JDBC for H2

How was this patch tested?

Update existed UT.

indexMap += (indexName -> newIndex)
} else {
val properties = new util.Properties()
if (StringUtils.isNotEmpty(indexComment)) properties.put("COMMENT", indexComment)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I found possible null pointer in the implementation of listIndexes(H2), indexComment default value is null.
However, the default value of MySQLDIalect is empty String.
@huaxingao

@panbingkun

Copy link
Copy Markdown
ContributorAuthor

ping @huaxingao

@AmplabJenkins

Copy link
Copy Markdown

Can one of the admins verify this patch?

Comment threadsql/core/src/main/scala/org/apache/spark/sql/jdbc/H2Dialect.scala Outdated
@huaxingao

Copy link
Copy Markdown
Contributor

Does H2 support composite index?

@panbingkun

panbingkun commented Jul 15, 2022

Copy link
Copy Markdown
ContributorAuthor

Does H2 support composite index?
Yes, support

1.add follow code in beforeAll:

conn.prepareStatement(
"CREATE TABLE "test"."people1" (name TEXT(32) NOT NULL, " +
"id1 INTEGER NOT NULL, id2 INTEGER NOT NULL)")
.executeUpdate()
conn.prepareStatement("INSERT INTO "test"."people1" VALUES ('fred', 1, 1)").
executeUpdate()
conn.prepareStatement("INSERT INTO "test"."people1" VALUES ('mary', 2, 2)").
executeUpdate()

2.change UT

val loaded = Catalogs.load("h2", conf)
val jdbcTable = loaded.asInstanceOf[TableCatalog]
.loadTable(Identifier.of(Array("test"), "people1"))
.asInstanceOf[SupportsIndex]
assert(jdbcTable != null)
assert(jdbcTable.indexExists("people_index") == false)
val indexes1 = jdbcTable.listIndexes()
assert(indexes1.isEmpty)

sql(s"CREATE INDEX people_index ON TABLE h2.test.people1 (id1, id2)")
assert(jdbcTable.indexExists("people_index"))
val indexes2 = jdbcTable.listIndexes()
assert(!indexes2.isEmpty)
assert(indexes2.size == 1)
val tableIndex = indexes2.head
assert(tableIndex.indexName() == "people_index")
sql(s"DROP INDEX people_index ON TABLE h2.test.people1")
assert(jdbcTable.indexExists("people_index") == false)
val indexes3 = jdbcTable.listIndexes()
assert(indexes3.isEmpty)

3.debug view

WX20220715-200648@2x

@huaxingao

Copy link
Copy Markdown
Contributor

Merged to master. Thanks @panbingkun

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@panbingkun@AmplabJenkins@huaxingao