2626import static com .google .common .base .Preconditions .checkState ;
2727import static com .google .common .base .Verify .verify ;
2828import static com .google .common .base .Verify .verifyNotNull ;
29+ import static com .google .common .collect .ImmutableList .toImmutableList ;
2930import static com .google .common .collect .ImmutableSet .toImmutableSet ;
3031import static io .airlift .slice .SliceUtf8 .getCodePointAt ;
3132import static io .trino .spi .StandardErrorCode .INVALID_FUNCTION_ARGUMENT ;
32- import static io .trino .spi .StandardErrorCode .NOT_SUPPORTED ;
33- import static io .trino .spi .connector .RetryMode .NO_RETRIES ;
3433import static io .trino .spi .expression .StandardFunctions .LIKE_FUNCTION_NAME ;
3534import static java .util .Objects .requireNonNull ;
3635
@@ -205,9 +204,7 @@ public void dropColumn(ConnectorSession session, ConnectorTableHandle tableHandl
205204 @ Override
206205 public ConnectorOutputTableHandle beginCreateTable (ConnectorSession session , ConnectorTableMetadata tableMetadata ,
207206 Optional <ConnectorTableLayout > layout , RetryMode retryMode ) {
208- if (retryMode != RetryMode .NO_RETRIES ) {
209- throw new TrinoException (StandardErrorCode .NOT_SUPPORTED , "This connector does not support query retries" );
210- }
207+ checkRetry (retryMode );
211208 List <RediSearchColumnHandle > columns = buildColumnHandles (tableMetadata );
212209
213210 rediSearchSession .createTable (tableMetadata .getTable (), columns );
@@ -218,6 +215,12 @@ public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, Con
218215 columns .stream ().filter (c -> !c .isHidden ()).collect (Collectors .toList ()));
219216 }
220217
218+ private void checkRetry (RetryMode retryMode ) {
219+ if (retryMode != RetryMode .NO_RETRIES ) {
220+ throw new TrinoException (StandardErrorCode .NOT_SUPPORTED , "This connector does not support retries" );
221+ }
222+ }
223+
221224 @ Override
222225 public Optional <ConnectorOutputMetadata > finishCreateTable (ConnectorSession session ,
223226 ConnectorOutputTableHandle tableHandle , Collection <Slice > fragments ,
@@ -229,9 +232,7 @@ public Optional<ConnectorOutputMetadata> finishCreateTable(ConnectorSession sess
229232 @ Override
230233 public ConnectorInsertTableHandle beginInsert (ConnectorSession session , ConnectorTableHandle tableHandle ,
231234 List <ColumnHandle > insertedColumns , RetryMode retryMode ) {
232- if (retryMode != RetryMode .NO_RETRIES ) {
233- throw new TrinoException (StandardErrorCode .NOT_SUPPORTED , "This connector does not support query retries" );
234- }
235+ checkRetry (retryMode );
235236 RediSearchTableHandle table = (RediSearchTableHandle ) tableHandle ;
236237 List <RediSearchColumnHandle > columns = rediSearchSession .getTable (table .getSchemaTableName ()).getColumns ();
237238
@@ -255,14 +256,34 @@ public RediSearchColumnHandle getDeleteRowIdColumnHandle(ConnectorSession sessio
255256 @ Override
256257 public RediSearchTableHandle beginDelete (ConnectorSession session , ConnectorTableHandle tableHandle ,
257258 RetryMode retryMode ) {
258- if (retryMode != NO_RETRIES ) {
259- throw new TrinoException (NOT_SUPPORTED , "This connector does not support query retries" );
260- }
259+ checkRetry (retryMode );
261260 return (RediSearchTableHandle ) tableHandle ;
262261 }
263262
264263 @ Override
265264 public void finishDelete (ConnectorSession session , ConnectorTableHandle tableHandle , Collection <Slice > fragments ) {
265+ // Do nothing
266+ }
267+
268+ @ Override
269+ public RediSearchColumnHandle getUpdateRowIdColumnHandle (ConnectorSession session , ConnectorTableHandle tableHandle ,
270+ List <ColumnHandle > updatedColumns ) {
271+ return RediSearchBuiltinField .ID .getColumnHandle ();
272+ }
273+
274+ @ Override
275+ public RediSearchTableHandle beginUpdate (ConnectorSession session , ConnectorTableHandle tableHandle ,
276+ List <ColumnHandle > updatedColumns , RetryMode retryMode ) {
277+ checkRetry (retryMode );
278+ RediSearchTableHandle table = (RediSearchTableHandle ) tableHandle ;
279+ return new RediSearchTableHandle (table .getType (), table .getSchemaTableName (), table .getConstraint (),
280+ table .getLimit (), table .getTermAggregations (), table .getMetricAggregations (), table .getWildcards (),
281+ updatedColumns .stream ().map (RediSearchColumnHandle .class ::cast ).collect (toImmutableList ()));
282+ }
283+
284+ @ Override
285+ public void finishUpdate (ConnectorSession session , ConnectorTableHandle tableHandle , Collection <Slice > fragments ) {
286+ // Do nothing
266287 }
267288
268289 @ Override
@@ -285,9 +306,11 @@ public Optional<LimitApplicationResult<ConnectorTableHandle>> applyLimit(Connect
285306 return Optional .empty ();
286307 }
287308
288- return Optional .of (new LimitApplicationResult <>(new RediSearchTableHandle (handle .getType (),
289- handle .getSchemaTableName (), handle .getConstraint (), OptionalLong .of (limit ),
290- handle .getTermAggregations (), handle .getMetricAggregations (), handle .getWildcards ()), true , false ));
309+ return Optional .of (new LimitApplicationResult <>(
310+ new RediSearchTableHandle (handle .getType (), handle .getSchemaTableName (), handle .getConstraint (),
311+ OptionalLong .of (limit ), handle .getTermAggregations (), handle .getMetricAggregations (),
312+ handle .getWildcards (), handle .getUpdatedColumns ()),
313+ true , false ));
291314 }
292315
293316 @ Override
@@ -350,7 +373,7 @@ public Optional<ConstraintApplicationResult<ConnectorTableHandle>> applyFilter(C
350373 }
351374
352375 handle = new RediSearchTableHandle (handle .getType (), handle .getSchemaTableName (), newDomain , handle .getLimit (),
353- handle .getTermAggregations (), handle .getMetricAggregations (), newWildcards );
376+ handle .getTermAggregations (), handle .getMetricAggregations (), newWildcards , handle . getUpdatedColumns () );
354377
355378 return Optional .of (new ConstraintApplicationResult <>(handle , TupleDomain .withColumnDomains (unsupported ),
356379 newExpression , false ));
@@ -476,7 +499,8 @@ public Optional<AggregationApplicationResult<ConnectorTableHandle>> applyAggrega
476499 return Optional .empty ();
477500 }
478501 RediSearchTableHandle tableHandle = new RediSearchTableHandle (Type .AGGREGATE , table .getSchemaTableName (),
479- table .getConstraint (), table .getLimit (), terms .build (), aggregationList , table .getWildcards ());
502+ table .getConstraint (), table .getLimit (), terms .build (), aggregationList , table .getWildcards (),
503+ table .getUpdatedColumns ());
480504 return Optional .of (new AggregationApplicationResult <>(tableHandle , projections .build (),
481505 resultAssignments .build (), Map .of (), false ));
482506 }
0 commit comments