drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jacq...@apache.org
Subject [14/17] git commit: DRILL-1145: Add testcase. Fix is in Optiq.
Date Mon, 21 Jul 2014 02:46:36 GMT
DRILL-1145: Add testcase. Fix is in Optiq.


Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/e5c2da0e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/e5c2da0e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/e5c2da0e

Branch: refs/heads/master
Commit: e5c2da0eb95df1a93d4ad909d5553757201dc903
Parents: fffd0d3
Author: vkorukanti <venki.korukanti@gmail.com>
Authored: Wed Jul 16 00:04:15 2014 -0700
Committer: Jacques Nadeau <jacques@apache.org>
Committed: Sun Jul 20 16:49:19 2014 -0700

----------------------------------------------------------------------
 .../org/apache/drill/jdbc/test/TestViews.java   | 58 ++++++++++++++++++++
 1 file changed, 58 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/e5c2da0e/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
----------------------------------------------------------------------
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 2cbba34..17772b6 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
@@ -510,4 +510,62 @@ public class TestViews extends JdbcTestQueryBase {
       }
     });
   }
+
+  private void createViewHelper(Statement statement, String schema, String viewName, String
query) throws Exception {
+    ResultSet resultSet =  statement.executeQuery(query);
+    String result = JdbcAssert.toString(resultSet).trim();
+    resultSet.close();
+    String expected = String.format("ok=true; summary=View '%s' created successfully in '%s'
schema", viewName, schema);
+    assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected),
expected.equals(result));
+  }
+
+  private void queryView(Statement statement, String query, String expectedResult) throws
Exception {
+    ResultSet resultSet = statement.executeQuery(query);
+    String actualResult = JdbcAssert.toString(resultSet).trim();
+    resultSet.close();
+    assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", actualResult,
expectedResult),
+        expectedResult.equals(actualResult));
+  }
+
+  private void dropView(Statement statement, String schema, String viewName) throws Exception
{
+    if (schema != null && !schema.isEmpty()) {
+      viewName = schema + "." + viewName;
+    }
+    statement.executeQuery("drop view innerView").close();
+  }
+
+  @Test
+  public void testViewCreatedFromView() throws Exception {
+    final String schema = "dfs_test.tmp";
+    JdbcAssert.withFull(schema).withConnection(new Function<Connection, Void>() {
+      public Void apply(Connection connection) {
+        try {
+          Statement statement = connection.createStatement();
+
+          // create a view
+          String createInnerView = "CREATE VIEW innerView AS SELECT region_id, sales_city
FROM cp.`region.json`";
+          String innerViewName = "innerView";
+          createViewHelper(statement, schema, "innerView", createInnerView);
+
+          // create another view from above created view
+          String createOuterView = "CREATE VIEW outerView AS SELECT region_id FROM innerView";
+          String outerViewName = "outerView";
+          createViewHelper(statement, schema, outerViewName, createOuterView);
+
+          // query on outer view
+          String queryView = "SELECT region_id FROM outerView LIMIT 1";
+          String expectedResult = "region_id=0";
+          queryView(statement, queryView, expectedResult);
+
+          dropView(statement, schema, outerViewName);
+          dropView(statement, schema, innerViewName);
+
+          statement.close();
+          return null;
+        } catch (Exception e) {
+          throw new RuntimeException(e);
+        }
+      }
+    });
+  }
 }


Mime
View raw message