Search in sources :

Example 1 with IcebergFilterGenerator

use of com.netflix.metacat.connector.hive.util.IcebergFilterGenerator in project metacat by Netflix.

the class IcebergTableHandler method getIcebergTablePartitionMap.

/**
 * get Partition Map.
 *
 * @param tableName         Qualified table name
 * @param partitionsRequest partitionsRequest
 * @param icebergTable      iceberg Table
 * @return partition map
 */
public Map<String, ScanSummary.PartitionMetrics> getIcebergTablePartitionMap(final QualifiedName tableName, final PartitionListRequest partitionsRequest, final Table icebergTable) {
    final long start = this.registry.clock().wallTime();
    final Map<String, ScanSummary.PartitionMetrics> result;
    try {
        if (!Strings.isNullOrEmpty(partitionsRequest.getFilter())) {
            final IcebergFilterGenerator icebergFilterGenerator = new IcebergFilterGenerator(icebergTable.schema().columns());
            final Expression filter = (Expression) new PartitionParser(new StringReader(partitionsRequest.getFilter())).filter().jjtAccept(icebergFilterGenerator, null);
            result = this.icebergTableOpWrapper.getPartitionMetricsMap(icebergTable, filter);
        } else {
            result = this.icebergTableOpWrapper.getPartitionMetricsMap(icebergTable, null);
        }
    } catch (ParseException ex) {
        log.error("Iceberg filter parse error: ", ex);
        throw new IllegalArgumentException(String.format("Iceberg filter parse error. Ex: %s", ex.getMessage()));
    } catch (IllegalStateException e) {
        registry.counter(registry.createId(IcebergRequestMetrics.CounterGetPartitionsExceedThresholdFailure.getMetricName()).withTags(tableName.parts())).increment();
        final String message = String.format("Number of partitions queried for table %s exceeded the threshold %d", tableName, connectorContext.getConfig().getMaxPartitionsThreshold());
        log.warn(message);
        throw new IllegalArgumentException(message);
    } finally {
        final long duration = registry.clock().wallTime() - start;
        log.info("Time taken to getIcebergTablePartitionMap {} is {} ms", tableName, duration);
        this.recordTimer(IcebergRequestMetrics.TagGetPartitionMap.getMetricName(), duration);
        this.increaseCounter(IcebergRequestMetrics.TagGetPartitionMap.getMetricName(), tableName);
    }
    return result;
}
Also used : PartitionParser(com.netflix.metacat.common.server.partition.parser.PartitionParser) Expression(org.apache.iceberg.expressions.Expression) StringReader(java.io.StringReader) ParseException(com.netflix.metacat.common.server.partition.parser.ParseException) IcebergFilterGenerator(com.netflix.metacat.connector.hive.util.IcebergFilterGenerator)

Aggregations

ParseException (com.netflix.metacat.common.server.partition.parser.ParseException)1 PartitionParser (com.netflix.metacat.common.server.partition.parser.PartitionParser)1 IcebergFilterGenerator (com.netflix.metacat.connector.hive.util.IcebergFilterGenerator)1 StringReader (java.io.StringReader)1 Expression (org.apache.iceberg.expressions.Expression)1