Github user arina-ielchiieva commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1033#discussion_r150512516
  
    --- Diff: 
exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTAS.java ---
    @@ -313,6 +313,59 @@ public void createTableWithCustomUmask() throws 
Exception {
         }
       }
     
    +  @Test // DRILL-5951
    +  public void 
testCreateTableIfNotExistsWhenTableWithSameNameAlreadyExists() throws Exception{
    +    final String newTblName = 
"createTableIfNotExistsWhenATableWithSameNameAlreadyExists";
    +
    +    try {
    +      test(String.format("CREATE TABLE %s.%s AS SELECT * from 
cp.`region.json`", TEMP_SCHEMA, newTblName));
    +
    +      final String ctasQuery =
    +        String.format("CREATE TABLE IF NOT EXISTS %s.%s AS SELECT * FROM 
cp.`employee.json`", TEMP_SCHEMA, newTblName);
    +
    +      testBuilder()
    +        .sqlQuery(ctasQuery)
    +        .unOrdered()
    +        .baselineColumns("ok", "summary")
    +        .baselineValues(false, String.format("A table or view with given 
name [%s] already exists in schema [%s]", newTblName, TEMP_SCHEMA))
    +        .go();
    +    } finally {
    +      test(String.format("DROP TABLE %s.%s", TEMP_SCHEMA, newTblName));
    +    }
    +  }
    +
    +  @Test // DRILL-5951
    +  public void 
testCreateTableIfNotExistsWhenViewWithSameNameAlreadyExists() throws Exception{
    +    final String newTblName = 
"createTableIfNotExistsWhenAViewWithSameNameAlreadyExists";
    +
    +    try {
    +      test(String.format("CREATE VIEW %s.%s AS SELECT * from 
cp.`region.json`", TEMP_SCHEMA, newTblName));
    +
    +      final String ctasQuery =
    +        String.format("CREATE TABLE IF NOT EXISTS %s.%s AS SELECT * FROM 
cp.`employee.json`", TEMP_SCHEMA, newTblName);
    +
    +      testBuilder()
    +        .sqlQuery(ctasQuery)
    +        .unOrdered()
    +        .baselineColumns("ok", "summary")
    +        .baselineValues(false, String.format("A table or view with given 
name [%s] already exists in schema [%s]", newTblName, TEMP_SCHEMA))
    +        .go();
    +    } finally {
    +      test(String.format("DROP VIEW %s.%s", TEMP_SCHEMA, newTblName));
    +    }
    +  }
    +
    +  @Test // DRILL-5951
    +  public void 
testCreateTableIfNotExistsWhenTableWithSameNameDoesNotExist() throws Exception{
    +    final String newTblName = 
"createTableIfNotExistsWhenATableWithSameNameDoesNotExist";
    +
    +    try {
    +      test(String.format("CREATE TABLE IF NOT EXISTS %s.%s AS SELECT * 
FROM cp.`employee.json`", TEMP_SCHEMA, newTblName));
    --- End diff --
    
    You might want to check baseline here as well but only for `true` to 
confirm that table was actually created.


---

Reply via email to