You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2020/11/03 14:16:51 UTC
[GitHub] [hive] mustafaiman opened a new pull request #1645: HIVE-24350: NullScanOptimizer can lookup emptiness info from stats fo…
mustafaiman opened a new pull request #1645:
URL: https://github.com/apache/hive/pull/1645
…r managed tables
Change-Id: I7cf7b8f7738c5660ee1c61bcb0456f1c70efe492
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
3. Ensure you have added or run the appropriate tests for your PR:
4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX: Your PR title ...'.
5. Be sure to keep the PR description updated to reflect all changes.
6. Please write your PR title to summarize what this PR proposes.
7. If possible, provide a concise example to reproduce the issue for a faster review.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducable example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
If no, write 'No'.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
-->
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] rbalamohan commented on pull request #1645: HIVE-24350: NullScanOptimizer can lookup emptiness info from stats fo…
Posted by GitBox <gi...@apache.org>.
rbalamohan commented on pull request #1645:
URL: https://github.com/apache/hive/pull/1645#issuecomment-726456209
LGTM pending tests.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] mustafaiman commented on a change in pull request #1645: HIVE-24350: NullScanOptimizer can lookup emptiness info from stats fo…
Posted by GitBox <gi...@apache.org>.
mustafaiman commented on a change in pull request #1645:
URL: https://github.com/apache/hive/pull/1645#discussion_r522558974
##########
File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/physical/NullScanTaskDispatcher.java
##########
@@ -93,94 +91,109 @@ private String getAliasForTableScanOperator(MapWork work,
return null;
}
- private PartitionDesc changePartitionToMetadataOnly(PartitionDesc desc,
- Path path) {
- if (desc == null) {
- return null;
- }
- FileStatus[] filesFoundInPartitionDir = null;
+ private void lookupAndProcessPath(MapWork work, Path path,
+ Collection<String> aliasesToOptimize) {
try {
- filesFoundInPartitionDir = Utilities.listNonHiddenFileStatus(physicalContext.getConf(), path);
+ boolean isEmpty = Utilities.listNonHiddenFileStatus(physicalContext.getConf(), path).length == 0;
+ processPath(work, path, aliasesToOptimize, isEmpty);
} catch (IOException e) {
- LOG.error("Cannot determine if the table is empty", e);
- }
- if (!isMetadataOnlyAllowed(filesFoundInPartitionDir)) {
- return desc;
+ LOG.warn("Could not determine if path {} was empty." +
+ "Cannot use null scan optimization for this path.", path, e);
}
-
- boolean isEmpty = filesFoundInPartitionDir == null || filesFoundInPartitionDir.length == 0;
- desc.setInputFileFormatClass(isEmpty ? ZeroRowsInputFormat.class : OneNullRowInputFormat.class);
- desc.setOutputFileFormatClass(HiveIgnoreKeyTextOutputFormat.class);
- desc.getProperties().setProperty(serdeConstants.SERIALIZATION_LIB,
- NullStructSerDe.class.getName());
- return desc;
}
- private boolean isMetadataOnlyAllowed(FileStatus[] filesFoundInPartitionDir) {
- if (filesFoundInPartitionDir == null || filesFoundInPartitionDir.length == 0) {
- return true; // empty folders are safe to convert to metadata-only
- }
- for (FileStatus f : filesFoundInPartitionDir) {
- if (AcidUtils.isDeleteDelta(f.getPath())) {
- /*
- * as described in HIVE-23712, an acid partition is not a safe subject of metadata-only
- * optimization, because there is a chance that it contains no data but contains folders
- * (e.g: delta_0000002_0000002_0000, delete_delta_0000003_0000003_0000), without scanning
- * the underlying file contents, we cannot tell whether this partition contains data or not
- */
- return false;
- }
+ private void processPath(MapWork work, Path path, Collection<String> aliasesToOptimize,
+ boolean isEmpty) {
+ PartitionDesc partDesc = work.getPathToPartitionInfo().get(path).clone();
+ partDesc.setInputFileFormatClass(isEmpty ? ZeroRowsInputFormat.class : OneNullRowInputFormat.class);
+ partDesc.setOutputFileFormatClass(HiveIgnoreKeyTextOutputFormat.class);
+ partDesc.getProperties().setProperty(serdeConstants.SERIALIZATION_LIB,
+ NullStructSerDe.class.getName());
+ Path fakePath =
+ new Path(NullScanFileSystem.getBase() + partDesc.getTableName()
+ + "/part" + encode(partDesc.getPartSpec()));
+ StringInternUtils.internUriStringsInPath(fakePath);
+ work.addPathToPartitionInfo(fakePath, partDesc);
+ work.addPathToAlias(fakePath, new ArrayList<>(aliasesToOptimize));
+ Collection<String> aliasesContainingPath = work.getPathToAliases().get(path);
+ aliasesContainingPath.removeAll(aliasesToOptimize);
+ if (aliasesContainingPath.isEmpty()) {
+ work.removePathToAlias(path);
+ work.removePathToPartitionInfo(path);
}
- return true;
}
- private void processAlias(MapWork work, Path path,
- Collection<String> aliasesAffected, Set<String> aliases) {
- // the aliases that are allowed to map to a null scan.
- Collection<String> allowed = aliasesAffected.stream()
- .filter(a -> aliases.contains(a)).collect(Collectors.toList());
- if (!allowed.isEmpty()) {
- PartitionDesc partDesc = work.getPathToPartitionInfo().get(path).clone();
- PartitionDesc newPartition =
- changePartitionToMetadataOnly(partDesc, path);
- // Prefix partition with something to avoid it being a hidden file.
- Path fakePath =
- new Path(NullScanFileSystem.getBase() + newPartition.getTableName()
- + "/part" + encode(newPartition.getPartSpec()));
- StringInternUtils.internUriStringsInPath(fakePath);
- work.addPathToPartitionInfo(fakePath, newPartition);
- work.addPathToAlias(fakePath, new ArrayList<>(allowed));
- aliasesAffected.removeAll(allowed);
- if (aliasesAffected.isEmpty()) {
- work.removePathToAlias(path);
- work.removePathToPartitionInfo(path);
- }
- }
+ private void addCandidatePath(Map<Path, Collection<String>> aliasesForPath, Path path, String alias) {
+ Collection<String> aliases = aliasesForPath.computeIfAbsent(path, k -> new ArrayList<>());
+ aliases.add(alias);
}
- private void processAlias(MapWork work, Set<TableScanOperator> tableScans) {
- Set<String> aliases = new HashSet<>();
+ private void processTableScans(MapWork work, Set<TableScanOperator> tableScans) {
+ Map<Path, Boolean> managedEmptyPathMap = new HashMap<>();
+ Map<Path, Collection<String>> candidatePathsToAliases = new HashMap<>();
+ Map<String, Boolean> aliasTypeMap = new HashMap<>();
+ Map<String, Map<Path, Partition>> allowedAliasesToPartitions = new HashMap<>();
for (TableScanOperator tso : tableScans) {
// use LinkedHashMap<String, Operator<? extends OperatorDesc>>
// getAliasToWork() should not apply this for non-native table
if (tso.getConf().getTableMetadata().getStorageHandler() != null) {
continue;
}
String alias = getAliasForTableScanOperator(work, tso);
- aliases.add(alias);
+ boolean isManagedTable = !MetaStoreUtils.isExternalTable(tso.getConf().getTableMetadata().getTTable());
+ aliasTypeMap.put(alias, isManagedTable);
+ allowedAliasesToPartitions.put(alias, getPathToPartitionMap(alias, tso));
tso.getConf().setIsMetadataOnly(true);
}
- // group path alias according to work
- Map<Path, List<String>> candidates = new HashMap<>();
+
for (Path path : work.getPaths()) {
- List<String> aliasesAffected = work.getPathToAliases().get(path);
- if (CollectionUtils.isNotEmpty(aliasesAffected)) {
- candidates.put(path, aliasesAffected);
+ List<String> aliases = work.getPathToAliases().get(path);
+ for (String alias: aliases) {
+ Map<Path, Partition> pathToPartitionMap = allowedAliasesToPartitions.get(alias);
+ if (pathToPartitionMap == null) {
+ continue;
+ }
+ addCandidatePath(candidatePathsToAliases, path, alias);
+ Partition partitionObject = pathToPartitionMap.get(path);
+ Map<String, String> partitionParameters = partitionObject != null ? partitionObject.getParameters() : null;
+ boolean isManagedTable = aliasTypeMap.get(alias);
+ if (isManagedTable && partitionParameters != null && StatsSetupConst.areBasicStatsUptoDate(partitionParameters)) {
+ long rwCount = Long.parseLong(partitionParameters.get(StatsSetupConst.ROW_COUNT));
+ if (rwCount == 0) {
+ managedEmptyPathMap.put(path, true);
+ } else {
+ managedEmptyPathMap.put(path, false);
+ }
+ }
+ }
+ }
+
+ for (Entry<Path, Collection<String>> entry : candidatePathsToAliases.entrySet()) {
Review comment:
Yes
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] rbalamohan commented on a change in pull request #1645: HIVE-24350: NullScanOptimizer can lookup emptiness info from stats fo…
Posted by GitBox <gi...@apache.org>.
rbalamohan commented on a change in pull request #1645:
URL: https://github.com/apache/hive/pull/1645#discussion_r520415139
##########
File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/physical/NullScanTaskDispatcher.java
##########
@@ -93,94 +91,109 @@ private String getAliasForTableScanOperator(MapWork work,
return null;
}
- private PartitionDesc changePartitionToMetadataOnly(PartitionDesc desc,
- Path path) {
- if (desc == null) {
- return null;
- }
- FileStatus[] filesFoundInPartitionDir = null;
+ private void lookupAndProcessPath(MapWork work, Path path,
+ Collection<String> aliasesToOptimize) {
try {
- filesFoundInPartitionDir = Utilities.listNonHiddenFileStatus(physicalContext.getConf(), path);
+ boolean isEmpty = Utilities.listNonHiddenFileStatus(physicalContext.getConf(), path).length == 0;
+ processPath(work, path, aliasesToOptimize, isEmpty);
} catch (IOException e) {
- LOG.error("Cannot determine if the table is empty", e);
- }
- if (!isMetadataOnlyAllowed(filesFoundInPartitionDir)) {
- return desc;
+ LOG.warn("Could not determine if path {} was empty." +
+ "Cannot use null scan optimization for this path.", path, e);
}
-
- boolean isEmpty = filesFoundInPartitionDir == null || filesFoundInPartitionDir.length == 0;
- desc.setInputFileFormatClass(isEmpty ? ZeroRowsInputFormat.class : OneNullRowInputFormat.class);
- desc.setOutputFileFormatClass(HiveIgnoreKeyTextOutputFormat.class);
- desc.getProperties().setProperty(serdeConstants.SERIALIZATION_LIB,
- NullStructSerDe.class.getName());
- return desc;
}
- private boolean isMetadataOnlyAllowed(FileStatus[] filesFoundInPartitionDir) {
- if (filesFoundInPartitionDir == null || filesFoundInPartitionDir.length == 0) {
- return true; // empty folders are safe to convert to metadata-only
- }
- for (FileStatus f : filesFoundInPartitionDir) {
- if (AcidUtils.isDeleteDelta(f.getPath())) {
- /*
- * as described in HIVE-23712, an acid partition is not a safe subject of metadata-only
- * optimization, because there is a chance that it contains no data but contains folders
- * (e.g: delta_0000002_0000002_0000, delete_delta_0000003_0000003_0000), without scanning
- * the underlying file contents, we cannot tell whether this partition contains data or not
- */
- return false;
- }
+ private void processPath(MapWork work, Path path, Collection<String> aliasesToOptimize,
+ boolean isEmpty) {
+ PartitionDesc partDesc = work.getPathToPartitionInfo().get(path).clone();
+ partDesc.setInputFileFormatClass(isEmpty ? ZeroRowsInputFormat.class : OneNullRowInputFormat.class);
+ partDesc.setOutputFileFormatClass(HiveIgnoreKeyTextOutputFormat.class);
+ partDesc.getProperties().setProperty(serdeConstants.SERIALIZATION_LIB,
+ NullStructSerDe.class.getName());
+ Path fakePath =
+ new Path(NullScanFileSystem.getBase() + partDesc.getTableName()
+ + "/part" + encode(partDesc.getPartSpec()));
+ StringInternUtils.internUriStringsInPath(fakePath);
+ work.addPathToPartitionInfo(fakePath, partDesc);
+ work.addPathToAlias(fakePath, new ArrayList<>(aliasesToOptimize));
+ Collection<String> aliasesContainingPath = work.getPathToAliases().get(path);
+ aliasesContainingPath.removeAll(aliasesToOptimize);
+ if (aliasesContainingPath.isEmpty()) {
+ work.removePathToAlias(path);
+ work.removePathToPartitionInfo(path);
}
- return true;
}
- private void processAlias(MapWork work, Path path,
- Collection<String> aliasesAffected, Set<String> aliases) {
- // the aliases that are allowed to map to a null scan.
- Collection<String> allowed = aliasesAffected.stream()
- .filter(a -> aliases.contains(a)).collect(Collectors.toList());
- if (!allowed.isEmpty()) {
- PartitionDesc partDesc = work.getPathToPartitionInfo().get(path).clone();
- PartitionDesc newPartition =
- changePartitionToMetadataOnly(partDesc, path);
- // Prefix partition with something to avoid it being a hidden file.
- Path fakePath =
- new Path(NullScanFileSystem.getBase() + newPartition.getTableName()
- + "/part" + encode(newPartition.getPartSpec()));
- StringInternUtils.internUriStringsInPath(fakePath);
- work.addPathToPartitionInfo(fakePath, newPartition);
- work.addPathToAlias(fakePath, new ArrayList<>(allowed));
- aliasesAffected.removeAll(allowed);
- if (aliasesAffected.isEmpty()) {
- work.removePathToAlias(path);
- work.removePathToPartitionInfo(path);
- }
- }
+ private void addCandidatePath(Map<Path, Collection<String>> aliasesForPath, Path path, String alias) {
+ Collection<String> aliases = aliasesForPath.computeIfAbsent(path, k -> new ArrayList<>());
+ aliases.add(alias);
}
- private void processAlias(MapWork work, Set<TableScanOperator> tableScans) {
- Set<String> aliases = new HashSet<>();
+ private void processTableScans(MapWork work, Set<TableScanOperator> tableScans) {
+ Map<Path, Boolean> managedEmptyPathMap = new HashMap<>();
+ Map<Path, Collection<String>> candidatePathsToAliases = new HashMap<>();
+ Map<String, Boolean> aliasTypeMap = new HashMap<>();
+ Map<String, Map<Path, Partition>> allowedAliasesToPartitions = new HashMap<>();
for (TableScanOperator tso : tableScans) {
// use LinkedHashMap<String, Operator<? extends OperatorDesc>>
// getAliasToWork() should not apply this for non-native table
if (tso.getConf().getTableMetadata().getStorageHandler() != null) {
continue;
}
String alias = getAliasForTableScanOperator(work, tso);
- aliases.add(alias);
+ boolean isManagedTable = !MetaStoreUtils.isExternalTable(tso.getConf().getTableMetadata().getTTable());
+ aliasTypeMap.put(alias, isManagedTable);
+ allowedAliasesToPartitions.put(alias, getPathToPartitionMap(alias, tso));
tso.getConf().setIsMetadataOnly(true);
}
- // group path alias according to work
- Map<Path, List<String>> candidates = new HashMap<>();
+
for (Path path : work.getPaths()) {
- List<String> aliasesAffected = work.getPathToAliases().get(path);
- if (CollectionUtils.isNotEmpty(aliasesAffected)) {
- candidates.put(path, aliasesAffected);
+ List<String> aliases = work.getPathToAliases().get(path);
+ for (String alias: aliases) {
+ Map<Path, Partition> pathToPartitionMap = allowedAliasesToPartitions.get(alias);
+ if (pathToPartitionMap == null) {
+ continue;
+ }
+ addCandidatePath(candidatePathsToAliases, path, alias);
+ Partition partitionObject = pathToPartitionMap.get(path);
+ Map<String, String> partitionParameters = partitionObject != null ? partitionObject.getParameters() : null;
+ boolean isManagedTable = aliasTypeMap.get(alias);
+ if (isManagedTable && partitionParameters != null && StatsSetupConst.areBasicStatsUptoDate(partitionParameters)) {
+ long rwCount = Long.parseLong(partitionParameters.get(StatsSetupConst.ROW_COUNT));
+ if (rwCount == 0) {
+ managedEmptyPathMap.put(path, true);
+ } else {
+ managedEmptyPathMap.put(path, false);
+ }
+ }
+ }
+ }
+
+ for (Entry<Path, Collection<String>> entry : candidatePathsToAliases.entrySet()) {
Review comment:
Wouldn't this have the same issue for external tables (e.g text?). For
##########
File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/physical/NullScanTaskDispatcher.java
##########
@@ -93,94 +91,109 @@ private String getAliasForTableScanOperator(MapWork work,
return null;
}
- private PartitionDesc changePartitionToMetadataOnly(PartitionDesc desc,
- Path path) {
- if (desc == null) {
- return null;
- }
- FileStatus[] filesFoundInPartitionDir = null;
+ private void lookupAndProcessPath(MapWork work, Path path,
+ Collection<String> aliasesToOptimize) {
try {
- filesFoundInPartitionDir = Utilities.listNonHiddenFileStatus(physicalContext.getConf(), path);
+ boolean isEmpty = Utilities.listNonHiddenFileStatus(physicalContext.getConf(), path).length == 0;
+ processPath(work, path, aliasesToOptimize, isEmpty);
} catch (IOException e) {
- LOG.error("Cannot determine if the table is empty", e);
- }
- if (!isMetadataOnlyAllowed(filesFoundInPartitionDir)) {
- return desc;
+ LOG.warn("Could not determine if path {} was empty." +
+ "Cannot use null scan optimization for this path.", path, e);
}
-
- boolean isEmpty = filesFoundInPartitionDir == null || filesFoundInPartitionDir.length == 0;
- desc.setInputFileFormatClass(isEmpty ? ZeroRowsInputFormat.class : OneNullRowInputFormat.class);
- desc.setOutputFileFormatClass(HiveIgnoreKeyTextOutputFormat.class);
- desc.getProperties().setProperty(serdeConstants.SERIALIZATION_LIB,
- NullStructSerDe.class.getName());
- return desc;
}
- private boolean isMetadataOnlyAllowed(FileStatus[] filesFoundInPartitionDir) {
- if (filesFoundInPartitionDir == null || filesFoundInPartitionDir.length == 0) {
- return true; // empty folders are safe to convert to metadata-only
- }
- for (FileStatus f : filesFoundInPartitionDir) {
- if (AcidUtils.isDeleteDelta(f.getPath())) {
- /*
- * as described in HIVE-23712, an acid partition is not a safe subject of metadata-only
- * optimization, because there is a chance that it contains no data but contains folders
- * (e.g: delta_0000002_0000002_0000, delete_delta_0000003_0000003_0000), without scanning
- * the underlying file contents, we cannot tell whether this partition contains data or not
- */
- return false;
- }
+ private void processPath(MapWork work, Path path, Collection<String> aliasesToOptimize,
+ boolean isEmpty) {
+ PartitionDesc partDesc = work.getPathToPartitionInfo().get(path).clone();
+ partDesc.setInputFileFormatClass(isEmpty ? ZeroRowsInputFormat.class : OneNullRowInputFormat.class);
+ partDesc.setOutputFileFormatClass(HiveIgnoreKeyTextOutputFormat.class);
+ partDesc.getProperties().setProperty(serdeConstants.SERIALIZATION_LIB,
+ NullStructSerDe.class.getName());
+ Path fakePath =
+ new Path(NullScanFileSystem.getBase() + partDesc.getTableName()
+ + "/part" + encode(partDesc.getPartSpec()));
+ StringInternUtils.internUriStringsInPath(fakePath);
+ work.addPathToPartitionInfo(fakePath, partDesc);
+ work.addPathToAlias(fakePath, new ArrayList<>(aliasesToOptimize));
+ Collection<String> aliasesContainingPath = work.getPathToAliases().get(path);
+ aliasesContainingPath.removeAll(aliasesToOptimize);
+ if (aliasesContainingPath.isEmpty()) {
+ work.removePathToAlias(path);
+ work.removePathToPartitionInfo(path);
}
- return true;
}
- private void processAlias(MapWork work, Path path,
- Collection<String> aliasesAffected, Set<String> aliases) {
- // the aliases that are allowed to map to a null scan.
- Collection<String> allowed = aliasesAffected.stream()
- .filter(a -> aliases.contains(a)).collect(Collectors.toList());
- if (!allowed.isEmpty()) {
- PartitionDesc partDesc = work.getPathToPartitionInfo().get(path).clone();
- PartitionDesc newPartition =
- changePartitionToMetadataOnly(partDesc, path);
- // Prefix partition with something to avoid it being a hidden file.
- Path fakePath =
- new Path(NullScanFileSystem.getBase() + newPartition.getTableName()
- + "/part" + encode(newPartition.getPartSpec()));
- StringInternUtils.internUriStringsInPath(fakePath);
- work.addPathToPartitionInfo(fakePath, newPartition);
- work.addPathToAlias(fakePath, new ArrayList<>(allowed));
- aliasesAffected.removeAll(allowed);
- if (aliasesAffected.isEmpty()) {
- work.removePathToAlias(path);
- work.removePathToPartitionInfo(path);
- }
- }
+ private void addCandidatePath(Map<Path, Collection<String>> aliasesForPath, Path path, String alias) {
+ Collection<String> aliases = aliasesForPath.computeIfAbsent(path, k -> new ArrayList<>());
+ aliases.add(alias);
}
- private void processAlias(MapWork work, Set<TableScanOperator> tableScans) {
- Set<String> aliases = new HashSet<>();
+ private void processTableScans(MapWork work, Set<TableScanOperator> tableScans) {
+ Map<Path, Boolean> managedEmptyPathMap = new HashMap<>();
+ Map<Path, Collection<String>> candidatePathsToAliases = new HashMap<>();
+ Map<String, Boolean> aliasTypeMap = new HashMap<>();
+ Map<String, Map<Path, Partition>> allowedAliasesToPartitions = new HashMap<>();
for (TableScanOperator tso : tableScans) {
// use LinkedHashMap<String, Operator<? extends OperatorDesc>>
// getAliasToWork() should not apply this for non-native table
if (tso.getConf().getTableMetadata().getStorageHandler() != null) {
continue;
}
String alias = getAliasForTableScanOperator(work, tso);
- aliases.add(alias);
+ boolean isManagedTable = !MetaStoreUtils.isExternalTable(tso.getConf().getTableMetadata().getTTable());
+ aliasTypeMap.put(alias, isManagedTable);
+ allowedAliasesToPartitions.put(alias, getPathToPartitionMap(alias, tso));
tso.getConf().setIsMetadataOnly(true);
}
- // group path alias according to work
- Map<Path, List<String>> candidates = new HashMap<>();
+
for (Path path : work.getPaths()) {
- List<String> aliasesAffected = work.getPathToAliases().get(path);
- if (CollectionUtils.isNotEmpty(aliasesAffected)) {
- candidates.put(path, aliasesAffected);
+ List<String> aliases = work.getPathToAliases().get(path);
+ for (String alias: aliases) {
+ Map<Path, Partition> pathToPartitionMap = allowedAliasesToPartitions.get(alias);
+ if (pathToPartitionMap == null) {
+ continue;
+ }
+ addCandidatePath(candidatePathsToAliases, path, alias);
Review comment:
Can be candidatePathsToAliases.computeIfAbsent(path, k -> new ArrayList<>()).add(alias) ?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] mustafaiman commented on a change in pull request #1645: HIVE-24350: NullScanOptimizer can lookup emptiness info from stats fo…
Posted by GitBox <gi...@apache.org>.
mustafaiman commented on a change in pull request #1645:
URL: https://github.com/apache/hive/pull/1645#discussion_r520745722
##########
File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/physical/NullScanTaskDispatcher.java
##########
@@ -93,94 +91,109 @@ private String getAliasForTableScanOperator(MapWork work,
return null;
}
- private PartitionDesc changePartitionToMetadataOnly(PartitionDesc desc,
- Path path) {
- if (desc == null) {
- return null;
- }
- FileStatus[] filesFoundInPartitionDir = null;
+ private void lookupAndProcessPath(MapWork work, Path path,
+ Collection<String> aliasesToOptimize) {
try {
- filesFoundInPartitionDir = Utilities.listNonHiddenFileStatus(physicalContext.getConf(), path);
+ boolean isEmpty = Utilities.listNonHiddenFileStatus(physicalContext.getConf(), path).length == 0;
+ processPath(work, path, aliasesToOptimize, isEmpty);
} catch (IOException e) {
- LOG.error("Cannot determine if the table is empty", e);
- }
- if (!isMetadataOnlyAllowed(filesFoundInPartitionDir)) {
- return desc;
+ LOG.warn("Could not determine if path {} was empty." +
+ "Cannot use null scan optimization for this path.", path, e);
}
-
- boolean isEmpty = filesFoundInPartitionDir == null || filesFoundInPartitionDir.length == 0;
- desc.setInputFileFormatClass(isEmpty ? ZeroRowsInputFormat.class : OneNullRowInputFormat.class);
- desc.setOutputFileFormatClass(HiveIgnoreKeyTextOutputFormat.class);
- desc.getProperties().setProperty(serdeConstants.SERIALIZATION_LIB,
- NullStructSerDe.class.getName());
- return desc;
}
- private boolean isMetadataOnlyAllowed(FileStatus[] filesFoundInPartitionDir) {
- if (filesFoundInPartitionDir == null || filesFoundInPartitionDir.length == 0) {
- return true; // empty folders are safe to convert to metadata-only
- }
- for (FileStatus f : filesFoundInPartitionDir) {
- if (AcidUtils.isDeleteDelta(f.getPath())) {
- /*
- * as described in HIVE-23712, an acid partition is not a safe subject of metadata-only
- * optimization, because there is a chance that it contains no data but contains folders
- * (e.g: delta_0000002_0000002_0000, delete_delta_0000003_0000003_0000), without scanning
- * the underlying file contents, we cannot tell whether this partition contains data or not
- */
- return false;
- }
+ private void processPath(MapWork work, Path path, Collection<String> aliasesToOptimize,
+ boolean isEmpty) {
+ PartitionDesc partDesc = work.getPathToPartitionInfo().get(path).clone();
+ partDesc.setInputFileFormatClass(isEmpty ? ZeroRowsInputFormat.class : OneNullRowInputFormat.class);
+ partDesc.setOutputFileFormatClass(HiveIgnoreKeyTextOutputFormat.class);
+ partDesc.getProperties().setProperty(serdeConstants.SERIALIZATION_LIB,
+ NullStructSerDe.class.getName());
+ Path fakePath =
+ new Path(NullScanFileSystem.getBase() + partDesc.getTableName()
+ + "/part" + encode(partDesc.getPartSpec()));
+ StringInternUtils.internUriStringsInPath(fakePath);
+ work.addPathToPartitionInfo(fakePath, partDesc);
+ work.addPathToAlias(fakePath, new ArrayList<>(aliasesToOptimize));
+ Collection<String> aliasesContainingPath = work.getPathToAliases().get(path);
+ aliasesContainingPath.removeAll(aliasesToOptimize);
+ if (aliasesContainingPath.isEmpty()) {
+ work.removePathToAlias(path);
+ work.removePathToPartitionInfo(path);
}
- return true;
}
- private void processAlias(MapWork work, Path path,
- Collection<String> aliasesAffected, Set<String> aliases) {
- // the aliases that are allowed to map to a null scan.
- Collection<String> allowed = aliasesAffected.stream()
- .filter(a -> aliases.contains(a)).collect(Collectors.toList());
- if (!allowed.isEmpty()) {
- PartitionDesc partDesc = work.getPathToPartitionInfo().get(path).clone();
- PartitionDesc newPartition =
- changePartitionToMetadataOnly(partDesc, path);
- // Prefix partition with something to avoid it being a hidden file.
- Path fakePath =
- new Path(NullScanFileSystem.getBase() + newPartition.getTableName()
- + "/part" + encode(newPartition.getPartSpec()));
- StringInternUtils.internUriStringsInPath(fakePath);
- work.addPathToPartitionInfo(fakePath, newPartition);
- work.addPathToAlias(fakePath, new ArrayList<>(allowed));
- aliasesAffected.removeAll(allowed);
- if (aliasesAffected.isEmpty()) {
- work.removePathToAlias(path);
- work.removePathToPartitionInfo(path);
- }
- }
+ private void addCandidatePath(Map<Path, Collection<String>> aliasesForPath, Path path, String alias) {
+ Collection<String> aliases = aliasesForPath.computeIfAbsent(path, k -> new ArrayList<>());
+ aliases.add(alias);
}
- private void processAlias(MapWork work, Set<TableScanOperator> tableScans) {
- Set<String> aliases = new HashSet<>();
+ private void processTableScans(MapWork work, Set<TableScanOperator> tableScans) {
+ Map<Path, Boolean> managedEmptyPathMap = new HashMap<>();
+ Map<Path, Collection<String>> candidatePathsToAliases = new HashMap<>();
+ Map<String, Boolean> aliasTypeMap = new HashMap<>();
+ Map<String, Map<Path, Partition>> allowedAliasesToPartitions = new HashMap<>();
for (TableScanOperator tso : tableScans) {
// use LinkedHashMap<String, Operator<? extends OperatorDesc>>
// getAliasToWork() should not apply this for non-native table
if (tso.getConf().getTableMetadata().getStorageHandler() != null) {
continue;
}
String alias = getAliasForTableScanOperator(work, tso);
- aliases.add(alias);
+ boolean isManagedTable = !MetaStoreUtils.isExternalTable(tso.getConf().getTableMetadata().getTTable());
+ aliasTypeMap.put(alias, isManagedTable);
+ allowedAliasesToPartitions.put(alias, getPathToPartitionMap(alias, tso));
tso.getConf().setIsMetadataOnly(true);
}
- // group path alias according to work
- Map<Path, List<String>> candidates = new HashMap<>();
+
for (Path path : work.getPaths()) {
- List<String> aliasesAffected = work.getPathToAliases().get(path);
- if (CollectionUtils.isNotEmpty(aliasesAffected)) {
- candidates.put(path, aliasesAffected);
+ List<String> aliases = work.getPathToAliases().get(path);
+ for (String alias: aliases) {
+ Map<Path, Partition> pathToPartitionMap = allowedAliasesToPartitions.get(alias);
+ if (pathToPartitionMap == null) {
+ continue;
+ }
+ addCandidatePath(candidatePathsToAliases, path, alias);
Review comment:
makes sense
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] mustafaiman closed pull request #1645: HIVE-24350: NullScanOptimizer can lookup emptiness info from stats fo…
Posted by GitBox <gi...@apache.org>.
mustafaiman closed pull request #1645:
URL: https://github.com/apache/hive/pull/1645
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] mustafaiman commented on a change in pull request #1645: HIVE-24350: NullScanOptimizer can lookup emptiness info from stats fo…
Posted by GitBox <gi...@apache.org>.
mustafaiman commented on a change in pull request #1645:
URL: https://github.com/apache/hive/pull/1645#discussion_r520745049
##########
File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/physical/NullScanTaskDispatcher.java
##########
@@ -93,94 +91,109 @@ private String getAliasForTableScanOperator(MapWork work,
return null;
}
- private PartitionDesc changePartitionToMetadataOnly(PartitionDesc desc,
- Path path) {
- if (desc == null) {
- return null;
- }
- FileStatus[] filesFoundInPartitionDir = null;
+ private void lookupAndProcessPath(MapWork work, Path path,
+ Collection<String> aliasesToOptimize) {
try {
- filesFoundInPartitionDir = Utilities.listNonHiddenFileStatus(physicalContext.getConf(), path);
+ boolean isEmpty = Utilities.listNonHiddenFileStatus(physicalContext.getConf(), path).length == 0;
+ processPath(work, path, aliasesToOptimize, isEmpty);
} catch (IOException e) {
- LOG.error("Cannot determine if the table is empty", e);
- }
- if (!isMetadataOnlyAllowed(filesFoundInPartitionDir)) {
- return desc;
+ LOG.warn("Could not determine if path {} was empty." +
+ "Cannot use null scan optimization for this path.", path, e);
}
-
- boolean isEmpty = filesFoundInPartitionDir == null || filesFoundInPartitionDir.length == 0;
- desc.setInputFileFormatClass(isEmpty ? ZeroRowsInputFormat.class : OneNullRowInputFormat.class);
- desc.setOutputFileFormatClass(HiveIgnoreKeyTextOutputFormat.class);
- desc.getProperties().setProperty(serdeConstants.SERIALIZATION_LIB,
- NullStructSerDe.class.getName());
- return desc;
}
- private boolean isMetadataOnlyAllowed(FileStatus[] filesFoundInPartitionDir) {
- if (filesFoundInPartitionDir == null || filesFoundInPartitionDir.length == 0) {
- return true; // empty folders are safe to convert to metadata-only
- }
- for (FileStatus f : filesFoundInPartitionDir) {
- if (AcidUtils.isDeleteDelta(f.getPath())) {
- /*
- * as described in HIVE-23712, an acid partition is not a safe subject of metadata-only
- * optimization, because there is a chance that it contains no data but contains folders
- * (e.g: delta_0000002_0000002_0000, delete_delta_0000003_0000003_0000), without scanning
- * the underlying file contents, we cannot tell whether this partition contains data or not
- */
- return false;
- }
+ private void processPath(MapWork work, Path path, Collection<String> aliasesToOptimize,
+ boolean isEmpty) {
+ PartitionDesc partDesc = work.getPathToPartitionInfo().get(path).clone();
+ partDesc.setInputFileFormatClass(isEmpty ? ZeroRowsInputFormat.class : OneNullRowInputFormat.class);
+ partDesc.setOutputFileFormatClass(HiveIgnoreKeyTextOutputFormat.class);
+ partDesc.getProperties().setProperty(serdeConstants.SERIALIZATION_LIB,
+ NullStructSerDe.class.getName());
+ Path fakePath =
+ new Path(NullScanFileSystem.getBase() + partDesc.getTableName()
+ + "/part" + encode(partDesc.getPartSpec()));
+ StringInternUtils.internUriStringsInPath(fakePath);
+ work.addPathToPartitionInfo(fakePath, partDesc);
+ work.addPathToAlias(fakePath, new ArrayList<>(aliasesToOptimize));
+ Collection<String> aliasesContainingPath = work.getPathToAliases().get(path);
+ aliasesContainingPath.removeAll(aliasesToOptimize);
+ if (aliasesContainingPath.isEmpty()) {
+ work.removePathToAlias(path);
+ work.removePathToPartitionInfo(path);
}
- return true;
}
- private void processAlias(MapWork work, Path path,
- Collection<String> aliasesAffected, Set<String> aliases) {
- // the aliases that are allowed to map to a null scan.
- Collection<String> allowed = aliasesAffected.stream()
- .filter(a -> aliases.contains(a)).collect(Collectors.toList());
- if (!allowed.isEmpty()) {
- PartitionDesc partDesc = work.getPathToPartitionInfo().get(path).clone();
- PartitionDesc newPartition =
- changePartitionToMetadataOnly(partDesc, path);
- // Prefix partition with something to avoid it being a hidden file.
- Path fakePath =
- new Path(NullScanFileSystem.getBase() + newPartition.getTableName()
- + "/part" + encode(newPartition.getPartSpec()));
- StringInternUtils.internUriStringsInPath(fakePath);
- work.addPathToPartitionInfo(fakePath, newPartition);
- work.addPathToAlias(fakePath, new ArrayList<>(allowed));
- aliasesAffected.removeAll(allowed);
- if (aliasesAffected.isEmpty()) {
- work.removePathToAlias(path);
- work.removePathToPartitionInfo(path);
- }
- }
+ private void addCandidatePath(Map<Path, Collection<String>> aliasesForPath, Path path, String alias) {
+ Collection<String> aliases = aliasesForPath.computeIfAbsent(path, k -> new ArrayList<>());
+ aliases.add(alias);
}
- private void processAlias(MapWork work, Set<TableScanOperator> tableScans) {
- Set<String> aliases = new HashSet<>();
+ private void processTableScans(MapWork work, Set<TableScanOperator> tableScans) {
+ Map<Path, Boolean> managedEmptyPathMap = new HashMap<>();
+ Map<Path, Collection<String>> candidatePathsToAliases = new HashMap<>();
+ Map<String, Boolean> aliasTypeMap = new HashMap<>();
+ Map<String, Map<Path, Partition>> allowedAliasesToPartitions = new HashMap<>();
for (TableScanOperator tso : tableScans) {
// use LinkedHashMap<String, Operator<? extends OperatorDesc>>
// getAliasToWork() should not apply this for non-native table
if (tso.getConf().getTableMetadata().getStorageHandler() != null) {
continue;
}
String alias = getAliasForTableScanOperator(work, tso);
- aliases.add(alias);
+ boolean isManagedTable = !MetaStoreUtils.isExternalTable(tso.getConf().getTableMetadata().getTTable());
+ aliasTypeMap.put(alias, isManagedTable);
+ allowedAliasesToPartitions.put(alias, getPathToPartitionMap(alias, tso));
tso.getConf().setIsMetadataOnly(true);
}
- // group path alias according to work
- Map<Path, List<String>> candidates = new HashMap<>();
+
for (Path path : work.getPaths()) {
- List<String> aliasesAffected = work.getPathToAliases().get(path);
- if (CollectionUtils.isNotEmpty(aliasesAffected)) {
- candidates.put(path, aliasesAffected);
+ List<String> aliases = work.getPathToAliases().get(path);
+ for (String alias: aliases) {
+ Map<Path, Partition> pathToPartitionMap = allowedAliasesToPartitions.get(alias);
+ if (pathToPartitionMap == null) {
+ continue;
+ }
+ addCandidatePath(candidatePathsToAliases, path, alias);
+ Partition partitionObject = pathToPartitionMap.get(path);
+ Map<String, String> partitionParameters = partitionObject != null ? partitionObject.getParameters() : null;
+ boolean isManagedTable = aliasTypeMap.get(alias);
+ if (isManagedTable && partitionParameters != null && StatsSetupConst.areBasicStatsUptoDate(partitionParameters)) {
+ long rwCount = Long.parseLong(partitionParameters.get(StatsSetupConst.ROW_COUNT));
+ if (rwCount == 0) {
+ managedEmptyPathMap.put(path, true);
+ } else {
+ managedEmptyPathMap.put(path, false);
+ }
+ }
+ }
+ }
+
+ for (Entry<Path, Collection<String>> entry : candidatePathsToAliases.entrySet()) {
Review comment:
Are you referring to performance issue? Yes this PR does not change anything for external tables. We cannot rely on statistics for external tables. I have another patch ready (need to test first) that deals with external tables. We'll run listStatus calls in parallel for external tables.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org
[GitHub] [hive] rbalamohan commented on a change in pull request #1645: HIVE-24350: NullScanOptimizer can lookup emptiness info from stats fo…
Posted by GitBox <gi...@apache.org>.
rbalamohan commented on a change in pull request #1645:
URL: https://github.com/apache/hive/pull/1645#discussion_r522558601
##########
File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/physical/NullScanTaskDispatcher.java
##########
@@ -93,94 +91,109 @@ private String getAliasForTableScanOperator(MapWork work,
return null;
}
- private PartitionDesc changePartitionToMetadataOnly(PartitionDesc desc,
- Path path) {
- if (desc == null) {
- return null;
- }
- FileStatus[] filesFoundInPartitionDir = null;
+ private void lookupAndProcessPath(MapWork work, Path path,
+ Collection<String> aliasesToOptimize) {
try {
- filesFoundInPartitionDir = Utilities.listNonHiddenFileStatus(physicalContext.getConf(), path);
+ boolean isEmpty = Utilities.listNonHiddenFileStatus(physicalContext.getConf(), path).length == 0;
+ processPath(work, path, aliasesToOptimize, isEmpty);
} catch (IOException e) {
- LOG.error("Cannot determine if the table is empty", e);
- }
- if (!isMetadataOnlyAllowed(filesFoundInPartitionDir)) {
- return desc;
+ LOG.warn("Could not determine if path {} was empty." +
+ "Cannot use null scan optimization for this path.", path, e);
}
-
- boolean isEmpty = filesFoundInPartitionDir == null || filesFoundInPartitionDir.length == 0;
- desc.setInputFileFormatClass(isEmpty ? ZeroRowsInputFormat.class : OneNullRowInputFormat.class);
- desc.setOutputFileFormatClass(HiveIgnoreKeyTextOutputFormat.class);
- desc.getProperties().setProperty(serdeConstants.SERIALIZATION_LIB,
- NullStructSerDe.class.getName());
- return desc;
}
- private boolean isMetadataOnlyAllowed(FileStatus[] filesFoundInPartitionDir) {
- if (filesFoundInPartitionDir == null || filesFoundInPartitionDir.length == 0) {
- return true; // empty folders are safe to convert to metadata-only
- }
- for (FileStatus f : filesFoundInPartitionDir) {
- if (AcidUtils.isDeleteDelta(f.getPath())) {
- /*
- * as described in HIVE-23712, an acid partition is not a safe subject of metadata-only
- * optimization, because there is a chance that it contains no data but contains folders
- * (e.g: delta_0000002_0000002_0000, delete_delta_0000003_0000003_0000), without scanning
- * the underlying file contents, we cannot tell whether this partition contains data or not
- */
- return false;
- }
+ private void processPath(MapWork work, Path path, Collection<String> aliasesToOptimize,
+ boolean isEmpty) {
+ PartitionDesc partDesc = work.getPathToPartitionInfo().get(path).clone();
+ partDesc.setInputFileFormatClass(isEmpty ? ZeroRowsInputFormat.class : OneNullRowInputFormat.class);
+ partDesc.setOutputFileFormatClass(HiveIgnoreKeyTextOutputFormat.class);
+ partDesc.getProperties().setProperty(serdeConstants.SERIALIZATION_LIB,
+ NullStructSerDe.class.getName());
+ Path fakePath =
+ new Path(NullScanFileSystem.getBase() + partDesc.getTableName()
+ + "/part" + encode(partDesc.getPartSpec()));
+ StringInternUtils.internUriStringsInPath(fakePath);
+ work.addPathToPartitionInfo(fakePath, partDesc);
+ work.addPathToAlias(fakePath, new ArrayList<>(aliasesToOptimize));
+ Collection<String> aliasesContainingPath = work.getPathToAliases().get(path);
+ aliasesContainingPath.removeAll(aliasesToOptimize);
+ if (aliasesContainingPath.isEmpty()) {
+ work.removePathToAlias(path);
+ work.removePathToPartitionInfo(path);
}
- return true;
}
- private void processAlias(MapWork work, Path path,
- Collection<String> aliasesAffected, Set<String> aliases) {
- // the aliases that are allowed to map to a null scan.
- Collection<String> allowed = aliasesAffected.stream()
- .filter(a -> aliases.contains(a)).collect(Collectors.toList());
- if (!allowed.isEmpty()) {
- PartitionDesc partDesc = work.getPathToPartitionInfo().get(path).clone();
- PartitionDesc newPartition =
- changePartitionToMetadataOnly(partDesc, path);
- // Prefix partition with something to avoid it being a hidden file.
- Path fakePath =
- new Path(NullScanFileSystem.getBase() + newPartition.getTableName()
- + "/part" + encode(newPartition.getPartSpec()));
- StringInternUtils.internUriStringsInPath(fakePath);
- work.addPathToPartitionInfo(fakePath, newPartition);
- work.addPathToAlias(fakePath, new ArrayList<>(allowed));
- aliasesAffected.removeAll(allowed);
- if (aliasesAffected.isEmpty()) {
- work.removePathToAlias(path);
- work.removePathToPartitionInfo(path);
- }
- }
+ private void addCandidatePath(Map<Path, Collection<String>> aliasesForPath, Path path, String alias) {
+ Collection<String> aliases = aliasesForPath.computeIfAbsent(path, k -> new ArrayList<>());
+ aliases.add(alias);
}
- private void processAlias(MapWork work, Set<TableScanOperator> tableScans) {
- Set<String> aliases = new HashSet<>();
+ private void processTableScans(MapWork work, Set<TableScanOperator> tableScans) {
+ Map<Path, Boolean> managedEmptyPathMap = new HashMap<>();
+ Map<Path, Collection<String>> candidatePathsToAliases = new HashMap<>();
+ Map<String, Boolean> aliasTypeMap = new HashMap<>();
+ Map<String, Map<Path, Partition>> allowedAliasesToPartitions = new HashMap<>();
for (TableScanOperator tso : tableScans) {
// use LinkedHashMap<String, Operator<? extends OperatorDesc>>
// getAliasToWork() should not apply this for non-native table
if (tso.getConf().getTableMetadata().getStorageHandler() != null) {
continue;
}
String alias = getAliasForTableScanOperator(work, tso);
- aliases.add(alias);
+ boolean isManagedTable = !MetaStoreUtils.isExternalTable(tso.getConf().getTableMetadata().getTTable());
+ aliasTypeMap.put(alias, isManagedTable);
+ allowedAliasesToPartitions.put(alias, getPathToPartitionMap(alias, tso));
tso.getConf().setIsMetadataOnly(true);
}
- // group path alias according to work
- Map<Path, List<String>> candidates = new HashMap<>();
+
for (Path path : work.getPaths()) {
- List<String> aliasesAffected = work.getPathToAliases().get(path);
- if (CollectionUtils.isNotEmpty(aliasesAffected)) {
- candidates.put(path, aliasesAffected);
+ List<String> aliases = work.getPathToAliases().get(path);
+ for (String alias: aliases) {
+ Map<Path, Partition> pathToPartitionMap = allowedAliasesToPartitions.get(alias);
+ if (pathToPartitionMap == null) {
+ continue;
+ }
+ addCandidatePath(candidatePathsToAliases, path, alias);
+ Partition partitionObject = pathToPartitionMap.get(path);
+ Map<String, String> partitionParameters = partitionObject != null ? partitionObject.getParameters() : null;
+ boolean isManagedTable = aliasTypeMap.get(alias);
+ if (isManagedTable && partitionParameters != null && StatsSetupConst.areBasicStatsUptoDate(partitionParameters)) {
+ long rwCount = Long.parseLong(partitionParameters.get(StatsSetupConst.ROW_COUNT));
+ if (rwCount == 0) {
+ managedEmptyPathMap.put(path, true);
+ } else {
+ managedEmptyPathMap.put(path, false);
+ }
+ }
+ }
+ }
+
+ for (Entry<Path, Collection<String>> entry : candidatePathsToAliases.entrySet()) {
Review comment:
Thanks for sharing the details. HIVE-24380 is what you are referring to I believe.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org