@@ -183,6 +183,9 @@ public class ThriftHiveMetastore
183
183
private final boolean isMetastoreAuthenticationEnabled ;
184
184
private final boolean deleteFilesOnTableDrop ;
185
185
186
+ private volatile boolean metastoreKnownToSupportTableParamEqualsPredicate ;
187
+ private volatile boolean metastoreKnownToSupportTableParamLikePredicate ;
188
+
186
189
@ Inject
187
190
public ThriftHiveMetastore (HiveCluster hiveCluster , MetastoreClientConfig config , HdfsEnvironment hdfsEnvironment )
188
191
{
@@ -896,11 +899,9 @@ public Optional<List<String>> getAllViews(MetastoreContext metastoreContext, Str
896
899
return retry ()
897
900
.stopOn (UnknownDBException .class )
898
901
.stopOnIllegalExceptions ()
899
- .run ("getAllViews" , stats .getGetAllViews ().wrap (() ->
900
- getMetastoreClientThenCall (metastoreContext , client -> {
901
- String filter = HIVE_FILTER_FIELD_PARAMS + PRESTO_VIEW_FLAG + " = \" true\" " ;
902
- return Optional .of (client .getTableNamesByFilter (databaseName , filter ));
903
- })));
902
+ .run ("getAllViews" , stats .getGetAllViews ().wrap (() -> {
903
+ return Optional .of (getPrestoViews (databaseName ));
904
+ }));
904
905
}
905
906
catch (UnknownDBException e ) {
906
907
return Optional .empty ();
@@ -1209,6 +1210,46 @@ public MetastoreOperationResult addPartitions(
1209
1210
return EMPTY_RESULT ;
1210
1211
}
1211
1212
1213
+ private List <String > getPrestoViews (String databaseName )
1214
+ throws TException
1215
+ {
1216
+ /*
1217
+ * Thrift call `get_table_names_by_filter` may be translated by Metastore to a SQL query against Metastore database.
1218
+ * Hive 2.3 on some databases uses CLOB for table parameter value column and some databases disallow `=` predicate over
1219
+ * CLOB values. At the same time, they allow `LIKE` predicates over them.
1220
+ */
1221
+ String filterWithEquals = HIVE_FILTER_FIELD_PARAMS + PRESTO_VIEW_FLAG + " = \" true\" " ;
1222
+ String filterWithLike = HIVE_FILTER_FIELD_PARAMS + PRESTO_VIEW_FLAG + " LIKE \" true\" " ;
1223
+ if (metastoreKnownToSupportTableParamEqualsPredicate ) {
1224
+ try (HiveMetastoreClient client = clientProvider .createMetastoreClient (Optional .empty ())) {
1225
+ return client .getTableNamesByFilter (databaseName , filterWithEquals );
1226
+ }
1227
+ }
1228
+ if (metastoreKnownToSupportTableParamLikePredicate ) {
1229
+ try (HiveMetastoreClient client = clientProvider .createMetastoreClient (Optional .empty ())) {
1230
+ return client .getTableNamesByFilter (databaseName , filterWithLike );
1231
+ }
1232
+ }
1233
+ try (HiveMetastoreClient client = clientProvider .createMetastoreClient (Optional .empty ())) {
1234
+ List <String > views = client .getTableNamesByFilter (databaseName , filterWithEquals );
1235
+ metastoreKnownToSupportTableParamEqualsPredicate = true ;
1236
+ return views ;
1237
+ }
1238
+ catch (TException | RuntimeException firstException ) {
1239
+ try (HiveMetastoreClient client = clientProvider .createMetastoreClient (Optional .empty ())) {
1240
+ List <String > views = client .getTableNamesByFilter (databaseName , filterWithLike );
1241
+ metastoreKnownToSupportTableParamLikePredicate = true ;
1242
+ return views ;
1243
+ }
1244
+ catch (TException | RuntimeException secondException ) {
1245
+ if (firstException != secondException ) {
1246
+ firstException .addSuppressed (secondException );
1247
+ }
1248
+ }
1249
+ throw firstException ;
1250
+ }
1251
+ }
1252
+
1212
1253
private void addPartitionsWithoutStatistics (MetastoreContext metastoreContext , String databaseName , String tableName , List <Partition > partitions )
1213
1254
{
1214
1255
if (partitions .isEmpty ()) {
0 commit comments