-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
[SPARK-36526][SQL] DSV2 Index Support: Add supportsIndex interface #33754
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a84794c
[SPARK-36526][SQL] DSV2 Index Support: Add supportsIndex interface
huaxingao b89b321
fix import
huaxingao f9f4e37
addess comments
huaxingao d4c1931
add columnPropertyList in createIndex
huaxingao 14a819a
address comments
huaxingao 120b477
make SupportsIndex extend Table
huaxingao f6ca2e8
address comments
huaxingao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/index/SupportsIndex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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.connector.catalog.Table; | ||
import org.apache.spark.sql.connector.expressions.NamedReference; | ||
|
||
/** | ||
* Table methods for working with index | ||
* | ||
* @since 3.3.0 | ||
*/ | ||
@Evolving | ||
public interface SupportsIndex extends Table { | ||
|
||
/** | ||
* Creates an index. | ||
* | ||
* @param indexName the name of the index to be created | ||
* @param indexType the IndexType of the index to be created | ||
* @param columns the columns on which index to be created | ||
* @param columnProperties 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) | ||
*/ | ||
void createIndex(String indexName, | ||
String indexType, | ||
NamedReference[] columns, | ||
Map<NamedReference, Properties>[] columnProperties, | ||
Properties properties) | ||
throws IndexAlreadyExistsException; | ||
|
||
/** | ||
* Drops the index with the given name. | ||
* | ||
* @param indexName the name of the index to be dropped. | ||
* @return true if the index is dropped | ||
* @throws NoSuchIndexException If the index does not exist (optional) | ||
*/ | ||
boolean dropIndex(String indexName) throws NoSuchIndexException; | ||
|
||
/** | ||
* Checks whether an index exists in this table. | ||
* | ||
* @param indexName the name of the index | ||
* @return true if the index exists, false otherwise | ||
*/ | ||
boolean indexExists(String indexName); | ||
|
||
/** | ||
* Lists all the indexes in this table. | ||
*/ | ||
TableIndex[] listIndexes(); | ||
} |
79 changes: 79 additions & 0 deletions
79
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/index/TableIndex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 java.util.Properties; | ||
|
||
import org.apache.spark.annotation.Evolving; | ||
import org.apache.spark.sql.connector.expressions.NamedReference; | ||
|
||
/** | ||
* Index in a table | ||
* | ||
* @since 3.3.0 | ||
*/ | ||
@Evolving | ||
public final class TableIndex { | ||
private String indexName; | ||
private String indexType; | ||
private NamedReference[] columns; | ||
private Map<NamedReference, Properties> columnProperties = Collections.emptyMap(); | ||
private Properties properties; | ||
|
||
public TableIndex( | ||
String indexName, | ||
String indexType, | ||
NamedReference[] columns, | ||
Map<NamedReference, Properties> columnProperties, | ||
Properties properties) { | ||
this.indexName = indexName; | ||
this.indexType = indexType; | ||
this.columns = columns; | ||
this.columnProperties = columnProperties; | ||
this.properties = properties; | ||
} | ||
|
||
/** | ||
* @return the Index name. | ||
*/ | ||
String indexName() { return indexName; } | ||
|
||
/** | ||
* @return the indexType of this Index. | ||
*/ | ||
String indexType() { return indexType; } | ||
|
||
/** | ||
* @return the column(s) this Index is on. Could be multi columns (a multi-column index). | ||
*/ | ||
NamedReference[] columns() { return columns; } | ||
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. |
||
|
||
/** | ||
* @return the map of column and column property map. | ||
*/ | ||
Map<NamedReference, Properties> columnProperties() { return columnProperties; } | ||
|
||
/** | ||
* Returns the index properties. | ||
*/ | ||
Properties properties() { | ||
return properties; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For partitioned table, do we plan to support index creation on table level (for all partitions), or on individual partition level?
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.
This is up to the data source implementation. I think it makes more sense at file level (each data file has an index file).
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 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.
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.
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.
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.
Thanks for your explain