//snippet-sourcedescription:[CreateNamedQueryExample.java demonstrates how to create a named query]
//snippet-keyword:[Java]
//snippet-sourcesyntax:[java]
//snippet-keyword:[Code Sample]
//snippet-keyword:[Amazon Athena]
//snippet-service:[athena]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[2019-04-15]
//snippet-sourceauthor:[jschwarzwalder AWS]
/*
 * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */ 
//snippet-start:[athena.java2.CreateNamedQueryExample.complete]
//snippet-start:[athena.java.CreateNamedQueryExample.complete]
package aws.example.athena;

//snippet-start:[athena.java2.CreateNamedQueryExample.import]
import software.amazon.awssdk.services.athena.AthenaClient;
import software.amazon.awssdk.services.athena.model.CreateNamedQueryRequest;
import software.amazon.awssdk.services.athena.model.CreateNamedQueryResponse;
//snippet-end:[athena.java2.CreateNamedQueryExample.import]

/**
 * CreateNamedQueryExample
 * -------------------------------------
 * This code shows how to create a named query.
 */
public class CreateNamedQueryExample {
    public static void main(String[] args) throws Exception {
        //snippet-start:[athena.java2.CreateNamedQueryExample.main]
        // Build an Athena client
        AthenaClientFactory factory = new AthenaClientFactory();
        AthenaClient athenaClient = factory.createClient();

        // Create the named query request.
        CreateNamedQueryRequest createNamedQueryRequest = CreateNamedQueryRequest.builder()
                .database(ExampleConstants.ATHENA_DEFAULT_DATABASE)
                .queryString(ExampleConstants.ATHENA_SAMPLE_QUERY)
                .description("Sample Description")
                .name("SampleQuery2").build();

        // Call Athena to create the named query. If it fails, an exception is thrown.
        CreateNamedQueryResponse createNamedQueryResult = athenaClient.createNamedQuery(createNamedQueryRequest);
        //snippet-end:[athena.java2.CreateNamedQueryExample.main]
    }
}
//snippet-end:[athena.java.CreateNamedQueryExample.complete]
//snippet-end:[athena.java2.CreateNamedQueryExample.complete]


@@ -303,18 +303,17 @@
 te:%5B
-2019-04-15
+4/15/2020
 %5D%0A//
@@ -338,22 +338,16 @@
 or:%5B
-j
 sc
-hwarzwalder
+macdon
  AWS
@@ -368,18 +368,8 @@
 ght 
-2010-2019 
 Amaz
@@ -922,17 +922,17 @@
 nse.%0A */
- 
+%0A
 %0A//snipp
@@ -1142,16 +1142,62 @@
 import%5D%0A
+import software.amazon.awssdk.regions.Region;%0A
 import s
@@ -1248,16 +1248,85 @@
 Client;%0A
+import software.amazon.awssdk.services.athena.model.AthenaException;%0A
 import s
@@ -1758,24 +1758,25 @@
 ption %7B%0A
+%0A
         
 //snippe
@@ -1771,67 +1771,480 @@
     
-//snippet-start:%5Ba
+final String USAGE = %22%5Cn%22 +%0A                %22Usage:%5Cn%22 +%0A                %22    CreateNamedQueryExample %3Cname%3E%5Cn%5Cn%22 +%0A                %22Where:%5Cn%22 +%0A                %22    name - 
 the
+ 
 na
-.java2.CreateNamedQueryExample.main%5D
+me of the query %5Cn%5Cn%22 +%0A                %22Example:%5Cn%22 +%0A                %22    DescribeTable SampleQuery%5Cn%22;%0A%0A        if (args.length %3C 1) %7B%0A            System.out.println(USAGE);%0A            System.exit(1);%0A        %7D%0A%0A        /* Read the name from command args */%0A        String name = args%5B0%5D;%0A
 %0A   
@@ -2273,33 +2273,32 @@
 a client%0A       
- 
 AthenaClientFact
@@ -2297,61 +2297,124 @@
 ient
-Factory factory = new AthenaClientFactory
+ athenaClient = AthenaClient.builder()%0A                .region(Region.US_WEST_2)%0A                .build
 ();%0A
+%0A
         
 Athe
@@ -2413,61 +2413,218 @@
     
-AthenaClient athenaClient = factory.createClient();%0A%0A
+createNamedQuery(athenaClient, name);%0A    %7D%0A%0A    //snippet-start:%5Bathena.java2.CreateNamedQueryExample.main%5D%0A    public static void createNamedQuery(AthenaClient athenaClient, String name) %7B%0A%0A        try %7B%0A    
     
@@ -2662,32 +2662,36 @@
 equest.%0A        
+  
+  
 CreateNamedQuery
@@ -2774,16 +2774,20 @@
         
+    
 .databas
@@ -2846,16 +2846,20 @@
         
+  
+  
 .querySt
@@ -2917,16 +2917,20 @@
         
+    
 .descrip
@@ -2976,29 +2976,44 @@
     
+ 
+   
 .name(
-%22SampleQuery2%22)
+name)%0A                    
 .bui
@@ -3011,32 +3011,36 @@
      .build();%0A%0A
+    
         // Call 
@@ -3110,16 +3110,20 @@
 thrown.%0A
+    
         
@@ -3228,16 +3228,165 @@
 quest);%0A
+            System.out.println(%22Done%22);%0A        %7D catch (AthenaException e) %7B%0A            e.printStackTrace();%0A            System.exit(1);%0A        %7D%0A
         
@@ -3574,9 +3574,8 @@
 mplete%5D%0A
-%0A

Update CreateNamedQueryExample.java