public boolean tableNotExistsOrDoesNotMatchSpecification(String tableName) {
    TableId tableId = TableId.of(projectId, datasetName, tableName);
    Table table = bigquery.getTable(tableId);
    if (table == null || !table.exists()) {
      return true;
    }
    ExternalTableDefinition externalTableDefinition = table.getDefinition();
    boolean manifestDoesNotExist =
        externalTableDefinition.getSourceUris() == null
            || externalTableDefinition.getSourceUris().stream().noneMatch(uri -> uri.contains(ManifestFileWriter.ABSOLUTE_PATH_MANIFEST_FOLDER_NAME));
    if (isBasePathUpdated(externalTableDefinition)) {
      // if table base path is outdated, we need to replace the table.
      return true;
    }
    if (!StringUtils.isNullOrEmpty(config.getString(BIGQUERY_SYNC_BIG_LAKE_CONNECTION_ID))) {
      // If bigLakeConnectionId is present and connectionId is not present in table definition, we need to replace the table.
      return manifestDoesNotExist || externalTableDefinition.getConnectionId() == null;
    }
    return manifestDoesNotExist;
  }
@Test
  void testTableNotExistsOrDoesNotMatchSpecification() {
    BigQuerySyncConfig config = new BigQuerySyncConfig(properties);
    client = new HoodieBigQuerySyncClient(config, mockBigQuery);
    // table does not exist
    assertTrue(client.tableNotExistsOrDoesNotMatchSpecification(TEST_TABLE));

    TableId tableId = TableId.of(PROJECT_ID, TEST_DATASET, TEST_TABLE);
    Table table = mock(Table.class);
    when(mockBigQuery.getTable(tableId)).thenReturn(table);

    ExternalTableDefinition externalTableDefinition = mock(ExternalTableDefinition.class);
    when(table.exists()).thenReturn(true);
    when(table.getDefinition()).thenReturn(externalTableDefinition);

    // manifest does not exist
    when(externalTableDefinition.getSourceUris()).thenReturn(Collections.emptyList());
    assertTrue(client.tableNotExistsOrDoesNotMatchSpecification(TEST_TABLE));

    // manifest exists but base path is outdated
    when(externalTableDefinition.getSourceUris()).thenReturn(Collections.singletonList(
        basePath + "/.hoodie/" + ManifestFileWriter.ABSOLUTE_PATH_MANIFEST_FOLDER_NAME));
    assertFalse(client.tableNotExistsOrDoesNotMatchSpecification(TEST_TABLE));

    // manifest exists but base path is outdated
    when(externalTableDefinition.getSourceUris()).thenReturn(Collections.singletonList(ManifestFileWriter.ABSOLUTE_PATH_MANIFEST_FOLDER_NAME));
    when(externalTableDefinition.getHivePartitioningOptions()).thenReturn(
        HivePartitioningOptions.newBuilder().setSourceUriPrefix(basePath + "1").build());
    assertTrue(client.tableNotExistsOrDoesNotMatchSpecification(TEST_TABLE));

    // manifest exists, base path is up-to-date
    when(externalTableDefinition.getHivePartitioningOptions()).thenReturn(
        HivePartitioningOptions.newBuilder().setSourceUriPrefix(basePath + "/").build());
    assertFalse(client.tableNotExistsOrDoesNotMatchSpecification(TEST_TABLE));
  }