@@ -117,6 +117,9 @@ public class ThriftHiveMetastore
117
117
private final Duration maxRetryTime ;
118
118
private final int maxRetries ;
119
119
120
+ private volatile boolean metastoreKnownToSupportTableParamEqualsPredicate ;
121
+ private volatile boolean metastoreKnownToSupportTableParamLikePredicate ;
122
+
120
123
@ Inject
121
124
public ThriftHiveMetastore (MetastoreLocator metastoreLocator , ThriftHiveMetastoreConfig thriftConfig )
122
125
{
@@ -722,10 +725,7 @@ public Optional<List<String>> getAllViews(String databaseName)
722
725
.stopOn (UnknownDBException .class )
723
726
.stopOnIllegalExceptions ()
724
727
.run ("getAllViews" , stats .getGetAllViews ().wrap (() -> {
725
- try (ThriftMetastoreClient client = clientProvider .createMetastoreClient ()) {
726
- String filter = HIVE_FILTER_FIELD_PARAMS + PRESTO_VIEW_FLAG + " = \" true\" " ;
727
- return Optional .of (client .getTableNamesByFilter (databaseName , filter ));
728
- }
728
+ return Optional .of (getPrestoViews (databaseName ));
729
729
}));
730
730
}
731
731
catch (UnknownDBException e ) {
@@ -739,6 +739,48 @@ public Optional<List<String>> getAllViews(String databaseName)
739
739
}
740
740
}
741
741
742
+ private List <String > getPrestoViews (String databaseName )
743
+ throws TException
744
+ {
745
+ /*
746
+ * Thrift call `get_table_names_by_filter` may be translated by Metastore to a SQL query against Metastore database.
747
+ * Hive 2.3 on some databases uses CLOB for table parameter value column and some databases disallow `=` predicate over
748
+ * CLOB values. At the same time, they allow `LIKE` predicates over them.
749
+ */
750
+ String filterWithEquals = HIVE_FILTER_FIELD_PARAMS + PRESTO_VIEW_FLAG + " = \" true\" " ;
751
+ String filterWithLike = HIVE_FILTER_FIELD_PARAMS + PRESTO_VIEW_FLAG + " LIKE \" true\" " ;
752
+
753
+ if (metastoreKnownToSupportTableParamEqualsPredicate ) {
754
+ try (ThriftMetastoreClient client = clientProvider .createMetastoreClient ()) {
755
+ return client .getTableNamesByFilter (databaseName , filterWithEquals );
756
+ }
757
+ }
758
+ if (metastoreKnownToSupportTableParamLikePredicate ) {
759
+ try (ThriftMetastoreClient client = clientProvider .createMetastoreClient ()) {
760
+ return client .getTableNamesByFilter (databaseName , filterWithLike );
761
+ }
762
+ }
763
+
764
+ try (ThriftMetastoreClient client = clientProvider .createMetastoreClient ()) {
765
+ List <String > views = client .getTableNamesByFilter (databaseName , filterWithEquals );
766
+ metastoreKnownToSupportTableParamEqualsPredicate = true ;
767
+ return views ;
768
+ }
769
+ catch (TException | RuntimeException firstException ) {
770
+ try (ThriftMetastoreClient client = clientProvider .createMetastoreClient ()) {
771
+ List <String > views = client .getTableNamesByFilter (databaseName , filterWithLike );
772
+ metastoreKnownToSupportTableParamLikePredicate = true ;
773
+ return views ;
774
+ }
775
+ catch (TException | RuntimeException secondException ) {
776
+ if (firstException != secondException ) {
777
+ firstException .addSuppressed (secondException );
778
+ }
779
+ }
780
+ throw firstException ;
781
+ }
782
+ }
783
+
742
784
@ Override
743
785
public void createDatabase (Database database )
744
786
{
0 commit comments