-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-36526][SQL] DSV2 Index Support: Add supportsIndex interface #33754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
a84794c
b89b321
f9f4e37
d4c1931
14a819a
120b477
f6ca2e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * 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.connector.catalog.index; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
| import org.apache.spark.sql.connector.catalog.Identifier; | ||
| import org.apache.spark.sql.connector.expressions.FieldReference; | ||
|
|
||
| /** | ||
| * An Index in a table | ||
| * | ||
| * @since 3.3.0 | ||
| */ | ||
| @Evolving | ||
| public class Index { | ||
|
||
| private String indexName; | ||
| private String indexType; | ||
| private Identifier table; | ||
| private FieldReference[] columns; | ||
| private Map<String, String> properties = Collections.emptyMap(); | ||
|
|
||
| public Index( | ||
| String indexName, | ||
| String indexType, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's up to the data source implementation.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have example index type in mind?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example index types are @cloud-fan Shall we use enum instead of String for index type? Even though the catalog implementation is responsible for recognizing and taking care of user-specified index type, we still need to add these specific index types in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Index is for performance only and Spark doesn't need to define the semantic, I think String is more convenient. Data source can define whatever index type they like and ask end-users to use. Spark doesn't need to be in the middle. |
||
| Identifier table, | ||
| FieldReference[] columns, | ||
| Map<String, String> properties) { | ||
| this.indexName = indexName; | ||
| this.indexType = indexType; | ||
| this.table = table; | ||
| this.columns = columns; | ||
| this.properties = properties; | ||
| } | ||
|
|
||
| /** | ||
| * @return the Index name. | ||
| */ | ||
| String indexName() { return indexName; } | ||
|
|
||
| /** | ||
| * @return the indexType of this Index. | ||
| */ | ||
| String indexType() { return indexType; } | ||
|
|
||
| /** | ||
| * @return the table this Index is on. | ||
| */ | ||
| Identifier table() { return table; } | ||
|
|
||
| /** | ||
| * @return the column(s) this Index is on. Could be multi columns (a multi-column index). | ||
| */ | ||
| FieldReference[] columns() { return columns; } | ||
|
|
||
| /** | ||
| * Returns the string map of index properties. | ||
| */ | ||
| Map<String, String> properties() { | ||
| return Collections.emptyMap(); | ||
|
||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we also add |
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,139 @@ | ||||||
| /* | ||||||
| * 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.connector.catalog.index; | ||||||
|
|
||||||
| import java.util.Map; | ||||||
| import java.util.Properties; | ||||||
|
|
||||||
| import org.apache.spark.annotation.Evolving; | ||||||
| import org.apache.spark.sql.catalyst.analysis.IndexAlreadyExistsException; | ||||||
| import org.apache.spark.sql.catalyst.analysis.NoSuchIndexException; | ||||||
| import org.apache.spark.sql.catalyst.analysis.NoSuchTableException; | ||||||
| import org.apache.spark.sql.connector.catalog.CatalogPlugin; | ||||||
| import org.apache.spark.sql.connector.catalog.Identifier; | ||||||
| import org.apache.spark.sql.connector.expressions.FieldReference; | ||||||
|
|
||||||
| /** | ||||||
| * Catalog methods for working with index | ||||||
|
||||||
| * | ||||||
| * @since 3.3.0 | ||||||
| */ | ||||||
| @Evolving | ||||||
| public interface SupportsIndex extends CatalogPlugin { | ||||||
|
||||||
|
|
||||||
| /** | ||||||
| * Creates an index. | ||||||
| * | ||||||
| * @param indexName the name of the index to be created | ||||||
| * @param indexType the IndexType of the index to be created | ||||||
| * @param table the table on which index to be created | ||||||
| * @param columns the columns on which index to be created | ||||||
| * @param columnPropertyList the properties of the columns on which index to be created | ||||||
| * @param properties the properties of the index to be created | ||||||
| * @throws IndexAlreadyExistsException If the index already exists (optional) | ||||||
| * @throws UnsupportedOperationException If create index is not a supported operation | ||||||
| */ | ||||||
| void createIndex(String indexName, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For partitioned table, do we plan to support index creation on table level (for all partitions), or on individual partition level?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is up to the data source implementation. I think it makes more sense at file level (each data file has an index file).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to support index creation on individual partition level. For the existing data in the production environment, if only support index creation on table level, it is likely to be an impossible job for users.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I think I didn't explain this clear: the index creation is actually done at the underlying data source. It's up to the data source's implementation on which level the index is created. For the implementation in file based data source, I believe the index is created at file level, not at table level or partition level.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your explain |
||||||
| String indexType, | ||||||
| Identifier table, | ||||||
| FieldReference[] columns, | ||||||
| Map<String, String>[] columnPropertyList, | ||||||
| Map<String, String> properties) | ||||||
| throws IndexAlreadyExistsException, UnsupportedOperationException; | ||||||
|
||||||
|
|
||||||
| /** | ||||||
| * Soft deletes the index with the given name. | ||||||
|
||||||
| * Deleted index can be restored by calling restoreIndex. | ||||||
| * | ||||||
| * @param indexName the name of the index to be deleted | ||||||
| * @return true if the index is deleted | ||||||
| * @throws NoSuchIndexException If the index does not exist (optional) | ||||||
| * @throws UnsupportedOperationException If delete index is not a supported operation | ||||||
| */ | ||||||
| default boolean deleteIndex(String indexName) | ||||||
| throws NoSuchIndexException, UnsupportedOperationException { | ||||||
| throw new UnsupportedOperationException("Delete index is not supported."); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Checks whether an index exists. | ||||||
|
||||||
| * Checks whether an index exists. | |
| * Checks whether an index exists in this table. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the corresponding SQL syntax for delete and drop index?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should follow TableCatalog.alterTable
alterIndex(String indexName, IndexChange[] changes)
It's not very clear to me what can be changed in ALTER INDEX though.
Uh oh!
There was an error while loading. Please reload this page.