Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public Map<String, Optional<Partition>> getPartitionsByNames(Table table, List<S
return resultBuilder.buildOrThrow();
}

private Partition fromMetastoreApiPartition(Table table, org.apache.hadoop.hive.metastore.api.Partition partition)
private static Partition fromMetastoreApiPartition(Table table, org.apache.hadoop.hive.metastore.api.Partition partition)
{
if (isAvroTableWithSchemaSet(table)) {
List<FieldSchema> schema = table.getDataColumns().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public CoalescingCounter(Duration coalescingDuration)
coalescingDurationMillis = requireNonNull(coalescingDuration, "coalescingDuration is null").toMillis();
}

public synchronized void increment()
private synchronized void increment()
{
long now = clock.instant().toEpochMilli();
if (lastUpdateTime + coalescingDurationMillis >= now) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;

import static java.lang.Math.toIntExact;
import static java.util.Collections.list;
Expand All @@ -57,6 +58,11 @@ public class DefaultThriftMetastoreClientFactory
private final HiveMetastoreAuthentication metastoreAuthentication;
private final String hostname;

private final MetastoreSupportsDateStatistics metastoreSupportsDateStatistics = new MetastoreSupportsDateStatistics();
private final AtomicInteger chosenGetTableAlternative = new AtomicInteger(Integer.MAX_VALUE);
private final AtomicInteger chosenTableParamAlternative = new AtomicInteger(Integer.MAX_VALUE);
private final AtomicInteger chosenGetAllViewsAlternative = new AtomicInteger(Integer.MAX_VALUE);

public DefaultThriftMetastoreClientFactory(
Optional<SSLContext> sslContext,
Optional<HostAndPort> socksProxy,
Expand Down Expand Up @@ -101,7 +107,11 @@ protected ThriftMetastoreClient create(TTransport transport, String hostname)
{
return new ThriftHiveMetastoreClient(
transport,
hostname);
hostname,
metastoreSupportsDateStatistics,
chosenGetTableAlternative,
chosenTableParamAlternative,
chosenGetAllViewsAlternative);
}

private TTransport createTransport(HostAndPort address, Optional<String> delegationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ public List<String> getAllTables(String databaseName)
}

@Override
public List<String> getTableNamesByFilter(String databaseName, String filter)
public List<String> getAllViews(String databaseName)
throws TException
{
return runWithHandle(() -> delegate.getTableNamesByFilter(databaseName, filter));
return runWithHandle(() -> delegate.getAllViews(databaseName));
}

@Override
public List<String> getTableNamesByType(String databaseName, String tableType)
public List<String> getTablesWithParameter(String databaseName, String parameterKey, String parameterValue)
throws TException
{
return runWithHandle(() -> delegate.getTableNamesByType(databaseName, tableType));
return runWithHandle(() -> delegate.getTablesWithParameter(databaseName, parameterKey, parameterValue));
}

@Override
Expand Down Expand Up @@ -153,13 +153,6 @@ public Table getTable(String databaseName, String tableName)
return runWithHandle(() -> delegate.getTable(databaseName, tableName));
}

@Override
public Table getTableWithCapabilities(String databaseName, String tableName)
throws TException
{
return runWithHandle(() -> delegate.getTableWithCapabilities(databaseName, tableName));
}

@Override
public List<FieldSchema> getFields(String databaseName, String tableName)
throws TException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,13 @@ private static class SaslClientCallbackHandler
public void handle(Callback[] callbacks)
{
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName(username);
if (callback instanceof NameCallback nameCallback) {
nameCallback.setName(username);
}
if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword(password.toCharArray());
if (callback instanceof PasswordCallback passwordCallback) {
passwordCallback.setPassword(password.toCharArray());
}
if (callback instanceof RealmCallback) {
RealmCallback realmCallback = (RealmCallback) callback;
if (callback instanceof RealmCallback realmCallback) {
Comment thread
dain marked this conversation as resolved.
Outdated
realmCallback.setText(realmCallback.getDefaultText());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.trino.plugin.hive.metastore.thrift;

import io.airlift.units.Duration;

import javax.annotation.concurrent.ThreadSafe;

import java.util.concurrent.atomic.AtomicReference;

import static io.trino.plugin.hive.metastore.thrift.MetastoreSupportsDateStatistics.DateStatisticsSupport.NOT_SUPPORTED;
import static io.trino.plugin.hive.metastore.thrift.MetastoreSupportsDateStatistics.DateStatisticsSupport.SUPPORTED;
import static io.trino.plugin.hive.metastore.thrift.MetastoreSupportsDateStatistics.DateStatisticsSupport.UNKNOWN;
import static java.util.concurrent.TimeUnit.SECONDS;

@ThreadSafe
class MetastoreSupportsDateStatistics
{
private static final int MAX_SET_DATE_STATISTICS_ATTEMPTS = 100;

public enum DateStatisticsSupport {
SUPPORTED, NOT_SUPPORTED, UNKNOWN
}

private final AtomicReference<DateStatisticsSupport> supported = new AtomicReference<>(UNKNOWN);
private final CoalescingCounter failures = new CoalescingCounter(new Duration(1, SECONDS));

public DateStatisticsSupport isSupported()
{
return supported.get();
}

public void succeeded()
{
supported.set(SUPPORTED);
}

public void failed()
{
// When `dateStatistics.size() > 1` we expect something like "TApplicationException: Required field 'colName' is unset! Struct:ColumnStatisticsObj(colName:null, colType:null, statsData:null)"
// When `dateStatistics.size() == 1` we expect something like "TTransportException: java.net.SocketTimeoutException: Read timed out"
Comment on lines +51 to +52
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does dateStatistics refer to?

if (failures.incrementAndGet() >= MAX_SET_DATE_STATISTICS_ATTEMPTS) {
supported.set(NOT_SUPPORTED);
}
}
}
Loading