From d2cf082f732755931231b1d4a5fc660077dfb82a Mon Sep 17 00:00:00 2001 From: Jiexi Lin Date: Mon, 4 Mar 2019 20:40:31 +0100 Subject: [PATCH] Add a system table to list all ANALYZE properties Extracted from: https://github.com/prestodb/presto/pull/12409 --- presto-docs/src/main/sphinx/sql/analyze.rst | 6 ++-- .../hive/TestHiveIntegrationSmokeTest.java | 8 +++++ .../system/AnalyzePropertiesSystemTable.java | 29 +++++++++++++++++++ .../system/SystemConnectorModule.java | 1 + .../prestosql/testing/LocalQueryRunner.java | 2 ++ .../selectInformationSchemaColumns.result | 5 ++++ .../system/showTablesSystemMetadata.result | 1 + .../tests/TestTpchDistributedQueries.java | 6 ++++ 8 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 presto-main/src/main/java/io/prestosql/connector/system/AnalyzePropertiesSystemTable.java diff --git a/presto-docs/src/main/sphinx/sql/analyze.rst b/presto-docs/src/main/sphinx/sql/analyze.rst index 2c0bf3a54a32..2d20cf53c3de 100644 --- a/presto-docs/src/main/sphinx/sql/analyze.rst +++ b/presto-docs/src/main/sphinx/sql/analyze.rst @@ -14,8 +14,10 @@ Description Collects table and column statistics for a given table. -The optional ``WITH`` clause can be used to provide -connector-specific properties. +The optional ``WITH`` clause can be used to provide connector-specific properties. +To list all available properties, run the following query:: + + SELECT * FROM system.metadata.analyze_properties Currently, this statement is only supported by the :ref:`Hive connector `. diff --git a/presto-hive/src/test/java/io/prestosql/plugin/hive/TestHiveIntegrationSmokeTest.java b/presto-hive/src/test/java/io/prestosql/plugin/hive/TestHiveIntegrationSmokeTest.java index 7f2bc3f64ef1..6f5e69a4cd77 100644 --- a/presto-hive/src/test/java/io/prestosql/plugin/hive/TestHiveIntegrationSmokeTest.java +++ b/presto-hive/src/test/java/io/prestosql/plugin/hive/TestHiveIntegrationSmokeTest.java @@ -3070,6 +3070,14 @@ public void testCollectColumnStatisticsOnInsert() assertUpdate(format("DROP TABLE %s", tableName)); } + @Test + public void testAnalyzePropertiesSystemTable() + { + assertQuery( + "SELECT * FROM system.metadata.analyze_properties WHERE catalog_name = 'hive'", + "SELECT 'hive', 'partitions', '', 'array(array(varchar))', 'Partitions to be analyzed'"); + } + @Test public void testAnalyzeEmptyTable() { diff --git a/presto-main/src/main/java/io/prestosql/connector/system/AnalyzePropertiesSystemTable.java b/presto-main/src/main/java/io/prestosql/connector/system/AnalyzePropertiesSystemTable.java new file mode 100644 index 000000000000..c124180838ea --- /dev/null +++ b/presto-main/src/main/java/io/prestosql/connector/system/AnalyzePropertiesSystemTable.java @@ -0,0 +1,29 @@ +/* + * 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 io.prestosql.connector.system; + +import io.prestosql.metadata.Metadata; +import io.prestosql.transaction.TransactionManager; + +import javax.inject.Inject; + +public class AnalyzePropertiesSystemTable + extends AbstractPropertiesSystemTable +{ + @Inject + public AnalyzePropertiesSystemTable(TransactionManager transactionManager, Metadata metadata) + { + super("analyze_properties", transactionManager, () -> metadata.getAnalyzePropertyManager().getAllProperties()); + } +} diff --git a/presto-main/src/main/java/io/prestosql/connector/system/SystemConnectorModule.java b/presto-main/src/main/java/io/prestosql/connector/system/SystemConnectorModule.java index 82b0fec4e64a..17baf3e4d0f3 100644 --- a/presto-main/src/main/java/io/prestosql/connector/system/SystemConnectorModule.java +++ b/presto-main/src/main/java/io/prestosql/connector/system/SystemConnectorModule.java @@ -52,6 +52,7 @@ public void configure(Binder binder) globalTableBinder.addBinding().to(SchemaPropertiesSystemTable.class).in(Scopes.SINGLETON); globalTableBinder.addBinding().to(TablePropertiesSystemTable.class).in(Scopes.SINGLETON); globalTableBinder.addBinding().to(ColumnPropertiesSystemTable.class).in(Scopes.SINGLETON); + globalTableBinder.addBinding().to(AnalyzePropertiesSystemTable.class).in(Scopes.SINGLETON); globalTableBinder.addBinding().to(TransactionsSystemTable.class).in(Scopes.SINGLETON); globalTableBinder.addBinding().to(AttributeJdbcTable.class).in(Scopes.SINGLETON); diff --git a/presto-main/src/main/java/io/prestosql/testing/LocalQueryRunner.java b/presto-main/src/main/java/io/prestosql/testing/LocalQueryRunner.java index 68fd8a894f80..6a599189f8a9 100644 --- a/presto-main/src/main/java/io/prestosql/testing/LocalQueryRunner.java +++ b/presto-main/src/main/java/io/prestosql/testing/LocalQueryRunner.java @@ -26,6 +26,7 @@ import io.prestosql.block.BlockEncodingManager; import io.prestosql.connector.ConnectorId; import io.prestosql.connector.ConnectorManager; +import io.prestosql.connector.system.AnalyzePropertiesSystemTable; import io.prestosql.connector.system.CatalogSystemTable; import io.prestosql.connector.system.ColumnPropertiesSystemTable; import io.prestosql.connector.system.GlobalSystemConnector; @@ -349,6 +350,7 @@ private LocalQueryRunner(Session defaultSession, FeaturesConfig featuresConfig, new SchemaPropertiesSystemTable(transactionManager, metadata), new TablePropertiesSystemTable(transactionManager, metadata), new ColumnPropertiesSystemTable(transactionManager, metadata), + new AnalyzePropertiesSystemTable(transactionManager, metadata), new TransactionsSystemTable(typeRegistry, transactionManager)), ImmutableSet.of()); diff --git a/presto-product-tests/src/main/resources/sql-tests/testcases/system/selectInformationSchemaColumns.result b/presto-product-tests/src/main/resources/sql-tests/testcases/system/selectInformationSchemaColumns.result index bb4bbffef93f..9b2d5f902ce3 100644 --- a/presto-product-tests/src/main/resources/sql-tests/testcases/system/selectInformationSchemaColumns.result +++ b/presto-product-tests/src/main/resources/sql-tests/testcases/system/selectInformationSchemaColumns.result @@ -35,6 +35,11 @@ system| information_schema| views| table_catalog| varchar| YES| null| null| system| information_schema| views| table_schema| varchar| YES| null| null| system| information_schema| views| table_name| varchar| YES| null| null| system| information_schema| views| view_definition| varchar| YES| null| null| +system| metadata| analyze_properties| catalog_name| varchar| YES| null| null| +system| metadata| analyze_properties| property_name| varchar| YES| null| null| +system| metadata| analyze_properties| default_value| varchar| YES| null| null| +system| metadata| analyze_properties| type| varchar| YES| null| null| +system| metadata| analyze_properties| description| varchar| YES| null| null| system| metadata| catalogs| catalog_name| varchar| YES| null| null| system| metadata| catalogs| connector_id| varchar| YES| null| null| system| metadata| column_properties| catalog_name| varchar| YES| null| null| diff --git a/presto-product-tests/src/main/resources/sql-tests/testcases/system/showTablesSystemMetadata.result b/presto-product-tests/src/main/resources/sql-tests/testcases/system/showTablesSystemMetadata.result index b830ebd06e04..d9a527ca236f 100644 --- a/presto-product-tests/src/main/resources/sql-tests/testcases/system/showTablesSystemMetadata.result +++ b/presto-product-tests/src/main/resources/sql-tests/testcases/system/showTablesSystemMetadata.result @@ -1,5 +1,6 @@ -- delimiter: |; ignoreOrder: true; catalogs| +analyze_properties| schema_properties| table_properties| column_properties| diff --git a/presto-tests/src/test/java/io/prestosql/tests/TestTpchDistributedQueries.java b/presto-tests/src/test/java/io/prestosql/tests/TestTpchDistributedQueries.java index 740ad4296246..ac3442e47fd6 100644 --- a/presto-tests/src/test/java/io/prestosql/tests/TestTpchDistributedQueries.java +++ b/presto-tests/src/test/java/io/prestosql/tests/TestTpchDistributedQueries.java @@ -36,6 +36,12 @@ public void testTooLongQuery() assertQueryFails(longQuery, "Query text length \\(1000037\\) exceeds the maximum length \\(1000000\\)"); } + @Test + public void testAnalyzePropertiesSystemTable() + { + assertQuery("SELECT COUNT(*) FROM system.metadata.analyze_properties WHERE catalog_name = 'tpch'", "SELECT 0"); + } + @Test public void testAnalyze() {