Source:
<code>public static BoundedRestoreSnapshot createStatement(AnalyzedRestoreSnapshot restoreSnapshot, CoordinatorTxnCtx txnCtx, Functions functions, Row parameters, SubQueryResults subQueryResults, Schemas schemas) { Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate( txnCtx, functions, x, parameters, subQueryResults ); Settings settings = GenericPropertiesConverter.genericPropertiesToSettings( restoreSnapshot.properties().map(eval), SnapshotSettings.SETTINGS ); HashSet<BoundedRestoreSnapshot.RestoreTableInfo> restoreTables = new HashSet<>(restoreSnapshot.tables().size()); for (Table<Symbol> table : restoreSnapshot.tables()) { var relationName = RelationName.of( table.getName(), txnCtx.sessionContext().searchPath().currentSchema()); if (schemas.tableExists(relationName)) { if (table.partitionProperties().isEmpty()) { throw new RelationAlreadyExists(relationName); } <START> DocTableInfo docTableInfo = schemas.getTableInfo(relationName, Operation.RESTORE_SNAPSHOT); <END> var partitionName = toPartitionName( relationName, docTableInfo, Lists2.map(table.partitionProperties(), x -> x.map(eval))); if (docTableInfo.partitions().contains(partitionName)) { throw new PartitionAlreadyExistsException(partitionName); } restoreTables.add(new BoundedRestoreSnapshot.RestoreTableInfo(relationName, partitionName)); } else { if (table.partitionProperties().isEmpty()) { restoreTables.add(new BoundedRestoreSnapshot.RestoreTableInfo(relationName, null)); } else { var partitionName = toPartitionName( relationName, null, Lists2.map(table.partitionProperties(), x -> x.map(eval))); restoreTables.add( new BoundedRestoreSnapshot.RestoreTableInfo(relationName, partitionName)); } } } return new BoundedRestoreSnapshot( restoreSnapshot.repository(), restoreSnapshot.snapshot(), restoreTables, settings); }</code><technical_language>I this a race condition tableExists getTableInfo. remove tableExists wrap getTableInfo a try/catch block</technical_language>

Target:
public static BoundedRestoreSnapshot createStatement(AnalyzedRestoreSnapshot restoreSnapshot, CoordinatorTxnCtx txnCtx, Functions functions, Row parameters, SubQueryResults subQueryResults, Schemas schemas) { Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate( txnCtx, functions, x, parameters, subQueryResults ); Settings settings = GenericPropertiesConverter.genericPropertiesToSettings( restoreSnapshot.properties().map(eval), SnapshotSettings.SETTINGS ); HashSet<BoundedRestoreSnapshot.RestoreTableInfo> restoreTables = new HashSet<>(restoreSnapshot.tables().size()); for (Table<Symbol> table : restoreSnapshot.tables()) { var relationName = RelationName.of( table.getName(), txnCtx.sessionContext().searchPath().currentSchema()); try { DocTableInfo docTableInfo = schemas.getTableInfo(relationName, Operation.RESTORE_SNAPSHOT); if (table.partitionProperties().isEmpty()) { throw new RelationAlreadyExists(relationName); } var partitionName = toPartitionName( relationName, docTableInfo, Lists2.map(table.partitionProperties(), x -> x.map(eval))); if (docTableInfo.partitions().contains(partitionName)) { throw new PartitionAlreadyExistsException(partitionName); } restoreTables.add(new BoundedRestoreSnapshot.RestoreTableInfo(relationName, partitionName)); } catch (RelationUnknown | SchemaUnknownException e) { if (table.partitionProperties().isEmpty()) { restoreTables.add(new BoundedRestoreSnapshot.RestoreTableInfo(relationName, null)); } else { var partitionName = toPartitionName( relationName, null, Lists2.map(table.partitionProperties(), x -> x.map(eval))); restoreTables.add( new BoundedRestoreSnapshot.RestoreTableInfo(relationName, partitionName)); } } } return new BoundedRestoreSnapshot( restoreSnapshot.repository(), restoreSnapshot.snapshot(), restoreTables, settings); }