14
14
package com .facebook .presto .iceberg ;
15
15
16
16
import com .facebook .airlift .json .JsonCodec ;
17
- import com .facebook .presto .common .predicate .TupleDomain ;
18
17
import com .facebook .presto .common .type .Type ;
19
18
import com .facebook .presto .common .type .TypeManager ;
20
19
import com .facebook .presto .hive .HdfsContext ;
51
50
import com .facebook .presto .spi .ViewNotFoundException ;
52
51
import com .facebook .presto .spi .function .StandardFunctionResolution ;
53
52
import com .facebook .presto .spi .plan .FilterStatsCalculatorService ;
54
- import com .facebook .presto .spi .relation .RowExpression ;
55
53
import com .facebook .presto .spi .relation .RowExpressionService ;
56
- import com .facebook .presto .spi .relation .VariableReferenceExpression ;
57
54
import com .facebook .presto .spi .security .PrestoPrincipal ;
58
55
import com .facebook .presto .spi .statistics .ColumnStatisticMetadata ;
59
56
import com .facebook .presto .spi .statistics .ColumnStatisticType ;
60
- import com .facebook .presto .spi .statistics .ColumnStatistics ;
61
57
import com .facebook .presto .spi .statistics .ComputedStatistics ;
62
58
import com .facebook .presto .spi .statistics .TableStatisticType ;
63
59
import com .facebook .presto .spi .statistics .TableStatistics ;
126
122
import static com .facebook .presto .iceberg .PartitionFields .parsePartitionFields ;
127
123
import static com .facebook .presto .iceberg .PartitionSpecConverter .toPrestoPartitionSpec ;
128
124
import static com .facebook .presto .iceberg .SchemaConverter .toPrestoSchema ;
129
- import static com .facebook .presto .iceberg .util .StatisticsUtil .calculateAndSetTableSize ;
125
+ import static com .facebook .presto .iceberg .util .StatisticsUtil .calculateBaseTableStatistics ;
126
+ import static com .facebook .presto .iceberg .util .StatisticsUtil .calculateStatisticsConsideringLayout ;
130
127
import static com .facebook .presto .iceberg .util .StatisticsUtil .mergeHiveStatistics ;
131
128
import static com .facebook .presto .spi .StandardErrorCode .INVALID_SCHEMA_PROPERTY ;
132
129
import static com .facebook .presto .spi .StandardErrorCode .NOT_SUPPORTED ;
133
130
import static com .facebook .presto .spi .StandardErrorCode .SCHEMA_NOT_EMPTY ;
134
131
import static com .facebook .presto .spi .security .PrincipalType .USER ;
135
- import static com .facebook .presto .spi .statistics .SourceInfo .ConfidenceLevel .LOW ;
136
132
import static com .facebook .presto .spi .statistics .TableStatisticType .ROW_COUNT ;
137
133
import static com .google .common .base .Verify .verify ;
138
134
import static com .google .common .collect .ImmutableList .toImmutableList ;
141
137
import static java .util .Collections .emptyList ;
142
138
import static java .util .Locale .ENGLISH ;
143
139
import static java .util .Objects .requireNonNull ;
144
- import static java .util .function .Function .identity ;
145
140
import static org .apache .iceberg .TableMetadata .newTableMetadata ;
146
141
import static org .apache .iceberg .TableProperties .OBJECT_STORE_PATH ;
147
142
import static org .apache .iceberg .TableProperties .WRITE_DATA_LOCATION ;
@@ -154,7 +149,6 @@ public class IcebergHiveMetadata
154
149
private final ExtendedHiveMetastore metastore ;
155
150
private final HdfsEnvironment hdfsEnvironment ;
156
151
private final DateTimeZone timeZone = DateTimeZone .forTimeZone (TimeZone .getTimeZone (ZoneId .of (TimeZone .getDefault ().getID ())));
157
- private final FilterStatsCalculatorService filterStatsCalculatorService ;
158
152
private final IcebergHiveTableOperationsConfig hiveTableOeprationsConfig ;
159
153
160
154
public IcebergHiveMetadata (
@@ -168,10 +162,9 @@ public IcebergHiveMetadata(
168
162
FilterStatsCalculatorService filterStatsCalculatorService ,
169
163
IcebergHiveTableOperationsConfig hiveTableOeprationsConfig )
170
164
{
171
- super (typeManager , functionResolution , rowExpressionService , commitTaskCodec , nodeVersion );
165
+ super (typeManager , functionResolution , rowExpressionService , commitTaskCodec , nodeVersion , filterStatsCalculatorService );
172
166
this .metastore = requireNonNull (metastore , "metastore is null" );
173
167
this .hdfsEnvironment = requireNonNull (hdfsEnvironment , "hdfsEnvironment is null" );
174
- this .filterStatsCalculatorService = requireNonNull (filterStatsCalculatorService , "filterStatsCalculatorService is null" );
175
168
this .hiveTableOeprationsConfig = requireNonNull (hiveTableOeprationsConfig , "hiveTableOperationsConfig is null" );
176
169
}
177
170
@@ -455,48 +448,16 @@ public TableStatistics getTableStatistics(ConnectorSession session, ConnectorTab
455
448
{
456
449
IcebergTableHandle handle = (IcebergTableHandle ) tableHandle ;
457
450
org .apache .iceberg .Table icebergTable = getIcebergTable (session , handle .getSchemaTableName ());
458
- TableStatistics icebergStatistics = super . getTableStatistics ( session , tableHandle , tableLayoutHandle , columnHandles , constraint );
451
+ TableStatistics icebergStatistics = calculateBaseTableStatistics ( this , typeManager , session , ( IcebergTableHandle ) tableHandle , tableLayoutHandle , columnHandles , constraint );
459
452
EnumSet <ColumnStatisticType > mergeFlags = getHiveStatisticsMergeStrategy (session );
460
- return tableLayoutHandle .map (IcebergTableLayoutHandle .class ::cast ).map (layoutHandle -> {
461
- TupleDomain <VariableReferenceExpression > predicate = layoutHandle .getValidPredicate ()
462
- .transform (columnHandle -> new VariableReferenceExpression (Optional .empty (), columnHandle .getName (), columnHandle .getType ()));
463
- RowExpression translatedPredicate = rowExpressionService .getDomainTranslator ().toPredicate (predicate );
464
- TableStatistics mergedStatistics = Optional .of (mergeFlags )
465
- .filter (set -> !set .isEmpty ())
466
- .map (flags -> {
467
- PartitionStatistics hiveStatistics = metastore .getTableStatistics (getMetastoreContext (session ), handle .getSchemaName (), handle .getIcebergTableName ().getTableName ());
468
- return mergeHiveStatistics (icebergStatistics , hiveStatistics , mergeFlags , icebergTable .spec ());
469
- })
470
- .orElse (icebergStatistics );
471
- TableStatistics .Builder filteredStatsBuilder = TableStatistics .builder ()
472
- .setRowCount (mergedStatistics .getRowCount ());
473
- Set <ColumnHandle > fullColumnSet = icebergStatistics .getColumnStatistics ().keySet ();
474
- for (ColumnHandle colHandle : fullColumnSet ) {
475
- IcebergColumnHandle icebergHandle = (IcebergColumnHandle ) colHandle ;
476
- if (mergedStatistics .getColumnStatistics ().containsKey (icebergHandle )) {
477
- ColumnStatistics stats = mergedStatistics .getColumnStatistics ().get (icebergHandle );
478
- filteredStatsBuilder .setColumnStatistics (icebergHandle , stats );
479
- }
480
- }
481
- return filterStatsCalculatorService .filterStats (
482
- calculateAndSetTableSize (filteredStatsBuilder ).setConfidenceLevel (LOW ).build (),
483
- translatedPredicate ,
484
- session ,
485
- fullColumnSet .stream ()
486
- .map (IcebergColumnHandle .class ::cast ).collect (toImmutableMap (
487
- identity (),
488
- IcebergColumnHandle ::getName )),
489
- fullColumnSet
490
- .stream ().map (IcebergColumnHandle .class ::cast ).collect (toImmutableMap (
491
- IcebergColumnHandle ::getName ,
492
- IcebergColumnHandle ::getType )));
493
- }).orElseGet (() -> {
494
- if (!mergeFlags .isEmpty ()) {
495
- PartitionStatistics hiveStats = metastore .getTableStatistics (getMetastoreContext (session ), handle .getSchemaName (), handle .getIcebergTableName ().getTableName ());
496
- return mergeHiveStatistics (icebergStatistics , hiveStats , mergeFlags , icebergTable .spec ());
497
- }
498
- return icebergStatistics ;
499
- });
453
+ TableStatistics mergedStatistics = Optional .of (mergeFlags )
454
+ .filter (set -> !set .isEmpty ())
455
+ .map (flags -> {
456
+ PartitionStatistics hiveStatistics = metastore .getTableStatistics (getMetastoreContext (session ), handle .getSchemaName (), handle .getIcebergTableName ().getTableName ());
457
+ return mergeHiveStatistics (icebergStatistics , hiveStatistics , mergeFlags , icebergTable .spec ());
458
+ })
459
+ .orElse (icebergStatistics );
460
+ return calculateStatisticsConsideringLayout (filterStatsCalculatorService , rowExpressionService , mergedStatistics , session , tableLayoutHandle );
500
461
}
501
462
502
463
@ Override
0 commit comments