|
16 | 16 | import jakarta.annotation.PostConstruct; |
17 | 17 | import jakarta.servlet.http.HttpServletResponse; |
18 | 18 | import lombok.extern.java.Log; |
19 | | -import org.springframework.web.bind.annotation.GetMapping; |
20 | | -import org.springframework.web.bind.annotation.RequestMapping; |
21 | | -import org.springframework.web.bind.annotation.RequestParam; |
22 | | -import org.springframework.web.bind.annotation.ResponseBody; |
23 | | -import org.springframework.web.bind.annotation.RestController; |
| 19 | +import org.springframework.web.bind.annotation.*; |
24 | 20 |
|
25 | 21 | import java.util.ArrayList; |
26 | 22 | import java.util.LinkedList; |
|
31 | 27 | import java.util.stream.Collectors; |
32 | 28 |
|
33 | 29 | /** |
34 | | - * Dataset API: |
35 | | - * - /direct/dataset/0/?limit=N - uses client v2 directly to fetch N rows from a virtual dataset. |
36 | | - * |
37 | | - * <p>Example: {@code curl -v http://localhost:8080/direct/dataset/0?limit=10}</p> |
| 30 | + * Class demonstrates using ClickHouse client directly from a service. |
| 31 | + * It avoids JDBC overhead and much easier to use. |
| 32 | + * Data may be streamed from database directly to the service response. |
38 | 33 | */ |
39 | 34 | @RestController |
40 | | -@RequestMapping("/") |
| 35 | +@RequestMapping("/dataset") |
41 | 36 | @Log |
42 | | -public class DatasetController { |
| 37 | +public class QueryController { |
43 | 38 |
|
44 | 39 | private final Client chDirectClient; |
45 | 40 |
|
46 | 41 | private static final int MAX_LIMIT = 100_000; |
47 | 42 |
|
48 | 43 | private BasicObjectsPool<ObjectsPreparedCollection<VirtualDatasetRecord>> pool; |
49 | 44 |
|
50 | | - public DatasetController(Client chDirectClient) { |
| 45 | + public QueryController(Client chDirectClient) { |
51 | 46 | this.chDirectClient = chDirectClient; |
52 | 47 | } |
53 | 48 |
|
@@ -95,7 +90,7 @@ VirtualDatasetRecord create() { |
95 | 90 | * @param limit |
96 | 91 | * @return |
97 | 92 | */ |
98 | | - @GetMapping("/dataset/reader") |
| 93 | + @GetMapping("/reader") |
99 | 94 | public List<VirtualDatasetRecord> directDatasetFetch(@RequestParam(name = "limit", required = false) Integer limit) { |
100 | 95 | limit = limit == null ? 100 : limit; |
101 | 96 |
|
@@ -140,7 +135,7 @@ public List<VirtualDatasetRecord> directDatasetFetch(@RequestParam(name = "limit |
140 | 135 | * @param httpResp |
141 | 136 | * @param limit |
142 | 137 | */ |
143 | | - @GetMapping("/dataset/json_each_row_in_and_out") |
| 138 | + @GetMapping("/json_each_row_in_and_out") |
144 | 139 | @ResponseBody |
145 | 140 | public void directDataFetchJSONEachRow(HttpServletResponse httpResp, @RequestParam(name = "limit", required = false) Integer limit) { |
146 | 141 | limit = limit == null ? 100 : limit; |
@@ -184,7 +179,7 @@ public void directDataFetchJSONEachRow(HttpServletResponse httpResp, @RequestPar |
184 | 179 | * @param limit |
185 | 180 | * @return |
186 | 181 | */ |
187 | | - @GetMapping("/dataset/read_to_pojo") |
| 182 | + @GetMapping("/read_to_pojo") |
188 | 183 | public CalculationResult directDatasetReadToPojo(@RequestParam(name = "limit", required = false) Integer limit, |
189 | 184 | @RequestParam(name = "cache", required = false) Boolean cache) { |
190 | 185 | limit = limit == null ? 100 : limit; |
|
0 commit comments