Range query using TiKV database

169 Views Asked by At

How do you do range query with TiKV and java-client?

Suppose I have this model:

public class Hub implements Serializable {
    private String name;
    private List<Schedule> schedules;
}

and

import java.time.LocalTime;

public class Schedule implements Serializable {
    private String day;
    private LocalTime opens; 
    private LocalTime closes;
}

How can I do a query that will satisfy this:

new Schedule().builder()
    .day("Monday")
    .opens(LocalTime.parse("09:00")
    .close(LocalTime.parse("17:00").build();
  1. How do you store the Hub model into TiKV
  2. And, how can you do a range query to the schedules in this example?
1

There are 1 best solutions below

1
On

you can use client-java-client, see https://github.com/tikv/client-java

  1. How do you store the Hub model into TiKV

if you want to use TiKV directly without TiDB, you can encode Hub into a ByteString and store the ByteString into TiKV.

https://github.com/tikv/client-java/blob/v3.0.0/src/main/java/org/tikv/raw/RawKVClient.java#L82

  1. And, how can you do a range query to the schedules in this example?

you can use scan API to do a range query

https://github.com/tikv/client-java/blob/v3.0.0/src/main/java/org/tikv/raw/RawKVClient.java#L152

Please submit issues on https://github.com/tikv/client-java/issues if you have any questions or requests.

update at https://github.com/tikv/client-java/issues/105