diff --git a/ql/src/test/org/apache/hadoop/hive/ql/plan/TestViewEntity.java b/ql/src/test/org/apache/hadoop/hive/ql/plan/TestViewEntity.java index e24208e..4f78ad4 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/plan/TestViewEntity.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/plan/TestViewEntity.java @@ -137,5 +137,46 @@ public void testViewInSubQuery() throws Exception { assertFalse("Table is not direct input", CheckInputReadEntity.readEntities[1].isDirect()); } + + @Test + public void testSparkEngine() throws Exception { + + String prefix = "tsparkview" + NAME_PREFIX; + final String tab1 = prefix + "t"; + final String view1 = prefix + "v"; + + // init spark driver + HiveConf conf = new HiveConf(Driver.class); + conf.setVar(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK, CheckInputReadEntity.class.getName()); + HiveConf.setBoolVar(conf, HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, false); + HiveConf.setVar(conf, HiveConf.ConfVars.HIVE_EXECUTION_ENGINE, "spark"); + SessionState.start(conf); + Driver sparkDriver = new Driver(conf); + sparkDriver.init(); + + int ret = sparkDriver.run("create table " + tab1 + "(id int) partitioned by (dt string)").getResponseCode(); + assertEquals("Checking command success", 0, ret); + ret = sparkDriver.run("create view " + view1 + " as select * from " + tab1 + " where id < 10").getResponseCode(); + assertEquals("Checking command success", 0, ret); + + ret = sparkDriver.run("alter table " + tab1 + " add partition(dt='1')").getResponseCode(); + assertEquals("Checking command success", 0, ret); + + sparkDriver.compile("select * from " + view1); + + // view entity + assertEquals("default@" + view1, CheckInputReadEntity.readEntities[0].getName()); + + // table as second read entity + assertEquals("default@" + tab1, CheckInputReadEntity.readEntities[1].getName()); + assertFalse("Table is not direct input", CheckInputReadEntity.readEntities[1].isDirect()); + + // table partition as third read entity + assertEquals("default@" + tab1 + "@dt=1", CheckInputReadEntity.readEntities[2].getName()); + // !!!! this will fail + assertFalse("Table partition is not direct input", CheckInputReadEntity.readEntities[2].isDirect()); + + System.out.println(CheckInputReadEntity.readEntities); + } }