-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[HUDI-4165] Support Create/Drop/Show/Refresh Index Syntax for Spark SQL #5761
Merged
XuQianJin-Stars
merged 2 commits into
apache:master
from
huberylee:HUDI-4165-support-index-sql
Jun 17, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
119 changes: 119 additions & 0 deletions
119
hudi-common/src/main/java/org/apache/hudi/common/index/HoodieIndex.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,119 @@ | ||
/* | ||
* 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.hudi.common.index; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
|
||
public class HoodieIndex { | ||
private String indexName; | ||
private String[] colNames; | ||
private HoodieIndexType indexType; | ||
private Map<String, Map<String, String>> colOptions; | ||
private Map<String, String> options; | ||
|
||
public HoodieIndex() { | ||
} | ||
|
||
public HoodieIndex( | ||
String indexName, | ||
String[] colNames, | ||
HoodieIndexType indexType, | ||
Map<String, Map<String, String>> colOptions, | ||
Map<String, String> options) { | ||
this.indexName = indexName; | ||
this.colNames = colNames; | ||
this.indexType = indexType; | ||
this.colOptions = colOptions; | ||
this.options = options; | ||
} | ||
|
||
public String getIndexName() { | ||
return indexName; | ||
} | ||
|
||
public String[] getColNames() { | ||
return colNames; | ||
} | ||
|
||
public HoodieIndexType getIndexType() { | ||
return indexType; | ||
} | ||
|
||
public Map<String, Map<String, String>> getColOptions() { | ||
return colOptions; | ||
} | ||
|
||
public Map<String, String> getOptions() { | ||
return options; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "HoodieIndex{" | ||
+ "indexName='" + indexName + '\'' | ||
+ ", colNames='" + Arrays.toString(colNames) + '\'' | ||
+ ", indexType=" + indexType | ||
+ ", colOptions=" + colOptions | ||
+ ", options=" + options | ||
+ '}'; | ||
} | ||
|
||
public static class Builder { | ||
private String indexName; | ||
private String[] colNames; | ||
private HoodieIndexType indexType; | ||
private Map<String, Map<String, String>> colOptions; | ||
private Map<String, String> options; | ||
|
||
public Builder setIndexName(String indexName) { | ||
this.indexName = indexName; | ||
return this; | ||
} | ||
|
||
public Builder setColNames(String[] colNames) { | ||
this.colNames = colNames; | ||
return this; | ||
} | ||
|
||
public Builder setIndexType(String indexType) { | ||
this.indexType = HoodieIndexType.of(indexType); | ||
return this; | ||
} | ||
|
||
public Builder setColOptions(Map<String, Map<String, String>> colOptions) { | ||
this.colOptions = colOptions; | ||
return this; | ||
} | ||
|
||
public Builder setOptions(Map<String, String> options) { | ||
this.options = options; | ||
return this; | ||
} | ||
|
||
public HoodieIndex build() { | ||
return new HoodieIndex(indexName, colNames, indexType, colOptions, options); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
hudi-common/src/main/java/org/apache/hudi/common/index/HoodieIndexType.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,54 @@ | ||
/* | ||
* 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.hudi.common.index; | ||
|
||
import org.apache.hudi.exception.HoodieIndexException; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum HoodieIndexType { | ||
LUCENE((byte) 1); | ||
|
||
private final byte type; | ||
|
||
HoodieIndexType(byte type) { | ||
this.type = type; | ||
} | ||
|
||
public byte getValue() { | ||
return type; | ||
} | ||
|
||
public static HoodieIndexType of(byte indexType) { | ||
return Arrays.stream(HoodieIndexType.values()) | ||
.filter(t -> t.type == indexType) | ||
.findAny() | ||
.orElseThrow(() -> | ||
new HoodieIndexException("Unknown hoodie index type:" + indexType)); | ||
} | ||
|
||
public static HoodieIndexType of(String indexType) { | ||
return Arrays.stream(HoodieIndexType.values()) | ||
.filter(t -> t.name().equals(indexType.toUpperCase())) | ||
.findAny() | ||
.orElseThrow(() -> | ||
new HoodieIndexException("Unknown hoodie index type:" + indexType)); | ||
} | ||
} |
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
111 changes: 111 additions & 0 deletions
111
...asource/hudi-spark/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/Index.scala
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,111 @@ | ||
/* | ||
* 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.catalyst.plans.logical | ||
|
||
import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference} | ||
import org.apache.spark.sql.types.StringType | ||
|
||
/** | ||
* The logical plan of the CREATE INDEX command. | ||
*/ | ||
case class CreateIndex( | ||
table: LogicalPlan, | ||
indexName: String, | ||
indexType: String, | ||
ignoreIfExists: Boolean, | ||
columns: Seq[(Attribute, Map[String, String])], | ||
properties: Map[String, String], | ||
override val output: Seq[Attribute] = CreateIndex.getOutputAttrs) extends Command { | ||
|
||
override def children: Seq[LogicalPlan] = Seq(table) | ||
|
||
override lazy val resolved: Boolean = table.resolved && columns.forall(_._1.resolved) | ||
|
||
def withNewChildrenInternal(newChild: IndexedSeq[LogicalPlan]): CreateIndex = { | ||
copy(table = newChild.head) | ||
} | ||
} | ||
|
||
object CreateIndex { | ||
def getOutputAttrs: Seq[Attribute] = Seq.empty | ||
} | ||
|
||
/** | ||
* The logical plan of the DROP INDEX command. | ||
*/ | ||
case class DropIndex( | ||
table: LogicalPlan, | ||
indexName: String, | ||
ignoreIfNotExists: Boolean, | ||
override val output: Seq[Attribute] = DropIndex.getOutputAttrs) extends Command { | ||
|
||
override def children: Seq[LogicalPlan] = Seq(table) | ||
|
||
def withNewChildrenInternal(newChild: IndexedSeq[LogicalPlan]): DropIndex = { | ||
copy(table = newChild.head) | ||
} | ||
} | ||
|
||
object DropIndex { | ||
def getOutputAttrs: Seq[Attribute] = Seq.empty | ||
} | ||
|
||
/** | ||
* The logical plan of the SHOW INDEXES command. | ||
*/ | ||
case class ShowIndexes( | ||
table: LogicalPlan, | ||
override val output: Seq[Attribute] = ShowIndexes.getOutputAttrs) extends Command { | ||
|
||
override def children: Seq[LogicalPlan] = Seq(table) | ||
|
||
def withNewChildrenInternal(newChild: IndexedSeq[LogicalPlan]): ShowIndexes = { | ||
copy(table = newChild.head) | ||
} | ||
} | ||
|
||
object ShowIndexes { | ||
def getOutputAttrs: Seq[Attribute] = Seq( | ||
AttributeReference("index_name", StringType, nullable = false)(), | ||
AttributeReference("col_name", StringType, nullable = false)(), | ||
AttributeReference("index_type", StringType, nullable = false)(), | ||
AttributeReference("col_options", StringType, nullable = true)(), | ||
AttributeReference("options", StringType, nullable = true)() | ||
) | ||
} | ||
|
||
/** | ||
* The logical plan of the REFRESH INDEX command. | ||
*/ | ||
case class RefreshIndex( | ||
table: LogicalPlan, | ||
indexName: String, | ||
override val output: Seq[Attribute] = RefreshIndex.getOutputAttrs) extends Command { | ||
|
||
override def children: Seq[LogicalPlan] = Seq(table) | ||
|
||
def withNewChildrenInternal(newChild: IndexedSeq[LogicalPlan]): RefreshIndex = { | ||
copy(table = newChild.head) | ||
} | ||
} | ||
|
||
object RefreshIndex { | ||
def getOutputAttrs: Seq[Attribute] = Seq.empty | ||
} |
Oops, something went wrong.
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.
other types?