Skip to content

Commit 448f4ff

Browse files
authored
Merge pull request #1 from beckandros/master
Athena edits
2 parents eede20e + 5d2aa94 commit 448f4ff

File tree

8 files changed

+50
-50
lines changed

8 files changed

+50
-50
lines changed

java/example_code/athena/src/main/java/aws/example/athena/AthenaClientFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//snippet-sourcedescription:[AthenaClientFactory.java demonstrates how to create and configure an Amazon Athena client]
1+
//snippet-sourcedescription:[AthenaClientFactory.java demonstrates how to create and configure an Amazon Athena client.]
22
//snippet-keyword:[Java]
33
//snippet-sourcesyntax:[java]
44
//snippet-keyword:[Code Sample]
@@ -23,9 +23,9 @@
2323
public class AthenaClientFactory
2424
{
2525
/**
26-
* AmazonAthenaClientBuilder to build Athena with the following properties:
27-
* - Set the region of the client
28-
* - Use the instance profile from the EC2 instance as the credentials provider
26+
* Use AmazonAthenaClientBuilder to build Athena with the following properties:
27+
* - Set the AWS Region of the client.
28+
* - Use the instance profile from the Amazon EC2 instance as the credentials provider.
2929
* - Configure the client to increase the execution timeout.
3030
*/
3131
private final AmazonAthenaClientBuilder builder = AmazonAthenaClientBuilder.standard()

java/example_code/athena/src/main/java/aws/example/athena/CreateNamedQueryExample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//snippet-sourcedescription:[CreateNamedQueryExample.java demonstrates how to create a named query]
1+
//snippet-sourcedescription:[CreateNamedQueryExample.java demonstrates how to create a named query.]
22
//snippet-keyword:[Java]
33
//snippet-sourcesyntax:[java]
44
//snippet-keyword:[Code Sample]
@@ -22,7 +22,7 @@ public class CreateNamedQueryExample
2222
{
2323
public static void main(String[] args) throws Exception
2424
{
25-
// Build an Athena client
25+
// Build an Athena client.
2626
AthenaClientFactory factory = new AthenaClientFactory();
2727
AmazonAthena athenaClient = factory.createClient();
2828

@@ -33,7 +33,7 @@ public static void main(String[] args) throws Exception
3333
.withDescription("Sample Description")
3434
.withName("SampleQuery2");
3535

36-
// Call Athena to create the named query. If it fails, an exception is thrown.
36+
// Call Athena to create the named query. If it fails, throw an exception.
3737
CreateNamedQueryResult createNamedQueryResult = athenaClient.createNamedQuery(createNamedQueryRequest);
3838
}
3939
}

java/example_code/athena/src/main/java/aws/example/athena/DeleteNamedQueryExample.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@ public class DeleteNamedQueryExample
2424
{
2525
private static String getNamedQueryId(AmazonAthena athenaClient)
2626
{
27-
// Create the NameQuery Request.
27+
// Create the named query request.
2828
CreateNamedQueryRequest createNamedQueryRequest = new CreateNamedQueryRequest()
2929
.withDatabase(ExampleConstants.ATHENA_DEFAULT_DATABASE)
3030
.withQueryString(ExampleConstants.ATHENA_SAMPLE_QUERY)
3131
.withName("SampleQueryName")
3232
.withDescription("Sample Description");
3333

34-
// Create the named query. If it fails, an exception is thrown.
34+
// Create the named query. If it fails, throw an exception.
3535
CreateNamedQueryResult createNamedQueryResult = athenaClient.createNamedQuery(createNamedQueryRequest);
3636
return createNamedQueryResult.getNamedQueryId();
3737
}
3838

3939
public static void main(String[] args) throws Exception
4040
{
41-
// Build an Athena client
41+
// Build an Athena client.
4242
AthenaClientFactory factory = new AthenaClientFactory();
4343
AmazonAthena athenaClient = factory.createClient();
4444

4545
String sampleNamedQueryId = getNamedQueryId(athenaClient);
4646

47-
// Create the delete named query request
47+
// Create the delete named query request.
4848
DeleteNamedQueryRequest deleteNamedQueryRequest = new DeleteNamedQueryRequest()
4949
.withNamedQueryId(sampleNamedQueryId);
5050

51-
// Delete the named query
51+
// Delete the named query.
5252
DeleteNamedQueryResult deleteNamedQueryResult = athenaClient.deleteNamedQuery(deleteNamedQueryRequest);
5353
}
5454
}

java/example_code/athena/src/main/java/aws/example/athena/ExampleConstants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//snippet-sourcedescription:[ExampleConstants.java demonstrates how to query a table created by the getting started tutorial in Athena]
1+
//snippet-sourcedescription:[ExampleConstants.java demonstrates how to query a table created using the getting started tutorial in Amazon Athena.]
22
//snippet-keyword:[Java]
33
//snippet-sourcesyntax:[java]
44
//snippet-keyword:[Code Sample]
@@ -13,7 +13,7 @@ public class ExampleConstants {
1313

1414
public static final int CLIENT_EXECUTION_TIMEOUT = 100000;
1515
public static final String ATHENA_OUTPUT_BUCKET = "s3://my-athena-bucket";
16-
// This is querying a table created by the getting started tutorial in Athena
16+
// This is querying a table created using the getting started tutorial in Amazon Athena.
1717
public static final String ATHENA_SAMPLE_QUERY = "SELECT elb_name, "
1818
+ " count(1)"
1919
+ " FROM elb_logs"

java/example_code/athena/src/main/java/aws/example/athena/ListNamedQueryExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void main(String[] args) throws Exception
2828
AthenaClientFactory factory = new AthenaClientFactory();
2929
AmazonAthena athenaClient = factory.createClient();
3030

31-
// Build the request
31+
// Build the request.
3232
ListNamedQueriesRequest listNamedQueriesRequest = new ListNamedQueriesRequest();
3333

3434
// Get the list results.
@@ -39,7 +39,7 @@ public static void main(String[] args) throws Exception
3939

4040
while (hasMoreResults) {
4141
List<String> namedQueryIds = listNamedQueriesResult.getNamedQueryIds();
42-
// process named query IDs
42+
// Process the named query IDs.
4343

4444
// If nextToken is not null, there are more results. Get the next page of results.
4545
if (listNamedQueriesResult.getNextToken() != null) {

java/example_code/athena/src/main/java/aws/example/athena/ListQueryExecutionsExample.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public class ListQueryExecutionsExample
2424
{
2525
public static void main(String[] args) throws Exception
2626
{
27-
// Build an Athena client
27+
// Build an Athena client.
2828
AthenaClientFactory factory = new AthenaClientFactory();
2929
AmazonAthena athenaClient = factory.createClient();
3030

31-
// Build the request
31+
// Build the request.
3232
ListQueryExecutionsRequest listQueryExecutionsRequest = new ListQueryExecutionsRequest();
3333

3434
// Get the list results.
@@ -38,11 +38,11 @@ public static void main(String[] args) throws Exception
3838
boolean hasMoreResults = true;
3939
while (hasMoreResults) {
4040
List<String> queryExecutionIds = listQueryExecutionsResult.getQueryExecutionIds();
41-
// process queryExecutionIds.
41+
// Process the query execution IDs.
4242

4343
System.out.println(queryExecutionIds);
4444

45-
//If nextToken is not null, then there are more results. Get the next page of results.
45+
// If nextToken is not null, there are more results. Get the next page of results.
4646
if (listQueryExecutionsResult.getNextToken() != null) {
4747
listQueryExecutionsResult = athenaClient.listQueryExecutions(
4848
listQueryExecutionsRequest.withNextToken(listQueryExecutionsResult.getNextToken()));

java/example_code/athena/src/main/java/aws/example/athena/StartQueryExample.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//snippet-sourcedescription:[StartQueryExample.java demonstrates how to submit a query to Athena for execution, wait till results are available, and then process the results.]
1+
//snippet-sourcedescription:[StartQueryExample.java demonstrates how to submit a query to Amazon Athena for execution, wait until results are available, and then process the results.]
22
//snippet-keyword:[Java]
33
//snippet-sourcesyntax:[java]
44
//snippet-keyword:[Code Sample]
@@ -27,14 +27,14 @@
2727
/**
2828
* StartQueryExample
2929
* -------------------------------------
30-
* This code shows how to submit a query to Athena for execution, wait till results
30+
* This code shows how to submit a query to Amazon Athena for execution, wait until results
3131
* are available, and then process the results.
3232
*/
3333
public class StartQueryExample
3434
{
3535
public static void main(String[] args) throws InterruptedException
3636
{
37-
// Build an AmazonAthena client
37+
// Build an Athena client.
3838
AthenaClientFactory factory = new AthenaClientFactory();
3939
AmazonAthena athenaClient = factory.createClient();
4040

@@ -50,16 +50,16 @@ public static void main(String[] args) throws InterruptedException
5050
*/
5151
private static String submitAthenaQuery(AmazonAthena athenaClient)
5252
{
53-
// The QueryExecutionContext allows us to set the Database.
53+
// The QueryExecutionContext allows us to set the database.
5454
QueryExecutionContext queryExecutionContext = new QueryExecutionContext().withDatabase(ExampleConstants.ATHENA_DEFAULT_DATABASE);
5555

56-
// The result configuration specifies where the results of the query should go in S3 and encryption options
56+
// The result configuration specifies where the results of the query should go in Amazon S3 and encryption options.
5757
ResultConfiguration resultConfiguration = new ResultConfiguration()
5858
// You can provide encryption options for the output that is written.
5959
// .withEncryptionConfiguration(encryptionConfiguration)
6060
.withOutputLocation(ExampleConstants.ATHENA_OUTPUT_BUCKET);
6161

62-
// Create the StartQueryExecutionRequest to send to Athena which will start the query.
62+
// Create the StartQueryExecutionRequest to send to Athena, which will start the query.
6363
StartQueryExecutionRequest startQueryExecutionRequest = new StartQueryExecutionRequest()
6464
.withQueryString(ExampleConstants.ATHENA_SAMPLE_QUERY)
6565
.withQueryExecutionContext(queryExecutionContext)
@@ -70,8 +70,8 @@ private static String submitAthenaQuery(AmazonAthena athenaClient)
7070
}
7171

7272
/**
73-
* Wait for an Athena query to complete, fail or to be cancelled. This is done by polling Athena over an
74-
* interval of time. If a query fails or is cancelled, then it will throw an exception.
73+
* Wait for an Athena query to complete or fail, or to be canceled. This is done by polling Athena over an
74+
* interval of time. If a query fails or is canceled, it will throw an exception.
7575
*/
7676

7777
private static void waitForQueryToComplete(AmazonAthena athenaClient, String queryExecutionId) throws InterruptedException
@@ -85,19 +85,19 @@ private static void waitForQueryToComplete(AmazonAthena athenaClient, String que
8585
getQueryExecutionResult = athenaClient.getQueryExecution(getQueryExecutionRequest);
8686
String queryState = getQueryExecutionResult.getQueryExecution().getStatus().getState();
8787
if (queryState.equals(QueryExecutionState.FAILED.toString())) {
88-
throw new RuntimeException("Query Failed to run with Error Message: " + getQueryExecutionResult.getQueryExecution().getStatus().getStateChangeReason());
88+
throw new RuntimeException("Query failed to run with error message: " + getQueryExecutionResult.getQueryExecution().getStatus().getStateChangeReason());
8989
}
9090
else if (queryState.equals(QueryExecutionState.CANCELLED.toString())) {
91-
throw new RuntimeException("Query was cancelled.");
91+
throw new RuntimeException("Query was canceled.");
9292
}
9393
else if (queryState.equals(QueryExecutionState.SUCCEEDED.toString())) {
9494
isQueryStillRunning = false;
9595
}
9696
else {
97-
// Sleep an amount of time before retrying again.
97+
// Sleep an amount of time before retrying.
9898
Thread.sleep(ExampleConstants.SLEEP_AMOUNT_IN_MS);
9999
}
100-
System.out.println("Current Status is: " + queryState);
100+
System.out.println("Current state is: " + queryState);
101101
}
102102
}
103103

@@ -109,8 +109,8 @@ else if (queryState.equals(QueryExecutionState.SUCCEEDED.toString())) {
109109
private static void processResultRows(AmazonAthena athenaClient, String queryExecutionId)
110110
{
111111
GetQueryResultsRequest getQueryResultsRequest = new GetQueryResultsRequest()
112-
// Max Results can be set but if its not set,
113-
// it will choose the maximum page size
112+
// MaxResults can be set, but if it is not set,
113+
// it will choose the maximum page size.
114114
// As of the writing of this code, the maximum value is 1000
115115
// .withMaxResults(1000)
116116
.withQueryExecutionId(queryExecutionId);
@@ -138,34 +138,34 @@ private static void processRow(Row row, List<ColumnInfo> columnInfoList)
138138
for (int i = 0; i < columnInfoList.size(); ++i) {
139139
switch (columnInfoList.get(i).getType()) {
140140
case "varchar":
141-
// Convert and Process as String
141+
// Convert and process as String.
142142
break;
143143
case "tinyint":
144-
// Convert and Process as tinyint
144+
// Convert and process as tinyint.
145145
break;
146146
case "smallint":
147-
// Convert and Process as smallint
147+
// Convert and process as smallint.
148148
break;
149149
case "integer":
150-
// Convert and Process as integer
150+
// Convert and process as integer.
151151
break;
152152
case "bigint":
153-
// Convert and Process as bigint
153+
// Convert and process as bigint.
154154
break;
155155
case "double":
156-
// Convert and Process as double
156+
// Convert and process as double.
157157
break;
158158
case "boolean":
159-
// Convert and Process as boolean
159+
// Convert and process as boolean.
160160
break;
161161
case "date":
162-
// Convert and Process as date
162+
// Convert and process as date.
163163
break;
164164
case "timestamp":
165-
// Convert and Process as timestamp
165+
// Convert and process as timestamp.
166166
break;
167167
default:
168-
throw new RuntimeException("Unexpected Type is not expected" + columnInfoList.get(i).getType());
168+
throw new RuntimeException("Unexpected type is not expected" + columnInfoList.get(i).getType());
169169
}
170170
}
171171
}

java/example_code/athena/src/main/java/aws/example/athena/StopQueryExecutionExample.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,32 @@
2424
* StopQueryExecutionExample
2525
* -------------------------------------
2626
* This code runs an example query, immediately stops the query, and checks the status of the query to
27-
* ensure that it was cancelled.
27+
* ensure that it was canceled.
2828
*/
2929
public class StopQueryExecutionExample
3030
{
3131
public static void main(String[] args) throws Exception
3232
{
33-
// Build an Athena client
33+
// Build an Athena client.
3434
AthenaClientFactory factory = new AthenaClientFactory();
3535
AmazonAthena athenaClient = factory.createClient();
3636

3737
String sampleQueryExecutionId = submitAthenaQuery(athenaClient);
3838

39-
// Submit the stop query Request
39+
// Submit the stop query request.
4040
StopQueryExecutionRequest stopQueryExecutionRequest = new StopQueryExecutionRequest()
4141
.withQueryExecutionId(sampleQueryExecutionId);
4242

4343
StopQueryExecutionResult stopQueryExecutionResult = athenaClient.stopQueryExecution(stopQueryExecutionRequest);
4444

45-
// Ensure that the query was stopped
45+
// Ensure that the query was stopped.
4646
GetQueryExecutionRequest getQueryExecutionRequest = new GetQueryExecutionRequest()
4747
.withQueryExecutionId(sampleQueryExecutionId);
4848

4949
GetQueryExecutionResult getQueryExecutionResult = athenaClient.getQueryExecution(getQueryExecutionRequest);
5050
if (getQueryExecutionResult.getQueryExecution().getStatus().getState().equals(QueryExecutionState.CANCELLED)) {
51-
// Query was cancelled.
52-
System.out.println("Query has been cancelled");
51+
// Query was canceled.
52+
System.out.println("Query has been canceled");
5353
}
5454
}
5555

0 commit comments

Comments
 (0)