-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
HIVE-26227: Add support of catalog related statements for Hive ql #3288
Open
wecharyu
wants to merge
8
commits into
apache:master
Choose a base branch
from
wecharyu:HIVE-26227
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e53b5b6
HIVE-26227: Add support of catalog related statements for Hive ql
wecharyu 8c7b6b5
fix tests
wecharyu 7c7fe40
Keep catalog as a non-reserved keyword
wecharyu e6a9777
merge master to resolve conflicts
wecharyu e402221
merge the master branch
wecharyu b077bdb
Merge remote-tracking branch 'upstream/master' into HIVE-26227
6291b3c
show desc catalog
wecharyu b8b8c72
split new lines for desc catalog result
wecharyu 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
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
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
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
48 changes: 48 additions & 0 deletions
48
ql/src/java/org/apache/hadoop/hive/ql/ddl/catalog/alter/AbstractAlterCatalogAnalyzer.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,48 @@ | ||
/* | ||
* 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.hadoop.hive.ql.ddl.catalog.alter; | ||
|
||
import org.apache.hadoop.hive.metastore.api.Catalog; | ||
import org.apache.hadoop.hive.ql.QueryState; | ||
import org.apache.hadoop.hive.ql.ddl.DDLWork; | ||
import org.apache.hadoop.hive.ql.exec.TaskFactory; | ||
import org.apache.hadoop.hive.ql.hooks.WriteEntity; | ||
import org.apache.hadoop.hive.ql.parse.ASTNode; | ||
import org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer; | ||
import org.apache.hadoop.hive.ql.parse.SemanticException; | ||
|
||
/** | ||
* Analyzer for database alteration commands. | ||
*/ | ||
public abstract class AbstractAlterCatalogAnalyzer extends BaseSemanticAnalyzer { | ||
public AbstractAlterCatalogAnalyzer(QueryState queryState) throws SemanticException { | ||
super(queryState); | ||
} | ||
|
||
@Override | ||
public void analyzeInternal(ASTNode root) throws SemanticException { | ||
AbstractAlterCatalogDesc alterDesc = buildAlterCatalogDesc(root); | ||
Catalog catalog = getCatalog(alterDesc.getCatalogName()); | ||
outputs.add(new WriteEntity(catalog, WriteEntity.WriteType.DDL_NO_LOCK)); | ||
rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), alterDesc))); | ||
} | ||
|
||
protected abstract AbstractAlterCatalogDesc buildAlterCatalogDesc(ASTNode root) | ||
throws SemanticException; | ||
} |
42 changes: 42 additions & 0 deletions
42
ql/src/java/org/apache/hadoop/hive/ql/ddl/catalog/alter/AbstractAlterCatalogDesc.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,42 @@ | ||
/* | ||
* 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.hadoop.hive.ql.ddl.catalog.alter; | ||
|
||
import org.apache.hadoop.hive.ql.ddl.DDLDesc; | ||
import org.apache.hadoop.hive.ql.plan.Explain; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* DDL task description for ALTER CATALOG commands. | ||
*/ | ||
public abstract class AbstractAlterCatalogDesc implements DDLDesc, Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private final String catalogName; | ||
|
||
public AbstractAlterCatalogDesc(String catalogName) { | ||
this.catalogName = catalogName; | ||
} | ||
|
||
@Explain(displayName="name", explainLevels = { Explain.Level.USER, Explain.Level.DEFAULT, Explain.Level.EXTENDED }) | ||
public String getCatalogName() { | ||
return catalogName; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
ql/src/java/org/apache/hadoop/hive/ql/ddl/catalog/alter/AbstractAlterCatalogOperation.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,49 @@ | ||
/* | ||
* 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.hadoop.hive.ql.ddl.catalog.alter; | ||
|
||
import org.apache.hadoop.hive.metastore.api.Catalog; | ||
import org.apache.hadoop.hive.ql.ErrorMsg; | ||
import org.apache.hadoop.hive.ql.ddl.DDLOperation; | ||
import org.apache.hadoop.hive.ql.ddl.DDLOperationContext; | ||
import org.apache.hadoop.hive.ql.metadata.HiveException; | ||
|
||
/** | ||
* Operation process of altering a catalog. | ||
*/ | ||
public abstract class AbstractAlterCatalogOperation<T extends AbstractAlterCatalogDesc> extends DDLOperation<T> { | ||
public AbstractAlterCatalogOperation(DDLOperationContext context, T desc) { | ||
super(context, desc); | ||
} | ||
|
||
@Override | ||
public int execute() throws Exception { | ||
String catalogName = desc.getCatalogName(); | ||
Catalog catalog = context.getDb().getMSC().getCatalog(catalogName); | ||
if (catalog == null) { | ||
throw new HiveException(ErrorMsg.CATALOG_NOT_EXISTS, catalogName); | ||
} | ||
doAlteration(catalog); | ||
|
||
context.getDb().alterCatalog(catalogName, catalog); | ||
return 0; | ||
} | ||
|
||
protected abstract void doAlteration(Catalog catalog) throws HiveException; | ||
} |
47 changes: 47 additions & 0 deletions
47
...org/apache/hadoop/hive/ql/ddl/catalog/alter/location/AlterCatalogSetLocationAnalyzer.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,47 @@ | ||
/* | ||
* 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.hadoop.hive.ql.ddl.catalog.alter.location; | ||
|
||
import org.apache.hadoop.hive.ql.QueryState; | ||
import org.apache.hadoop.hive.ql.ddl.DDLSemanticAnalyzerFactory.DDLType; | ||
import org.apache.hadoop.hive.ql.ddl.catalog.alter.AbstractAlterCatalogAnalyzer; | ||
import org.apache.hadoop.hive.ql.ddl.catalog.alter.AbstractAlterCatalogDesc; | ||
import org.apache.hadoop.hive.ql.parse.ASTNode; | ||
import org.apache.hadoop.hive.ql.parse.HiveParser; | ||
import org.apache.hadoop.hive.ql.parse.SemanticException; | ||
|
||
/** | ||
* Analyzer for catalog set location commands. | ||
*/ | ||
@DDLType(types = HiveParser.TOK_ALTERCATALOG_LOCATION) | ||
public class AlterCatalogSetLocationAnalyzer extends AbstractAlterCatalogAnalyzer { | ||
public AlterCatalogSetLocationAnalyzer(QueryState queryState) throws SemanticException { | ||
super(queryState); | ||
} | ||
|
||
@Override | ||
protected AbstractAlterCatalogDesc buildAlterCatalogDesc(ASTNode root) throws SemanticException { | ||
String catalogName = getUnescapedName((ASTNode) root.getChild(0)); | ||
String newLocation = unescapeSQLString(root.getChild(1).getText()); | ||
|
||
outputs.add(toWriteEntity(newLocation)); | ||
|
||
return new AlterCatalogSetLocationDesc(catalogName, newLocation); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ava/org/apache/hadoop/hive/ql/ddl/catalog/alter/location/AlterCatalogSetLocationDesc.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,40 @@ | ||
/* | ||
* 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.hadoop.hive.ql.ddl.catalog.alter.location; | ||
|
||
import org.apache.hadoop.hive.ql.ddl.catalog.alter.AbstractAlterCatalogDesc; | ||
import org.apache.hadoop.hive.ql.plan.Explain; | ||
|
||
/** | ||
* DDL task description for ALTER CATALOG ... SET LOCATION ... commands. | ||
*/ | ||
@Explain(displayName = "Set Catalog Location", explainLevels = { Explain.Level.USER, Explain.Level.DEFAULT, Explain.Level.EXTENDED }) | ||
public class AlterCatalogSetLocationDesc extends AbstractAlterCatalogDesc { | ||
private final String location; | ||
|
||
public AlterCatalogSetLocationDesc(String catalogName, String location) { | ||
super(catalogName); | ||
this.location = location; | ||
} | ||
|
||
@Explain(displayName="location") | ||
public String getLocation() { | ||
return location; | ||
} | ||
} |
Oops, something went wrong.
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.
I confirmed
CATALOG
is not a reserved word in SQL:2023 👍