public static Map<String, SqlType> resolveOldAndNewLambdaMapping(
      final Map<String, SqlType> newMapping,
      final Map<String, SqlType> oldMapping
  ) {
    final HashMap<String, SqlType> updatedMapping = new HashMap<>(oldMapping);
    for (final Entry<String, SqlType> entry : newMapping.entrySet()) {
      final String key = entry.getKey();
      if (oldMapping.containsKey(key) && !oldMapping.get(key).equals(newMapping.get(key))) {
        throw new IllegalStateException(String.format(
            "Could not map type %s to lambda variable %s, "
                + "%s was already mapped to %s",
            newMapping.get(key).toString(),
            key,
            key,
            oldMapping.get(key).toString()));
      }
      updatedMapping.put(key, entry.getValue());
    }
    return updatedMapping;
  }
@Test
  public void shouldCopyContextWithLambdaMapping() {
    // Given
    final Map<String, SqlType> oldMapping = new HashMap<>(ImmutableMap.of("x", SqlTypes.STRING, "y", SqlTypes.BIGINT));
    final Map<String, SqlType> newMapping = new HashMap<>(ImmutableMap.of("x", SqlTypes.STRING, "z", SqlTypes.BOOLEAN));

    // When
    final Map<String, SqlType> updatedMapping = LambdaMappingUtil.resolveOldAndNewLambdaMapping(oldMapping, newMapping);

    // Then
    assertThat(updatedMapping.get("x"), is(SqlTypes.STRING));
    assertThat(updatedMapping.get("y"), is(SqlTypes.BIGINT));
    assertThat(updatedMapping.get("z"), is(SqlTypes.BOOLEAN));
  }