-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-29807 #6700
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
Open
dengzhhu653
wants to merge
5
commits into
apache:master
Choose a base branch
from
dengzhhu653:HIVE-29807
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
HIVE-29807 #6700
Changes from all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
124 changes: 124 additions & 0 deletions
124
ql/src/test/org/apache/hadoop/hive/ql/parse/TestMaterializedCTEInputs.java
This file contains hidden or 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,124 @@ | ||
| /* | ||
| * 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.parse; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import org.apache.hadoop.hive.conf.HiveConf; | ||
| import org.apache.hadoop.hive.conf.HiveConfForTest; | ||
| import org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder; | ||
| import org.apache.hadoop.hive.metastore.client.builder.TableBuilder; | ||
| import org.apache.hadoop.hive.ql.Context; | ||
| import org.apache.hadoop.hive.ql.QueryState; | ||
| import org.apache.hadoop.hive.ql.ddl.database.drop.DropDatabaseDesc; | ||
| import org.apache.hadoop.hive.ql.hooks.ReadEntity; | ||
| import org.apache.hadoop.hive.ql.metadata.Hive; | ||
| import org.apache.hadoop.hive.ql.session.SessionState; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| public class TestMaterializedCTEInputs { | ||
| private static final String DB_NAME = "test_materialized_cte"; | ||
| private static final String TABLE_FQ_NAME = DB_NAME + "@src"; | ||
|
|
||
| private static Hive db; | ||
| private static HiveConf conf; | ||
|
|
||
| @BeforeAll | ||
| public static void beforeClass() throws Exception { | ||
| conf = new HiveConfForTest(TestMaterializedCTEInputs.class); | ||
| conf.set("hive.security.authorization.enabled", "false"); | ||
| conf.set("hive.security.authorization.manager", | ||
| "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdConfOnlyAuthorizerFactory"); | ||
| conf.setIntVar(HiveConf.ConfVars.HIVE_CTE_MATERIALIZE_THRESHOLD, 1); | ||
| conf.setBoolVar(HiveConf.ConfVars.HIVE_CTE_MATERIALIZE_FULL_AGGREGATE_ONLY, false); | ||
| conf.setBoolVar(HiveConf.ConfVars.HIVE_STATS_COLLECT_SCANCOLS, true); | ||
| db = Hive.get(conf); | ||
| SessionState.start(conf); | ||
| new DatabaseBuilder().setName(DB_NAME).create(db.getMSC(), conf); | ||
| SessionState.get().setCurrentDatabase(DB_NAME); | ||
| new TableBuilder().setDbName(DB_NAME).setTableName("src") | ||
| .addCol("key", "string") | ||
| .addCol("value", "string") | ||
| .addCol("col1", "int") | ||
| .create(db.getMSC(), conf); | ||
| } | ||
|
|
||
| public static Stream<Arguments> casesForMaterializedCteInputs() { | ||
| return Stream.of( | ||
| Arguments.of("chain cte", "with q1 as ( select key from q2 where key = '5')," | ||
| + "q2 as ( select key from test_materialized_cte.src where key = '5') " | ||
| + "select * from (select key from q1) a", Set.of("key")), | ||
| Arguments.of("nested cte", "WITH q1 AS (" | ||
| + "WITH q2 AS (SELECT key, value FROM test_materialized_cte.src WHERE key = '4') " | ||
| + "SELECT * FROM q2 UNION ALL SELECT * FROM q2) " | ||
| + "SELECT * FROM q1 t1 JOIN q1 t2 ON t1.key = t2.key", Set.of("key", "value")) | ||
| ); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "{0}") | ||
| @MethodSource("casesForMaterializedCteInputs") | ||
| void testMaterializedCteInputs(String type, String query, Set<String> expectedCols) throws Exception { | ||
| HiveConf testConf = new HiveConf(conf); | ||
| Context ctx = new Context(testConf); | ||
| ASTNode astNode = ParseUtils.parse(query, ctx); | ||
| QueryState queryState = new QueryState.Builder().withHiveConf(testConf).build(); | ||
| SemanticAnalyzer analyzer = (SemanticAnalyzer) SemanticAnalyzerFactory.get(queryState, astNode); | ||
| analyzer.initCtx(ctx); | ||
| analyzer.analyze(astNode, ctx); | ||
|
|
||
| Set<ReadEntity> directInputs = analyzer.getInputs(); | ||
| Set<ReadEntity> allInputs = analyzer.getAllInputs(); | ||
|
|
||
| assertTrue(directInputs.stream().noneMatch(e -> isTableNamed(e, "src")), | ||
| "Materialized CTE should not expose base table in direct inputs"); | ||
| assertTrue(allInputs.stream().anyMatch(e -> isTableNamed(e, "src")), | ||
| "Materialized CTE base table must appear in getAllInputs"); | ||
|
|
||
| ColumnAccessInfo columnAccessInfo = analyzer.getColumnAccessInfo(); | ||
| assertNotNull(columnAccessInfo); | ||
| List<String> srcCols = columnAccessInfo.getTableToColumnAccessMap().get(TABLE_FQ_NAME); | ||
| assertNotNull(srcCols, "Column must include materialized CTE base table"); | ||
| assertTrue(new HashSet<>(srcCols).containsAll(expectedCols), | ||
| () -> "Expected columns " + expectedCols + " but got " + srcCols); | ||
| ctx.clear(); | ||
| } | ||
|
|
||
| private static boolean isTableNamed(ReadEntity entity, String tableName) { | ||
| return entity.getTable() != null && tableName.equals(entity.getTable().getTableName()); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public static void afterClass() throws Exception { | ||
| try { | ||
| db.dropDatabase(new DropDatabaseDesc(DB_NAME, DB_NAME, true, true, true)); | ||
| } catch (Exception ignored) { | ||
| } | ||
| db.close(true); | ||
| } | ||
| } |
This file contains hidden or 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
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.
Why was
ColumnAccessInforeplaced withSemanticAnalyzer? The referenceanalyzeris not used elsewhere in this method.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.
It's used in
getMaterializedCteColumnAccessInfo(analyzer.rootClause.asExecutionOrder())to merge parent CTEs column access