com.amazonaws.services.s3.model.SelectObjectContentEventVisitor Java Examples
The following examples show how to use
com.amazonaws.services.s3.model.SelectObjectContentEventVisitor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrestoS3SelectClient.java From presto with Apache License 2.0 | 5 votes |
public InputStream getRecordsContent(SelectObjectContentRequest selectObjectRequest) { this.selectObjectRequest = requireNonNull(selectObjectRequest, "selectObjectRequest is null"); this.selectObjectContentResult = s3Client.selectObjectContent(selectObjectRequest); return selectObjectContentResult.getPayload() .getRecordsInputStream( new SelectObjectContentEventVisitor() { @Override public void visit(EndEvent endEvent) { requestComplete = true; } }); }
Example #2
Source File: S3QueryUtil.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** Run SQL query over non-compressed CSV file saved in s3 object. */ static String queryFile( AmazonS3 s3client, String bucket, String s3file, @SuppressWarnings("SameParameterValue") String query) { SelectObjectContentRequest request = generateBaseCSVRequest(bucket, s3file, query); final AtomicBoolean isResultComplete = new AtomicBoolean(false); String res; try (SelectObjectContentResult result = s3client.selectObjectContent(request); SelectObjectContentEventStream payload = result.getPayload(); ByteArrayOutputStream out = new ByteArrayOutputStream()) { InputStream resultInputStream = payload.getRecordsInputStream( new SelectObjectContentEventVisitor() { @Override public void visit(SelectObjectContentEvent.EndEvent event) { isResultComplete.set(true); } } ); copy(resultInputStream, out); res = out.toString().trim(); } catch (Throwable e) { System.out.println("SQL query failure"); throw new RuntimeException("SQL query failure", e); } /* * The End Event indicates all matching records have been transmitted. * If the End Event is not received, the results may be incomplete. */ if (!isResultComplete.get()) { throw new RuntimeException("S3 Select request was incomplete as End Event was not received."); } return res; }
Example #3
Source File: S3QueryUtil.java From flink with Apache License 2.0 | 5 votes |
/** Run SQL query over non-compressed CSV file saved in s3 object. */ static String queryFile( AmazonS3 s3client, String bucket, String s3file, @SuppressWarnings("SameParameterValue") String query) { SelectObjectContentRequest request = generateBaseCSVRequest(bucket, s3file, query); final AtomicBoolean isResultComplete = new AtomicBoolean(false); String res; try (SelectObjectContentResult result = s3client.selectObjectContent(request); SelectObjectContentEventStream payload = result.getPayload(); ByteArrayOutputStream out = new ByteArrayOutputStream()) { InputStream resultInputStream = payload.getRecordsInputStream( new SelectObjectContentEventVisitor() { @Override public void visit(SelectObjectContentEvent.EndEvent event) { isResultComplete.set(true); } } ); copy(resultInputStream, out); res = out.toString().trim(); } catch (Throwable e) { System.out.println("SQL query failure"); throw new RuntimeException("SQL query failure", e); } /* * The End Event indicates all matching records have been transmitted. * If the End Event is not received, the results may be incomplete. */ if (!isResultComplete.get()) { throw new RuntimeException("S3 Select request was incomplete as End Event was not received."); } return res; }