@Override
  public KsMaterializedQueryResult<WindowedRow> get(
      final GenericKey key,
      final int partition,
      final Range<Instant> windowStartBounds,
      final Range<Instant> windowEndBounds,
      final Optional<Position> position
  ) {
    try {
      final ReadOnlyWindowStore<GenericKey, ValueAndTimestamp<GenericRow>> store = stateStore
          .store(QueryableStoreTypes.timestampedWindowStore(), partition);

      final Instant lower = calculateLowerBound(windowStartBounds, windowEndBounds);

      final Instant upper = calculateUpperBound(windowStartBounds, windowEndBounds);

      try (WindowStoreIterator<ValueAndTimestamp<GenericRow>> it
          = cacheBypassFetcher.fetch(store, key, lower, upper)) {

        final Builder<WindowedRow> builder = ImmutableList.builder();

        while (it.hasNext()) {
          final KeyValue<Long, ValueAndTimestamp<GenericRow>> next = it.next();

          final Instant windowStart = Instant.ofEpochMilli(next.key);
          if (!windowStartBounds.contains(windowStart)) {
            continue;
          }

          final Instant windowEnd = windowStart.plus(windowSize);
          if (!windowEndBounds.contains(windowEnd)) {
            continue;
          }

          final TimeWindow window =
              new TimeWindow(windowStart.toEpochMilli(), windowEnd.toEpochMilli());

          final WindowedRow row = WindowedRow.of(
              stateStore.schema(),
              new Windowed<>(key, window),
              next.value.value(),
              next.value.timestamp()
          );

          builder.add(row);
        }

        return KsMaterializedQueryResult.rowIterator(builder.build().iterator());
      }
    } catch (final Exception e) {
      throw new MaterializationException("Failed to get value from materialized table", e);
    }
  }
@Test
  public void shouldReturnValuesForClosedEndBounds() {
    // Given:
    final Range<Instant> end = Range.closed(
        NOW,
        NOW.plusSeconds(10)
    );

    final Range<Instant> startEqiv = Range.closed(
        end.lowerEndpoint().minus(WINDOW_SIZE),
        end.lowerEndpoint().minus(WINDOW_SIZE)
    );

    when(fetchIterator.hasNext())
        .thenReturn(true)
        .thenReturn(true)
        .thenReturn(false);

    when(fetchIterator.next())
        .thenReturn(new KeyValue<>(startEqiv.lowerEndpoint().toEpochMilli(), VALUE_1))
        .thenReturn(new KeyValue<>(startEqiv.upperEndpoint().toEpochMilli(), VALUE_2))
        .thenThrow(new AssertionError());

    when(cacheBypassFetcher.fetch(eq(tableStore), any(), any(), any())).thenReturn(fetchIterator);

    // When:
    final Iterator<WindowedRow> rowIterator =
        table.get(A_KEY, PARTITION, Range.all(), end).rowIterator;

    // Then:
    
    assertThat(rowIterator.hasNext(), is(true));
    final List<WindowedRow> resultList = Lists.newArrayList(rowIterator);
    assertThat(resultList, contains(
        WindowedRow.of(
            SCHEMA,
            windowedKey(startEqiv.lowerEndpoint()),
            VALUE_1.value(),
            VALUE_1.timestamp()
        ),
        WindowedRow.of(
            SCHEMA,
            windowedKey(startEqiv.upperEndpoint()),
            VALUE_2.value(),
            VALUE_2.timestamp()
        )
    ));
  }