mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(athena): real SQL execution via floci-duck DuckDB sidecar (#584)
* feat(athena): real SQL execution via floci-duck DuckDB sidecar
- Lazy-start floci/floci-duck:latest on first StartQueryExecution call;
reuse the running container for all subsequent queries
- Inject Glue tables as CREATE OR REPLACE VIEW statements via setup_sql
before the user SQL so DDL runs outside the COPY(...) wrapper
- SerDe-aware format inference: inferReadFunction now checks
SerdeInfo.SerializationLibrary in addition to InputFormat, so standard
AWS JSON tables (TextInputFormat + JsonSerDe) map to read_json_auto
- ImageCacheService: skip Docker Hub pull when image is already present
locally, preventing local builds from being overwritten
- Add AthenaIntegrationTest (5 unit integration tests)
- Add AthenaTest and DataLakeTest SDK compatibility tests
- Update docs: athena.md (full rewrite), glue.md, README, CHANGELOG
* fix: docker image check fix
This commit is contained in:
1 parent
5ad4c06d74
commit
1ddbec0efb
22 files changed
+1231
-81
No files matched your search
@@ -0,0 +1,109 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.services.athena.AthenaClient;
|
||||
import software.amazon.awssdk.services.athena.model.*;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@DisplayName("Athena Query Execution")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class AthenaTest {
|
||||
|
||||
private static AthenaClient athena;
|
||||
private static String queryExecutionId;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
athena = TestFixtures.athenaClient();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (athena != null) {
|
||||
athena.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@DisplayName("Start query execution returns an execution ID")
|
||||
void startQueryExecution() {
|
||||
StartQueryExecutionResponse response = athena.startQueryExecution(
|
||||
StartQueryExecutionRequest.builder()
|
||||
.queryString("SELECT 1 AS value")
|
||||
.workGroup("primary")
|
||||
.resultConfiguration(ResultConfiguration.builder()
|
||||
.outputLocation("s3://floci-athena-results/sdk-tests/")
|
||||
.build())
|
||||
.build());
|
||||
|
||||
assertThat(response.queryExecutionId()).isNotBlank();
|
||||
queryExecutionId = response.queryExecutionId();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
@DisplayName("Get query execution returns execution details")
|
||||
void getQueryExecution() {
|
||||
GetQueryExecutionResponse response = athena.getQueryExecution(
|
||||
GetQueryExecutionRequest.builder()
|
||||
.queryExecutionId(queryExecutionId)
|
||||
.build());
|
||||
|
||||
QueryExecution execution = response.queryExecution();
|
||||
assertThat(execution.queryExecutionId()).isEqualTo(queryExecutionId);
|
||||
assertThat(execution.query()).isEqualTo("SELECT 1 AS value");
|
||||
assertThat(execution.status().state()).isIn(
|
||||
QueryExecutionState.RUNNING, QueryExecutionState.SUCCEEDED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
@DisplayName("Get query results returns result set")
|
||||
void getQueryResults() {
|
||||
// Poll until succeeded (mock mode completes immediately, real duck may take a moment)
|
||||
QueryExecutionState state = QueryExecutionState.RUNNING;
|
||||
int attempts = 0;
|
||||
while (state == QueryExecutionState.RUNNING && attempts++ < 20) {
|
||||
GetQueryExecutionResponse exec = athena.getQueryExecution(
|
||||
GetQueryExecutionRequest.builder().queryExecutionId(queryExecutionId).build());
|
||||
state = exec.queryExecution().status().state();
|
||||
if (state == QueryExecutionState.RUNNING) {
|
||||
try { Thread.sleep(500); } catch (InterruptedException ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
assertThat(state).isEqualTo(QueryExecutionState.SUCCEEDED);
|
||||
|
||||
GetQueryResultsResponse results = athena.getQueryResults(
|
||||
GetQueryResultsRequest.builder()
|
||||
.queryExecutionId(queryExecutionId)
|
||||
.build());
|
||||
|
||||
assertThat(results.resultSet()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
@DisplayName("List query executions includes started execution")
|
||||
void listQueryExecutions() {
|
||||
ListQueryExecutionsResponse response = athena.listQueryExecutions(
|
||||
ListQueryExecutionsRequest.builder().build());
|
||||
|
||||
assertThat(response.queryExecutionIds()).contains(queryExecutionId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
@DisplayName("Get non-existent query execution throws InvalidRequestException")
|
||||
void getQueryExecutionNotFound() {
|
||||
assertThatThrownBy(() -> athena.getQueryExecution(
|
||||
GetQueryExecutionRequest.builder()
|
||||
.queryExecutionId("00000000-0000-0000-0000-000000000000")
|
||||
.build()))
|
||||
.isInstanceOf(InvalidRequestException.class);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ import software.amazon.awssdk.services.glue.model.*;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -42,14 +44,19 @@ class DataLakeTest {
|
||||
.databaseInput(DatabaseInput.builder().name(DB_NAME).build())
|
||||
.build());
|
||||
|
||||
// 2. Glue Table
|
||||
// 2. Glue Table — standard AWS JSON table config: TextInputFormat + JsonSerDe
|
||||
glue.createTable(CreateTableRequest.builder()
|
||||
.databaseName(DB_NAME)
|
||||
.tableInput(TableInput.builder()
|
||||
.name(TABLE_NAME)
|
||||
.storageDescriptor(StorageDescriptor.builder()
|
||||
.location("s3://floci-firehose-results/" + STREAM_NAME + "/")
|
||||
.inputFormat("Parquet")
|
||||
.inputFormat("org.apache.hadoop.mapred.TextInputFormat")
|
||||
.outputFormat("org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat")
|
||||
.serdeInfo(SerDeInfo.builder()
|
||||
.serializationLibrary("org.openx.data.jsonserde.JsonSerDe")
|
||||
.parameters(Map.of("serialization.format", "1"))
|
||||
.build())
|
||||
.columns(
|
||||
software.amazon.awssdk.services.glue.model.Column.builder().name("id").type("int").build(),
|
||||
software.amazon.awssdk.services.glue.model.Column.builder().name("amount").type("double").build()
|
||||
@@ -102,13 +109,22 @@ class DataLakeTest {
|
||||
|
||||
assertThat(status.state()).isEqualTo(QueryExecutionState.SUCCEEDED);
|
||||
|
||||
// Get Results — Athena is in mock mode; query execution is accepted and the state
|
||||
// machine runs correctly, but results are empty until the DuckDB sidecar is integrated.
|
||||
GetQueryResultsResponse results = athena.getQueryResults(GetQueryResultsRequest.builder()
|
||||
.queryExecutionId(queryId)
|
||||
.build());
|
||||
|
||||
assertThat(results.resultSet()).isNotNull();
|
||||
assertThat(results.resultSet().rows()).isEmpty();
|
||||
// Athena GetQueryResults includes a header row + data rows
|
||||
assertThat(results.resultSet().rows()).hasSizeGreaterThanOrEqualTo(2);
|
||||
|
||||
// Header row must contain the column name
|
||||
List<String> header = results.resultSet().rows().get(0).data().stream()
|
||||
.map(d -> d.varCharValue())
|
||||
.collect(Collectors.toList());
|
||||
assertThat(header).containsExactly("total");
|
||||
|
||||
// Data row: sum(amount) = 10+20+30+40+50 = 150
|
||||
String total = results.resultSet().rows().get(1).data().get(0).varCharValue();
|
||||
assertThat(Double.parseDouble(total)).isEqualTo(150.0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.core.SdkBytes;
|
||||
import software.amazon.awssdk.services.firehose.FirehoseClient;
|
||||
import software.amazon.awssdk.services.firehose.model.*;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@DisplayName("Firehose Delivery Streams")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class FirehoseTest {
|
||||
|
||||
private static FirehoseClient firehose;
|
||||
private static final String STREAM_NAME = "sdk-test-stream-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
firehose = TestFixtures.firehoseClient();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (firehose != null) {
|
||||
try {
|
||||
firehose.deleteDeliveryStream(DeleteDeliveryStreamRequest.builder()
|
||||
.deliveryStreamName(STREAM_NAME).build());
|
||||
} catch (Exception ignored) {}
|
||||
firehose.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@DisplayName("Create delivery stream")
|
||||
void createDeliveryStream() {
|
||||
CreateDeliveryStreamResponse response = firehose.createDeliveryStream(
|
||||
CreateDeliveryStreamRequest.builder()
|
||||
.deliveryStreamName(STREAM_NAME)
|
||||
.deliveryStreamType(DeliveryStreamType.DIRECT_PUT)
|
||||
.s3DestinationConfiguration(S3DestinationConfiguration.builder()
|
||||
.bucketARN("arn:aws:s3:::floci-firehose-sdk-test")
|
||||
.roleARN("arn:aws:iam::000000000000:role/firehose-role")
|
||||
.bufferingHints(BufferingHints.builder()
|
||||
.intervalInSeconds(60)
|
||||
.sizeInMBs(1)
|
||||
.build())
|
||||
.build())
|
||||
.build());
|
||||
|
||||
assertThat(response.deliveryStreamARN()).contains(STREAM_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
@DisplayName("Describe delivery stream")
|
||||
void describeDeliveryStream() {
|
||||
DescribeDeliveryStreamResponse response = firehose.describeDeliveryStream(
|
||||
DescribeDeliveryStreamRequest.builder()
|
||||
.deliveryStreamName(STREAM_NAME)
|
||||
.build());
|
||||
|
||||
DeliveryStreamDescription desc = response.deliveryStreamDescription();
|
||||
assertThat(desc.deliveryStreamName()).isEqualTo(STREAM_NAME);
|
||||
assertThat(desc.deliveryStreamStatus()).isEqualTo(DeliveryStreamStatus.ACTIVE);
|
||||
assertThat(desc.deliveryStreamARN()).contains(STREAM_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
@DisplayName("List delivery streams includes created stream")
|
||||
void listDeliveryStreams() {
|
||||
ListDeliveryStreamsResponse response = firehose.listDeliveryStreams(
|
||||
ListDeliveryStreamsRequest.builder().build());
|
||||
|
||||
assertThat(response.deliveryStreamNames()).contains(STREAM_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
@DisplayName("Put single record")
|
||||
void putRecord() {
|
||||
PutRecordResponse response = firehose.putRecord(PutRecordRequest.builder()
|
||||
.deliveryStreamName(STREAM_NAME)
|
||||
.record(software.amazon.awssdk.services.firehose.model.Record.builder()
|
||||
.data(SdkBytes.fromString("{\"event\":\"test\"}", StandardCharsets.UTF_8))
|
||||
.build())
|
||||
.build());
|
||||
|
||||
assertThat(response.recordId()).isNotBlank();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
@DisplayName("Put record batch")
|
||||
void putRecordBatch() {
|
||||
List<software.amazon.awssdk.services.firehose.model.Record> records = List.of(
|
||||
software.amazon.awssdk.services.firehose.model.Record.builder().data(SdkBytes.fromString("{\"i\":1}", StandardCharsets.UTF_8)).build(),
|
||||
software.amazon.awssdk.services.firehose.model.Record.builder().data(SdkBytes.fromString("{\"i\":2}", StandardCharsets.UTF_8)).build(),
|
||||
software.amazon.awssdk.services.firehose.model.Record.builder().data(SdkBytes.fromString("{\"i\":3}", StandardCharsets.UTF_8)).build()
|
||||
);
|
||||
|
||||
PutRecordBatchResponse response = firehose.putRecordBatch(PutRecordBatchRequest.builder()
|
||||
.deliveryStreamName(STREAM_NAME)
|
||||
.records(records)
|
||||
.build());
|
||||
|
||||
assertThat(response.failedPutCount()).isEqualTo(0);
|
||||
assertThat(response.requestResponses()).hasSize(3);
|
||||
response.requestResponses().forEach(r -> assertThat(r.recordId()).isNotBlank());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@DisplayName("Describe non-existent stream throws ResourceNotFoundException")
|
||||
void describeNonExistentStream() {
|
||||
assertThatThrownBy(() -> firehose.describeDeliveryStream(
|
||||
DescribeDeliveryStreamRequest.builder()
|
||||
.deliveryStreamName("nonexistent-stream-xyz")
|
||||
.build()))
|
||||
.isInstanceOf(ResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
@DisplayName("Delete delivery stream")
|
||||
void deleteDeliveryStream() {
|
||||
firehose.deleteDeliveryStream(DeleteDeliveryStreamRequest.builder()
|
||||
.deliveryStreamName(STREAM_NAME)
|
||||
.build());
|
||||
|
||||
assertThatThrownBy(() -> firehose.describeDeliveryStream(
|
||||
DescribeDeliveryStreamRequest.builder()
|
||||
.deliveryStreamName(STREAM_NAME)
|
||||
.build()))
|
||||
.isInstanceOf(ResourceNotFoundException.class);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user