22
22
import com .google .errorprone .annotations .concurrent .GuardedBy ;
23
23
import com .google .inject .Inject ;
24
24
import io .airlift .slice .Slice ;
25
+ import io .trino .plugin .memory .MemoryInsertTableHandle .InsertMode ;
25
26
import io .trino .spi .HostAddress ;
26
27
import io .trino .spi .Node ;
27
28
import io .trino .spi .NodeManager ;
@@ -277,7 +278,7 @@ public synchronized void renameTable(ConnectorSession session, ConnectorTableHan
277
278
long tableId = handle .id ();
278
279
279
280
TableInfo oldInfo = tables .get (tableId );
280
- tables .put (tableId , new TableInfo (tableId , newTableName .getSchemaName (), newTableName .getTableName (), oldInfo .columns (), oldInfo .dataFragments (), oldInfo .comment ()));
281
+ tables .put (tableId , new TableInfo (tableId , newTableName .getSchemaName (), newTableName .getTableName (), oldInfo .columns (), oldInfo .truncated (), oldInfo . dataFragments (), oldInfo .comment ()));
281
282
282
283
tableIds .remove (oldInfo .getSchemaTableName ());
283
284
tableIds .put (newTableName , tableId );
@@ -311,6 +312,7 @@ public synchronized MemoryOutputTableHandle beginCreateTable(ConnectorSession se
311
312
tableMetadata .getTable ().getSchemaName (),
312
313
tableMetadata .getTable ().getTableName (),
313
314
columns .build (),
315
+ false ,
314
316
new HashMap <>(),
315
317
tableMetadata .getComment ()));
316
318
@@ -350,7 +352,10 @@ public synchronized Optional<ConnectorOutputMetadata> finishCreateTable(Connecto
350
352
public synchronized MemoryInsertTableHandle beginInsert (ConnectorSession session , ConnectorTableHandle tableHandle , List <ColumnHandle > columns , RetryMode retryMode )
351
353
{
352
354
MemoryTableHandle memoryTableHandle = (MemoryTableHandle ) tableHandle ;
353
- return new MemoryInsertTableHandle (memoryTableHandle .id (), ImmutableSet .copyOf (tableIds .values ()));
355
+ TableInfo tableInfo = tables .get (memoryTableHandle .id ());
356
+ InsertMode mode = tableInfo .truncated () ? InsertMode .OVERWRITE : InsertMode .APPEND ;
357
+ tables .put (tableInfo .id (), new TableInfo (tableInfo .id (), tableInfo .schemaName (), tableInfo .tableName (), tableInfo .columns (), false , tableInfo .dataFragments (), tableInfo .comment ()));
358
+ return new MemoryInsertTableHandle (memoryTableHandle .id (), mode , ImmutableSet .copyOf (tableIds .values ()));
354
359
}
355
360
356
361
@ Override
@@ -374,7 +379,7 @@ public synchronized void truncateTable(ConnectorSession session, ConnectorTableH
374
379
MemoryTableHandle handle = (MemoryTableHandle ) tableHandle ;
375
380
long tableId = handle .id ();
376
381
TableInfo info = tables .get (handle .id ());
377
- tables .put (tableId , new TableInfo (tableId , info .schemaName (), info .tableName (), info .columns (), ImmutableMap .of (), info .comment ()));
382
+ tables .put (tableId , new TableInfo (tableId , info .schemaName (), info .tableName (), info .columns (), true , ImmutableMap .of (), info .comment ()));
378
383
}
379
384
380
385
@ Override
@@ -393,7 +398,7 @@ public synchronized void addColumn(ConnectorSession session, ConnectorTableHandl
393
398
.add (new ColumnInfo (new MemoryColumnHandle (table .columns ().size (), column .getType ()), column .getName (), column .getType (), column .isNullable (), Optional .ofNullable (column .getComment ())))
394
399
.build ();
395
400
396
- tables .put (tableId , new TableInfo (tableId , table .schemaName (), table .tableName (), columns , table .dataFragments (), table .comment ()));
401
+ tables .put (tableId , new TableInfo (tableId , table .schemaName (), table .tableName (), columns , table .truncated (), table . dataFragments (), table .comment ()));
397
402
}
398
403
399
404
@ Override
@@ -408,7 +413,7 @@ public synchronized void renameColumn(ConnectorSession session, ConnectorTableHa
408
413
ColumnInfo columnInfo = columns .get (column .columnIndex ());
409
414
columns .set (column .columnIndex (), new ColumnInfo (columnInfo .handle (), target , columnInfo .type (), columnInfo .nullable (), columnInfo .comment ()));
410
415
411
- tables .put (tableId , new TableInfo (tableId , table .schemaName (), table .tableName (), ImmutableList .copyOf (columns ), table .dataFragments (), table .comment ()));
416
+ tables .put (tableId , new TableInfo (tableId , table .schemaName (), table .tableName (), ImmutableList .copyOf (columns ), table .truncated (), table . dataFragments (), table .comment ()));
412
417
}
413
418
414
419
@ Override
@@ -423,7 +428,7 @@ public synchronized void dropNotNullConstraint(ConnectorSession session, Connect
423
428
ColumnInfo columnInfo = columns .get (column .columnIndex ());
424
429
columns .set (column .columnIndex (), new ColumnInfo (columnInfo .handle (), columnInfo .name (), columnInfo .type (), true , columnInfo .comment ()));
425
430
426
- tables .put (tableId , new TableInfo (tableId , table .schemaName (), table .tableName (), ImmutableList .copyOf (columns ), table .dataFragments (), table .comment ()));
431
+ tables .put (tableId , new TableInfo (tableId , table .schemaName (), table .tableName (), ImmutableList .copyOf (columns ), table .truncated (), table . dataFragments (), table .comment ()));
427
432
}
428
433
429
434
@ Override
@@ -538,7 +543,7 @@ private void updateRowsOnHosts(long tableId, Collection<Slice> fragments)
538
543
dataFragments .merge (memoryDataFragment .hostAddress (), memoryDataFragment , MemoryDataFragment ::merge );
539
544
}
540
545
541
- tables .put (tableId , new TableInfo (tableId , info .schemaName (), info .tableName (), info .columns (), dataFragments , info .comment ()));
546
+ tables .put (tableId , new TableInfo (tableId , info .schemaName (), info .tableName (), info .columns (), info . truncated (), dataFragments , info .comment ()));
542
547
}
543
548
544
549
public synchronized List <MemoryDataFragment > getDataFragments (long tableId )
@@ -599,7 +604,7 @@ public synchronized void setTableComment(ConnectorSession session, ConnectorTabl
599
604
MemoryTableHandle table = (MemoryTableHandle ) tableHandle ;
600
605
TableInfo info = tables .get (table .id ());
601
606
checkArgument (info != null , "Table not found" );
602
- tables .put (table .id (), new TableInfo (table .id (), info .schemaName (), info .tableName (), info .columns (), info .dataFragments (), comment ));
607
+ tables .put (table .id (), new TableInfo (table .id (), info .schemaName (), info .tableName (), info .columns (), info .truncated (), info . dataFragments (), comment ));
603
608
}
604
609
605
610
@ Override
@@ -617,6 +622,7 @@ public synchronized void setColumnComment(ConnectorSession session, ConnectorTab
617
622
info .columns ().stream ()
618
623
.map (tableColumn -> Objects .equals (tableColumn .handle (), columnHandle ) ? new ColumnInfo (tableColumn .handle (), tableColumn .name (), tableColumn .getMetadata ().getType (), tableColumn .nullable (), comment ) : tableColumn )
619
624
.collect (toImmutableList ()),
625
+ info .truncated (),
620
626
info .dataFragments (),
621
627
info .comment ()));
622
628
}
0 commit comments