Skip to content

Commit

Permalink
Merge pull request #31 from Anant/fix/threads
Browse files Browse the repository at this point in the history
Fix/threads
  • Loading branch information
anomnaco authored Sep 9, 2024
2 parents 92a36ae + 16744ee commit 2578681
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 171 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/datastax/oss/cass_stac/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ CREATE CUSTOM INDEX IF NOT EXISTS item_centroid_ann_idx ON item (centroid) USING

CqlSession cqlSession = cqlSessionBuilder.build();

// Execute for Table
try {
cqlSession.execute(item_create_table_statement);
// Execute for Table
cqlSession.execute(item_create_table_statement);
log.info("Verification of Item table is successful");
cqlSession.execute(itemids_create_table_statement);
log.info("Verification of Item_ids table is successful");
Expand Down
58 changes: 0 additions & 58 deletions src/main/java/com/datastax/oss/cass_stac/OffsetDateTimeCodec.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
package com.datastax.oss.cass_stac.controller;

import com.datastax.oss.cass_stac.model.ImageResponse;
import com.datastax.oss.cass_stac.model.ItemModelRequest;
import com.datastax.oss.cass_stac.model.ItemModelResponse;
import com.datastax.oss.cass_stac.service.ItemService;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

Expand All @@ -32,17 +27,15 @@
@Schema(hidden = true)
public class ParallelItemController {

private static final Logger logger = LoggerFactory.getLogger(ItemController.class);
private final ItemService itemService;
private final ObjectMapper objectMapper = new ObjectMapper();

@Operation(description = "Get method to fetch Item data in parallel based on a list of item IDs")
@GetMapping
public ResponseEntity<?> getItemsParallel(@RequestParam final List<String> ids) {
try {
final List<ItemModelResponse> itemModels = ids.stream()
.map(itemService::getItemsByIdParallel)
.collect(Collectors.toList()).stream().map(CompletableFuture::join).collect(Collectors.toList());
.toList().stream().map(CompletableFuture::join).collect(Collectors.toList());
return new ResponseEntity<>(itemModels, HttpStatus.OK);
} catch (Exception ex) {
final Map<String, String> message = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.cassandra.core.query.CassandraPageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.ErrorResponse;
Expand All @@ -26,6 +24,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -96,7 +95,7 @@ The bounding box is provided as four or six numbers, depending on whether the co
""", description = "Search items that intersect this polygon, coordinates should be of length 4")}) @RequestParam(required = false) String intersects,
@Parameter(description = "Either a date-time or an interval, open or closed. Date and time expressions adhere to RFC 3339. Open intervals are expressed using double-dots.",
examples = {
@ExampleObject(name = "A closed interval", value = "2023-01-30T00:00:00Z/2018-03-18T12:31:12Z"),
@ExampleObject(name = "A closed interval", value = "2018-03-18T12:31:12Z/2023-01-30T00:00:00Z"),
@ExampleObject(name = "Open intervals", value = """
"2023-01-30T00:00:00Z/.." or "../2023-01-30T12:31:12Z
"""),
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/com/datastax/oss/cass_stac/dao/GeoTimePartition.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@


import org.jetbrains.annotations.NotNull;
import org.locationtech.jts.geom.*;
import java.time.*;
import java.time.temporal.IsoFields;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Polygon;

import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.time.temporal.IsoFields;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class GeoTimePartition extends GeoPartition {

public enum TimeResolution {
DAY, WEEK, FORTNIGHT, MONTH, QUARTER, YEAR
}
Expand Down Expand Up @@ -43,6 +47,18 @@ public String getGeoTimePartitionForPoint(@NotNull Point point, @NotNull OffsetD
return spatialIndex + "-" + temporalIndex;
}

public List<String> getGeoTimePartitionsForPoint(@NotNull Point point, @NotNull OffsetDateTime minDateTime, @NotNull OffsetDateTime maxDateTime) {
String spatialIndex = getGeoPartitionForPoint(point);
List<String> timePartitions = getDateRange(minDateTime, maxDateTime)
.map(this::getTimePartition)
.distinct()
.toList();

return timePartitions.stream()
.map(timePartition -> spatialIndex + "-" + timePartition)
.collect(Collectors.toList());
}

public Stream<String> streamGeoTimePartitions(@NotNull Polygon polygon, @NotNull OffsetDateTime minDateTime, @NotNull OffsetDateTime maxDateTime) {
Stream<String> spatialIndexes = streamGeoPartitions(polygon);
List<String> timePartitions = getDateRange(minDateTime, maxDateTime)
Expand Down
Loading

0 comments on commit 2578681

Please sign in to comment.