All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.responsive.kafka.store.TTDWindowedSchema Maven / Gradle / Ivy

/*
 * Copyright 2023 Responsive Computing, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package dev.responsive.kafka.store;

import com.datastax.oss.driver.api.core.cql.BoundStatement;
import dev.responsive.db.RemoteWindowedSchema;
import dev.responsive.kafka.clients.TTDCassandraClient;
import dev.responsive.model.Stamped;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.apache.kafka.common.utils.Bytes;
import org.apache.kafka.streams.state.KeyValueIterator;

public class TTDWindowedSchema extends TTDSchema> implements RemoteWindowedSchema {

  private final Map tableNameToStore = new HashMap<>();

  public TTDWindowedSchema(final TTDCassandraClient client) {
    super(client);
  }

  @Override
  public void create(final String tableName, final Optional ttl) {
    tableNameToStore.put(tableName, new WindowStoreStub());
  }

  @Override
  public long count(final String tableName) {
    return tableNameToStore.containsKey(tableName) ? tableNameToStore.get(tableName).count() : 0L;
  }

  @Override
  public BoundStatement insert(
      final String tableName,
      final int partitionKey,
      final Stamped key,
      final byte[] value,
      final long epochMillis
  ) {
    tableNameToStore.get(tableName).put(key, value);
    return null;
  }

  @Override
  public BoundStatement delete(
      final String tableName,
      final int partitionKey,
      final Stamped key
  ) {
    tableNameToStore.get(tableName).delete(key);
    return null;
  }

  @Override
  public byte[] fetch(
      String tableName,
      int partition,
      Bytes key,
      long windowStart
  ) {
    return tableNameToStore.get(tableName).fetch(key, windowStart);
  }

  @Override
  public KeyValueIterator, byte[]> fetch(
      final String tableName,
      final int partition,
      final Bytes key,
      final long timeFrom,
      final long timeTo
  ) {
    return tableNameToStore.get(tableName).fetch(key, timeFrom, timeTo);
  }

  @Override
  public KeyValueIterator, byte[]> backFetch(
      final String tableName,
      final int partition,
      final Bytes key,
      final long timeFrom,
      final long timeTo
  ) {
    return tableNameToStore.get(tableName).backFetch(key, timeFrom, timeTo);
  }

  @Override
  public KeyValueIterator, byte[]> fetchRange(
      final String tableName,
      final int partition,
      final Bytes fromKey,
      final Bytes toKey,
      final long timeFrom,
      final long timeTo
  ) {
    return tableNameToStore.get(tableName).fetchRange(fromKey, toKey, timeFrom, timeTo);
  }

  @Override
  public KeyValueIterator, byte[]> backFetchRange(
      final String tableName,
      final int partition,
      final Bytes fromKey,
      final Bytes toKey,
      final long timeFrom,
      final long timeTo
  ) {
    return tableNameToStore.get(tableName).backFetchRange(fromKey, toKey, timeFrom, timeTo);
  }

  @Override
  public KeyValueIterator, byte[]> fetchAll(
      final String tableName,
      final int partition,
      final long timeFrom,
      final long timeTo
  ) {
    return tableNameToStore.get(tableName).fetchAll(timeFrom, timeTo);
  }

  @Override
  public KeyValueIterator, byte[]> backFetchAll(
      final String tableName,
      final int partition,
      final long timeFrom,
      final long timeTo
  ) {
    return tableNameToStore.get(tableName).backFetchAll(timeFrom, timeTo);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy