|
30 | 30 | import com.amazonaws.athena.connector.lambda.domain.predicate.ConstraintEvaluator; |
31 | 31 | import com.amazonaws.athena.connector.lambda.domain.predicate.Constraints; |
32 | 32 | import com.amazonaws.athena.connector.lambda.domain.spill.S3SpillLocation; |
| 33 | +import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException; |
33 | 34 | import com.amazonaws.athena.connector.lambda.records.ReadRecordsRequest; |
34 | 35 | import com.amazonaws.athena.connector.lambda.security.EncryptionKey; |
35 | 36 | import com.amazonaws.athena.connector.lambda.security.EncryptionKeyFactory; |
|
70 | 71 | import org.mockito.junit.MockitoJUnitRunner; |
71 | 72 | import software.amazon.awssdk.services.athena.AthenaClient; |
72 | 73 | import software.amazon.awssdk.services.glue.GlueClient; |
| 74 | +import software.amazon.awssdk.services.glue.model.ErrorDetails; |
| 75 | +import software.amazon.awssdk.services.glue.model.FederationSourceErrorCode; |
73 | 76 | import software.amazon.awssdk.services.glue.model.GetSchemaRequest; |
74 | 77 | import software.amazon.awssdk.services.glue.model.GetSchemaResponse; |
75 | 78 | import software.amazon.awssdk.services.glue.model.GetSchemaVersionRequest; |
|
78 | 81 | import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient; |
79 | 82 |
|
80 | 83 | import java.io.FileInputStream; |
| 84 | +import java.io.IOException; |
81 | 85 | import java.nio.file.Files; |
82 | 86 | import java.nio.file.Path; |
83 | 87 | import java.nio.file.Paths; |
@@ -515,9 +519,9 @@ private Schema createAvroSchema(AvroTopicSchema avroTopicSchema) throws Exceptio |
515 | 519 | private Schema createProtobufSchema(String protobufSchema) throws Exception |
516 | 520 | { |
517 | 521 | SchemaBuilder schemaBuilder = SchemaBuilder.newBuilder(); |
518 | | - |
519 | | - // Create a temporary directory and files |
520 | | - Path protoDir = Paths.get("src/test/resources/proto"); |
| 522 | + |
| 523 | + // Use a unique temporary directory under /tmp |
| 524 | + Path protoDir = Paths.get("/tmp", "proto_" + UUID.randomUUID()); |
521 | 525 | Files.createDirectories(protoDir); |
522 | 526 | Path protoFile = protoDir.resolve("test.proto"); |
523 | 527 | Path descFile = protoDir.resolve("test.desc"); |
@@ -557,15 +561,26 @@ private Schema createProtobufSchema(String protobufSchema) throws Exception |
557 | 561 | Field arrowField = new Field(field.getName(), arrowFieldType, null); |
558 | 562 | schemaBuilder.addField(arrowField); |
559 | 563 | } |
560 | | - } else { |
| 564 | + } |
| 565 | + else { |
561 | 566 | throw new RuntimeException("No message types found in compiled schema"); |
562 | 567 | } |
563 | 568 | } |
564 | | - } finally { |
565 | | - // Clean up |
566 | | - Files.deleteIfExists(protoFile); |
567 | | - Files.deleteIfExists(descFile); |
568 | | - Files.deleteIfExists(protoDir); |
| 569 | + } |
| 570 | + finally { |
| 571 | + try { |
| 572 | + Files.deleteIfExists(protoFile); |
| 573 | + Files.deleteIfExists(descFile); |
| 574 | + Files.deleteIfExists(protoDir); |
| 575 | + } |
| 576 | + catch (IOException e) { |
| 577 | + throw new AthenaConnectorException( |
| 578 | + "Failed to clean up temporary proto directory: " + protoDir.toAbsolutePath(), |
| 579 | + ErrorDetails.builder() |
| 580 | + .errorCode(FederationSourceErrorCode.INTERNAL_SERVICE_EXCEPTION.toString()) |
| 581 | + .build() |
| 582 | + ); |
| 583 | + } |
569 | 584 | } |
570 | 585 |
|
571 | 586 | schemaBuilder.addMetadata("dataFormat", PROTOBUF_DATA_FORMAT); |
|
0 commit comments