From c66438c4c26f99ad23445bad35be2dffa49980b0 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 --- .../com/facebook/presto/plugin/jdbc/BaseJdbcClient.java | 9 +++++++++ .../java/com/facebook/presto/plugin/jdbc/JdbcClient.java | 5 +++++ .../com/facebook/presto/plugin/jdbc/JdbcMetadata.java | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/BaseJdbcClient.java b/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/BaseJdbcClient.java index 7096fa0adc3f..9c1355ef563f 100644 --- a/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/BaseJdbcClient.java +++ b/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/BaseJdbcClient.java @@ -13,6 +13,7 @@ */ package com.facebook.presto.plugin.jdbc; +import com.facebook.presto.spi.ColumnHandle; import com.facebook.presto.spi.ColumnMetadata; import com.facebook.presto.spi.ConnectorSession; import com.facebook.presto.spi.ConnectorSplitSource; @@ -21,6 +22,8 @@ import com.facebook.presto.spi.PrestoException; import com.facebook.presto.spi.SchemaTableName; import com.facebook.presto.spi.TableNotFoundException; +import com.facebook.presto.spi.predicate.TupleDomain; +import com.facebook.presto.spi.statistics.TableStatistics; import com.facebook.presto.spi.type.CharType; import com.facebook.presto.spi.type.DecimalType; import com.facebook.presto.spi.type.Type; @@ -454,6 +457,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/com/facebook/presto/plugin/jdbc/JdbcClient.java b/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/JdbcClient.java index b82689b24836..d154d9506f3f 100644 --- a/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/JdbcClient.java +++ b/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/JdbcClient.java @@ -13,10 +13,13 @@ */ package com.facebook.presto.plugin.jdbc; +import com.facebook.presto.spi.ColumnHandle; import com.facebook.presto.spi.ConnectorSession; import com.facebook.presto.spi.ConnectorSplitSource; import com.facebook.presto.spi.ConnectorTableMetadata; import com.facebook.presto.spi.SchemaTableName; +import com.facebook.presto.spi.predicate.TupleDomain; +import com.facebook.presto.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/com/facebook/presto/plugin/jdbc/JdbcMetadata.java b/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/JdbcMetadata.java index 1641ec459590..5e3519c6fe6a 100644 --- a/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/JdbcMetadata.java +++ b/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/JdbcMetadata.java @@ -32,6 +32,7 @@ import com.facebook.presto.spi.connector.ConnectorMetadata; import com.facebook.presto.spi.connector.ConnectorOutputMetadata; import com.facebook.presto.spi.statistics.ComputedStatistics; +import com.facebook.presto.spi.statistics.TableStatistics; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import io.airlift.slice.Slice; @@ -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()); + } }