20
20
import io .airlift .log .Logger ;
21
21
import io .trino .plugin .hive .HdfsEnvironment ;
22
22
import io .trino .plugin .hive .HiveColumnHandle ;
23
- import io .trino .plugin .hive .HivePartition ;
24
23
import io .trino .plugin .hive .acid .AcidSchema ;
25
24
import io .trino .plugin .hive .metastore .Column ;
26
25
import io .trino .plugin .hive .metastore .HiveMetastore ;
32
31
import io .trino .spi .connector .ConnectorSession ;
33
32
import io .trino .spi .connector .ConnectorTableHandle ;
34
33
import io .trino .spi .connector .ConnectorTableMetadata ;
35
- import io .trino .spi .connector .ConnectorTableProperties ;
36
34
import io .trino .spi .connector .Constraint ;
37
35
import io .trino .spi .connector .ConstraintApplicationResult ;
38
36
import io .trino .spi .connector .SchemaTableName ;
39
37
import io .trino .spi .connector .SchemaTablePrefix ;
38
+ import io .trino .spi .connector .TableColumnsMetadata ;
40
39
import io .trino .spi .connector .TableNotFoundException ;
41
40
import io .trino .spi .predicate .TupleDomain ;
42
41
import io .trino .spi .type .TypeManager ;
43
42
import org .apache .hadoop .conf .Configuration ;
44
43
import org .apache .hadoop .fs .Path ;
45
44
import org .apache .hudi .common .model .HoodieTableType ;
46
- import org .apache .hudi .common .table .HoodieTableMetaClient ;
47
45
48
46
import java .util .List ;
49
47
import java .util .Map ;
50
48
import java .util .Optional ;
51
49
import java .util .function .Function ;
50
+ import java .util .stream .Stream ;
52
51
53
52
import static com .google .common .collect .ImmutableList .toImmutableList ;
54
53
import static com .google .common .collect .ImmutableMap .toImmutableMap ;
67
66
import static io .trino .plugin .hive .util .HiveUtil .hiveColumnHandles ;
68
67
import static io .trino .plugin .hive .util .HiveUtil .isHiveSystemSchema ;
69
68
import static io .trino .plugin .hudi .HudiErrorCode .HUDI_UNKNOWN_TABLE_TYPE ;
70
- import static io .trino .plugin .hudi .HudiUtil .splitPredicate ;
71
69
import static io .trino .spi .connector .SchemaTableName .schemaTableName ;
72
70
import static java .lang .String .format ;
73
71
import static java .util .Collections .singletonList ;
@@ -120,8 +118,7 @@ public HudiTableHandle getTableHandle(ConnectorSession session, SchemaTableName
120
118
table .get ().getStorage ().getLocation (),
121
119
HoodieTableType .COPY_ON_WRITE ,
122
120
TupleDomain .all (),
123
- TupleDomain .all (),
124
- Optional .of (getTableMetaClient (session , table .get ())));
121
+ TupleDomain .all ());
125
122
}
126
123
127
124
@ Override
@@ -135,12 +132,14 @@ public ConnectorTableMetadata getTableMetadata(ConnectorSession session, Connect
135
132
public Optional <ConstraintApplicationResult <ConnectorTableHandle >> applyFilter (ConnectorSession session , ConnectorTableHandle tableHandle , Constraint constraint )
136
133
{
137
134
HudiTableHandle handle = (HudiTableHandle ) tableHandle ;
138
- HudiPredicates predicates = splitPredicate (constraint .getSummary ());
139
- HudiTableHandle newHudiTableHandle = handle .withPredicates (predicates );
135
+ HudiPredicates predicates = HudiPredicates .from (constraint .getSummary ());
136
+ HudiTableHandle newHudiTableHandle = handle .withPredicates (
137
+ predicates .getPartitionColumnPredicates (),
138
+ predicates .getRegularColumnPredicates ());
140
139
141
140
if (handle .getPartitionPredicates ().equals (newHudiTableHandle .getPartitionPredicates ())
142
141
&& handle .getRegularPredicates ().equals (newHudiTableHandle .getRegularPredicates ())) {
143
- log .info ("No new predicates to apply" );
142
+ log .debug ("No new predicates to apply" );
144
143
return Optional .empty ();
145
144
}
146
145
@@ -150,12 +149,6 @@ public Optional<ConstraintApplicationResult<ConnectorTableHandle>> applyFilter(C
150
149
false ));
151
150
}
152
151
153
- @ Override
154
- public ConnectorTableProperties getTableProperties (ConnectorSession session , ConnectorTableHandle tableHandle )
155
- {
156
- return new ConnectorTableProperties ();
157
- }
158
-
159
152
@ Override
160
153
public Map <String , ColumnHandle > getColumnHandles (ConnectorSession session , ConnectorTableHandle tableHandle )
161
154
{
@@ -175,11 +168,8 @@ public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTable
175
168
@ Override
176
169
public Optional <Object > getInfo (ConnectorTableHandle table )
177
170
{
178
- return ((HudiTableHandle ) table ).getPartitions ()
179
- .map (partitions -> new HudiInputInfo (
180
- partitions .stream ()
181
- .map (HivePartition ::getPartitionId )
182
- .collect (toImmutableList ())));
171
+ HudiTableHandle hudiTable = (HudiTableHandle ) table ;
172
+ return Optional .of (HudiTableInfo .from (hudiTable ));
183
173
}
184
174
185
175
@ Override
@@ -191,40 +181,26 @@ public List<SchemaTableName> listTables(ConnectorSession session, Optional<Strin
191
181
tableNames .add (schemaTableName (schemaName , tableName ));
192
182
}
193
183
}
194
-
195
- tableNames .addAll (listMaterializedViews (session , optionalSchemaName ));
196
184
return tableNames .build ();
197
185
}
198
186
199
187
@ Override
200
- public Map < SchemaTableName , List < ColumnMetadata >> listTableColumns (ConnectorSession session , SchemaTablePrefix prefix )
188
+ public Stream < TableColumnsMetadata > streamTableColumns (ConnectorSession session , SchemaTablePrefix prefix )
201
189
{
202
190
List <SchemaTableName > tables = prefix .getTable ()
203
191
.map (ignored -> singletonList (prefix .toSchemaTableName ()))
204
192
.orElseGet (() -> listTables (session , prefix .getSchema ()));
205
-
206
- ImmutableMap .Builder <SchemaTableName , List <ColumnMetadata >> columns = ImmutableMap .builder ();
207
- for (SchemaTableName table : tables ) {
208
- try {
209
- columns .put (table , getTableMetadata (table ).getColumns ());
210
- }
211
- catch (TableNotFoundException e ) {
212
- // table disappeared during listing operation
213
- }
214
- }
215
- return columns .buildOrThrow ();
193
+ return tables .stream ().map (table -> {
194
+ List <ColumnMetadata > columns = getTableMetadata (table ).getColumns ();
195
+ return TableColumnsMetadata .forTable (table , columns );
196
+ });
216
197
}
217
198
218
199
HiveMetastore getMetastore ()
219
200
{
220
201
return metastore ;
221
202
}
222
203
223
- void rollback ()
224
- {
225
- // TODO: cleanup open transaction when write will be supported
226
- }
227
-
228
204
private static Function <HiveColumnHandle , ColumnMetadata > columnMetadataGetter (Table table )
229
205
{
230
206
ImmutableList .Builder <String > columnNames = ImmutableList .builder ();
@@ -288,13 +264,6 @@ private boolean isHudiTable(ConnectorSession session, Table table)
288
264
return true ;
289
265
}
290
266
291
- private HoodieTableMetaClient getTableMetaClient (ConnectorSession session , Table table )
292
- {
293
- String basePath = table .getStorage ().getLocation ();
294
- Configuration conf = hdfsEnvironment .getConfiguration (new HdfsEnvironment .HdfsContext (session ), new Path (basePath ));
295
- return HoodieTableMetaClient .builder ().setConf (conf ).setBasePath (basePath ).build ();
296
- }
297
-
298
267
private ConnectorTableMetadata getTableMetadata (SchemaTableName tableName )
299
268
{
300
269
Table table = metastore .getTable (tableName .getSchemaName (), tableName .getTableName ())
0 commit comments