1
1
package com .redis .trino ;
2
2
3
- import static com .google .common .base .Preconditions .checkState ;
4
- import static com .google .common .collect .ImmutableList .toImmutableList ;
5
3
import static java .lang .Math .toIntExact ;
6
4
import static java .util .Objects .requireNonNull ;
7
5
import static java .util .stream .Collectors .toList ;
8
6
9
- import java .util .Collection ;
10
7
import java .util .List ;
11
8
import java .util .Map ;
12
9
import java .util .Optional ;
13
10
import java .util .OptionalInt ;
14
- import java .util .concurrent .atomic .AtomicReference ;
15
11
16
12
import com .google .common .collect .ImmutableList ;
17
13
import com .google .common .collect .ImmutableMap ;
18
14
19
- import io .airlift .slice .Slice ;
20
15
import io .trino .spi .connector .ColumnHandle ;
21
16
import io .trino .spi .connector .ColumnMetadata ;
22
- import io .trino .spi .connector .ConnectorInsertTableHandle ;
23
17
import io .trino .spi .connector .ConnectorMetadata ;
24
- import io .trino .spi .connector .ConnectorNewTableLayout ;
25
- import io .trino .spi .connector .ConnectorOutputMetadata ;
26
- import io .trino .spi .connector .ConnectorOutputTableHandle ;
27
18
import io .trino .spi .connector .ConnectorSession ;
28
19
import io .trino .spi .connector .ConnectorTableHandle ;
29
20
import io .trino .spi .connector .ConnectorTableMetadata ;
34
25
import io .trino .spi .connector .NotFoundException ;
35
26
import io .trino .spi .connector .SchemaTableName ;
36
27
import io .trino .spi .connector .SchemaTablePrefix ;
28
+ import io .trino .spi .connector .TableNotFoundException ;
37
29
import io .trino .spi .predicate .TupleDomain ;
38
- import io .trino .spi .statistics .ComputedStatistics ;
39
30
40
31
public class RediSearchMetadata implements ConnectorMetadata {
41
32
42
33
private final RediSearchSession rediSearchSession ;
43
- private final AtomicReference <Runnable > rollbackAction = new AtomicReference <>();
34
+ // private final AtomicReference<Runnable> rollbackAction = new AtomicReference<>();
44
35
private final String schemaName ;
45
36
46
37
public RediSearchMetadata (RediSearchSession rediSearchSession ) {
@@ -58,7 +49,11 @@ public RediSearchTableHandle getTableHandle(ConnectorSession session, SchemaTabl
58
49
requireNonNull (tableName , "tableName is null" );
59
50
60
51
if (tableName .getSchemaName ().equals (schemaName )) {
61
- return rediSearchSession .getTable (tableName ).getTableHandle ();
52
+ try {
53
+ return rediSearchSession .getTable (tableName ).getTableHandle ();
54
+ } catch (TableNotFoundException e ) {
55
+ // ignore and return null
56
+ }
62
57
}
63
58
return null ;
64
59
}
@@ -119,65 +114,55 @@ public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTable
119
114
return ((RediSearchColumnHandle ) columnHandle ).toColumnMetadata ();
120
115
}
121
116
122
- @ Override
123
- public void createTable (ConnectorSession session , ConnectorTableMetadata tableMetadata , boolean ignoreExisting ) {
124
- rediSearchSession .createTable (tableMetadata .getTable (), buildColumnHandles (tableMetadata ));
125
- }
126
-
127
- @ Override
128
- public void dropTable (ConnectorSession session , ConnectorTableHandle tableHandle ) {
129
- RediSearchTableHandle table = (RediSearchTableHandle ) tableHandle ;
130
-
131
- rediSearchSession .dropTable (table .getSchemaTableName ());
132
- }
133
-
134
- @ Override
135
- public void addColumn (ConnectorSession session , ConnectorTableHandle tableHandle , ColumnMetadata column ) {
136
- rediSearchSession .addColumn (((RediSearchTableHandle ) tableHandle ).getSchemaTableName (), column );
137
- }
138
-
139
- @ Override
140
- public void dropColumn (ConnectorSession session , ConnectorTableHandle tableHandle , ColumnHandle column ) {
141
- // TODO
142
- }
143
-
144
- @ Override
145
- public ConnectorOutputTableHandle beginCreateTable (ConnectorSession session , ConnectorTableMetadata tableMetadata ,
146
- Optional <ConnectorNewTableLayout > layout ) {
147
- List <RediSearchColumnHandle > columns = buildColumnHandles (tableMetadata );
148
-
149
- rediSearchSession .createTable (tableMetadata .getTable (), columns );
150
-
151
- setRollback (() -> rediSearchSession .dropTable (tableMetadata .getTable ()));
152
-
153
- return new RediSearchOutputTableHandle (tableMetadata .getTable (),
154
- columns .stream ().filter (c -> !c .isHidden ()).collect (toList ()));
155
- }
156
-
157
- @ Override
158
- public Optional <ConnectorOutputMetadata > finishCreateTable (ConnectorSession session ,
159
- ConnectorOutputTableHandle tableHandle , Collection <Slice > fragments ,
160
- Collection <ComputedStatistics > computedStatistics ) {
161
- clearRollback ();
162
- return Optional .empty ();
163
- }
164
-
165
- @ Override
166
- public ConnectorInsertTableHandle beginInsert (ConnectorSession session , ConnectorTableHandle tableHandle ) {
167
- RediSearchTableHandle table = (RediSearchTableHandle ) tableHandle ;
168
- List <RediSearchColumnHandle > columns = rediSearchSession .getTable (table .getSchemaTableName ()).getColumns ();
169
-
170
- return new RediSearchInsertTableHandle (table .getSchemaTableName (),
171
- columns .stream ().filter (column -> !column .isHidden ())
172
- .peek (column -> validateColumnNameForInsert (column .getName ())).collect (toImmutableList ()));
173
- }
174
-
175
- @ Override
176
- public Optional <ConnectorOutputMetadata > finishInsert (ConnectorSession session ,
177
- ConnectorInsertTableHandle insertHandle , Collection <Slice > fragments ,
178
- Collection <ComputedStatistics > computedStatistics ) {
179
- return Optional .empty ();
180
- }
117
+ // @Override
118
+ // public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting) {
119
+ // rediSearchSession.createTable(tableMetadata.getTable(), buildColumnHandles(tableMetadata));
120
+ // }
121
+ //
122
+ // @Override
123
+ // public void dropTable(ConnectorSession session, ConnectorTableHandle tableHandle) {
124
+ // RediSearchTableHandle table = (RediSearchTableHandle) tableHandle;
125
+ //
126
+ // rediSearchSession.dropTable(table.getSchemaTableName());
127
+ // }
128
+ //
129
+ // @Override
130
+ // public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata,
131
+ // Optional<ConnectorNewTableLayout> layout) {
132
+ // List<RediSearchColumnHandle> columns = buildColumnHandles(tableMetadata);
133
+ //
134
+ // rediSearchSession.createTable(tableMetadata.getTable(), columns);
135
+ //
136
+ // setRollback(() -> rediSearchSession.dropTable(tableMetadata.getTable()));
137
+ //
138
+ // return new RediSearchOutputTableHandle(tableMetadata.getTable(),
139
+ // columns.stream().filter(c -> !c.isHidden()).collect(toList()));
140
+ // }
141
+
142
+ // @Override
143
+ // public Optional<ConnectorOutputMetadata> finishCreateTable(ConnectorSession session,
144
+ // ConnectorOutputTableHandle tableHandle, Collection<Slice> fragments,
145
+ // Collection<ComputedStatistics> computedStatistics) {
146
+ // clearRollback();
147
+ // return Optional.empty();
148
+ // }
149
+
150
+ // @Override
151
+ // public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle tableHandle) {
152
+ // RediSearchTableHandle table = (RediSearchTableHandle) tableHandle;
153
+ // List<RediSearchColumnHandle> columns = rediSearchSession.getTable(table.getSchemaTableName()).getColumns();
154
+ //
155
+ // return new RediSearchInsertTableHandle(table.getSchemaTableName(),
156
+ // columns.stream().filter(column -> !column.isHidden())
157
+ // .peek(column -> validateColumnNameForInsert(column.getName())).collect(toImmutableList()));
158
+ // }
159
+ //
160
+ // @Override
161
+ // public Optional<ConnectorOutputMetadata> finishInsert(ConnectorSession session,
162
+ // ConnectorInsertTableHandle insertHandle, Collection<Slice> fragments,
163
+ // Collection<ComputedStatistics> computedStatistics) {
164
+ // return Optional.empty();
165
+ // }
181
166
182
167
@ Override
183
168
public boolean usesLegacyTableLayouts () {
@@ -225,17 +210,17 @@ public Optional<ConstraintApplicationResult<ConnectorTableHandle>> applyFilter(C
225
210
return Optional .of (new ConstraintApplicationResult <>(handle , constraint .getSummary (), false ));
226
211
}
227
212
228
- private void setRollback (Runnable action ) {
229
- checkState (rollbackAction .compareAndSet (null , action ), "rollback action is already set" );
230
- }
231
-
232
- private void clearRollback () {
233
- rollbackAction .set (null );
234
- }
213
+ // private void setRollback(Runnable action) {
214
+ // checkState(rollbackAction.compareAndSet(null, action), "rollback action is already set");
215
+ // }
216
+ //
217
+ // private void clearRollback() {
218
+ // rollbackAction.set(null);
219
+ // }
235
220
236
- public void rollback () {
237
- Optional .ofNullable (rollbackAction .getAndSet (null )).ifPresent (Runnable ::run );
238
- }
221
+ // public void rollback() {
222
+ // Optional.ofNullable(rollbackAction.getAndSet(null)).ifPresent(Runnable::run);
223
+ // }
239
224
240
225
private static SchemaTableName getTableName (ConnectorTableHandle tableHandle ) {
241
226
return ((RediSearchTableHandle ) tableHandle ).getSchemaTableName ();
@@ -251,14 +236,14 @@ private ConnectorTableMetadata getTableMetadata(ConnectorSession session, Schema
251
236
return new ConnectorTableMetadata (tableName , columns );
252
237
}
253
238
254
- private static List <RediSearchColumnHandle > buildColumnHandles (ConnectorTableMetadata tableMetadata ) {
255
- return tableMetadata .getColumns ().stream ()
256
- .map (m -> new RediSearchColumnHandle (m .getName (), m .getType (), m .isHidden ())).collect (toList ());
257
- }
239
+ // private static List<RediSearchColumnHandle> buildColumnHandles(ConnectorTableMetadata tableMetadata) {
240
+ // return tableMetadata.getColumns().stream()
241
+ // .map(m -> new RediSearchColumnHandle(m.getName(), m.getType(), m.isHidden())).collect(toList());
242
+ // }
258
243
259
- private static void validateColumnNameForInsert (String columnName ) {
260
- if (columnName .contains ("$" ) || columnName .contains ("." )) {
261
- throw new IllegalArgumentException ("Column name must not contain '$' or '.' for INSERT: " + columnName );
262
- }
263
- }
244
+ // private static void validateColumnNameForInsert(String columnName) {
245
+ // if (columnName.contains("$") || columnName.contains(".")) {
246
+ // throw new IllegalArgumentException("Column name must not contain '$' or '.' for INSERT: " + columnName);
247
+ // }
248
+ // }
264
249
}
0 commit comments