public QueryConfiguration applyOverrides(QueryConfigurationOverrides overrides)
    {
        Map<String, String> sessionProperties;
        if (overrides.getSessionPropertiesOverrideStrategy() == OVERRIDE) {
            sessionProperties = new HashMap<>(overrides.getSessionPropertiesOverride());
        }
        else {
            sessionProperties = new HashMap<>(this.sessionProperties);
            if (overrides.getSessionPropertiesOverrideStrategy() == SUBSTITUTE) {
                sessionProperties.putAll(overrides.getSessionPropertiesOverride());
            }
        }
        overrides.getSessionPropertiesToRemove().forEach(sessionProperties::remove);
        return new QueryConfiguration(
                overrides.getCatalogOverride().orElse(catalog),
                overrides.getSchemaOverride().orElse(schema),
                Optional.ofNullable(overrides.getUsernameOverride().orElse(username.orElse(null))),
                Optional.ofNullable(overrides.getPasswordOverride().orElse(password.orElse(null))),
                Optional.of(sessionProperties),
                isReusableTable,
                Optional.of(partitions));
    }
@Test
    public void testSessionPropertySubstitute()
    {
        overrides.setSessionPropertiesOverrideStrategy(SUBSTITUTE);
        QueryConfiguration substituted1 = new QueryConfiguration(
                CATALOG_OVERRIDE,
                SCHEMA_OVERRIDE,
                Optional.of(USERNAME_OVERRIDE),
                Optional.of(PASSWORD_OVERRIDE),
                Optional.of(ImmutableMap.of("property_1", "value_x", "property_2", "value_2", "property_3", "value_3")),
                Optional.of(CLIENT_TAGS),
                Optional.empty());

        assertEquals(CONFIGURATION_1.applyOverrides(overrides), substituted1);

        QueryConfiguration substituted2 = new QueryConfiguration(
                CATALOG_OVERRIDE,
                SCHEMA_OVERRIDE,
                Optional.of(USERNAME_OVERRIDE),
                Optional.of(PASSWORD_OVERRIDE),
                Optional.of(SESSION_PROPERTIES_OVERRIDE),
                false,
                Optional.empty());
        assertEquals(CONFIGURATION_2.applyOverrides(overrides), substituted2);
    }