aboutsummaryrefslogtreecommitdiff
path: root/exec/jdbc
diff options
context:
space:
mode:
authorvkorukanti <venki.korukanti@gmail.com>2014-07-15 09:02:46 -0700
committerJacques Nadeau <jacques@apache.org>2014-07-20 16:49:19 -0700
commitfffd0d38af93aee16e0103a3133306c0eb07092e (patch)
treef23dc4e48486bc447a196c2514b9e90b6d253730 /exec/jdbc
parent7e561def4bceca83a302d85154274eec199cdd9c (diff)
DRILL-1136: Check for existance of view before creating one when no OR REPLACE clause is provided
Diffstat (limited to 'exec/jdbc')
-rw-r--r--exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
index 89d9573b0..2cbba340f 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
@@ -463,4 +463,51 @@ public class TestViews extends JdbcTestQueryBase {
}
});
}
+
+ @Test
+ public void testCreateViewWhenViewAlreadyExists() throws Exception{
+ JdbcAssert.withFull("dfs_test.tmp").withConnection(new Function<Connection, Void>() {
+ public Void apply(Connection connection) {
+ try {
+ Statement statement = connection.createStatement();
+
+ // create a view
+ ResultSet resultSet = statement.executeQuery(
+ "CREATE VIEW testCreateViewWhenViewAlreadyExists AS SELECT region_id, sales_city FROM cp.`region.json`");
+ String result = JdbcAssert.toString(resultSet).trim();
+ resultSet.close();
+ String expected = "ok=true; summary=View 'testCreateViewWhenViewAlreadyExists' " +
+ "created successfully in 'dfs_test.tmp' schema";
+ assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected),
+ expected.equals(result));
+
+ // try to create the view with same name
+ resultSet = statement.executeQuery(
+ "CREATE VIEW testCreateViewWhenViewAlreadyExists AS SELECT region_id FROM cp.`region.json`");
+ result = JdbcAssert.toString(resultSet).trim();
+ resultSet.close();
+ expected = "ok=false; summary=View with given name already exists in current schema";
+ assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected),
+ expected.equals(result));
+
+ // try creating the view with same name but with a OR REPLACE clause
+ resultSet = statement.executeQuery(
+ "CREATE OR REPLACE VIEW testCreateViewWhenViewAlreadyExists AS SELECT region_id FROM cp.`region.json`");
+ result = JdbcAssert.toString(resultSet).trim();
+ resultSet.close();
+ expected = "ok=true; summary=View 'testCreateViewWhenViewAlreadyExists' " +
+ "replaced successfully in 'dfs_test.tmp' schema";
+ assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected),
+ expected.equals(result));
+
+ statement.executeQuery("drop view dfs_test.tmp.testCreateViewWhenViewAlreadyExists").close();
+
+ statement.close();
+ return null;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ }
}