Skip to content

Conversation

@panbingkun
Copy link
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.

@github-actions github-actions bot added the SQL label Jul 13, 2022
indexMap += (indexName -> newIndex)
} else {
val properties = new util.Properties()
if (StringUtils.isNotEmpty(indexComment)) properties.put("COMMENT", indexComment)
Copy link
Contributor Author

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
Contributor Author

ping @huaxingao

@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@huaxingao
Copy link
Contributor

Does H2 support composite index?

@panbingkun
Copy link
Contributor Author

panbingkun commented Jul 15, 2022

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

@panbingkun panbingkun requested a review from huaxingao July 15, 2022 12:12
@huaxingao huaxingao closed this in 6278bec Jul 19, 2022
@huaxingao
Copy link
Contributor

Merged to master. Thanks @panbingkun

Sign up for free to 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