|
33 | 33 | import io.trino.metadata.QualifiedObjectName; |
34 | 34 | import io.trino.metadata.TableHandle; |
35 | 35 | import io.trino.operator.OperatorStats; |
| 36 | +import io.trino.plugin.base.metrics.DistributionSnapshot; |
| 37 | +import io.trino.plugin.base.metrics.LongCount; |
36 | 38 | import io.trino.plugin.hive.HiveCompressionCodec; |
37 | 39 | import io.trino.plugin.hive.TestingHivePlugin; |
38 | 40 | import io.trino.server.DynamicFilterService; |
|
42 | 44 | import io.trino.spi.connector.ConstraintApplicationResult; |
43 | 45 | import io.trino.spi.connector.SchemaTableName; |
44 | 46 | import io.trino.spi.connector.TableNotFoundException; |
| 47 | +import io.trino.spi.metrics.Metrics; |
45 | 48 | import io.trino.spi.predicate.Domain; |
46 | 49 | import io.trino.spi.predicate.TupleDomain; |
47 | 50 | import io.trino.sql.planner.Plan; |
|
56 | 59 | import io.trino.testing.DistributedQueryRunner; |
57 | 60 | import io.trino.testing.MaterializedResult; |
58 | 61 | import io.trino.testing.MaterializedRow; |
| 62 | +import io.trino.testing.QueryFailedException; |
59 | 63 | import io.trino.testing.QueryRunner; |
60 | 64 | import io.trino.testing.QueryRunner.MaterializedResultWithPlan; |
61 | 65 | import io.trino.testing.TestingConnectorBehavior; |
| 66 | +import io.trino.testing.TestingSession; |
62 | 67 | import io.trino.testing.sql.TestTable; |
63 | 68 | import org.apache.avro.Schema; |
64 | 69 | import org.apache.avro.file.DataFileReader; |
|
111 | 116 | import static com.google.common.collect.Iterables.getOnlyElement; |
112 | 117 | import static com.google.common.collect.MoreCollectors.onlyElement; |
113 | 118 | import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly; |
| 119 | +import static io.airlift.units.Duration.succinctDuration; |
114 | 120 | import static io.trino.SystemSessionProperties.DETERMINE_PARTITION_COUNT_FOR_WRITE_ENABLED; |
115 | 121 | import static io.trino.SystemSessionProperties.ENABLE_DYNAMIC_FILTERING; |
| 122 | +import static io.trino.SystemSessionProperties.ITERATIVE_OPTIMIZER_TIMEOUT; |
116 | 123 | import static io.trino.SystemSessionProperties.MAX_HASH_PARTITION_COUNT; |
117 | 124 | import static io.trino.SystemSessionProperties.MAX_WRITER_TASK_COUNT; |
118 | 125 | import static io.trino.SystemSessionProperties.SCALE_WRITERS; |
|
179 | 186 | import static org.assertj.core.api.Assertions.assertThat; |
180 | 187 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
181 | 188 | import static org.assertj.core.api.Assertions.offset; |
| 189 | +import static org.assertj.core.api.Fail.fail; |
182 | 190 | import static org.junit.jupiter.api.Assumptions.abort; |
183 | 191 |
|
184 | 192 | public abstract class BaseIcebergConnectorTest |
@@ -9214,6 +9222,52 @@ public void testCreateTableWithDataLocationButObjectStoreLayoutDisabled() |
9214 | 9222 | "Data location can only be set when object store layout is enabled"); |
9215 | 9223 | } |
9216 | 9224 |
|
| 9225 | + @Test |
| 9226 | + public void testCatalogMetadataMetrics() |
| 9227 | + { |
| 9228 | + MaterializedResultWithPlan result = getQueryRunner().executeWithPlan( |
| 9229 | + getSession(), |
| 9230 | + "SELECT count(*) FROM region r, nation n WHERE r.regionkey = n.regionkey"); |
| 9231 | + Map<String, Metrics> metrics = getCatalogMetadataMetrics(result.queryId()); |
| 9232 | + assertCountMetricExists(metrics, "iceberg", "metastore.all.time.total"); |
| 9233 | + assertDistributionMetricExists(metrics, "iceberg", "metastore.all.time.distribution"); |
| 9234 | + assertCountMetricExists(metrics, "iceberg", "metastore.getTable.time.total"); |
| 9235 | + assertDistributionMetricExists(metrics, "iceberg", "metastore.getTable.time.distribution"); |
| 9236 | + } |
| 9237 | + |
| 9238 | + @Test |
| 9239 | + public void testCatalogMetadataMetricsWithOptimizerTimeoutExceeded() |
| 9240 | + { |
| 9241 | + String query = "SELECT count(*) FROM region r, nation n WHERE r.regionkey = n.regionkey"; |
| 9242 | + try { |
| 9243 | + Session smallOptimizerTimeout = TestingSession.testSessionBuilder(getSession()) |
| 9244 | + .setSystemProperty(ITERATIVE_OPTIMIZER_TIMEOUT, succinctDuration(1, MILLISECONDS).toString()) |
| 9245 | + .build(); |
| 9246 | + MaterializedResultWithPlan result = getQueryRunner().executeWithPlan(smallOptimizerTimeout, query); |
| 9247 | + fail(format("Expected query to fail: %s [QueryId: %s]", query, result.queryId())); |
| 9248 | + } |
| 9249 | + catch (QueryFailedException e) { |
| 9250 | + assertThat(e.getMessage()).contains("The optimizer exhausted the time limit"); |
| 9251 | + Map<String, Metrics> metrics = getCatalogMetadataMetrics(e.getQueryId()); |
| 9252 | + assertCountMetricExists(metrics, "iceberg", "metastore.all.time.total"); |
| 9253 | + assertCountMetricExists(metrics, "iceberg", "metastore.getTable.time.total"); |
| 9254 | + } |
| 9255 | + } |
| 9256 | + |
| 9257 | + protected static void assertDistributionMetricExists(Map<String, Metrics> metrics, String catalog, String metricKey) |
| 9258 | + { |
| 9259 | + assertThat(metrics.get(catalog).getMetrics()).isNotEmpty(); |
| 9260 | + assertThat(metrics.get(catalog).getMetrics()).containsKey(metricKey); |
| 9261 | + assertThat(((DistributionSnapshot) metrics.get(catalog).getMetrics().get(metricKey)).total()).isGreaterThan(0); |
| 9262 | + } |
| 9263 | + |
| 9264 | + protected static void assertCountMetricExists(Map<String, Metrics> metrics, String catalog, String metricKey) |
| 9265 | + { |
| 9266 | + assertThat(metrics.get(catalog).getMetrics()).isNotEmpty(); |
| 9267 | + assertThat(metrics.get(catalog).getMetrics()).containsKey(metricKey); |
| 9268 | + assertThat(((LongCount) metrics.get(catalog).getMetrics().get(metricKey)).getTotal()).isGreaterThan(0); |
| 9269 | + } |
| 9270 | + |
9217 | 9271 | @Test |
9218 | 9272 | @Override |
9219 | 9273 | public void testSetFieldMapKeyType() |
|
0 commit comments