-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ANALYZE statement: Implement ANALYZE in Hive connector
- Loading branch information
1 parent
70add48
commit b7079d3
Showing
15 changed files
with
1,268 additions
and
35 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
presto-hive/src/main/java/com/facebook/presto/hive/HiveAnalyzeProperties.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,89 @@ | ||
/* | ||
* Licensed 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 com.facebook.presto.hive; | ||
|
||
import com.facebook.presto.spi.PrestoException; | ||
import com.facebook.presto.spi.session.PropertyMetadata; | ||
import com.facebook.presto.spi.type.TypeManager; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import javax.inject.Inject; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import static com.facebook.presto.hive.HivePartitionKey.HIVE_DEFAULT_DYNAMIC_PARTITION; | ||
import static com.facebook.presto.spi.StandardErrorCode.INVALID_ANALYZE_PROPERTY; | ||
import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature; | ||
import static com.google.common.base.MoreObjects.firstNonNull; | ||
import static com.google.common.collect.ImmutableList.toImmutableList; | ||
import static com.google.common.collect.ImmutableSet.toImmutableSet; | ||
|
||
public class HiveAnalyzeProperties | ||
{ | ||
public static final String PARTITIONS_PROPERTY = "partitions"; | ||
|
||
private final List<PropertyMetadata<?>> analyzeProperties; | ||
|
||
@Inject | ||
public HiveAnalyzeProperties(TypeManager typeManager) | ||
{ | ||
analyzeProperties = ImmutableList.of( | ||
new PropertyMetadata<>( | ||
PARTITIONS_PROPERTY, | ||
"Partitions to be analyzed", | ||
typeManager.getType(parseTypeSignature("array(array(varchar))")), | ||
List.class, | ||
null, | ||
false, | ||
HiveAnalyzeProperties::decodePartitionLists, | ||
value -> value)); | ||
} | ||
|
||
public List<PropertyMetadata<?>> getAnalyzeProperties() | ||
{ | ||
return analyzeProperties; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static Optional<List<List<String>>> getPartitionList(Map<String, Object> properties) | ||
{ | ||
List<List<String>> partitions = (List<List<String>>) properties.get(PARTITIONS_PROPERTY); | ||
return partitions == null ? Optional.empty() : Optional.of(partitions); | ||
} | ||
|
||
private static List<List<String>> decodePartitionLists(Object object) | ||
{ | ||
if (object == null) { | ||
return null; | ||
} | ||
|
||
// replace null partition value with hive default partition | ||
return ImmutableList.copyOf(((Collection<?>) object).stream() | ||
.peek(HiveAnalyzeProperties::throwIfNull) | ||
.map(partition -> ((Collection<?>) partition).stream() | ||
.map(name -> firstNonNull((String) name, HIVE_DEFAULT_DYNAMIC_PARTITION)) | ||
.collect(toImmutableList())) | ||
.collect(toImmutableSet())); | ||
} | ||
|
||
private static void throwIfNull(Object object) | ||
{ | ||
if (object == null) { | ||
throw new PrestoException(INVALID_ANALYZE_PROPERTY, "Invalid null value in analyze partitions property"); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.