@Override
  public boolean schemaExists(SnowflakeIdentifier schema) {
    Preconditions.checkArgument(
        schema.type() == SnowflakeIdentifier.Type.SCHEMA,
        "schemaExists requires a SCHEMA identifier, got '%s'",
        schema);

    if (!databaseExists(SnowflakeIdentifier.ofDatabase(schema.databaseName()))) {
      return false;
    }

    final String finalQuery = "SHOW TABLES IN SCHEMA IDENTIFIER(?) LIMIT 1";

    try {
      connectionPool.run(
          conn ->
              queryHarness.query(
                  conn, finalQuery, TABLE_RESULT_SET_HANDLER, schema.toIdentifierString()));
    } catch (SQLException e) {
      if (SCHEMA_NOT_FOUND_ERROR_CODES.contains(e.getErrorCode())) {
        return false;
      }
      throw new UncheckedSQLException(e, "Failed to check if schema '%s' exists", schema);
    } catch (InterruptedException e) {
      throw new UncheckedInterruptedException(
          e, "Interrupted while checking if schema '%s' exists", schema);
    }

    return true;
  }
@SuppressWarnings("unchecked")
  @Test
  public void testSchemaExists() throws SQLException {
    when(mockResultSet.next())
        .thenReturn(true)
        .thenReturn(false)
        .thenReturn(true)
        .thenReturn(false);
    when(mockResultSet.getString("name")).thenReturn("DB1").thenReturn("SCHEMA1");
    when(mockResultSet.getString("database_name")).thenReturn("DB1");
    when(mockResultSet.getString("schema_name")).thenReturn("SCHEMA1");

    assertThat(snowflakeClient.schemaExists(SnowflakeIdentifier.ofSchema("DB1", "SCHEMA1")))
        .isTrue();

    verify(mockQueryHarness)
        .query(
            eq(mockConnection),
            eq("SHOW SCHEMAS IN DATABASE IDENTIFIER(?) LIMIT 1"),
            any(JdbcSnowflakeClient.ResultSetParser.class),
            eq("DB1"));
    verify(mockQueryHarness)
        .query(
            eq(mockConnection),
            eq("SHOW TABLES IN SCHEMA IDENTIFIER(?) LIMIT 1"),
            any(JdbcSnowflakeClient.ResultSetParser.class),
            eq("DB1.SCHEMA1"));
  }