From fa65182245b989c20bb36267e048f3cc25c0b256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Kokosi=C5=84ski?= Date: Tue, 15 Jan 2019 10:25:19 +0100 Subject: [PATCH] Add support for getTableStatistics to base-jdbc connector --- .../java/io/prestosql/plugin/jdbc/BaseJdbcClient.java | 9 +++++++++ .../main/java/io/prestosql/plugin/jdbc/JdbcClient.java | 5 +++++ .../main/java/io/prestosql/plugin/jdbc/JdbcMetadata.java | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/BaseJdbcClient.java b/presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/BaseJdbcClient.java index f5cf1bf736a7..8df6143cee8e 100644 --- a/presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/BaseJdbcClient.java +++ b/presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/BaseJdbcClient.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableSet; import io.airlift.log.Logger; import io.prestosql.spi.PrestoException; +import io.prestosql.spi.connector.ColumnHandle; import io.prestosql.spi.connector.ColumnMetadata; import io.prestosql.spi.connector.ConnectorSession; import io.prestosql.spi.connector.ConnectorSplitSource; @@ -26,6 +27,8 @@ import io.prestosql.spi.connector.FixedSplitSource; import io.prestosql.spi.connector.SchemaTableName; import io.prestosql.spi.connector.TableNotFoundException; +import io.prestosql.spi.predicate.TupleDomain; +import io.prestosql.spi.statistics.TableStatistics; import io.prestosql.spi.type.CharType; import io.prestosql.spi.type.DecimalType; import io.prestosql.spi.type.Type; @@ -449,6 +452,12 @@ protected SchemaTableName getSchemaTableName(ResultSet resultSet) resultSet.getString("TABLE_NAME").toLowerCase(ENGLISH)); } + @Override + public TableStatistics getTableStatistics(ConnectorSession session, JdbcTableHandle handle, TupleDomain tupleDomain) + { + return TableStatistics.empty(); + } + protected void execute(Connection connection, String query) throws SQLException { diff --git a/presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/JdbcClient.java b/presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/JdbcClient.java index f8b4e23a4deb..199f982fa568 100644 --- a/presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/JdbcClient.java +++ b/presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/JdbcClient.java @@ -13,10 +13,13 @@ */ package io.prestosql.plugin.jdbc; +import io.prestosql.spi.connector.ColumnHandle; import io.prestosql.spi.connector.ConnectorSession; import io.prestosql.spi.connector.ConnectorSplitSource; import io.prestosql.spi.connector.ConnectorTableMetadata; import io.prestosql.spi.connector.SchemaTableName; +import io.prestosql.spi.predicate.TupleDomain; +import io.prestosql.spi.statistics.TableStatistics; import javax.annotation.Nullable; @@ -78,4 +81,6 @@ Connection getConnection(JdbcOutputTableHandle handle) PreparedStatement getPreparedStatement(Connection connection, String sql) throws SQLException; + + TableStatistics getTableStatistics(ConnectorSession session, JdbcTableHandle handle, TupleDomain tupleDomain); } diff --git a/presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/JdbcMetadata.java b/presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/JdbcMetadata.java index 0d3dc4c5799d..e6c68c1ef6d2 100644 --- a/presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/JdbcMetadata.java +++ b/presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/JdbcMetadata.java @@ -35,6 +35,7 @@ import io.prestosql.spi.connector.SchemaTablePrefix; import io.prestosql.spi.connector.TableNotFoundException; import io.prestosql.spi.statistics.ComputedStatistics; +import io.prestosql.spi.statistics.TableStatistics; import java.util.Collection; import java.util.List; @@ -212,4 +213,11 @@ public Optional finishInsert(ConnectorSession session, jdbcClient.finishInsertTable(jdbcInsertHandle); return Optional.empty(); } + + @Override + public TableStatistics getTableStatistics(ConnectorSession session, ConnectorTableHandle tableHandle, Constraint constraint) + { + JdbcTableHandle handle = (JdbcTableHandle) tableHandle; + return jdbcClient.getTableStatistics(session, handle, constraint.getSummary()); + } }