@@ -212,7 +212,7 @@ public synchronized ConnectorTableHandle getTableHandle(ConnectorSession session
212212 return null ;
213213 }
214214
215- return new MemoryTableHandle (id , OptionalLong .empty (), OptionalDouble .empty ());
215+ return new MemoryTableHandle (id , schemaTableName , OptionalLong .empty (), OptionalDouble .empty ());
216216 }
217217
218218 @ Override
@@ -243,9 +243,8 @@ public synchronized List<SchemaTableName> listTables(ConnectorSession session, O
243243 public synchronized Map <String , ColumnHandle > getColumnHandles (ConnectorSession session , ConnectorTableHandle tableHandle )
244244 {
245245 MemoryTableHandle handle = (MemoryTableHandle ) tableHandle ;
246- return tables .get (handle .id ())
247- .columns ().stream ()
248- .collect (toImmutableMap (ColumnInfo ::name , ColumnInfo ::handle ));
246+ return tables .get (handle .id ()).columns ().stream ()
247+ .collect (toImmutableMap (column -> column .handle ().name (), ColumnInfo ::handle ));
249248 }
250249
251250 @ Override
@@ -348,7 +347,8 @@ public synchronized MemoryOutputTableHandle beginCreateTable(ConnectorSession se
348347 ImmutableList .Builder <ColumnInfo > columns = ImmutableList .builder ();
349348 for (int i = 0 ; i < tableMetadata .getColumns ().size (); i ++) {
350349 ColumnMetadata column = tableMetadata .getColumns ().get (i );
351- columns .add (new ColumnInfo (new MemoryColumnHandle (i , column .getType ()), column .getName (), column .getType (), column .isNullable (), Optional .ofNullable (column .getComment ())));
350+ MemoryColumnHandle handle = new MemoryColumnHandle (i , column .getName (), column .getType ());
351+ columns .add (new ColumnInfo (handle , column .isNullable (), Optional .ofNullable (column .getComment ())));
352352 }
353353
354354 tableIds .put (tableMetadata .getTable (), tableId );
@@ -446,9 +446,11 @@ public synchronized void addColumn(ConnectorSession session, ConnectorTableHandl
446446 throw new TrinoException (NOT_SUPPORTED , format ("Unable to add NOT NULL column '%s' for non-empty table: %s" , column .getName (), table .getSchemaTableName ()));
447447 }
448448
449+ MemoryColumnHandle newColumn = new MemoryColumnHandle (table .columns ().size (), column .getName (), column .getType ());
450+
449451 List <ColumnInfo > columns = ImmutableList .<ColumnInfo >builderWithExpectedSize (table .columns ().size () + 1 )
450452 .addAll (table .columns ())
451- .add (new ColumnInfo (new MemoryColumnHandle ( table . columns (). size (), column . getType ()), column . getName (), column . getType () , column .isNullable (), Optional .ofNullable (column .getComment ())))
453+ .add (new ColumnInfo (newColumn , column .isNullable (), Optional .ofNullable (column .getComment ())))
452454 .build ();
453455
454456 tables .put (tableId , new TableInfo (tableId , table .schemaName (), table .tableName (), columns , table .truncated (), table .dataFragments (), table .comment ()));
@@ -462,9 +464,11 @@ public synchronized void renameColumn(ConnectorSession session, ConnectorTableHa
462464 long tableId = handle .id ();
463465 TableInfo table = tables .get (handle .id ());
464466
467+ MemoryColumnHandle newColumn = new MemoryColumnHandle (column .columnIndex (), target , column .type ());
468+
465469 List <ColumnInfo > columns = new ArrayList <>(table .columns ());
466470 ColumnInfo columnInfo = columns .get (column .columnIndex ());
467- columns .set (column .columnIndex (), new ColumnInfo (columnInfo . handle (), target , columnInfo . type () , columnInfo .nullable (), columnInfo .comment ()));
471+ columns .set (column .columnIndex (), new ColumnInfo (newColumn , columnInfo .nullable (), columnInfo .comment ()));
468472
469473 tables .put (tableId , new TableInfo (tableId , table .schemaName (), table .tableName (), ImmutableList .copyOf (columns ), table .truncated (), table .dataFragments (), table .comment ()));
470474 }
@@ -479,7 +483,7 @@ public synchronized void dropNotNullConstraint(ConnectorSession session, Connect
479483
480484 List <ColumnInfo > columns = new ArrayList <>(table .columns ());
481485 ColumnInfo columnInfo = columns .get (column .columnIndex ());
482- columns .set (column .columnIndex (), new ColumnInfo (columnInfo .handle (), columnInfo . name (), columnInfo . type (), true , columnInfo .comment ()));
486+ columns .set (column .columnIndex (), new ColumnInfo (columnInfo .handle (), true , columnInfo .comment ()));
483487
484488 tables .put (tableId , new TableInfo (tableId , table .schemaName (), table .tableName (), ImmutableList .copyOf (columns ), table .truncated (), table .dataFragments (), table .comment ()));
485489 }
@@ -626,10 +630,7 @@ public Optional<LimitApplicationResult<ConnectorTableHandle>> applyLimit(Connect
626630 return Optional .empty ();
627631 }
628632
629- return Optional .of (new LimitApplicationResult <>(
630- new MemoryTableHandle (table .id (), OptionalLong .of (limit ), OptionalDouble .empty ()),
631- true ,
632- true ));
633+ return Optional .of (new LimitApplicationResult <>(table .withLimit (limit ), true , true ));
633634 }
634635
635636 @ Override
@@ -641,9 +642,8 @@ public Optional<SampleApplicationResult<ConnectorTableHandle>> applySample(Conne
641642 return Optional .empty ();
642643 }
643644
644- return Optional .of (new SampleApplicationResult <>(
645- new MemoryTableHandle (table .id (), table .limit (), OptionalDouble .of (table .sampleRatio ().orElse (1 ) * sampleRatio )),
646- true ));
645+ double newRatio = table .sampleRatio ().orElse (1 ) * sampleRatio ;
646+ return Optional .of (new SampleApplicationResult <>(table .withSampleRatio (newRatio ), true ));
647647 }
648648
649649 @ Override
@@ -667,18 +667,12 @@ public synchronized void setColumnComment(ConnectorSession session, ConnectorTab
667667 MemoryTableHandle table = (MemoryTableHandle ) tableHandle ;
668668 TableInfo info = tables .get (table .id ());
669669 checkArgument (info != null , "Table not found" );
670- tables .put (
671- table .id (),
672- new TableInfo (
673- table .id (),
674- info .schemaName (),
675- info .tableName (),
676- info .columns ().stream ()
677- .map (tableColumn -> Objects .equals (tableColumn .handle (), columnHandle ) ? new ColumnInfo (tableColumn .handle (), tableColumn .name (), tableColumn .getMetadata ().getType (), tableColumn .nullable (), comment ) : tableColumn )
678- .collect (toImmutableList ()),
679- info .truncated (),
680- info .dataFragments (),
681- info .comment ()));
670+ List <ColumnInfo > newColumns = info .columns ().stream ()
671+ .map (column -> column .handle ().equals (columnHandle )
672+ ? new ColumnInfo (column .handle (), column .nullable (), comment )
673+ : column )
674+ .collect (toImmutableList ());
675+ tables .put (table .id (), new TableInfo (table .id (), info .schemaName (), info .tableName (), newColumns , info .truncated (), info .dataFragments (), info .comment ()));
682676 }
683677
684678 @ Override
0 commit comments